2016-05-11 14:31:39 +05:30
|
|
|
#!/usr/bin/env python2
|
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
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
|
|
|
|
Transform X,Y,Z,F APS BeamLine 34 coordinates to x,y,z APS strain coordinates.
|
|
|
|
|
|
|
|
""", version = scriptID)
|
|
|
|
|
2016-03-02 01:14:43 +05:30
|
|
|
parser.add_option('-f','--frame', dest='frame', nargs=4, type='string', metavar='string string string string',
|
2015-05-11 19:45:50 +05:30
|
|
|
help='APS X,Y,Z coords, and depth F')
|
|
|
|
parser.set_defaults(frame = None)
|
|
|
|
|
|
|
|
(options,filenames) = parser.parse_args()
|
|
|
|
|
2016-03-02 01:14:43 +05:30
|
|
|
if options.frame is None:
|
2015-05-11 19:45:50 +05:30
|
|
|
parser.error('no data column specified...')
|
|
|
|
|
|
|
|
|
|
|
|
datainfo = {'len':3,
|
|
|
|
'label':[]
|
|
|
|
}
|
|
|
|
|
2016-03-02 01:14:43 +05:30
|
|
|
datainfo['label'] += options.frame
|
2015-05-11 19:45:50 +05:30
|
|
|
|
|
|
|
# --- loop over input files -------------------------------------------------------------------------
|
|
|
|
if filenames == []:
|
|
|
|
filenames = ['STDIN']
|
|
|
|
|
|
|
|
for name in filenames:
|
|
|
|
if name == 'STDIN':
|
|
|
|
file = {'name':'STDIN', 'input':sys.stdin, 'output':sys.stdout, 'croak':sys.stderr}
|
|
|
|
file['croak'].write('\033[1m'+scriptName+'\033[0m\n')
|
|
|
|
else:
|
|
|
|
if not os.path.exists(name): continue
|
|
|
|
file = {'name':name, 'input':open(name), 'output':open(name+'_tmp','w'), 'croak':sys.stderr}
|
|
|
|
file['croak'].write('\033[1m'+scriptName+'\033[0m: '+file['name']+'\n')
|
|
|
|
|
|
|
|
table = damask.ASCIItable(file['input'],file['output'],buffered=False) # make unbuffered ASCII_table
|
|
|
|
table.head_read() # read ASCII header info
|
|
|
|
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
|
|
|
|
|
|
|
|
# --------------- figure out columns to process ---------------------------------------------------
|
|
|
|
active = []
|
|
|
|
column = {}
|
|
|
|
columnMissing = False
|
|
|
|
|
|
|
|
for label in datainfo['label']:
|
|
|
|
key = label
|
|
|
|
if key in table.labels:
|
|
|
|
active.append(label)
|
|
|
|
column[label] = table.labels.index(key) # remember columns of requested data
|
|
|
|
else:
|
|
|
|
file['croak'].write('column %s not found...\n'%label)
|
|
|
|
columnMissing = True
|
|
|
|
|
|
|
|
if columnMissing: continue
|
|
|
|
|
|
|
|
# ------------------------------------------ assemble header ---------------------------------------
|
|
|
|
table.labels_append(['%i_coord'%(i+1) for i in xrange(3)]) # extend ASCII header with new labels
|
|
|
|
table.head_write()
|
|
|
|
|
|
|
|
# ------------------------------------------ process data ------------------------------------------
|
2015-05-19 03:58:24 +05:30
|
|
|
theta=-0.75*np.pi
|
|
|
|
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-11 19:45:50 +05:30
|
|
|
vec = np.zeros(4)
|
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
|
|
|
|
for i,label in enumerate(active):
|
2015-05-12 21:00:00 +05:30
|
|
|
vec[i] = table.data[column[label]]
|
2015-05-19 03:58:24 +05:30
|
|
|
|
|
|
|
table.data_append(np.dot(RotMat2TSL,np.array([-vec[0], -vec[1],-vec[2]+vec[3]])))
|
|
|
|
|
2015-05-11 19:45:50 +05:30
|
|
|
outputAlive = table.data_write() # output processed line
|
|
|
|
|
|
|
|
# ------------------------------------------ output result -----------------------------------------
|
|
|
|
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
|
|
|
|
|
|
|
table.input_close() # close input ASCII table (works for stdin)
|
|
|
|
table.output_close() # close output ASCII table (works for stdout)
|
|
|
|
if file['name'] != 'STDIN':
|
2016-03-02 01:14:43 +05:30
|
|
|
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|