homochoric representation vectorized
This commit is contained in:
parent
99655c9f61
commit
cb9daccdd7
|
@ -968,19 +968,31 @@ class Rotation:
|
||||||
+0.0001703481934140054, -0.00012062065004116828,
|
+0.0001703481934140054, -0.00012062065004116828,
|
||||||
+0.000059719705868660826, -0.00001980756723965647,
|
+0.000059719705868660826, -0.00001980756723965647,
|
||||||
+0.000003953714684212874, -0.00000036555001439719544])
|
+0.000003953714684212874, -0.00000036555001439719544])
|
||||||
# normalize h and store the magnitude
|
if len(ho.shape) == 1:
|
||||||
hmag_squared = np.sum(ho**2.)
|
# normalize h and store the magnitude
|
||||||
if iszero(hmag_squared):
|
hmag_squared = np.sum(ho**2.)
|
||||||
ax = np.array([ 0.0, 0.0, 1.0, 0.0 ])
|
if iszero(hmag_squared):
|
||||||
else:
|
ax = np.array([ 0.0, 0.0, 1.0, 0.0 ])
|
||||||
hm = hmag_squared
|
else:
|
||||||
|
hm = hmag_squared
|
||||||
|
|
||||||
# convert the magnitude to the rotation angle
|
# convert the magnitude to the rotation angle
|
||||||
|
s = tfit[0] + tfit[1] * hmag_squared
|
||||||
|
for i in range(2,16):
|
||||||
|
hm *= hmag_squared
|
||||||
|
s += tfit[i] * hm
|
||||||
|
ax = np.append(ho/np.sqrt(hmag_squared),2.0*np.arccos(np.clip(s,-1.0,1.0)))
|
||||||
|
else:
|
||||||
|
hmag_squared = np.sum(ho**2.,axis=-1,keepdims=True)
|
||||||
|
hm = hmag_squared.copy()
|
||||||
s = tfit[0] + tfit[1] * hmag_squared
|
s = tfit[0] + tfit[1] * hmag_squared
|
||||||
for i in range(2,16):
|
for i in range(2,16):
|
||||||
hm *= hmag_squared
|
hm *= hmag_squared
|
||||||
s += tfit[i] * hm
|
s += tfit[i] * hm
|
||||||
ax = np.append(ho/np.sqrt(hmag_squared),2.0*np.arccos(np.clip(s,-1.0,1.0)))
|
with np.errstate(invalid='ignore',divide='ignore'):
|
||||||
|
ax = np.where(np.broadcast_to(np.abs(hmag_squared)<1.e-6,ho.shape[:-1]+(4,)),
|
||||||
|
np.array([ 0.0, 0.0, 1.0, 0.0 ]),
|
||||||
|
np.block([ho/np.sqrt(hmag_squared),2.0*np.arccos(np.clip(s,-1.0,1.0))]))
|
||||||
return ax
|
return ax
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -226,3 +226,17 @@ class TestRotation:
|
||||||
for r,c in zip(ro,co):
|
for r,c in zip(ro,co):
|
||||||
print(r,c)
|
print(r,c)
|
||||||
assert np.allclose(conversion(r),c)
|
assert np.allclose(conversion(r),c)
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('conversion',[Rotation.ho2qu,
|
||||||
|
Rotation.ho2om,
|
||||||
|
Rotation.ho2eu,
|
||||||
|
Rotation.ho2ax,
|
||||||
|
Rotation.ho2ro,
|
||||||
|
])
|
||||||
|
def test_homochoric_vectorization(self,default,conversion):
|
||||||
|
ho = np.array([rot.asHomochoric() for rot in default])
|
||||||
|
conversion(ho.reshape(ho.shape[0]//2,-1,3))
|
||||||
|
co = conversion(ho)
|
||||||
|
for h,c in zip(ho,co):
|
||||||
|
print(h,c)
|
||||||
|
assert np.allclose(conversion(h),c)
|
||||||
|
|
Loading…
Reference in New Issue