streamlined column processing based on recently introduced asciitable functionality.
This commit is contained in:
parent
ef243d3e19
commit
812d17f91c
|
@ -58,15 +58,8 @@ strains = []
|
||||||
if options.right: stretches.append('U')
|
if options.right: stretches.append('U')
|
||||||
if options.left: stretches.append('V')
|
if options.left: stretches.append('V')
|
||||||
if options.logarithmic: strains.append('ln')
|
if options.logarithmic: strains.append('ln')
|
||||||
if options.biot: strains.append('Biot')
|
if options.biot: strains.append('Biot')
|
||||||
if options.green: strains.append('Green')
|
if options.green: strains.append('Green')
|
||||||
|
|
||||||
datainfo = { # list of requested labels per datatype
|
|
||||||
'defgrad': {'len':9,
|
|
||||||
'label':[]},
|
|
||||||
}
|
|
||||||
|
|
||||||
datainfo['defgrad']['label'] = options.defgrad
|
|
||||||
|
|
||||||
# ------------------------------------------ setup file handles ------------------------------------
|
# ------------------------------------------ setup file handles ------------------------------------
|
||||||
files = []
|
files = []
|
||||||
|
@ -86,38 +79,43 @@ for file in files:
|
||||||
table.head_read() # read ASCII header info
|
table.head_read() # read ASCII header info
|
||||||
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
|
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
|
||||||
|
|
||||||
active = []
|
# --------------- figure out columns to process ---------------------------------------------------
|
||||||
column = defaultdict(dict)
|
|
||||||
|
|
||||||
for label in datainfo['defgrad']['label']:
|
errors = []
|
||||||
key = '1_%s'%label
|
active = []
|
||||||
if key not in table.labels:
|
for i,length in enumerate(table.label_dimension(options.defgrad)):
|
||||||
sys.stderr.write('column %s not found...\n'%key)
|
if length == 9:
|
||||||
|
active.append(options.defgrad[i])
|
||||||
else:
|
else:
|
||||||
active.append(label)
|
errors.append('no deformation gradient tensor (1..9_%s) found...'%options.defgrad[i])
|
||||||
column[label] = table.labels.index(key)
|
|
||||||
|
if errors != []:
|
||||||
|
file['croak'].write('\n'.join(errors)+'\n')
|
||||||
|
table.close(dismiss = True)
|
||||||
|
continue
|
||||||
|
|
||||||
# ------------------------------------------ assemble header ---------------------------------------
|
# ------------------------------------------ assemble header ---------------------------------------
|
||||||
|
|
||||||
for label in active:
|
for label in active:
|
||||||
for theStretch in stretches:
|
for theStretch in stretches:
|
||||||
for theStrain in strains:
|
for theStrain in strains:
|
||||||
table.labels_append(['%i_%s(%s)%s'%(i+1,theStrain,theStretch,
|
table.labels_append(['%i_%s(%s)%s'%(i+1,
|
||||||
{True: label,False: ''}[label!='f'])for i in xrange(9)]) # extend ASCII header with new labels
|
theStrain,
|
||||||
|
theStretch,
|
||||||
|
label if label != 'f' else '') for i in xrange(9)]) # extend ASCII header with new labels
|
||||||
table.head_write()
|
table.head_write()
|
||||||
|
|
||||||
# ------------------------------------------ process data ------------------------------------------
|
# ------------------------------------------ process data ------------------------------------------
|
||||||
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 label in active: # loop over all requested norms
|
for column in table.label_index(active): # loop over all requested norms
|
||||||
F = np.array(map(float,table.data[column[label]:
|
F = np.array(map(float,table.data[column:column+9]),'d').reshape(3,3)
|
||||||
column[label]+datainfo['defgrad']['len']]),'d').reshape(3,3)
|
|
||||||
(U,S,Vh) = np.linalg.svd(F)
|
(U,S,Vh) = np.linalg.svd(F)
|
||||||
R = np.dot(U,Vh)
|
R = np.dot(U,Vh)
|
||||||
stretch['U'] = np.dot(np.linalg.inv(R),F)
|
stretch['U'] = np.dot(np.linalg.inv(R),F)
|
||||||
stretch['V'] = np.dot(F,np.linalg.inv(R))
|
stretch['V'] = np.dot(F,np.linalg.inv(R))
|
||||||
for theStretch in stretches:
|
for theStretch in stretches:
|
||||||
for i in range(9):
|
for i in xrange(9):
|
||||||
if abs(stretch[theStretch][i%3,i//3]) < 1e-12: # kill nasty noisy data
|
if abs(stretch[theStretch][i%3,i//3]) < 1e-12: # kill nasty noisy data
|
||||||
stretch[theStretch][i%3,i//3] = 0.0
|
stretch[theStretch][i%3,i//3] = 0.0
|
||||||
(D,V) = np.linalg.eig(stretch[theStretch]) # eigen decomposition (of symmetric matrix)
|
(D,V) = np.linalg.eig(stretch[theStretch]) # eigen decomposition (of symmetric matrix)
|
||||||
|
@ -138,7 +136,6 @@ for file in files:
|
||||||
# ------------------------------------------ output result -----------------------------------------
|
# ------------------------------------------ output result -----------------------------------------
|
||||||
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
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 table
|
||||||
table.output_close() # close output ASCII table (works for stdout)
|
|
||||||
if file['name'] != 'STDIN':
|
if file['name'] != 'STDIN':
|
||||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||||
|
|
Loading…
Reference in New Issue