2018-12-09 11:40:31 +05:30
|
|
|
#!/usr/bin/env python3
|
2014-12-13 05:42:55 +05:30
|
|
|
# -*- coding: UTF-8 no BOM -*-
|
|
|
|
|
2018-12-09 15:33:18 +05:30
|
|
|
import os,sys
|
2014-12-13 05:42:55 +05:30
|
|
|
import numpy as np
|
|
|
|
from optparse import OptionParser
|
|
|
|
import damask
|
|
|
|
|
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
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# 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()
|
|
|
|
|
|
|
|
pole = np.array(options.pole)
|
|
|
|
pole /= np.linalg.norm(pole)
|
|
|
|
|
2015-08-21 01:12:05 +05:30
|
|
|
# --- loop over input files -------------------------------------------------------------------------
|
2015-08-08 00:33:26 +05:30
|
|
|
|
2015-08-21 01:12:05 +05:30
|
|
|
if filenames == []: filenames = [None]
|
2014-12-13 05:42:55 +05:30
|
|
|
|
2015-03-06 22:34:44 +05:30
|
|
|
for name in filenames:
|
2015-08-21 01:12:05 +05:30
|
|
|
try:
|
|
|
|
table = damask.ASCIItable(name = name,
|
|
|
|
buffered = False)
|
|
|
|
except: continue
|
2015-09-24 14:54:42 +05:30
|
|
|
damask.util.report(scriptName,name)
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
# ------------------------------------------ read header ------------------------------------------
|
2014-12-13 05:42:55 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
table.head_read()
|
2014-12-13 05:42:55 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# ------------------------------------------ sanity checks ----------------------------------------
|
2014-12-13 05:42:55 +05:30
|
|
|
|
2018-12-09 11:40:31 +05:30
|
|
|
if not table.label_dimension(options.quaternion) == 4:
|
|
|
|
damask.util.croak('input {} does not have dimension 4.'.format(options.quaternion))
|
|
|
|
table.close(dismiss = True) # close ASCIItable and remove empty file
|
2014-12-13 05:42:55 +05:30
|
|
|
continue
|
|
|
|
|
2018-12-09 11:40:31 +05:30
|
|
|
column = table.label_index(options.quaternion)
|
|
|
|
|
2014-12-13 05:42:55 +05:30
|
|
|
# ------------------------------------------ assemble header ---------------------------------------
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
|
2016-10-25 00:46:29 +05:30
|
|
|
table.labels_append(['{}_pole_{}{}{}'.format(i+1,*options.pole) for i in range(2)])
|
2014-12-13 05:42:55 +05:30
|
|
|
table.head_write()
|
|
|
|
|
|
|
|
# ------------------------------------------ process data ------------------------------------------
|
|
|
|
outputAlive = True
|
|
|
|
while outputAlive and table.data_read(): # read next data line of ASCII table
|
2018-12-09 11:40:31 +05:30
|
|
|
o = damask.Orientation(quaternion = np.array(list(map(float,table.data[column:column+4]))))
|
2014-12-13 05:42:55 +05:30
|
|
|
|
|
|
|
rotatedPole = o.quaternion*pole # rotate pole according to crystal orientation
|
|
|
|
(x,y) = rotatedPole[0:2]/(1.+abs(pole[2])) # stereographic projection
|
|
|
|
|
2016-03-02 01:41:43 +05:30
|
|
|
table.data_append([np.sqrt(x*x+y*y),np.arctan2(y,x)] if options.polar else [x,y]) # cartesian coordinates
|
2014-12-13 05:42:55 +05:30
|
|
|
|
|
|
|
outputAlive = table.data_write() # output processed line
|
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# ------------------------------------------ output finalization -----------------------------------
|
2014-12-13 05:42:55 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
table.close() # close ASCII tables
|