2018-12-09 15:22:37 +05:30
|
|
|
#!/usr/bin/env python3
|
2015-05-11 19:45:50 +05:30
|
|
|
# -*- coding: UTF-8 no BOM -*-
|
|
|
|
|
2016-03-01 22:55:14 +05:30
|
|
|
import os,sys
|
2015-09-24 14:54:42 +05:30
|
|
|
import numpy as np
|
2015-05-11 19:45:50 +05:30
|
|
|
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])
|
2015-05-11 19:45:50 +05:30
|
|
|
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
2019-02-16 22:11:56 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """
|
2015-05-11 19:45:50 +05:30
|
|
|
Transform X,Y,Z,F APS BeamLine 34 coordinates to x,y,z APS strain coordinates.
|
|
|
|
|
|
|
|
""", version = scriptID)
|
|
|
|
|
2019-02-16 22:53:00 +05:30
|
|
|
parser.add_option('-f','--frame',dest='frame', metavar='string',
|
|
|
|
help='label of APS X,Y,Z coords')
|
2019-02-15 23:22:47 +05:30
|
|
|
parser.add_option('--depth', dest='depth', metavar='string',
|
|
|
|
help='depth')
|
2015-05-11 19:45:50 +05:30
|
|
|
|
|
|
|
(options,filenames) = parser.parse_args()
|
|
|
|
|
2016-03-02 01:14:43 +05:30
|
|
|
if options.frame is None:
|
2018-12-09 15:22:37 +05:30
|
|
|
parser.error('frame not specified')
|
|
|
|
if options.depth is None:
|
|
|
|
parser.error('depth not specified')
|
2015-05-11 19:45:50 +05:30
|
|
|
|
2018-12-09 11:40:31 +05:30
|
|
|
# --- loop over input files ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
if filenames == []: filenames = [None]
|
2015-05-11 19:45:50 +05:30
|
|
|
|
|
|
|
for name in filenames:
|
2018-12-09 11:40:31 +05:30
|
|
|
try: table = damask.ASCIItable(name = name,
|
|
|
|
buffered = False)
|
|
|
|
except: continue
|
|
|
|
damask.util.report(scriptName,name)
|
|
|
|
|
|
|
|
# ------------------------------------------ read header ------------------------------------------
|
|
|
|
|
|
|
|
table.head_read()
|
|
|
|
|
2018-12-09 15:22:37 +05:30
|
|
|
# ------------------------------------------ sanity checks -----------------------------------------
|
|
|
|
errors = []
|
|
|
|
if table.label_dimension(options.frame) != 3:
|
|
|
|
errors.append('input {} does not have dimension 3.'.format(options.frame))
|
|
|
|
if table.label_dimension(options.depth) != 1:
|
|
|
|
errors.append('input {} does not have dimension 1.'.format(options.depth))
|
|
|
|
if errors != []:
|
|
|
|
damask.util.croak(errors)
|
|
|
|
table.close(dismiss = True)
|
2018-12-09 11:40:31 +05:30
|
|
|
continue
|
|
|
|
|
2015-05-11 19:45:50 +05:30
|
|
|
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
|
|
|
|
|
|
|
|
# ------------------------------------------ assemble header ---------------------------------------
|
2016-10-25 00:46:29 +05:30
|
|
|
table.labels_append(['%i_coord'%(i+1) for i in range(3)]) # extend ASCII header with new labels
|
2015-05-11 19:45:50 +05:30
|
|
|
table.head_write()
|
|
|
|
|
|
|
|
# ------------------------------------------ process data ------------------------------------------
|
2015-05-19 03:58:24 +05:30
|
|
|
theta=-0.75*np.pi
|
2018-06-18 03:35:55 +05:30
|
|
|
RotMat2TSL=np.array([[1., 0., 0.],
|
2016-03-02 01:14:43 +05:30
|
|
|
[0., np.cos(theta), np.sin(theta)], # Orientation to account for -135 deg
|
|
|
|
[0., -np.sin(theta), np.cos(theta)]]) # rotation for TSL convention
|
2015-05-19 03:58:24 +05:30
|
|
|
outputAlive = True
|
2015-05-11 19:45:50 +05:30
|
|
|
while outputAlive and table.data_read(): # read next data line of ASCII table
|
2018-12-09 15:22:37 +05:30
|
|
|
coord = list(map(float,table.data[table.label_index(options.frame):table.label_index(options.frame)+3]))
|
|
|
|
depth = float(table.data[table.label_index(options.depth)])
|
2015-05-19 03:58:24 +05:30
|
|
|
|
2018-12-09 15:22:37 +05:30
|
|
|
table.data_append(np.dot(RotMat2TSL,np.array([-coord[0],-coord[1],-coord[2]+depth])))
|
2015-05-19 03:58:24 +05:30
|
|
|
|
2015-05-11 19:45:50 +05:30
|
|
|
outputAlive = table.data_write() # output processed line
|
|
|
|
|
2018-12-09 15:22:37 +05:30
|
|
|
# ------------------------------------------ output finalization -----------------------------------
|
2015-05-11 19:45:50 +05:30
|
|
|
|
2018-12-09 15:22:37 +05:30
|
|
|
table.close() # close ASCII tables
|