modernized string formatting, updated help strings, using label_indexrange for data-slicing.

This commit is contained in:
Philip Eisenlohr 2016-04-24 10:09:28 -05:00
parent 45e237058b
commit 9e5a8d2391
1 changed files with 89 additions and 82 deletions

View File

@ -112,84 +112,92 @@ Generate geometry description and material configuration by standard Voronoi tes
group = OptionGroup(parser, "Tessellation","") group = OptionGroup(parser, "Tessellation","")
group.add_option('-l', '--laguerre', group.add_option('-l',
dest = 'laguerre', '--laguerre',
action = 'store_true', dest = 'laguerre',
help = 'use Laguerre (weighted Voronoi) tessellation') action = 'store_true',
help = 'use Laguerre (weighted Voronoi) tessellation')
group.add_option('--cpus', group.add_option('--cpus',
dest = 'cpus', dest = 'cpus',
type = 'int', metavar = 'int', type = 'int', metavar = 'int',
help = 'number of parallel processes to use for Laguerre tessellation [%default]') help = 'number of parallel processes to use for Laguerre tessellation [%default]')
group.add_option('--nonperiodic', group.add_option('--nonperiodic',
dest = 'nonperiodic', dest = 'nonperiodic',
action = 'store_true', action = 'store_true',
help = 'use nonperiodic tessellation') help = 'nonperiodic tessellation')
parser.add_option_group(group) parser.add_option_group(group)
group = OptionGroup(parser, "Geometry","") group = OptionGroup(parser, "Geometry","")
group.add_option('-g', '--grid', group.add_option('-g',
dest = 'grid', '--grid',
type = 'int', nargs = 3, metavar = ' '.join(['int']*3), dest = 'grid',
help = 'a,b,c grid of hexahedral box [auto]') type = 'int', nargs = 3, metavar = ' '.join(['int']*3),
group.add_option('-s', '--size', help = 'a,b,c grid of hexahedral box [auto]')
dest = 'size', group.add_option('-s',
type = 'float', nargs = 3, metavar=' '.join(['float']*3), '--size',
help = 'x,y,z size of hexahedral box [auto]') dest = 'size',
group.add_option('-o', '--origin', type = 'float', nargs = 3, metavar=' '.join(['float']*3),
dest = 'origin', help = 'x,y,z size of hexahedral box [auto]')
type = 'float', nargs = 3, metavar=' '.join(['float']*3), group.add_option('-o',
help = 'origin of grid') '--origin',
dest = 'origin',
type = 'float', nargs = 3, metavar=' '.join(['float']*3),
help = 'origin of grid')
parser.add_option_group(group) parser.add_option_group(group)
group = OptionGroup(parser, "Seeds","") group = OptionGroup(parser, "Seeds","")
group.add_option('-p', '--position', group.add_option('-p',
dest = 'position', '--pos', '--seedposition',
dest = 'pos',
type = 'string', metavar = 'string', type = 'string', metavar = 'string',
help = 'column label for seed positions [%default]') help = 'label of coordinates [%default]')
group.add_option('-w', '--weight', group.add_option('-w',
dest = 'weight', '--weight',
type = 'string', metavar = 'string', dest = 'weight',
help = 'column label for seed weights [%default]') type = 'string', metavar = 'string',
group.add_option('-m', '--microstructure', help = 'label of weights [%default]')
dest = 'microstructure', group.add_option('-m',
type = 'string', metavar = 'string', '--microstructure',
help = 'column label for seed microstructures [%default]') dest = 'microstructure',
group.add_option('-e', '--eulers', type = 'string', metavar = 'string',
dest = 'eulers', help = 'label of microstructures [%default]')
type = 'string', metavar = 'string', group.add_option('-e',
help = 'column label for seed Euler angles [%default]') '--eulers',
dest = 'eulers',
type = 'string', metavar = 'string',
help = 'label of Euler angles [%default]')
group.add_option('--axes', group.add_option('--axes',
dest = 'axes', dest = 'axes',
type = 'string', nargs = 3, metavar = ' '.join(['string']*3), type = 'string', nargs = 3, metavar = ' '.join(['string']*3),
help = 'orientation coordinate frame in terms of position coordinate frame') help = 'orientation coordinate frame in terms of position coordinate frame')
parser.add_option_group(group) parser.add_option_group(group)
group = OptionGroup(parser, "Configuration","") group = OptionGroup(parser, "Configuration","")
group.add_option('--homogenization', group.add_option('--homogenization',
dest = 'homogenization', dest = 'homogenization',
type = 'int', metavar = 'int', type = 'int', metavar = 'int',
help = 'homogenization index to be used [%default]') help = 'homogenization index to be used [%default]')
group.add_option('--crystallite', group.add_option('--crystallite',
dest = 'crystallite', dest = 'crystallite',
type = 'int', metavar = 'int', type = 'int', metavar = 'int',
help = 'crystallite index to be used [%default]') help = 'crystallite index to be used [%default]')
group.add_option('--phase', group.add_option('--phase',
dest = 'phase', dest = 'phase',
type = 'int', metavar = 'int', type = 'int', metavar = 'int',
help = 'phase index to be used [%default]') help = 'phase index to be used [%default]')
parser.add_option_group(group) parser.add_option_group(group)
parser.set_defaults(position = 'pos', parser.set_defaults(pos = 'pos',
weight = 'weight', weight = 'weight',
microstructure = 'microstructure', microstructure = 'microstructure',
eulers = 'eulerangles', eulers = 'euler',
homogenization = 1, homogenization = 1,
crystallite = 1, crystallite = 1,
phase = 1, phase = 1,
@ -205,7 +213,7 @@ if filenames == []: filenames = [None]
for name in filenames: for name in filenames:
try: table = damask.ASCIItable(name = name, try: table = damask.ASCIItable(name = name,
outname = os.path.splitext(name)[-2]+'.geom' if name else name, outname = os.path.splitext(name)[0]+'.geom' if name else name,
buffered = False) buffered = False)
except: continue except: continue
damask.util.report(scriptName,name) damask.util.report(scriptName,name)
@ -238,11 +246,11 @@ for name in filenames:
info['size'][i] = float(info['grid'][i])/max(info['grid']) # normalize to grid info['size'][i] = float(info['grid'][i])/max(info['grid']) # normalize to grid
remarks.append('rescaling size {} to {}...'.format({0:'x',1:'y',2:'z'}[i],info['size'][i])) remarks.append('rescaling size {} to {}...'.format({0:'x',1:'y',2:'z'}[i],info['size'][i]))
if table.label_dimension(options.position) != 3: if table.label_dimension(options.pos) != 3:
errors.append('position columns "{}" have dimension {}.'.format(options.position, errors.append('seed positions "{}" have dimension {}.'.format(options.pos,
table.label_dimension(options.position))) table.label_dimension(options.pos)))
else: else:
labels += [options.position] labels += [options.pos]
if not hasEulers: remarks.append('missing seed orientations...') if not hasEulers: remarks.append('missing seed orientations...')
else: labels += [options.eulers] else: labels += [options.eulers]
@ -260,15 +268,14 @@ for name in filenames:
# ------------------------------------------ read seeds --------------------------------------- # ------------------------------------------ read seeds ---------------------------------------
table.data_readArray(labels) table.data_readArray(labels)
coords = table.data[:,table.label_index(options.position):table.label_index(options.position)+3]\ coords = table.data[:,table.label_indexrange(options.pos)] * info['size']
* info['size'] eulers = table.data[:,table.label_indexrange(options.eulers)] if hasEulers \
eulers = table.data[:,table.label_index(options.eulers ):table.label_index(options.eulers )+3]\ else np.zeros(3*len(coords))
if hasEulers else np.zeros(3*len(coords)) grains = table.data[:,table.label_indexrange(options.microstructure)].astype('i') if hasGrains \
grains = table.data[:,table.label_index(options.microstructure)].astype('i')\ else 1+np.arange(len(coords))
if hasGrains else 1+np.arange(len(coords)) weights = table.data[:,table.label_indexrange(options.weight)] if hasWeights \
weights = table.data[:,table.label_index(options.weight)]\ else np.zeros(len(coords))
if hasWeights else np.zeros(len(coords)) grainIDs = np.unique(grains).astype('i')
grainIDs = np.unique(grains).astype('i')
NgrainIDs = len(grainIDs) NgrainIDs = len(grainIDs)
# --- tessellate microstructure ------------------------------------------------------------ # --- tessellate microstructure ------------------------------------------------------------
@ -289,12 +296,12 @@ for name in filenames:
if info['homogenization'] == 0: info['homogenization'] = options.homogenization if info['homogenization'] == 0: info['homogenization'] = options.homogenization
damask.util.croak(['grid a b c: %s'%(' x '.join(map(str,info['grid']))), damask.util.croak(['grid a b c: {}'.format(' x '.join(map(str,info['grid']))),
'size x y z: %s'%(' x '.join(map(str,info['size']))), 'size x y z: {}'.format(' x '.join(map(str,info['size']))),
'origin x y z: %s'%(' : '.join(map(str,info['origin']))), 'origin x y z: {}'.format(' : '.join(map(str,info['origin']))),
'homogenization: %i'%info['homogenization'], 'homogenization: {}'.format(info['homogenization']),
'microstructures: %i%s'%(info['microstructures'], 'microstructures: {}{}'.format(info['microstructures'],
(' out of %i'%NgrainIDs if NgrainIDs != info['microstructures'] else '')), (' out of {}'.format(NgrainIDs) if NgrainIDs != info['microstructures'] else '')),
]) ])
config_header = [] config_header = []
@ -302,28 +309,28 @@ for name in filenames:
config_header += ['<microstructure>'] config_header += ['<microstructure>']
for i,ID in enumerate(grainIDs): for i,ID in enumerate(grainIDs):
config_header += ['[Grain%s]'%(str(ID).zfill(formatwidth)), config_header += ['[Grain{}]'.format(str(ID).zfill(formatwidth)),
'crystallite %i'%options.crystallite, 'crystallite {}'.format(options.crystallite),
'(constituent)\tphase %i\ttexture %s\tfraction 1.0'%(options.phase,str(ID).rjust(formatwidth)), '(constituent)\tphase {}\ttexture {}\tfraction 1.0'.format(options.phase,str(ID).rjust(formatwidth)),
] ]
if hasEulers: if hasEulers:
config_header += ['<texture>'] config_header += ['<texture>']
for ID in grainIDs: for ID in grainIDs:
eulerID = np.nonzero(grains == ID)[0][0] # find first occurrence of this grain id eulerID = np.nonzero(grains == ID)[0][0] # find first occurrence of this grain id
config_header += ['[Grain%s]'%(str(ID).zfill(formatwidth)), config_header += ['[Grain{}]'.format(str(ID).zfill(formatwidth)),
'(gauss)\tphi1 %g\tPhi %g\tphi2 %g\tscatter 0.0\tfraction 1.0'%tuple(eulers[eulerID]) '(gauss)\tphi1 {:g}\tPhi {:g}\tphi2 {:g}\tscatter 0.0\tfraction 1.0'.format(*eulers[eulerID])
] ]
if options.axes is not None: config_header.append('axes\t%s %s %s'%tuple(options.axes)) if options.axes is not None: config_header.append('axes\t{} {} {}'.format(*options.axes))
table.labels_clear() table.labels_clear()
table.info_clear() table.info_clear()
table.info_append([ table.info_append([
scriptID + ' ' + ' '.join(sys.argv[1:]), scriptID + ' ' + ' '.join(sys.argv[1:]),
"grid\ta {grid[0]}\tb {grid[1]}\tc {grid[2]}".format(grid=info['grid']), "grid\ta {}\tb {}\tc {}".format(*info['grid']),
"size\tx {size[0]}\ty {size[1]}\tz {size[2]}".format(size=info['size']), "size\tx {}\ty {}\tz {}".format(*info['size']),
"origin\tx {origin[0]}\ty {origin[1]}\tz {origin[2]}".format(origin=info['origin']), "origin\tx {}\ty {}\tz {}".format(*info['origin']),
"homogenization\t{homog}".format(homog=info['homogenization']), "homogenization\t{}".format(info['homogenization']),
"microstructures\t{microstructures}".format(microstructures=info['microstructures']), "microstructures\t{}".format(info['microstructures']),
config_header, config_header,
]) ])
table.head_write() table.head_write()