Check SVD with orientations

Created by Mauro Alberti

Last run: 2019-06-16


In [1]:
import numpy as np

import sys

sys.path.append(r"C:\Users\mauro\Documents\projects\gsf")

from pygsf.orientations.orientations import Plane, Axis, Direct
from pygsf.mathematics.arrays import svd

In [2]:
plane1 = Plane(90, 0)
plane2 = Plane(90, 5)

# plane to xyz

n_axis_1 = plane1.normAxis()
n_axis_2 = plane2.normAxis()

normal_1 = n_axis_1.toXYZ()
normal_2 = n_axis_2.toXYZ()

print(normal_1)
print(normal_2)

xyzes = (normal_1, normal_2)

# pack tuples into array

a = np.stack(xyzes)
print(type(a))
print(a.shape)

# svd

res = svd(a)

"""
print(type(res))
for res_el in res:
    print(res_el)
"""

u = res[0]
s = res[1]
vh = res[2]

#print(vh)

print("mean", vh[0,:]) # mean value
print("girdle normal", vh[2, :]) # normal to girdle


(-6.123233995736766e-17, -1.1248198369963932e-32, -1.0)
(-0.08715574274765814, -1.6010250207484453e-17, -0.9961946980917455)
<class 'numpy.ndarray'>
(2, 3)
mean [4.36193874e-02 9.68544963e-18 9.99048222e-01]
girdle normal [-2.22044605e-16  1.00000000e+00  0.00000000e+00]

In [3]:
# axes to xyz

axis_1 = Axis.fromAzPl(270, 80)
axis_2 = Axis.fromAzPl(270, 90)
axis_3 = Axis.fromAzPl(90, 80)

print(axis_1)
print(axis_2)
print(axis_3)

xyz_1 = axis_1.toXYZ()
xyz_2 = axis_2.toXYZ()
xyz_3 = axis_3.toXYZ()

print(xyz_1)
print(xyz_2)
print(xyz_3)

xyzes = (xyz_1, xyz_2, xyz_3)

# pack tuples into array

a = np.stack(xyzes)
print(type(a))
print(a.shape)

# svd

res = svd(a)

u = res[0]
s = res[1]
vh = res[2]

print("\nu")
print(u)
print("\ns")
print(s)
print("\nvh")
print(vh)

print("\nmean", vh[0,:]) # mean value
print("\ngirdle normal", vh[2, :]) # normal to girdle


Axis(az: 270.00°, pl: 80.00°)
Axis(az: 270.00°, pl: 90.00°)
Axis(az: 90.00°, pl: 80.00°)
(-0.17364817766693041, -3.1898652743636585e-17, -0.984807753012208)
(-6.123233995736766e-17, -1.1248198369963932e-32, -1.0)
(0.17364817766693041, 1.0632884247878861e-17, -0.984807753012208)
<class 'numpy.ndarray'>
(3, 3)

u
[[-5.74381572e-01 -7.07106781e-01  4.12414609e-01]
 [-5.83242334e-01 -2.49342109e-16 -8.12298209e-01]
 [-5.74381572e-01  7.07106781e-01  4.12414609e-01]]

s
[1.71455318e+00 2.45575608e-01 8.29293425e-17]

vh
[[-0.00000000e+00  2.22044605e-16  1.00000000e+00]
 [ 1.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00 -1.00000000e+00  0.00000000e+00]]

mean [-0.00000000e+00  2.22044605e-16  1.00000000e+00]

girdle normal [ 0. -1.  0.]

In [4]:
# axes to xyz

axis_1 = Axis.fromAzPl(270, 10)
axis_2 = Axis.fromAzPl(270, 0)
axis_3 = Axis.fromAzPl(90, 5)
axis_4 = Axis.fromAzPl(270, 3)

print(axis_1)
print(axis_2)
print(axis_3)
print(axis_4)

xyz_1 = axis_1.toXYZ()
xyz_2 = axis_2.toXYZ()
xyz_3 = axis_3.toXYZ()
xyz_4 = axis_4.toXYZ()

print(xyz_1)
print(xyz_2)
print(xyz_3)
print(xyz_4)


xyzes = (xyz_1, xyz_2, xyz_3, xyz_4)

# pack tuples into array

a = np.stack(xyzes)
print(type(a))
print(a.shape)

# svd

res = svd(a)

u = res[0]
s = res[1]
vh = res[2]

print("\nu")
print(u)
print("\ns")
print(s)
print("\nvh")
print(vh)

print("\nmean", vh[0,:]) # mean value
print("\ngirdle normal", vh[2, :]) # normal to girdle


Axis(az: 270.00°, pl: 10.00°)
Axis(az: 270.00°, pl: 0.00°)
Axis(az: 90.00°, pl: 5.00°)
Axis(az: 270.00°, pl: 3.00°)
(-0.984807753012208, -1.8090624937528466e-16, -0.17364817766693033)
(-1.0, -1.8369701987210297e-16, -0.0)
(0.9961946980917455, 6.099933241728101e-17, -0.08715574274765817)
(-0.9986295347545738, -1.8344526949067989e-16, -0.052335956242943835)
<class 'numpy.ndarray'>
(4, 3)

u
[[-0.49735106  0.73689204  0.40015519 -0.22250366]
 [-0.50194565 -0.18382661 -0.61037976 -0.58454674]
 [ 0.49851427  0.64384321 -0.57993576 -0.02497924]
 [-0.5021713   0.09307971 -0.36192111  0.77985465]]

s
[1.99104401e+00 1.89060221e-01 6.84798416e-17]

vh
[[ 9.99395887e-01  1.52655666e-16  3.47542987e-02]
 [ 3.47542987e-02 -4.44089210e-15 -9.99395887e-01]
 [-0.00000000e+00  1.00000000e+00 -4.44089210e-15]]

mean [9.99395887e-01 1.52655666e-16 3.47542987e-02]

girdle normal [-0.0000000e+00  1.0000000e+00 -4.4408921e-15]

In [5]:
# directions to xyz

d_1 = Direct.fromAzPl(270, 10)
d_2 = Direct.fromAzPl(270, 5)
d_3 = Direct.fromAzPl(270, -5)
d_4 = Direct.fromAzPl(270, -10)

print(d_1)
print(d_2)
print(d_3)
print(d_4)

xyz_1 = d_1.toXYZ()
xyz_2 = d_2.toXYZ()
xyz_3 = d_3.toXYZ()
xyz_4 = d_4.toXYZ()

print(xyz_1)
print(xyz_2)
print(xyz_3)
print(xyz_4)


xyzes = (xyz_1, xyz_2, xyz_3, xyz_4)

# pack tuples into array

a = np.stack(xyzes)
print(type(a))
print(a.shape)

# svd

res = svd(a)

u = res[0]
s = res[1]
vh = res[2]

print("\nu")
print(u)
print("\ns")
print(s)
print("\nvh")
print(vh)

print("\nmean", vh[0,:]) # mean value
print("\ngirdle normal", vh[2, :]) # normal to girdle


Direct(az: 270.00°, pl: 10.00°)
Direct(az: 270.00°, pl: 5.00°)
Direct(az: 270.00°, pl: -5.00°)
Direct(az: 270.00°, pl: -10.00°)
(-0.984807753012208, -1.8090624937528466e-16, -0.17364817766693033)
(-0.9961946980917455, -1.82997997251843e-16, -0.08715574274765817)
(-0.9961946980917455, -1.82997997251843e-16, 0.08715574274765817)
(-0.984807753012208, -1.8090624937528466e-16, 0.17364817766693033)
<class 'numpy.ndarray'>
(4, 3)

u
[[-0.49711775  0.63197199 -0.59453833  0.00308586]
 [-0.50286573  0.31719301  0.75900821  0.26536992]
 [-0.50286573 -0.31719301  0.07914917 -0.80015627]
 [-0.49711775 -0.63197199 -0.25331034  0.53788402]]

s
[1.98103518e+00 2.74771953e-01 2.91302040e-32]

vh
[[ 1.00000000e+00  0.00000000e+00  0.00000000e+00]
 [-0.00000000e+00  1.13615189e-31 -1.00000000e+00]
 [-0.00000000e+00 -1.00000000e+00 -1.13615189e-31]]

mean [1. 0. 0.]

girdle normal [-0.00000000e+00 -1.00000000e+00 -1.13615189e-31]

In [6]:
# directions to xyz

d_1 = Direct.fromAzPl(90, 10)
d_2 = Direct.fromAzPl(90, 5)
d_3 = Direct.fromAzPl(90, -5)
d_4 = Direct.fromAzPl(90, -10)

print(d_1)
print(d_2)
print(d_3)
print(d_4)

xyz_1 = d_1.toXYZ()
xyz_2 = d_2.toXYZ()
xyz_3 = d_3.toXYZ()
xyz_4 = d_4.toXYZ()

print(xyz_1)
print(xyz_2)
print(xyz_3)
print(xyz_4)


xyzes = (xyz_1, xyz_2, xyz_3, xyz_4)

# pack tuples into array

a = np.stack(xyzes)
print(type(a))
print(a.shape)

# svd

res = svd(a)

u = res[0]
s = res[1]
vh = res[2]

print("\nu")
print(u)
print("\ns")
print(s)
print("\nvh")
print(vh)

print("\nmean", vh[0,:]) # mean value
print("\ngirdle normal", vh[2, :]) # normal to girdle


Direct(az: 90.00°, pl: 10.00°)
Direct(az: 90.00°, pl: 5.00°)
Direct(az: 90.00°, pl: -5.00°)
Direct(az: 90.00°, pl: -10.00°)
(0.984807753012208, 6.030208312509488e-17, -0.17364817766693033)
(0.9961946980917455, 6.099933241728101e-17, -0.08715574274765817)
(0.9961946980917455, 6.099933241728101e-17, 0.08715574274765817)
(0.984807753012208, 6.030208312509488e-17, 0.17364817766693033)
<class 'numpy.ndarray'>
(4, 3)

u
[[-0.49711775  0.63197199 -0.54665591 -0.23377908]
 [-0.50286573  0.31719301  0.59070205  0.5455142 ]
 [-0.50286573 -0.31719301  0.3910516  -0.70256195]
 [-0.49711775 -0.63197199 -0.44644937  0.39264272]]

s
[1.98103518e+00 2.74771953e-01 1.66275278e-32]

vh
[[-1.00000000e+00 -0.00000000e+00 -0.00000000e+00]
 [-0.00000000e+00 -1.90446047e-32 -1.00000000e+00]
 [-0.00000000e+00  1.00000000e+00 -1.90446047e-32]]

mean [-1. -0. -0.]

girdle normal [-0.00000000e+00  1.00000000e+00 -1.90446047e-32]

In [7]:
## directions to xyz

d_1 = Direct.fromAzPl(90, 85)
d_2 = Direct.fromAzPl(90, 88)
d_3 = Direct.fromAzPl(270, 88)
d_4 = Direct.fromAzPl(270, 85)

print(d_1)
print(d_2)
print(d_3)
print(d_4)

xyz_1 = d_1.toXYZ()
xyz_2 = d_2.toXYZ()
xyz_3 = d_3.toXYZ()
xyz_4 = d_4.toXYZ()

print(xyz_1)
print(xyz_2)
print(xyz_3)
print(xyz_4)


xyzes = (xyz_1, xyz_2, xyz_3, xyz_4)

# pack tuples into array

a = np.stack(xyzes)
print(type(a))
print(a.shape)

# svd

res = svd(a)

u = res[0]
s = res[1]
vh = res[2]

print("\nu")
print(u)
print("\ns")
print(s)
print("\nvh")
print(vh)

print("\nmean", vh[0,:]) # mean value
print("\ngirdle normal", vh[2, :]) # normal to girdle


Direct(az: 90.00°, pl: 85.00°)
Direct(az: 90.00°, pl: 88.00°)
Direct(az: 270.00°, pl: 88.00°)
Direct(az: 270.00°, pl: 85.00°)
(0.08715574274765814, 5.336750069161484e-18, -0.9961946980917455)
(0.03489949670250108, 2.136977846428578e-18, -0.9993908270190958)
(-0.03489949670250108, -6.410933539285733e-18, -0.9993908270190958)
(-0.08715574274765814, -1.6010250207484453e-17, -0.9961946980917455)
<class 'numpy.ndarray'>
(4, 3)

u
[[-0.49919856 -0.65643551  0.54055174  0.16642428]
 [-0.50080016 -0.26285438 -0.61124957 -0.55360703]
 [-0.50080016  0.26285438 -0.37017077  0.73693987]
 [-0.49919856  0.65643551  0.44401732 -0.35034531]]

s
[1.99558808e+00 1.32771220e-01 8.23878420e-17]

vh
[[-0.00000000e+00  0.00000000e+00  1.00000000e+00]
 [-1.00000000e+00 -0.00000000e+00 -0.00000000e+00]
 [-0.00000000e+00  1.00000000e+00  1.11022302e-16]]

mean [-0.  0.  1.]

girdle normal [-0.00000000e+00  1.00000000e+00  1.11022302e-16]

In [8]:
# directions to xyz

d_1 = Direct.fromAzPl(90, -85)
d_2 = Direct.fromAzPl(90, -88)
d_3 = Direct.fromAzPl(270, -88)
d_4 = Direct.fromAzPl(270, -85)

print(d_1)
print(d_2)
print(d_3)
print(d_4)

xyz_1 = d_1.toXYZ()
xyz_2 = d_2.toXYZ()
xyz_3 = d_3.toXYZ()
xyz_4 = d_4.toXYZ()

print(xyz_1)
print(xyz_2)
print(xyz_3)
print(xyz_4)


xyzes = (xyz_1, xyz_2, xyz_3, xyz_4)

# pack tuples into array

a = np.stack(xyzes)
print(type(a))
print(a.shape)

# svd

res = svd(a)

u = res[0]
s = res[1]
vh = res[2]

print("\nu")
print(u)
print("\ns")
print(s)
print("\nvh")
print(vh)

print("\nmean", vh[0,:]) # mean value
print("\ngirdle normal", vh[2, :]) # normal to girdle


Direct(az: 90.00°, pl: -85.00°)
Direct(az: 90.00°, pl: -88.00°)
Direct(az: 270.00°, pl: -88.00°)
Direct(az: 270.00°, pl: -85.00°)
(0.08715574274765814, 5.336750069161484e-18, 0.9961946980917455)
(0.03489949670250108, 2.136977846428578e-18, 0.9993908270190958)
(-0.03489949670250108, -6.410933539285733e-18, 0.9993908270190958)
(-0.08715574274765814, -1.6010250207484453e-17, 0.9961946980917455)
<class 'numpy.ndarray'>
(4, 3)

u
[[-0.49919856 -0.65643551 -0.54055174 -0.16642428]
 [-0.50080016 -0.26285438  0.61124957  0.55360703]
 [-0.50080016  0.26285438  0.37017077 -0.73693987]
 [-0.49919856  0.65643551 -0.44401732  0.35034531]]

s
[1.99558808e+00 1.32771220e-01 8.23878420e-17]

vh
[[-0.00000000e+00  0.00000000e+00 -1.00000000e+00]
 [-1.00000000e+00 -0.00000000e+00  0.00000000e+00]
 [-0.00000000e+00 -1.00000000e+00  1.11022302e-16]]

mean [-0.  0. -1.]

girdle normal [-0.00000000e+00 -1.00000000e+00  1.11022302e-16]

In [9]:
# directions to xyz

d_1 = Direct.fromAzPl(88, 0)
d_2 = Direct.fromAzPl(89, 0)
d_3 = Direct.fromAzPl(91, 0)
d_4 = Direct.fromAzPl(92, 0)

print(d_1)
print(d_2)
print(d_3)
print(d_4)

xyz_1 = d_1.toXYZ()
xyz_2 = d_2.toXYZ()
xyz_3 = d_3.toXYZ()
xyz_4 = d_4.toXYZ()

print(xyz_1)
print(xyz_2)
print(xyz_3)
print(xyz_4)


xyzes = (xyz_1, xyz_2, xyz_3, xyz_4)

# pack tuples into array

a = np.stack(xyzes)
print(type(a))
print(a.shape)

# svd

res = svd(a)

u = res[0]
s = res[1]
vh = res[2]

print("\nu")
print(u)
print("\ns")
print(s)
print("\nvh")
print(vh)

print("\nmean", vh[0,:]) # mean value
print("\ngirdle normal", vh[2, :]) # normal to girdle


Direct(az: 88.00°, pl: 0.00°)
Direct(az: 89.00°, pl: 0.00°)
Direct(az: 91.00°, pl: 0.00°)
Direct(az: 92.00°, pl: 0.00°)
(0.9993908270190958, 0.03489949670250108, -0.0)
(0.9998476951563913, 0.0174524064372836, -0.0)
(0.9998476951563913, -0.017452406437283477, -0.0)
(0.9993908270190958, -0.034899496702500955, -0.0)
<class 'numpy.ndarray'>
(4, 3)

u
[[-0.49988573 -0.63243626 -0.43701202 -0.39894753]
 [-0.50011425 -0.3162663   0.38142756  0.7101932 ]
 [-0.50011425  0.3162663   0.60289914 -0.53513923]
 [-0.49988573  0.63243626 -0.54776467  0.22381353]]

s
[ 1.99923857  0.05518263 -0.        ]

vh
[[-1.00000000e+00 -5.90480478e-17 -0.00000000e+00]
 [ 5.90480478e-17 -1.00000000e+00 -0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  1.00000000e+00]]

mean [-1.00000000e+00 -5.90480478e-17 -0.00000000e+00]

girdle normal [0. 0. 1.]