more output options, frame input changed to "lab expressed in crystal"
This commit is contained in:
parent
3d7a73a0de
commit
ac45a9e2d3
|
@ -21,19 +21,22 @@ Additional (globally fixed) rotations of the lab frame and/or crystal frame can
|
|||
|
||||
""", version = scriptID)
|
||||
|
||||
outputChoices = ['quaternion','rodrigues','eulers']
|
||||
outputChoices = {
|
||||
'quaternion': ['quat',4],
|
||||
'rodrigues': ['rodr',3],
|
||||
'eulers': ['eulr',3],
|
||||
'matrix': ['mtrx',9],
|
||||
'angleaxis': ['aaxs',4],
|
||||
}
|
||||
|
||||
parser.add_option('-o', '--output',
|
||||
dest = 'output',
|
||||
action = 'extend', metavar = '<string LIST>',
|
||||
help = 'output orientation formats {{{}}}'.format(', '.join(outputChoices)))
|
||||
parser.add_option('-s', '--symmetry',
|
||||
dest = 'symmetry',
|
||||
type = 'choice', choices = damask.Symmetry.lattices[1:], metavar='string',
|
||||
help = 'crystal symmetry [%default] {{{}}} '.format(', '.join(damask.Symmetry.lattices[1:])))
|
||||
parser.add_option('-d', '--degrees',
|
||||
dest = 'degrees',
|
||||
action = 'store_true',
|
||||
help = 'angles are given in degrees [%default]')
|
||||
help = 'all angles in degrees')
|
||||
parser.add_option('-R', '--labrotation',
|
||||
dest='labrotation',
|
||||
type = 'float', nargs = 4, metavar = ' '.join(['float']*4),
|
||||
|
@ -58,21 +61,20 @@ parser.add_option( '--quaternion',
|
|||
dest = 'quaternion',
|
||||
type = 'string', metavar = 'string',
|
||||
help = 'quaternion label')
|
||||
parser.add_option('-a',
|
||||
dest = 'a',
|
||||
parser.add_option('-x',
|
||||
dest = 'x',
|
||||
type = 'string', metavar = 'string',
|
||||
help = 'crystal frame a vector label')
|
||||
parser.add_option('-b',
|
||||
dest = 'b',
|
||||
help = 'label of lab x vector (expressed in crystal coords)')
|
||||
parser.add_option('-y',
|
||||
dest = 'y',
|
||||
type = 'string', metavar = 'string',
|
||||
help = 'crystal frame b vector label')
|
||||
parser.add_option('-c',
|
||||
dest = 'c',
|
||||
help = 'label of lab y vector (expressed in crystal coords)')
|
||||
parser.add_option('-z',
|
||||
dest = 'z',
|
||||
type = 'string', metavar = 'string',
|
||||
help = 'crystal frame c vector label')
|
||||
help = 'label of lab z vector (expressed in crystal coords)')
|
||||
|
||||
parser.set_defaults(output = [],
|
||||
symmetry = damask.Symmetry.lattices[-1],
|
||||
labrotation = (0.,1.,1.,1.), # no rotation about 1,1,1
|
||||
crystalrotation = (0.,1.,1.,1.), # no rotation about 1,1,1
|
||||
degrees = False,
|
||||
|
@ -86,9 +88,9 @@ if options.output == [] or (not set(options.output).issubset(set(outputChoices))
|
|||
|
||||
input = [options.eulers is not None,
|
||||
options.rodrigues is not None,
|
||||
options.a is not None and \
|
||||
options.b is not None and \
|
||||
options.c is not None,
|
||||
options.x is not None and \
|
||||
options.y is not None and \
|
||||
options.z is not None,
|
||||
options.matrix is not None,
|
||||
options.quaternion is not None,
|
||||
]
|
||||
|
@ -97,13 +99,13 @@ if np.sum(input) != 1: parser.error('needs exactly one input format.')
|
|||
|
||||
(label,dim,inputtype) = [(options.eulers,3,'eulers'),
|
||||
(options.rodrigues,3,'rodrigues'),
|
||||
([options.a,options.b,options.c],[3,3,3],'frame'),
|
||||
([options.x,options.y,options.z],[3,3,3],'frame'),
|
||||
(options.matrix,9,'matrix'),
|
||||
(options.quaternion,4,'quaternion'),
|
||||
][np.where(input)[0][0]] # select input label that was requested
|
||||
toRadians = math.pi/180.0 if options.degrees else 1.0 # rescale degrees to radians
|
||||
r = damask.Quaternion().fromAngleAxis(toRadians*options.crystalrotation[0],options.crystalrotation[1:]) # crystal frame rotation
|
||||
R = damask.Quaternion().fromAngleAxis(toRadians*options. labrotation[0],options. labrotation[1:]) # lab frame rotation
|
||||
r = damask.Quaternion.fromAngleAxis(toRadians*options.crystalrotation[0],options.crystalrotation[1:]) # crystal frame rotation
|
||||
R = damask.Quaternion.fromAngleAxis(toRadians*options. labrotation[0],options. labrotation[1:]) # lab frame rotation
|
||||
|
||||
# --- loop over input files ------------------------------------------------------------------------
|
||||
|
||||
|
@ -137,9 +139,9 @@ for name in filenames:
|
|||
|
||||
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
|
||||
for output in options.output:
|
||||
if output == 'quaternion': table.labels_append(['{}_{}_{}({})'.format(i+1,'quat',options.symmetry,label) for i in range(4)])
|
||||
elif output == 'rodrigues': table.labels_append(['{}_{}_{}({})'.format(i+1,'rodr',options.symmetry,label) for i in range(3)])
|
||||
elif output == 'eulers': table.labels_append(['{}_{}_{}({})'.format(i+1,'eulr',options.symmetry,label) for i in range(3)])
|
||||
if output in outputChoices:
|
||||
table.labels_append(['{}_{}({})'.format(i+1,outputChoices[output][0],label) \
|
||||
for i in range(outputChoices[output][1])])
|
||||
table.head_write()
|
||||
|
||||
# ------------------------------------------ process data ------------------------------------------
|
||||
|
@ -147,22 +149,18 @@ for name in filenames:
|
|||
outputAlive = True
|
||||
while outputAlive and table.data_read(): # read next data line of ASCII table
|
||||
if inputtype == 'eulers':
|
||||
o = damask.Orientation(Eulers = np.array(list(map(float,table.data[column:column+3])))*toRadians,
|
||||
symmetry = options.symmetry).reduced()
|
||||
o = damask.Orientation(Eulers = np.array(list(map(float,table.data[column:column+3])))*toRadians)
|
||||
elif inputtype == 'rodrigues':
|
||||
o = damask.Orientation(Rodrigues= np.array(list(map(float,table.data[column:column+3]))),
|
||||
symmetry = options.symmetry).reduced()
|
||||
o = damask.Orientation(Rodrigues= np.array(list(map(float,table.data[column:column+3]))))
|
||||
elif inputtype == 'matrix':
|
||||
o = damask.Orientation(matrix = np.array(list(map(float,table.data[column:column+9]))).reshape(3,3).transpose(),
|
||||
symmetry = options.symmetry).reduced()
|
||||
o = damask.Orientation(matrix = np.array(list(map(float,table.data[column:column+9]))).reshape(3,3))
|
||||
elif inputtype == 'frame':
|
||||
o = damask.Orientation(matrix = np.array(list(map(float,table.data[column[0]:column[0]+3] + \
|
||||
M = np.array(list(map(float,table.data[column[0]:column[0]+3] + \
|
||||
table.data[column[1]:column[1]+3] + \
|
||||
table.data[column[2]:column[2]+3]))).reshape(3,3),
|
||||
symmetry = options.symmetry).reduced()
|
||||
table.data[column[2]:column[2]+3]))).reshape(3,3).T
|
||||
o = damask.Orientation(matrix = M/np.linalg.norm(M,axis=0))
|
||||
elif inputtype == 'quaternion':
|
||||
o = damask.Orientation(quaternion = np.array(list(map(float,table.data[column:column+4]))),
|
||||
symmetry = options.symmetry).reduced()
|
||||
o = damask.Orientation(quaternion = np.array(list(map(float,table.data[column:column+4]))))
|
||||
|
||||
o.quaternion = r*o.quaternion*R # apply additional lab and crystal frame rotations
|
||||
|
||||
|
@ -170,6 +168,8 @@ for name in filenames:
|
|||
if output == 'quaternion': table.data_append(o.asQuaternion())
|
||||
elif output == 'rodrigues': table.data_append(o.asRodrigues())
|
||||
elif output == 'eulers': table.data_append(o.asEulers(degrees=options.degrees))
|
||||
elif output == 'matrix': table.data_append(o.asMatrix())
|
||||
elif output == 'angleaxis': table.data_append(o.asAngleAxis(degrees=options.degrees,flat=True))
|
||||
outputAlive = table.data_write() # output processed line
|
||||
|
||||
# ------------------------------------------ output finalization -----------------------------------
|
||||
|
|
Loading…
Reference in New Issue