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)
|
""", 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',
|
parser.add_option('-o', '--output',
|
||||||
dest = 'output',
|
dest = 'output',
|
||||||
action = 'extend', metavar = '<string LIST>',
|
action = 'extend', metavar = '<string LIST>',
|
||||||
help = 'output orientation formats {{{}}}'.format(', '.join(outputChoices)))
|
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',
|
parser.add_option('-d', '--degrees',
|
||||||
dest = 'degrees',
|
dest = 'degrees',
|
||||||
action = 'store_true',
|
action = 'store_true',
|
||||||
help = 'angles are given in degrees [%default]')
|
help = 'all angles in degrees')
|
||||||
parser.add_option('-R', '--labrotation',
|
parser.add_option('-R', '--labrotation',
|
||||||
dest='labrotation',
|
dest='labrotation',
|
||||||
type = 'float', nargs = 4, metavar = ' '.join(['float']*4),
|
type = 'float', nargs = 4, metavar = ' '.join(['float']*4),
|
||||||
|
@ -58,21 +61,20 @@ parser.add_option( '--quaternion',
|
||||||
dest = 'quaternion',
|
dest = 'quaternion',
|
||||||
type = 'string', metavar = 'string',
|
type = 'string', metavar = 'string',
|
||||||
help = 'quaternion label')
|
help = 'quaternion label')
|
||||||
parser.add_option('-a',
|
parser.add_option('-x',
|
||||||
dest = 'a',
|
dest = 'x',
|
||||||
type = 'string', metavar = 'string',
|
type = 'string', metavar = 'string',
|
||||||
help = 'crystal frame a vector label')
|
help = 'label of lab x vector (expressed in crystal coords)')
|
||||||
parser.add_option('-b',
|
parser.add_option('-y',
|
||||||
dest = 'b',
|
dest = 'y',
|
||||||
type = 'string', metavar = 'string',
|
type = 'string', metavar = 'string',
|
||||||
help = 'crystal frame b vector label')
|
help = 'label of lab y vector (expressed in crystal coords)')
|
||||||
parser.add_option('-c',
|
parser.add_option('-z',
|
||||||
dest = 'c',
|
dest = 'z',
|
||||||
type = 'string', metavar = 'string',
|
type = 'string', metavar = 'string',
|
||||||
help = 'crystal frame c vector label')
|
help = 'label of lab z vector (expressed in crystal coords)')
|
||||||
|
|
||||||
parser.set_defaults(output = [],
|
parser.set_defaults(output = [],
|
||||||
symmetry = damask.Symmetry.lattices[-1],
|
|
||||||
labrotation = (0.,1.,1.,1.), # no rotation about 1,1,1
|
labrotation = (0.,1.,1.,1.), # no rotation about 1,1,1
|
||||||
crystalrotation = (0.,1.,1.,1.), # no rotation about 1,1,1
|
crystalrotation = (0.,1.,1.,1.), # no rotation about 1,1,1
|
||||||
degrees = False,
|
degrees = False,
|
||||||
|
@ -86,9 +88,9 @@ if options.output == [] or (not set(options.output).issubset(set(outputChoices))
|
||||||
|
|
||||||
input = [options.eulers is not None,
|
input = [options.eulers is not None,
|
||||||
options.rodrigues is not None,
|
options.rodrigues is not None,
|
||||||
options.a is not None and \
|
options.x is not None and \
|
||||||
options.b is not None and \
|
options.y is not None and \
|
||||||
options.c is not None,
|
options.z is not None,
|
||||||
options.matrix is not None,
|
options.matrix is not None,
|
||||||
options.quaternion 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'),
|
(label,dim,inputtype) = [(options.eulers,3,'eulers'),
|
||||||
(options.rodrigues,3,'rodrigues'),
|
(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.matrix,9,'matrix'),
|
||||||
(options.quaternion,4,'quaternion'),
|
(options.quaternion,4,'quaternion'),
|
||||||
][np.where(input)[0][0]] # select input label that was requested
|
][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
|
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.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. labrotation[0],options. labrotation[1:]) # lab frame rotation
|
||||||
|
|
||||||
# --- loop over input files ------------------------------------------------------------------------
|
# --- loop over input files ------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -137,9 +139,9 @@ for name in filenames:
|
||||||
|
|
||||||
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
|
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
|
||||||
for output in options.output:
|
for output in options.output:
|
||||||
if output == 'quaternion': table.labels_append(['{}_{}_{}({})'.format(i+1,'quat',options.symmetry,label) for i in range(4)])
|
if output in outputChoices:
|
||||||
elif output == 'rodrigues': table.labels_append(['{}_{}_{}({})'.format(i+1,'rodr',options.symmetry,label) for i in range(3)])
|
table.labels_append(['{}_{}({})'.format(i+1,outputChoices[output][0],label) \
|
||||||
elif output == 'eulers': table.labels_append(['{}_{}_{}({})'.format(i+1,'eulr',options.symmetry,label) for i in range(3)])
|
for i in range(outputChoices[output][1])])
|
||||||
table.head_write()
|
table.head_write()
|
||||||
|
|
||||||
# ------------------------------------------ process data ------------------------------------------
|
# ------------------------------------------ process data ------------------------------------------
|
||||||
|
@ -147,22 +149,18 @@ for name in filenames:
|
||||||
outputAlive = True
|
outputAlive = True
|
||||||
while outputAlive and table.data_read(): # read next data line of ASCII table
|
while outputAlive and table.data_read(): # read next data line of ASCII table
|
||||||
if inputtype == 'eulers':
|
if inputtype == 'eulers':
|
||||||
o = damask.Orientation(Eulers = np.array(list(map(float,table.data[column:column+3])))*toRadians,
|
o = damask.Orientation(Eulers = np.array(list(map(float,table.data[column:column+3])))*toRadians)
|
||||||
symmetry = options.symmetry).reduced()
|
|
||||||
elif inputtype == 'rodrigues':
|
elif inputtype == 'rodrigues':
|
||||||
o = damask.Orientation(Rodrigues= np.array(list(map(float,table.data[column:column+3]))),
|
o = damask.Orientation(Rodrigues= np.array(list(map(float,table.data[column:column+3]))))
|
||||||
symmetry = options.symmetry).reduced()
|
|
||||||
elif inputtype == 'matrix':
|
elif inputtype == 'matrix':
|
||||||
o = damask.Orientation(matrix = np.array(list(map(float,table.data[column:column+9]))).reshape(3,3).transpose(),
|
o = damask.Orientation(matrix = np.array(list(map(float,table.data[column:column+9]))).reshape(3,3))
|
||||||
symmetry = options.symmetry).reduced()
|
|
||||||
elif inputtype == 'frame':
|
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[1]:column[1]+3] + \
|
||||||
table.data[column[2]:column[2]+3]))).reshape(3,3),
|
table.data[column[2]:column[2]+3]))).reshape(3,3).T
|
||||||
symmetry = options.symmetry).reduced()
|
o = damask.Orientation(matrix = M/np.linalg.norm(M,axis=0))
|
||||||
elif inputtype == 'quaternion':
|
elif inputtype == 'quaternion':
|
||||||
o = damask.Orientation(quaternion = np.array(list(map(float,table.data[column:column+4]))),
|
o = damask.Orientation(quaternion = np.array(list(map(float,table.data[column:column+4]))))
|
||||||
symmetry = options.symmetry).reduced()
|
|
||||||
|
|
||||||
o.quaternion = r*o.quaternion*R # apply additional lab and crystal frame rotations
|
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())
|
if output == 'quaternion': table.data_append(o.asQuaternion())
|
||||||
elif output == 'rodrigues': table.data_append(o.asRodrigues())
|
elif output == 'rodrigues': table.data_append(o.asRodrigues())
|
||||||
elif output == 'eulers': table.data_append(o.asEulers(degrees=options.degrees))
|
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
|
outputAlive = table.data_write() # output processed line
|
||||||
|
|
||||||
# ------------------------------------------ output finalization -----------------------------------
|
# ------------------------------------------ output finalization -----------------------------------
|
||||||
|
|
Loading…
Reference in New Issue