Merge branch 'development' of magit1.mpie.de:damask/DAMASK into development
This commit is contained in:
commit
33391fcf5b
|
@ -53,6 +53,20 @@ def report(who,what):
|
||||||
"""reports script and file name"""
|
"""reports script and file name"""
|
||||||
croak( (emph(who) if who else '') + (': '+what if what else '') )
|
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):
|
def emph(what):
|
||||||
"""emphasizes string on screen"""
|
"""emphasizes string on screen"""
|
||||||
|
|
|
@ -15,25 +15,29 @@ scriptID = ' '.join([scriptName,damask.version])
|
||||||
|
|
||||||
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
|
||||||
Changes the (three-dimensional) canvas of a spectral geometry 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)
|
""", version = scriptID)
|
||||||
|
|
||||||
parser.add_option('-g', '--grid',
|
parser.add_option('-g',
|
||||||
|
'--grid',
|
||||||
dest = 'grid',
|
dest = 'grid',
|
||||||
type = 'string', nargs = 3, metavar = ' '.join(['string']*3),
|
type = 'string', nargs = 3, metavar = ' '.join(['string']*3),
|
||||||
help = 'a,b,c grid of hexahedral box [auto]')
|
help = 'a,b,c grid of hexahedral box. [auto]')
|
||||||
parser.add_option('-o', '--offset',
|
parser.add_option('-o',
|
||||||
|
'--offset',
|
||||||
dest = 'offset',
|
dest = 'offset',
|
||||||
type = 'int', nargs = 3, metavar = ' '.join(['int']*3),
|
type = 'int', nargs = 3, metavar = ' '.join(['int']*3),
|
||||||
help = 'a,b,c offset from old to new origin of grid [%default]')
|
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',
|
dest = 'fill',
|
||||||
type = 'float', metavar = 'float',
|
type = 'float', metavar = 'float',
|
||||||
help = '(background) canvas grain index. "0" selects maximum microstructure index + 1 [%default]')
|
help = '(background) canvas grain index. "0" selects maximum microstructure index + 1 [%default]')
|
||||||
parser.add_option('--float',
|
parser.add_option('--float',
|
||||||
dest = 'real',
|
dest = 'real',
|
||||||
action = 'store_true',
|
action = 'store_true',
|
||||||
help = 'input data is float [%default]')
|
help = 'use float input')
|
||||||
|
|
||||||
parser.set_defaults(grid = ['0','0','0'],
|
parser.set_defaults(grid = ['0','0','0'],
|
||||||
offset = (0,0,0),
|
offset = (0,0,0),
|
||||||
|
@ -61,13 +65,7 @@ for name in filenames:
|
||||||
|
|
||||||
table.head_read()
|
table.head_read()
|
||||||
info,extra_header = table.head_getGeom()
|
info,extra_header = table.head_getGeom()
|
||||||
|
damask.util.report_geom(info)
|
||||||
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'],
|
|
||||||
])
|
|
||||||
|
|
||||||
errors = []
|
errors = []
|
||||||
if np.any(info['grid'] < 1): errors.append('invalid grid a b c.')
|
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_y = [i - options.offset[1] for i in yindex]
|
||||||
translate_z = [i - options.offset[2] for i in zindex]
|
translate_z = [i - options.offset[2] for i in zindex]
|
||||||
if 0 in map(len,[xindex,yindex,zindex,translate_x,translate_y,translate_z]):
|
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)
|
table.close(dismiss = True)
|
||||||
continue
|
continue
|
||||||
microstructure_cropped[min(translate_x):(max(translate_x)+1),\
|
microstructure_cropped[min(translate_x):(max(translate_x)+1),\
|
||||||
|
@ -125,13 +123,13 @@ for name in filenames:
|
||||||
errors = []
|
errors = []
|
||||||
|
|
||||||
if (any(newInfo['grid'] != info['grid'])):
|
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'])):
|
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'])):
|
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']):
|
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['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.')
|
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_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=newInfo['grid']),
|
"grid\ta {}\tb {}\tc {}".format(*newInfo['grid']),
|
||||||
"size\tx {size[0]}\ty {size[1]}\tz {size[2]}".format(size=newInfo['size']),
|
"size\tx {}\ty {}\tz {}".format(*newInfo['size']),
|
||||||
"origin\tx {origin[0]}\ty {origin[1]}\tz {origin[2]}".format(origin=newInfo['origin']),
|
"origin\tx {}\ty {}\tz {}".format(*newInfo['origin']),
|
||||||
"homogenization\t{homog}".format(homog=info['homogenization']),
|
"homogenization\t{}".format(info['homogenization']),
|
||||||
"microstructures\t{microstructures}".format(microstructures=newInfo['microstructures']),
|
"microstructures\t{}".format(newInfo['microstructures']),
|
||||||
extra_header
|
extra_header
|
||||||
])
|
])
|
||||||
table.labels_clear()
|
table.labels_clear()
|
||||||
|
|
|
@ -296,11 +296,8 @@ 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: {}'.format(' x '.join(map(str,info['grid']))),
|
damask.util.report_geom(info,['grid','size','origin','homogenization',])
|
||||||
'size x y z: {}'.format(' x '.join(map(str,info['size']))),
|
damask.util.croak(['microstructures: {}{}'.format(info['microstructures'],
|
||||||
'origin x y z: {}'.format(' : '.join(map(str,info['origin']))),
|
|
||||||
'homogenization: {}'.format(info['homogenization']),
|
|
||||||
'microstructures: {}{}'.format(info['microstructures'],
|
|
||||||
(' out of {}'.format(NgrainIDs) if NgrainIDs != info['microstructures'] else '')),
|
(' out of {}'.format(NgrainIDs) if NgrainIDs != info['microstructures'] else '')),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
|
@ -23,29 +23,38 @@ Examples:
|
||||||
|
|
||||||
""", version = scriptID)
|
""", version = scriptID)
|
||||||
|
|
||||||
parser.add_option('-p', '--positions',
|
parser.add_option('-p',
|
||||||
|
'--pos', '--seedposition',
|
||||||
dest = 'pos',
|
dest = 'pos',
|
||||||
type = 'string', metavar = 'string',
|
type = 'string', metavar = 'string',
|
||||||
help = 'coordinate label [%default]')
|
help = 'label of coordinates [%default]')
|
||||||
parser.add_option('--boundingbox',
|
parser.add_option('--boundingbox',
|
||||||
dest = 'box',
|
dest = 'box',
|
||||||
type = 'float', nargs = 6, metavar = ' '.join(['float']*6),
|
type = 'float', nargs = 6, metavar = ' '.join(['float']*6),
|
||||||
help = 'min (x,y,z) and max (x,y,z) coordinates of bounding box [tight]')
|
help = 'min (x,y,z) and max (x,y,z) coordinates of bounding box [tight]')
|
||||||
parser.add_option('-i', '--index',
|
parser.add_option('-m',
|
||||||
dest = 'index',
|
'--microstructure',
|
||||||
|
dest = 'microstructure',
|
||||||
type = 'string', metavar = 'string',
|
type = 'string', metavar = 'string',
|
||||||
help = 'microstructure index label [%default]')
|
help = 'label of microstructures [%default]')
|
||||||
parser.add_option('-w','--white',
|
parser.add_option('--weight',
|
||||||
|
dest = 'weight',
|
||||||
|
type = 'string', metavar = 'string',
|
||||||
|
help = 'label of weights [%default]')
|
||||||
|
parser.add_option('-w',
|
||||||
|
'--white',
|
||||||
dest = 'whitelist',
|
dest = 'whitelist',
|
||||||
action = 'extend', metavar = '<int LIST>',
|
action = 'extend', metavar = '<int LIST>',
|
||||||
help = 'whitelist of microstructure indices')
|
help = 'whitelist of microstructure indices')
|
||||||
parser.add_option('-b','--black',
|
parser.add_option('-b',
|
||||||
|
'--black',
|
||||||
dest = 'blacklist',
|
dest = 'blacklist',
|
||||||
action = 'extend', metavar = '<int LIST>',
|
action = 'extend', metavar = '<int LIST>',
|
||||||
help = 'blacklist of microstructure indices')
|
help = 'blacklist of microstructure indices')
|
||||||
|
|
||||||
parser.set_defaults(pos = 'pos',
|
parser.set_defaults(pos = 'pos',
|
||||||
index ='microstructure',
|
microstructure = 'microstructure',
|
||||||
|
weight = None,
|
||||||
)
|
)
|
||||||
|
|
||||||
(options,filenames) = parser.parse_args()
|
(options,filenames) = parser.parse_args()
|
||||||
|
@ -58,8 +67,7 @@ if options.blacklist is not None: options.blacklist = map(int,options.blacklist)
|
||||||
if filenames == []: filenames = [None]
|
if filenames == []: filenames = [None]
|
||||||
|
|
||||||
for name in filenames:
|
for name in filenames:
|
||||||
try:
|
try: table = damask.ASCIItable(name = name,
|
||||||
table = damask.ASCIItable(name = name,
|
|
||||||
outname = os.path.splitext(name)[0]+'.seeds' if name else name,
|
outname = os.path.splitext(name)[0]+'.seeds' if name else name,
|
||||||
buffered = False)
|
buffered = False)
|
||||||
except: continue
|
except: continue
|
||||||
|
@ -69,14 +77,17 @@ for name in filenames:
|
||||||
|
|
||||||
# ------------------------------------------ sanity checks ---------------------------------------
|
# ------------------------------------------ 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 = []
|
errors = []
|
||||||
if len(missing_labels) > 0:
|
if len(missing_labels) > 0:
|
||||||
errors.append('column{} {} not found'.format('s' if len(missing_labels) > 1 else '',
|
errors.append('column{} {} not found'.format('s' if len(missing_labels) > 1 else '',
|
||||||
', '.join(missing_labels)))
|
', '.join(missing_labels)))
|
||||||
for label, dim in {options.pos: 3,
|
input = {options.pos: 3,
|
||||||
options.index: 1}.iteritems():
|
options.microstructure: 1,}
|
||||||
|
if options.weight: input.update({options.weight: 1})
|
||||||
|
for label, dim in input.iteritems():
|
||||||
if table.label_dimension(label) != dim:
|
if table.label_dimension(label) != dim:
|
||||||
errors.append('column {} has wrong dimension'.format(label))
|
errors.append('column {} has wrong dimension'.format(label))
|
||||||
|
|
||||||
|
@ -113,11 +124,12 @@ for name in filenames:
|
||||||
|
|
||||||
table.info = [
|
table.info = [
|
||||||
scriptID,
|
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,:])))))),
|
map(str,boundingBox[1,:]-boundingBox[0,:])))))),
|
||||||
]
|
]
|
||||||
table.labels_clear()
|
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()
|
table.head_write()
|
||||||
|
|
||||||
# ------------------------------------------ output result ---------------------------------------
|
# ------------------------------------------ output result ---------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue