Merge branch 'development' of magit1.mpie.de:damask/DAMASK into development

This commit is contained in:
Martin Diehl 2016-04-24 18:58:32 +02:00
commit 33391fcf5b
4 changed files with 69 additions and 48 deletions

View File

@ -53,6 +53,20 @@ def report(who,what):
"""reports script and file name"""
croak( (emph(who) if who else '') + (': '+what if what else '') )
# -----------------------------
def report_geom(info,
what = ['grid','size','origin','homogenization','microstructures']):
"""reports (selected) geometry information"""
output = {
'grid' : 'grid a b c: {}'.format(' x '.join(map(str,info['grid' ]))),
'size' : 'size x y z: {}'.format(' x '.join(map(str,info['size' ]))),
'origin' : 'origin x y z: {}'.format(' : '.join(map(str,info['origin']))),
'homogenization' : 'homogenization: {}'.format(info['homogenization']),
'microstructures' : 'microstructures: {}'.format(info['microstructures']),
}
for item in what: croak(output[item.lower()])
# -----------------------------
def emph(what):
"""emphasizes string on screen"""

View File

@ -15,25 +15,29 @@ scriptID = ' '.join([scriptName,damask.version])
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
Changes the (three-dimensional) canvas of a spectral geometry description.
Grid can be given as absolute or relative values, e.g. 16 16 16 or 2x 0.5x 32.
""", version = scriptID)
parser.add_option('-g', '--grid',
parser.add_option('-g',
'--grid',
dest = 'grid',
type = 'string', nargs = 3, metavar = ' '.join(['string']*3),
help = 'a,b,c grid of hexahedral box [auto]')
parser.add_option('-o', '--offset',
help = 'a,b,c grid of hexahedral box. [auto]')
parser.add_option('-o',
'--offset',
dest = 'offset',
type = 'int', nargs = 3, metavar = ' '.join(['int']*3),
help = 'a,b,c offset from old to new origin of grid [%default]')
parser.add_option('-f', '--fill',
parser.add_option('-f',
'--fill',
dest = 'fill',
type = 'float', metavar = 'float',
help = '(background) canvas grain index. "0" selects maximum microstructure index + 1 [%default]')
parser.add_option('--float',
dest = 'real',
action = 'store_true',
help = 'input data is float [%default]')
help = 'use float input')
parser.set_defaults(grid = ['0','0','0'],
offset = (0,0,0),
@ -61,13 +65,7 @@ for name in filenames:
table.head_read()
info,extra_header = table.head_getGeom()
damask.util.croak(['grid a b c: %s'%(' x '.join(map(str,info['grid']))),
'size x y z: %s'%(' x '.join(map(str,info['size']))),
'origin x y z: %s'%(' : '.join(map(str,info['origin']))),
'homogenization: %i'%info['homogenization'],
'microstructures: %i'%info['microstructures'],
])
damask.util.report_geom(info)
errors = []
if np.any(info['grid'] < 1): errors.append('invalid grid a b c.')
@ -105,7 +103,7 @@ for name in filenames:
translate_y = [i - options.offset[1] for i in yindex]
translate_z = [i - options.offset[2] for i in zindex]
if 0 in map(len,[xindex,yindex,zindex,translate_x,translate_y,translate_z]):
damask.util.croak('Invaldid grid-offset comination')
damask.util.croak('invaldid grid-offset combination.')
table.close(dismiss = True)
continue
microstructure_cropped[min(translate_x):(max(translate_x)+1),\
@ -125,13 +123,13 @@ for name in filenames:
errors = []
if (any(newInfo['grid'] != info['grid'])):
remarks.append('--> grid a b c: %s'%(' x '.join(map(str,newInfo['grid']))))
remarks.append('--> grid a b c: {}'.format(' x '.join(map(str,newInfo['grid']))))
if (any(newInfo['size'] != info['size'])):
remarks.append('--> size x y z: %s'%(' x '.join(map(str,newInfo['size']))))
remarks.append('--> size x y z: {}'.format(' x '.join(map(str,newInfo['size']))))
if (any(newInfo['origin'] != info['origin'])):
remarks.append('--> origin x y z: %s'%(' : '.join(map(str,newInfo['origin']))))
remarks.append('--> origin x y z: {}'.format(' : '.join(map(str,newInfo['origin']))))
if ( newInfo['microstructures'] != info['microstructures']):
remarks.append('--> microstructures: %i'%newInfo['microstructures'])
remarks.append('--> microstructures: {}'.format(newInfo['microstructures']))
if np.any(newInfo['grid'] < 1): errors.append('invalid new grid a b c.')
if np.any(newInfo['size'] <= 0.0): errors.append('invalid new size x y z.')
@ -147,11 +145,11 @@ for name in filenames:
table.info_clear()
table.info_append([
scriptID + ' ' + ' '.join(sys.argv[1:]),
"grid\ta {grid[0]}\tb {grid[1]}\tc {grid[2]}".format(grid=newInfo['grid']),
"size\tx {size[0]}\ty {size[1]}\tz {size[2]}".format(size=newInfo['size']),
"origin\tx {origin[0]}\ty {origin[1]}\tz {origin[2]}".format(origin=newInfo['origin']),
"homogenization\t{homog}".format(homog=info['homogenization']),
"microstructures\t{microstructures}".format(microstructures=newInfo['microstructures']),
"grid\ta {}\tb {}\tc {}".format(*newInfo['grid']),
"size\tx {}\ty {}\tz {}".format(*newInfo['size']),
"origin\tx {}\ty {}\tz {}".format(*newInfo['origin']),
"homogenization\t{}".format(info['homogenization']),
"microstructures\t{}".format(newInfo['microstructures']),
extra_header
])
table.labels_clear()

View File

@ -296,13 +296,10 @@ for name in filenames:
if info['homogenization'] == 0: info['homogenization'] = options.homogenization
damask.util.croak(['grid a b c: {}'.format(' x '.join(map(str,info['grid']))),
'size x y z: {}'.format(' x '.join(map(str,info['size']))),
'origin x y z: {}'.format(' : '.join(map(str,info['origin']))),
'homogenization: {}'.format(info['homogenization']),
'microstructures: {}{}'.format(info['microstructures'],
damask.util.report_geom(info,['grid','size','origin','homogenization',])
damask.util.croak(['microstructures: {}{}'.format(info['microstructures'],
(' out of {}'.format(NgrainIDs) if NgrainIDs != info['microstructures'] else '')),
])
])
config_header = []
formatwidth = 1+int(math.log10(NgrainIDs))

View File

@ -23,29 +23,38 @@ Examples:
""", version = scriptID)
parser.add_option('-p', '--positions',
dest = 'pos',
type = 'string', metavar = 'string',
help = 'coordinate label [%default]')
parser.add_option('-p',
'--pos', '--seedposition',
dest = 'pos',
type = 'string', metavar = 'string',
help = 'label of coordinates [%default]')
parser.add_option('--boundingbox',
dest = 'box',
type = 'float', nargs = 6, metavar = ' '.join(['float']*6),
help = 'min (x,y,z) and max (x,y,z) coordinates of bounding box [tight]')
parser.add_option('-i', '--index',
dest = 'index',
parser.add_option('-m',
'--microstructure',
dest = 'microstructure',
type = 'string', metavar = 'string',
help = 'microstructure index label [%default]')
parser.add_option('-w','--white',
help = 'label of microstructures [%default]')
parser.add_option('--weight',
dest = 'weight',
type = 'string', metavar = 'string',
help = 'label of weights [%default]')
parser.add_option('-w',
'--white',
dest = 'whitelist',
action = 'extend', metavar = '<int LIST>',
help = 'whitelist of microstructure indices')
parser.add_option('-b','--black',
parser.add_option('-b',
'--black',
dest = 'blacklist',
action = 'extend', metavar = '<int LIST>',
help = 'blacklist of microstructure indices')
parser.set_defaults(pos = 'pos',
index ='microstructure',
parser.set_defaults(pos = 'pos',
microstructure = 'microstructure',
weight = None,
)
(options,filenames) = parser.parse_args()
@ -58,10 +67,9 @@ if options.blacklist is not None: options.blacklist = map(int,options.blacklist)
if filenames == []: filenames = [None]
for name in filenames:
try:
table = damask.ASCIItable(name = name,
outname = os.path.splitext(name)[0]+'.seeds' if name else name,
buffered = False)
try: table = damask.ASCIItable(name = name,
outname = os.path.splitext(name)[0]+'.seeds' if name else name,
buffered = False)
except: continue
damask.util.report(scriptName,name)
@ -69,14 +77,17 @@ for name in filenames:
# ------------------------------------------ sanity checks ---------------------------------------
missing_labels = table.data_readArray([options.pos,options.index])
missing_labels = table.data_readArray([options.pos,options.microstructure] +
([options.weight] if options.weight else []))
errors = []
if len(missing_labels) > 0:
errors.append('column{} {} not found'.format('s' if len(missing_labels) > 1 else '',
', '.join(missing_labels)))
for label, dim in {options.pos: 3,
options.index: 1}.iteritems():
input = {options.pos: 3,
options.microstructure: 1,}
if options.weight: input.update({options.weight: 1})
for label, dim in input.iteritems():
if table.label_dimension(label) != dim:
errors.append('column {} has wrong dimension'.format(label))
@ -113,11 +124,12 @@ for name in filenames:
table.info = [
scriptID,
'size %s'%(' '.join(list(itertools.chain.from_iterable(zip(['x','y','z'],
'size {}'.format(' '.join(list(itertools.chain.from_iterable(zip(['x','y','z'],
map(str,boundingBox[1,:]-boundingBox[0,:])))))),
]
table.labels_clear()
table.labels_append(['1_pos','2_pos','3_pos','microstructure']) # implicitly switching label processing/writing on
table.labels_append(['1_pos','2_pos','3_pos','microstructure'] +
['weight'] if options.weight else []) # implicitly switching label processing/writing on
table.head_write()
# ------------------------------------------ output result ---------------------------------------