improved converte, now with test

still needs to figure out how +P is handled
This commit is contained in:
Martin Diehl 2019-02-24 14:39:34 +01:00
parent 0d7fd587e3
commit e88182b007
3 changed files with 8 additions and 4 deletions

@ -1 +1 @@
Subproject commit 8deb37dd4526fb5e1425fe1d2360508d01b6ac3e
Subproject commit 144e729811024fd5f99225fa10b6d8fa40e7d492

View File

@ -95,7 +95,7 @@ for name in filenames:
except:
errors.append('Pointwise orientation data ({}) not found'.format(dataset))
texture = [damask.Rotation.fromQuaternion(q,P=+1) for q in quats]
texture = [damask.Rotation.fromQuaternion(q,True,P=+1) for q in quats]
dataset = os.path.join(group_pointwise,options.phase)
try:
@ -118,7 +118,7 @@ for name in filenames:
dataset = os.path.join(group_average,options.quaternion)
try:
texture = [damask.Rotation.fromQuaternion(q,P=+1) for q in inFile[dataset][...][1:]] # skip first entry (unindexed)
texture = [damask.Rotation.fromQuaternion(q,True,P=+1) for q in inFile[dataset][...][1:]] # skip first entry (unindexed)
except:
errors.append('Average orientation data ({}) not found'.format(dataset))

View File

@ -301,11 +301,15 @@ class Rotation:
@classmethod
def fromQuaternion(cls,
quaternion,
acceptHomomorph = False,
P = -1):
qu = quaternion if isinstance(quaternion, np.ndarray) else np.array(quaternion)
if P > 0: qu[1:4] *= -1 # convert from P=1 to P=-1
if qu[0] < 0.0:
if acceptHomomorph:
qu *= -1.
else:
raise ValueError('Quaternion has negative first component.\n{}'.format(qu[0]))
if not np.isclose(np.linalg.norm(qu), 1.0):
raise ValueError('Quaternion is not of unit length.\n{} {} {} {}'.format(*qu))