2018-11-17 12:42:12 +05:30
|
|
|
#!/usr/bin/env python3
|
2013-11-26 00:41:02 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
import os
|
|
|
|
import sys
|
2020-05-16 13:10:44 +05:30
|
|
|
from io import StringIO
|
2014-07-25 01:51:18 +05:30
|
|
|
from optparse import OptionParser
|
2019-06-14 16:33:30 +05:30
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
2014-07-25 01:51:18 +05:30
|
|
|
import damask
|
2013-11-26 00:41:02 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2016-01-27 22:36:00 +05:30
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
2013-11-26 00:41:02 +05:30
|
|
|
|
2014-07-25 01:51:18 +05:30
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
2019-02-17 02:50:10 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """
|
2013-11-26 00:41:02 +05:30
|
|
|
Add quaternion and/or Bunge Euler angle representation of crystal lattice orientation.
|
2016-03-02 01:44:06 +05:30
|
|
|
Orientation is given by quaternion, Euler angles, rotation matrix, or crystal frame coordinates
|
|
|
|
(i.e. component vectors of rotation matrix).
|
2016-08-01 05:05:10 +05:30
|
|
|
Additional (globally fixed) rotations of the lab frame and/or crystal frame can be applied.
|
2013-11-26 00:41:02 +05:30
|
|
|
|
2014-08-06 18:57:09 +05:30
|
|
|
""", version = scriptID)
|
2013-11-26 00:41:02 +05:30
|
|
|
|
2020-05-16 13:10:44 +05:30
|
|
|
representations = ['quaternion', 'rodrigues', 'eulers', 'matrix', 'axisangle']
|
|
|
|
|
2018-12-08 08:33:14 +05:30
|
|
|
|
2018-12-10 13:57:39 +05:30
|
|
|
parser.add_option('-o',
|
|
|
|
'--output',
|
2015-08-08 00:33:26 +05:30
|
|
|
dest = 'output',
|
|
|
|
action = 'extend', metavar = '<string LIST>',
|
2019-02-12 13:28:23 +05:30
|
|
|
help = 'output orientation formats {{{}}}'.format(', '.join(representations)))
|
2018-12-10 13:57:39 +05:30
|
|
|
parser.add_option('-d',
|
|
|
|
'--degrees',
|
2016-07-31 00:37:44 +05:30
|
|
|
dest = 'degrees',
|
|
|
|
action = 'store_true',
|
2018-12-08 08:33:14 +05:30
|
|
|
help = 'all angles in degrees')
|
2018-12-10 13:57:39 +05:30
|
|
|
parser.add_option('-R',
|
|
|
|
'--labrotation',
|
2016-08-01 05:05:10 +05:30
|
|
|
dest='labrotation',
|
2016-07-31 00:37:44 +05:30
|
|
|
type = 'float', nargs = 4, metavar = ' '.join(['float']*4),
|
2019-03-10 00:28:17 +05:30
|
|
|
help = 'axis and angle of additional lab frame rotation [%default]')
|
2018-12-10 13:57:39 +05:30
|
|
|
parser.add_option('-r',
|
|
|
|
'--crystalrotation',
|
2016-08-01 05:05:10 +05:30
|
|
|
dest='crystalrotation',
|
|
|
|
type = 'float', nargs = 4, metavar = ' '.join(['float']*4),
|
2019-03-10 00:28:17 +05:30
|
|
|
help = 'axis and angle of additional crystal frame rotation [%default]')
|
2018-12-10 13:57:39 +05:30
|
|
|
parser.add_option('--eulers',
|
2015-08-08 00:33:26 +05:30
|
|
|
dest = 'eulers',
|
2018-12-10 13:57:39 +05:30
|
|
|
metavar = 'string',
|
2015-05-10 03:02:23 +05:30
|
|
|
help = 'Euler angles label')
|
2018-12-10 13:57:39 +05:30
|
|
|
parser.add_option('--rodrigues',
|
2017-08-23 23:40:56 +05:30
|
|
|
dest = 'rodrigues',
|
2018-12-10 13:57:39 +05:30
|
|
|
metavar = 'string',
|
2017-08-23 23:40:56 +05:30
|
|
|
help = 'Rodrigues vector label')
|
2018-12-10 13:57:39 +05:30
|
|
|
parser.add_option('--matrix',
|
2015-08-08 00:33:26 +05:30
|
|
|
dest = 'matrix',
|
2018-12-10 13:57:39 +05:30
|
|
|
metavar = 'string',
|
2015-05-10 03:02:23 +05:30
|
|
|
help = 'orientation matrix label')
|
2018-12-10 13:57:39 +05:30
|
|
|
parser.add_option('--quaternion',
|
2017-08-23 23:40:56 +05:30
|
|
|
dest = 'quaternion',
|
2018-12-10 13:57:39 +05:30
|
|
|
metavar = 'string',
|
2017-08-23 23:40:56 +05:30
|
|
|
help = 'quaternion label')
|
2018-12-08 08:33:14 +05:30
|
|
|
parser.add_option('-x',
|
|
|
|
dest = 'x',
|
2018-12-10 13:57:39 +05:30
|
|
|
metavar = 'string',
|
2018-12-08 08:33:14 +05:30
|
|
|
help = 'label of lab x vector (expressed in crystal coords)')
|
|
|
|
parser.add_option('-y',
|
|
|
|
dest = 'y',
|
2018-12-10 13:57:39 +05:30
|
|
|
metavar = 'string',
|
2018-12-08 08:33:14 +05:30
|
|
|
help = 'label of lab y vector (expressed in crystal coords)')
|
|
|
|
parser.add_option('-z',
|
|
|
|
dest = 'z',
|
2018-12-10 13:57:39 +05:30
|
|
|
metavar = 'string',
|
2018-12-08 08:33:14 +05:30
|
|
|
help = 'label of lab z vector (expressed in crystal coords)')
|
2019-09-11 00:38:49 +05:30
|
|
|
parser.add_option('--lattice',
|
|
|
|
dest = 'lattice',
|
|
|
|
metavar = 'string',
|
|
|
|
help = 'lattice structure to reduce rotation into fundamental zone')
|
2013-11-26 00:41:02 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.set_defaults(output = [],
|
2019-03-10 00:28:17 +05:30
|
|
|
labrotation = (1.,1.,1.,0.), # no rotation about (1,1,1)
|
|
|
|
crystalrotation = (1.,1.,1.,0.), # no rotation about (1,1,1)
|
2019-09-11 00:38:49 +05:30
|
|
|
lattice = None,
|
2015-08-08 00:33:26 +05:30
|
|
|
)
|
2013-11-26 00:41:02 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
(options, filenames) = parser.parse_args()
|
2020-05-16 13:10:44 +05:30
|
|
|
if filenames == []: filenames = [None]
|
2014-08-04 23:23:41 +05:30
|
|
|
|
2019-02-12 13:28:23 +05:30
|
|
|
if options.output == [] or (not set(options.output).issubset(set(representations))):
|
2020-05-16 13:10:44 +05:30
|
|
|
parser.error('output must be chosen from {}.'.format(', '.join(representations)))
|
2015-08-08 00:33:26 +05:30
|
|
|
|
2016-03-02 01:41:43 +05:30
|
|
|
input = [options.eulers is not None,
|
2017-08-23 23:40:56 +05:30
|
|
|
options.rodrigues is not None,
|
2018-12-08 08:33:14 +05:30
|
|
|
options.x is not None and \
|
|
|
|
options.y is not None and \
|
|
|
|
options.z is not None,
|
2016-03-02 01:41:43 +05:30
|
|
|
options.matrix is not None,
|
|
|
|
options.quaternion is not None,
|
2015-08-08 00:33:26 +05:30
|
|
|
]
|
|
|
|
|
|
|
|
if np.sum(input) != 1: parser.error('needs exactly one input format.')
|
|
|
|
|
2020-05-16 13:10:44 +05:30
|
|
|
r = damask.Rotation.from_axis_angle(np.array(options.crystalrotation),options.degrees,normalise=True)
|
|
|
|
R = damask.Rotation.from_axis_angle(np.array(options.labrotation),options.degrees,normalise=True)
|
2015-06-05 17:17:27 +05:30
|
|
|
|
|
|
|
for name in filenames:
|
2020-05-16 13:10:44 +05:30
|
|
|
damask.util.report(scriptName,name)
|
|
|
|
|
|
|
|
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
|
|
|
|
|
|
|
if options.eulers is not None:
|
|
|
|
label = options.eulers
|
|
|
|
print(np.max(table.get(options.eulers),axis=0))
|
|
|
|
o = damask.Rotation.from_Eulers(table.get(options.eulers), options.degrees)
|
|
|
|
elif options.rodrigues is not None:
|
|
|
|
label = options.rodrigues
|
|
|
|
o = damask.Rotation.from_Rodrigues(table.get(options.rodrigues))
|
|
|
|
elif options.matrix is not None:
|
|
|
|
label = options.matrix
|
|
|
|
o = damask.Rotation.from_matrix(table.get(options.matrix).reshape(-1,3,3))
|
|
|
|
elif options.x is not None:
|
|
|
|
label = '<{},{},{}>'.format(options.x,options.y,options.z)
|
|
|
|
M = np.block([table.get(options.x),table.get(options.y),table.get(options.z)]).reshape(-1,3,3)
|
|
|
|
o = damask.Rotation.from_matrix(M/np.linalg.norm(M,axis=0))
|
|
|
|
elif options.quaternion is not None:
|
|
|
|
label = options.quaternion
|
|
|
|
o = damask.Rotation.from_quaternion(table.get(options.quaternion))
|
|
|
|
|
|
|
|
o = r.broadcast_to(o.shape) @ o @ R.broadcast_to(o.shape)
|
|
|
|
|
|
|
|
#if options.lattice is not None:
|
|
|
|
# o = damask.Orientation(rotation = o,lattice = options.lattice).reduced().rotation
|
|
|
|
|
|
|
|
|
|
|
|
if 'rodrigues' in options.output:
|
2020-05-17 10:55:17 +05:30
|
|
|
table.add('ro({})'.format(label),o.as_Rodrigues(), scriptID+' '+' '.join(sys.argv[1:]))
|
2020-05-16 13:10:44 +05:30
|
|
|
if 'eulers' in options.output:
|
|
|
|
table.add('eu({})'.format(label),o.as_Eulers(options.degrees), scriptID+' '+' '.join(sys.argv[1:]))
|
|
|
|
if 'quaternion' in options.output:
|
|
|
|
table.add('qu({})'.format(label),o.as_quaternion(), scriptID+' '+' '.join(sys.argv[1:]))
|
|
|
|
if 'matrix' in options.output:
|
|
|
|
table.add('om({})'.format(label),o.as_matrix(), scriptID+' '+' '.join(sys.argv[1:]))
|
|
|
|
if 'axisangle' in options.output:
|
|
|
|
table.add('om({})'.format(label),o.as_axisangle(options.degrees), scriptID+' '+' '.join(sys.argv[1:]))
|
|
|
|
|
2020-09-03 20:49:19 +05:30
|
|
|
table.to_file(sys.stdout if name is None else name)
|