use new table class
This commit is contained in:
parent
f9772a3df8
commit
ff60cf0b67
|
@ -2,6 +2,7 @@
|
|||
|
||||
import os
|
||||
import sys
|
||||
from io import StringIO
|
||||
from optparse import OptionParser
|
||||
|
||||
import numpy as np
|
||||
|
@ -28,57 +29,29 @@ parser.add_option('--depth', dest='depth', metavar='string',
|
|||
help='depth')
|
||||
|
||||
(options,filenames) = parser.parse_args()
|
||||
if filenames == []: filenames = [None]
|
||||
|
||||
if options.frame is None:
|
||||
parser.error('frame not specified')
|
||||
if options.depth is None:
|
||||
parser.error('depth not specified')
|
||||
|
||||
# --- loop over input files ------------------------------------------------------------------------
|
||||
|
||||
if filenames == []: filenames = [None]
|
||||
|
||||
for name in filenames:
|
||||
try: table = damask.ASCIItable(name = name,
|
||||
buffered = False)
|
||||
except: continue
|
||||
damask.util.report(scriptName,name)
|
||||
|
||||
# ------------------------------------------ read header ------------------------------------------
|
||||
|
||||
table.head_read()
|
||||
|
||||
# ------------------------------------------ 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)
|
||||
continue
|
||||
|
||||
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
|
||||
|
||||
# ------------------------------------------ assemble header ---------------------------------------
|
||||
table.labels_append(['%i_coord'%(i+1) for i in range(3)]) # extend ASCII header with new labels
|
||||
table.head_write()
|
||||
|
||||
# ------------------------------------------ process data ------------------------------------------
|
||||
theta=-0.75*np.pi
|
||||
RotMat2TSL=np.array([[1., 0., 0.],
|
||||
theta=-0.75*np.pi
|
||||
RotMat2TSL=np.array([[1., 0., 0.],
|
||||
[0., np.cos(theta), np.sin(theta)], # Orientation to account for -135 deg
|
||||
[0., -np.sin(theta), np.cos(theta)]]) # rotation for TSL convention
|
||||
outputAlive = True
|
||||
while outputAlive and table.data_read(): # read next data line of ASCII table
|
||||
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)])
|
||||
|
||||
table.data_append(np.dot(RotMat2TSL,np.array([-coord[0],-coord[1],-coord[2]+depth])))
|
||||
for name in filenames:
|
||||
damask.util.report(scriptName,name)
|
||||
|
||||
outputAlive = table.data_write() # output processed line
|
||||
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
||||
|
||||
# ------------------------------------------ output finalization -----------------------------------
|
||||
coord = - table.get(options.frame)
|
||||
coord[:,2] += table.get(options.depth)[:,0]
|
||||
|
||||
table.close() # close ASCII tables
|
||||
table.add('coord',
|
||||
np.einsum('ijk,ik->ij',np.broadcast_to(RotMat2TSL,(coord.shape[0],3,3)),coord),
|
||||
scriptID+' '+' '.join(sys.argv[1:]))
|
||||
|
||||
table.to_ASCII(sys.stdout if name is None else name)
|
||||
|
|
Loading…
Reference in New Issue