2018-12-09 11:40:31 +05:30
|
|
|
#!/usr/bin/env python3
|
2014-12-13 05:42:55 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
import os
|
|
|
|
import sys
|
2019-12-21 22:49:54 +05:30
|
|
|
from io import StringIO
|
2014-12-13 05:42:55 +05:30
|
|
|
from optparse import OptionParser
|
2019-06-14 16:33:30 +05:30
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
2014-12-13 05:42:55 +05:30
|
|
|
import damask
|
|
|
|
|
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])
|
2014-12-13 05:42:55 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2014-12-13 05:42:55 +05:30
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
2019-02-17 02:50:10 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """
|
2018-12-10 13:57:39 +05:30
|
|
|
Add coordinates of stereographic projection of given direction (pole) in crystal frame.
|
2014-12-13 05:42:55 +05:30
|
|
|
|
|
|
|
""", version = scriptID)
|
|
|
|
|
2018-12-10 13:57:39 +05:30
|
|
|
parser.add_option('-p',
|
|
|
|
'--pole',
|
2015-08-08 00:33:26 +05:30
|
|
|
dest = 'pole',
|
|
|
|
type = 'float', nargs = 3, metavar = 'float float float',
|
2015-05-10 03:02:23 +05:30
|
|
|
help = 'crystal frame direction for pole figure [%default]')
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('--polar',
|
|
|
|
dest = 'polar',
|
|
|
|
action = 'store_true',
|
2018-12-10 13:57:39 +05:30
|
|
|
help = 'output polar coordinates (r,φ) instead of Cartesian coordinates (x,y)')
|
|
|
|
parser.add_option('-o',
|
|
|
|
'--orientation',
|
2015-08-08 00:33:26 +05:30
|
|
|
dest = 'quaternion',
|
2018-12-10 13:57:39 +05:30
|
|
|
metavar = 'string',
|
|
|
|
help = 'label of crystal orientation given as unit quaternion [%default]')
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
parser.set_defaults(pole = (1.0,0.0,0.0),
|
2018-12-09 11:40:31 +05:30
|
|
|
quaternion = 'orientation',
|
2015-08-08 00:33:26 +05:30
|
|
|
)
|
2014-12-13 05:42:55 +05:30
|
|
|
|
|
|
|
(options, filenames) = parser.parse_args()
|
2019-12-21 19:42:01 +05:30
|
|
|
if filenames == []: filenames = [None]
|
2014-12-13 05:42:55 +05:30
|
|
|
|
|
|
|
pole = np.array(options.pole)
|
|
|
|
pole /= np.linalg.norm(pole)
|
|
|
|
|
2015-03-06 22:34:44 +05:30
|
|
|
for name in filenames:
|
2019-12-21 19:42:01 +05:30
|
|
|
damask.util.report(scriptName,name)
|
|
|
|
|
|
|
|
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
|
|
|
orientation = table.get(options.quaternion)
|
|
|
|
poles = np.empty((orientation.shape[0],2))
|
|
|
|
for i,o in enumerate(orientation):
|
|
|
|
rotatedPole = damask.Rotation(o)*pole # rotate pole according to crystal orientation
|
|
|
|
(x,y) = rotatedPole[0:2]/(1.+abs(pole[2])) # stereographic projection
|
|
|
|
poles[i] = [np.sqrt(x*x+y*y),np.arctan2(y,x)] if options.polar else [x,y] # cartesian coordinates
|
|
|
|
|
|
|
|
table.add('pole_{}{}{}'.format(*options.pole),
|
|
|
|
poles,
|
|
|
|
scriptID+' '+' '.join(sys.argv[1:]))
|
|
|
|
table.to_ASCII(sys.stdout if name is None else name)
|