DAMASK_EICMD/processing/pre/geom_canvas.py

62 lines
2.1 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
2019-05-27 00:06:41 +05:30
import os
import sys
from io import StringIO
from optparse import OptionParser
import numpy as np
import damask
2019-05-31 13:57:26 +05:30
scriptName = os.path.splitext(os.path.basename(__file__))[0]
scriptID = ' '.join([scriptName,damask.version])
# --------------------------------------------------------------------
2013-05-15 22:53:21 +05:30
# MAIN
# --------------------------------------------------------------------
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """
Increases or decreases the (three-dimensional) canvas.
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',
dest = 'grid',
type = 'string', nargs = 3, metavar = ' '.join(['string']*3),
help = 'a,b,c grid of hexahedral box')
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',
dest = 'fill',
type = 'float', metavar = 'int',
help = 'background microstructure index, defaults to max microstructure index + 1')
parser.set_defaults(offset = (0,0,0))
(options, filenames) = parser.parse_args()
if filenames == []: filenames = [None]
2020-05-24 12:36:42 +05:30
for name in filenames:
2015-09-24 22:22:58 +05:30
damask.util.report(scriptName,name)
2019-05-30 17:37:49 +05:30
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
offset = np.asarray(options.offset)
2019-06-03 23:09:45 +05:30
if options.grid is not None:
2020-05-24 12:36:42 +05:30
grid = np.maximum(1,
np.array([int(o*float(n.lower().replace('x',''))) if n.lower().endswith('x') \
else int(n) for o,n in zip(geom.grid,options.grid)],dtype=int))
else:
grid = np.array(options.grid,dtype=int)
2020-05-24 12:36:42 +05:30
damask.util.croak(geom.canvas(grid,np.asarray(options.offset),options.fill))
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
2019-11-24 23:32:19 +05:30
geom.to_file(sys.stdout if name is None else name,pack=False)