improved help for automatic documentation and simplified some scripts

This commit is contained in:
Martin Diehl 2015-05-09 21:32:23 +00:00
parent 213d096932
commit 18831e0e80
6 changed files with 59 additions and 81 deletions

View File

@ -21,29 +21,28 @@ Orientation is given by quaternion, Euler angles, rotation matrix, or crystal fr
outputChoices = ['quaternion','eulers']
parser.add_option('-o', '--output', dest='output', action='extend', metavar='<string LIST>',
help = 'output orientation formats (%s)'%(','.join(outputChoices)))
help = 'output orientation formats {%s}'%(','.join(outputChoices)))
parser.add_option('-s', '--symmetry', dest='symmetry', type='choice',
choices=damask.Symmetry.lattices[1:], metavar='string',
help = 'crystal symmetry (%s) [cubic]'%(', '.join(damask.Symmetry.lattices[1:])))
choices=damask.Symmetry.lattices[1:], metavar='string',
help = 'crystal symmetry [cubic] {%s}'%(', '.join(damask.Symmetry.lattices[1:])))
parser.add_option('-r', '--rotation', dest='rotation', type='float', nargs=4, metavar='float float float float',
help = 'angle and axis to (pre)rotate orientation')
help = 'angle and axis to (pre)rotate orientation')
parser.add_option('-e', '--eulers', dest='eulers', metavar='string',
help = 'Euler angles label')
help = 'Euler angles label')
parser.add_option('-d', '--degrees', dest='degrees', action='store_true',
help = 'Euler angles are given in degrees [%default]')
help = 'Euler angles are given in degrees [%default]')
parser.add_option('-m', '--matrix', dest='matrix', metavar='string',
help = 'orientation matrix label')
help = 'orientation matrix label')
parser.add_option('-a', dest='a', metavar='string',
help = 'crystal frame a vector label')
help = 'crystal frame a vector label')
parser.add_option('-b', dest='b', metavar='string',
help = 'crystal frame b vector label')
help = 'crystal frame b vector label')
parser.add_option('-c', dest='c', metavar='string',
help = 'crystal frame c vector label')
help = 'crystal frame c vector label')
parser.add_option('-q', '--quaternion', dest='quaternion', metavar='string',
help = 'quaternion label')
parser.set_defaults(output = [])
help = 'quaternion label')
parser.set_defaults(symmetry = 'cubic')
parser.set_defaults(rotation = [0.,1.,1.,1.]) # no rotation about 1,1,1
parser.set_defaults(rotation = (0.,1.,1.,1.)) # no rotation about 1,1,1
parser.set_defaults(degrees = False)
(options, filenames) = parser.parse_args()
@ -75,10 +74,8 @@ if options.quaternion != None:
datainfo['quaternion']['label'] += [options.quaternion]
input = 'quaternion'
inputGiven = 0
for datatype,info in datainfo.items():
inputGiven += len(info['label'])
if inputGiven != 1: parser.error('select exactly one input format...')
if len(input) != 1: parser.error('needs exactly one input format...')
input = input[0]
toRadians = math.pi/180.0 if options.degrees else 1.0 # rescale degrees to radians
options.output = map(lambda x: x.lower(), options.output)

View File

@ -20,24 +20,14 @@ Add column(s) containing Second Piola--Kirchhoff stress based on given column(s)
""", version = scriptID)
parser.add_option('-f','--defgrad', dest='defgrad', metavar='string',
help='heading of columns containing deformation gradient [%default]')
help='heading of columns containing deformation gradient [%default]')
parser.add_option('-p','--stress', dest='stress', metavar='string',
help='heading of columns containing first Piola--Kirchhoff stress [%default]')
help='heading of columns containing first Piola--Kirchhoff stress [%default]')
parser.set_defaults(defgrad = 'f')
parser.set_defaults(stress = 'p')
(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 ------------------------------------
files = []
if filenames == []:
@ -56,37 +46,28 @@ for file in files:
table.head_read() # read ASCII header info
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
# --------------- figure out columns to process ---------------------------------------------------
missingColumns = False
column={ 'defgrad': table.labels.index('1_'+options.defgrad),
'stress': table.labels.index('1_'+options.stress)}
for key in column:
if column[key]<1:
file['croak'].write('column %s not found...\n'%key)
missingColumns=True
if missingColumns: continue
active = defaultdict(list)
column = defaultdict(dict)
missingColumns = False
for datatype,info in datainfo.items():
for label in info['label']:
key = '1_%s'%label
if key not in table.labels:
file['croak'].write('column %s not found...\n'%key)
missingColumns = True # break if label not found
else:
active[datatype].append(label)
column[datatype][label] = table.labels.index(key) # remember columns of requested data
if missingColumns:
continue
# ------------------------------------------ assemble header --------------------------------------
# ------------------------------------------ assemble header --------------------------------------
table.labels_append(['%i_S'%(i+1) for i in xrange(datainfo['stress']['len'])]) # extend ASCII header with new labels
table.head_write()
# ------------------------------------------ process data ------------------------------------------
outputAlive = True
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]]:
column['defgrad'][active['defgrad'][0]]+
datainfo['defgrad']['len']]),'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)
F = np.array(map(float,table.data[column['defgrad']:column['defgrad']+9]),'d').reshape(3,3)
P = np.array(map(float,table.data[column['stress'] :column['stress']+9]),'d').reshape(3,3)
table.data_append(list(np.dot(np.linalg.inv(F),P).reshape(9))) # [S] =[P].[F-1]
outputAlive = table.data_write() # output processed line

View File

@ -19,24 +19,24 @@ Add x,y coordinates of stereographic projection of given direction (pole) in cry
""", version = scriptID)
parser.add_option('-p', '--pole', dest='pole', type='float', nargs=3, metavar='float float float',
help = 'crystal frame direction for pole figure %default')
help = 'crystal frame direction for pole figure [%default]')
parser.add_option('--polar', dest='polar', action='store_true',
help = 'output polar coordinates r,phi [%default]')
help = 'output polar coordinates r,phi [%default]')
parser.add_option('-e', '--eulers', dest='eulers', metavar='string',
help = 'Euler angles label')
help = 'Euler angles label')
parser.add_option('-d', '--degrees', dest='degrees', action='store_true',
help = 'Euler angles are given in degrees [%default]')
help = 'Euler angles are given in degrees [%default]')
parser.add_option('-m', '--matrix', dest='matrix', metavar='string',
help = 'orientation matrix label')
help = 'orientation matrix label')
parser.add_option('-a', dest='a', metavar='string',
help = 'crystal frame a vector label')
help = 'crystal frame a vector label')
parser.add_option('-b', dest='b', metavar='string',
help = 'crystal frame b vector label')
help = 'crystal frame b vector label')
parser.add_option('-c', dest='c', metavar='string',
help = 'crystal frame c vector label')
help = 'crystal frame c vector label')
parser.add_option('-q', '--quaternion', dest='quaternion', metavar='string',
help = 'quaternion label')
parser.set_defaults(pole = [1.0,0.0,0.0])
help = 'quaternion label')
parser.set_defaults(pole = (1.0,0.0,0.0))
parser.set_defaults(degrees = False)
parser.set_defaults(polar = False)

View File

@ -247,33 +247,34 @@ Add columns listing Schmid factors (and optional trace vector of selected system
""", version = scriptID)
parser.add_option('-l','--lattice', dest='lattice', type='choice',
choices=('fcc','bcc','hex'), metavar='string',
help="type of lattice structure {'fcc','bcc','hex'} [%default]")
parser.add_option('-l','--lattice', dest='lattice', type='choice', choices=('fcc','bcc','hex'), metavar='string',
help="type of lattice structure [%default] {fcc,bcc',hex}")
parser.add_option('--direction', dest='forcedirection', type='int', nargs=3, metavar='int int int',
help='force direction in lab coordinates %default')
help='force direction in lab coordinates %default')
parser.add_option('-n','--normal', dest='stressnormal', type='int', nargs=3, metavar='int int int',
help='stress plane normal in lab coordinates ')
help='stress plane normal in lab coordinates ')
parser.add_option('--trace', dest='traceplane', type='int', nargs=3, metavar='int int int',
help='normal (in lab coordinates) of plane on which the plane trace of the Schmid factor(s) is reported')
help='normal (in lab coordinates) of plane on which the plane trace of the Schmid factor(s) is reported')
parser.add_option('--covera', dest='CoverA', type='float', metavar='float',
help='C over A ratio for hexagonal systems')
help='C over A ratio for hexagonal systems')
parser.add_option('-r','--rank', dest='rank', type='int', nargs=3, metavar='int int int',
help="report trace of r'th highest Schmid factor [%default]")
help="report trace of r'th highest Schmid factor [%default]")
parser.add_option('-e', '--eulers', dest='eulers', metavar='string',
help='Euler angles label')
help='Euler angles label')
parser.add_option('-d', '--degrees', dest='degrees', action='store_true',
help='Euler angles are given in degrees [%default]')
help='Euler angles are given in degrees [%default]')
parser.set_defaults(lattice = 'fcc')
parser.set_defaults(forcedirection = [0, 0, 1])
parser.set_defaults(forcedirection = (0, 0, 1))
parser.set_defaults(stressnormal = None)
parser.set_defaults(traceplane = None)
parser.set_defaults(rank = 0)
parser.set_defaults(CoverA = 1.587)
parser.set_defaults(eulers = 'eulerangles')
(options,filenames) = parser.parse_args()
if options.lattice=='hex' and options.CoverA == None:
parser.error('hex lattice needs c over a ration...')
options.forcedirection = normalize(options.forcedirection)
if options.stressnormal:
if abs(sum([options.forcedirection[i] * options.stressnormal[i] for i in range(3)])) < 1e-3:

View File

@ -20,12 +20,11 @@ Add column(s) containing eigenvalues and eigenvectors of requested tensor column
""", version = scriptID)
parser.add_option('-t','--tensor', dest='tensor', action='extend', metavar='<string LIST>',
help='heading of columns containing tensor field values')
parser.set_defaults(tensor = [])
help='heading of columns containing tensor field values')
(options,filenames) = parser.parse_args()
if len(options.tensor) == 0:
if options.tensor == None:
parser.error('no data column specified...')
datainfo = { # list of requested labels per datatype

View File

@ -31,17 +31,17 @@ Add column(s) containing given strains based on given stretches of requested def
""", version = scriptID)
parser.add_option('-u','--right', dest='right', action='store_true',
help='material strains based on right Cauchy--Green deformation, i.e., C and U [%default]')
help='material strains based on right Cauchy--Green deformation, i.e., C and U [%default]')
parser.add_option('-v','--left', dest='left', action='store_true',
help='spatial strains based on left Cauchy--Green deformation, i.e., B and V [%default]')
help='spatial strains based on left Cauchy--Green deformation, i.e., B and V [%default]')
parser.add_option('-l','-0','--logarithmic', dest='logarithmic', action='store_true',
help='calculate logarithmic strain tensor [%default]')
help='calculate logarithmic strain tensor [%default]')
parser.add_option('-b','-1','--biot', dest='biot', action='store_true',
help='calculate biot strain tensor [%default]')
help='calculate biot strain tensor [%default]')
parser.add_option('-g','-2','--green', dest='green', action='store_true',
help='calculate green strain tensor [%default]')
help='calculate green strain tensor [%default]')
parser.add_option('-f','--defgrad', dest='defgrad', action='extend', metavar = '<string LIST>',
help='heading(s) of columns containing deformation tensor values %default')
help='heading(s) of columns containing deformation tensor values %default')
parser.set_defaults(right = False)
parser.set_defaults(left = False)
parser.set_defaults(logarithmic = False)