improved help for automatic documentation and simplified some scripts

This commit is contained in:
Martin Diehl 2015-05-09 12:45:30 +00:00
parent 88e16f9344
commit 59e546e3d7
6 changed files with 33 additions and 67 deletions

View File

@ -30,12 +30,12 @@ parser.add_option('-l','--label', dest='labels', action='extend', metavar='<st
help='(list of) new column labels') help='(list of) new column labels')
parser.add_option('-f','--formula', dest='formulas', action='extend', metavar='<string LIST>', parser.add_option('-f','--formula', dest='formulas', action='extend', metavar='<string LIST>',
help='(list of) formulas corresponding to labels') help='(list of) formulas corresponding to labels')
parser.set_defaults(labels= [])
parser.set_defaults(formulas= [])
(options,filenames) = parser.parse_args() (options,filenames) = parser.parse_args()
if len(options.labels) != len(options.formulas): if options.labels == None or options.formulas == None:
parser.error('no formulas and/or labels specified')
elif len(options.labels) != len(options.formulas):
parser.error('number of labels (%i) and formulas (%i) do not match'%(len(options.labels),len(options.formulas))) parser.error('number of labels (%i) and formulas (%i) do not match'%(len(options.labels),len(options.formulas)))
for i in xrange(len(options.formulas)): for i in xrange(len(options.formulas)):
@ -104,8 +104,8 @@ for file in files:
if labelLen[label] == 0: if labelLen[label] == 0:
brokenFormula[label] = True brokenFormula[label] = True
if label not in brokenFormula: if label not in brokenFormula:
table.labels_append({True:['%i_%s'%(i+1,label) for i in xrange(labelLen[label])], table.labels_append(['%i_%s'%(i+1,label) for i in xrange(labelLen[label])] if labelLen[label]>1
False:label}[labelLen[label]>1] ) else label)
table.head_write() table.head_write()
firstLine = False firstLine = False

View File

@ -3,7 +3,6 @@
import os,sys,string import os,sys,string
import numpy as np import numpy as np
from collections import defaultdict
from optparse import OptionParser from optparse import OptionParser
import damask import damask
@ -28,16 +27,6 @@ parser.set_defaults(stress = 'p')
(options,filenames) = parser.parse_args() (options,filenames) = parser.parse_args()
datainfo = { # list of requested labels per datatype
'defgrad': {'len':9,
'label':[]},
'stress': {'len':9,
'label':[]},
}
datainfo['defgrad']['label'].append(options.defgrad)
datainfo['stress']['label'].append(options.stress)
# ------------------------------------------ setup file handles ------------------------------------ # ------------------------------------------ setup file handles ------------------------------------
files = [] files = []
if filenames == []: if filenames == []:
@ -57,36 +46,24 @@ for file in files:
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:])) table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
# --------------- figure out columns to process --------------------------------------------------- # --------------- figure out columns to process ---------------------------------------------------
active = defaultdict(list)
column = defaultdict(dict)
missingColumns = False missingColumns = False
column={ 'defgrad': table.labels.index('1_'+options.defgrad),
for datatype,info in datainfo.items(): 'stress': table.labels.index('1_'+options.stress)}
for label in info['label']: for key in column:
key = '1_%s'%label if column[key]<1:
if key not in table.labels:
file['croak'].write('column %s not found...\n'%key) file['croak'].write('column %s not found...\n'%key)
missingColumns = True # break if label not found missingColumns=True
else: if missingColumns: continue
active[datatype].append(label)
column[datatype][label] = table.labels.index(key) # remember columns of requested data
if missingColumns: # ------------------------------------------ assemble header --------------------------------------
continue
# ------------------------------------------ assemble header --------------------------------------
table.labels_append(['%i_Cauchy'%(i+1) for i in xrange(9)]) # extend ASCII header with new labels table.labels_append(['%i_Cauchy'%(i+1) 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
F = np.array(map(float,table.data[column['defgrad'][active['defgrad'][0]]: F = np.array(map(float,table.data[column['defgrad']:column['defgrad']+9]),'d').reshape(3,3)
column['defgrad'][active['defgrad'][0]]+datainfo['defgrad']['len']]),\ P = np.array(map(float,table.data[column['stress'] :column['stress']+9]),'d').reshape(3,3)
'd').reshape(3,3)
P = np.array(map(float,table.data[column['stress'][active['stress'][0]]:
column['stress'][active['stress'][0]]+datainfo['stress']['len']]),\
'd').reshape(3,3)
table.data_append(list(1.0/np.linalg.det(F)*np.dot(P,F.T).reshape(9))) # [Cauchy] = (1/det(F)) * [P].[F_transpose] table.data_append(list(1.0/np.linalg.det(F)*np.dot(P,F.T).reshape(9))) # [Cauchy] = (1/det(F)) * [P].[F_transpose]
outputAlive = table.data_write() # output processed line outputAlive = table.data_write() # output processed line

View File

@ -23,7 +23,7 @@ Operates on periodic ordered three-dimensional data sets.
parser.add_option('-c','--coordinates', dest='coords', metavar='string', parser.add_option('-c','--coordinates', dest='coords', metavar='string',
help='column heading for coordinates [%default]') help='column heading for coordinates [%default]')
parser.add_option('-f','--defgrad', dest='defgrad', metavar='string', parser.add_option('-f','--defgrad', dest='defgrad', metavar='string',
help='heading of columns containing tensor field values') help='heading of columns containing tensor field values [%default]')
parser.set_defaults(coords = 'ipinitialcoord') parser.set_defaults(coords = 'ipinitialcoord')
parser.set_defaults(defgrad = 'f' ) parser.set_defaults(defgrad = 'f' )

View File

@ -28,11 +28,10 @@ Add column(s) containing determinant of requested tensor column(s).
parser.add_option('-t','--tensor', dest='tensor', action='extend', metavar='<string LIST>', parser.add_option('-t','--tensor', dest='tensor', action='extend', metavar='<string LIST>',
help='heading of columns containing tensor field values') help='heading of columns containing tensor field values')
parser.set_defaults(tensor = [])
(options,filenames) = parser.parse_args() (options,filenames) = parser.parse_args()
if len(options.tensor) == 0: if options.tensor == None:
parser.error('no data column specified...') parser.error('no data column specified...')
datainfo = { # list of requested labels per datatype datainfo = { # list of requested labels per datatype
@ -60,10 +59,9 @@ 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:]))
# --------------- figure out columns to process ---------------------------------------------------
active = [] active = []
column = defaultdict(dict) column = defaultdict(dict)
# --------------- figure out columns to process ---------------------------------------------------
for label in datainfo['tensor']['label']: for label in datainfo['tensor']['label']:
key = '1_%s'%label key = '1_%s'%label
if key not in table.labels: if key not in table.labels:

View File

@ -30,12 +30,10 @@ parser.add_option('-t','--tensor', dest='tensor', action='extend', metavar=
help='heading of columns containing tensor field values') help='heading of columns containing tensor field values')
parser.add_option('-s','--spherical', dest='hydrostatic', action='store_true', parser.add_option('-s','--spherical', dest='hydrostatic', action='store_true',
help='also add sperical part of tensor (hydrostatic component, pressure)') help='also add sperical part of tensor (hydrostatic component, pressure)')
parser.set_defaults(hydrostatic = False)
parser.set_defaults(tensor = [])
(options,filenames) = parser.parse_args() (options,filenames) = parser.parse_args()
if len(options.tensor) == 0: if options.tensor == None:
parser.error('no data column specified...') parser.error('no data column specified...')
datainfo = { # list of requested labels per datatype datainfo = { # list of requested labels per datatype

View File

@ -10,11 +10,6 @@ import damask
scriptID = string.replace('$Id$','\n','\\n') scriptID = string.replace('$Id$','\n','\\n')
scriptName = os.path.splitext(scriptID.split()[1])[0] scriptName = os.path.splitext(scriptID.split()[1])[0]
#--------------------------------------------------------------------------------------------------
#> @brief calculates curl field using differentation in Fourier space
#> @todo enable odd resolution
#--------------------------------------------------------------------------------------------------
def divFFT(geomdim,field): def divFFT(geomdim,field):
grid = np.array(np.shape(field)[0:3]) grid = np.array(np.shape(field)[0:3])
wgt = 1.0/np.array(grid).prod() wgt = 1.0/np.array(grid).prod()
@ -73,12 +68,10 @@ parser.add_option('-v','--vector', dest='vector', action='extend', metavar=
parser.add_option('-t','--tensor', dest='tensor', action='extend', metavar='<string LIST>', parser.add_option('-t','--tensor', dest='tensor', action='extend', metavar='<string LIST>',
help='heading of columns containing tensor field values') help='heading of columns containing tensor field values')
parser.set_defaults(coords = 'ipinitialcoord') parser.set_defaults(coords = 'ipinitialcoord')
parser.set_defaults(vector = [])
parser.set_defaults(tensor = [])
(options,filenames) = parser.parse_args() (options,filenames) = parser.parse_args()
if len(options.vector) + len(options.tensor) == 0: if (options.vector == None) and (options.tensor == None):
parser.error('no data column specified...') parser.error('no data column specified...')
datainfo = { # list of requested labels per datatype datainfo = { # list of requested labels per datatype