modernized
split arguments logically, assume 3-vector for coordinates
This commit is contained in:
parent
7eaea64d09
commit
d9b47f09bc
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env python2.7
|
#!/usr/bin/env python3
|
||||||
# -*- coding: UTF-8 no BOM -*-
|
# -*- coding: UTF-8 no BOM -*-
|
||||||
|
|
||||||
import os,sys
|
import os,sys
|
||||||
|
@ -19,21 +19,22 @@ Transform X,Y,Z,F APS BeamLine 34 coordinates to x,y,z APS strain coordinates.
|
||||||
|
|
||||||
""", version = scriptID)
|
""", version = scriptID)
|
||||||
|
|
||||||
parser.add_option('-f','--frame', dest='frame', nargs=4, type='string', metavar='string string string string',
|
parser.add_option('-f',
|
||||||
help='APS X,Y,Z coords, and depth F')
|
'--frame',
|
||||||
parser.set_defaults(frame = None)
|
dest='frame',
|
||||||
|
metavar='string',
|
||||||
|
help='APS X,Y,Z coords')
|
||||||
|
parser.add_option('--depth',
|
||||||
|
dest='depth',
|
||||||
|
metavar='string',
|
||||||
|
help='depth')
|
||||||
|
|
||||||
(options,filenames) = parser.parse_args()
|
(options,filenames) = parser.parse_args()
|
||||||
|
|
||||||
if options.frame is None:
|
if options.frame is None:
|
||||||
parser.error('no data column specified...')
|
parser.error('frame not specified')
|
||||||
|
if options.depth is None:
|
||||||
|
parser.error('depth not specified')
|
||||||
datainfo = {'len':3,
|
|
||||||
'label':[]
|
|
||||||
}
|
|
||||||
|
|
||||||
datainfo['label'] += options.frame
|
|
||||||
|
|
||||||
# --- loop over input files ------------------------------------------------------------------------
|
# --- loop over input files ------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -49,31 +50,19 @@ for name in filenames:
|
||||||
|
|
||||||
table.head_read()
|
table.head_read()
|
||||||
|
|
||||||
if not table.label_dimension(options.quaternion) == 4:
|
# ------------------------------------------ sanity checks -----------------------------------------
|
||||||
damask.util.croak('input {} does not have dimension 4.'.format(options.quaternion))
|
errors = []
|
||||||
table.close(dismiss = True) # close ASCIItable and remove empty file
|
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)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
|
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(raw = True):
|
|
||||||
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 ---------------------------------------
|
# ------------------------------------------ assemble header ---------------------------------------
|
||||||
table.labels_append(['%i_coord'%(i+1) for i in range(3)]) # extend ASCII header with new labels
|
table.labels_append(['%i_coord'%(i+1) for i in range(3)]) # extend ASCII header with new labels
|
||||||
table.head_write()
|
table.head_write()
|
||||||
|
@ -83,21 +72,15 @@ for name in filenames:
|
||||||
RotMat2TSL=np.array([[1., 0., 0.],
|
RotMat2TSL=np.array([[1., 0., 0.],
|
||||||
[0., np.cos(theta), np.sin(theta)], # Orientation to account for -135 deg
|
[0., np.cos(theta), np.sin(theta)], # Orientation to account for -135 deg
|
||||||
[0., -np.sin(theta), np.cos(theta)]]) # rotation for TSL convention
|
[0., -np.sin(theta), np.cos(theta)]]) # rotation for TSL convention
|
||||||
vec = np.zeros(4)
|
|
||||||
|
|
||||||
outputAlive = True
|
outputAlive = True
|
||||||
while outputAlive and table.data_read(): # read next data line of ASCII table
|
while outputAlive and table.data_read(): # read next data line of ASCII table
|
||||||
for i,label in enumerate(active):
|
coord = list(map(float,table.data[table.label_index(options.frame):table.label_index(options.frame)+3]))
|
||||||
vec[i] = table.data[column[label]]
|
depth = float(table.data[table.label_index(options.depth)])
|
||||||
|
|
||||||
table.data_append(np.dot(RotMat2TSL,np.array([-vec[0], -vec[1],-vec[2]+vec[3]])))
|
table.data_append(np.dot(RotMat2TSL,np.array([-coord[0],-coord[1],-coord[2]+depth])))
|
||||||
|
|
||||||
outputAlive = table.data_write() # output processed line
|
outputAlive = table.data_write() # output processed line
|
||||||
|
|
||||||
# ------------------------------------------ output result -----------------------------------------
|
# ------------------------------------------ output finalization -----------------------------------
|
||||||
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
|
||||||
|
|
||||||
table.input_close() # close input ASCII table (works for stdin)
|
table.close() # close ASCII tables
|
||||||
table.output_close() # close output ASCII table (works for stdout)
|
|
||||||
if file['name'] != 'STDIN':
|
|
||||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
|
||||||
|
|
Loading…
Reference in New Issue