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 -*-
|
|
|
|
|
2016-03-01 22:55:14 +05:30
|
|
|
import os,sys,math
|
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
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
|
|
|
|
Add x,y coordinates of stereographic projection of given direction (pole) in crystal frame.
|
|
|
|
|
|
|
|
""", version = scriptID)
|
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-p', '--pole',
|
|
|
|
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',
|
2015-05-10 03:02:23 +05:30
|
|
|
help = 'output polar coordinates r,phi [%default]')
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-q', '--quaternion',
|
|
|
|
dest = 'quaternion',
|
|
|
|
type = 'string', metavar = 'string',
|
2015-05-10 03:02:23 +05:30
|
|
|
help = 'quaternion label')
|
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
|
|
|
polar = False,
|
|
|
|
)
|
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
|