adopted recent changes to API in ASCIItable.
This commit is contained in:
parent
31a6ac328d
commit
8217fdb115
|
@ -30,13 +30,14 @@ parser.set_defaults(data = True,
|
||||||
|
|
||||||
# --- loop over input files -------------------------------------------------------------------------
|
# --- loop over input files -------------------------------------------------------------------------
|
||||||
|
|
||||||
if filenames == []: filenames = ['STDIN']
|
if filenames == []: filenames = [None]
|
||||||
|
|
||||||
for name in filenames:
|
for name in filenames:
|
||||||
if not (name == 'STDIN' or os.path.exists(name)): continue
|
try:
|
||||||
table = damask.ASCIItable(name = name, outname = None,
|
table = damask.ASCIItable(name = name,
|
||||||
buffered = False, labeled = False, readonly = True)
|
buffered = False, labeled = False, readonly = True)
|
||||||
table.croak('\033[1m'+scriptName+'\033[0m'+(': '+name if name != 'STDIN' else ''))
|
except: continue
|
||||||
|
table.croak('\033[1m'+scriptName+'\033[0m'+(': '+name if name else ''))
|
||||||
|
|
||||||
# --- interpret header ----------------------------------------------------------------------------
|
# --- interpret header ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -86,16 +87,7 @@ for name in filenames:
|
||||||
|
|
||||||
# --- write data -----------------------------------------------------------------------------------
|
# --- write data -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
if name == 'STDIN':
|
if name:
|
||||||
writer = vtk.vtkRectilinearGridWriter()
|
|
||||||
writer.WriteToOutputStringOn()
|
|
||||||
writer.SetFileTypeToASCII()
|
|
||||||
writer.SetHeader('# powered by '+scriptID)
|
|
||||||
if vtk.VTK_MAJOR_VERSION <= 5: writer.SetInput(grid)
|
|
||||||
else: writer.SetInputData(grid)
|
|
||||||
writer.Write()
|
|
||||||
sys.stdout.write(writer.GetOutputString()[0:writer.GetOutputStringLength()])
|
|
||||||
else:
|
|
||||||
(dir,filename) = os.path.split(name)
|
(dir,filename) = os.path.split(name)
|
||||||
writer = vtk.vtkXMLRectilinearGridWriter()
|
writer = vtk.vtkXMLRectilinearGridWriter()
|
||||||
writer.SetDataModeToBinary()
|
writer.SetDataModeToBinary()
|
||||||
|
@ -105,5 +97,14 @@ for name in filenames:
|
||||||
if vtk.VTK_MAJOR_VERSION <= 5: writer.SetInput(grid)
|
if vtk.VTK_MAJOR_VERSION <= 5: writer.SetInput(grid)
|
||||||
else: writer.SetInputData(grid)
|
else: writer.SetInputData(grid)
|
||||||
writer.Write()
|
writer.Write()
|
||||||
|
else:
|
||||||
|
writer = vtk.vtkRectilinearGridWriter()
|
||||||
|
writer.WriteToOutputStringOn()
|
||||||
|
writer.SetFileTypeToASCII()
|
||||||
|
writer.SetHeader('# powered by '+scriptID)
|
||||||
|
if vtk.VTK_MAJOR_VERSION <= 5: writer.SetInput(grid)
|
||||||
|
else: writer.SetInputData(grid)
|
||||||
|
writer.Write()
|
||||||
|
sys.stdout.write(writer.GetOutputString()[0:writer.GetOutputStringLength()])
|
||||||
|
|
||||||
table.close()
|
table.close()
|
||||||
|
|
|
@ -32,13 +32,14 @@ parser.set_defaults(homogenization = 1,
|
||||||
|
|
||||||
# --- loop over input files -------------------------------------------------------------------------
|
# --- loop over input files -------------------------------------------------------------------------
|
||||||
|
|
||||||
if filenames == []: filenames = ['STDIN']
|
if filenames == []: filenames = [None]
|
||||||
|
|
||||||
for name in filenames:
|
for name in filenames:
|
||||||
if not (name == 'STDIN' or os.path.exists(name)): continue
|
try:
|
||||||
table = damask.ASCIItable(name = name, outname = os.path.splitext(name)[0] +'.geom',
|
table = damask.ASCIItable(name = name, outname = os.path.splitext(name)[0] +'.geom',
|
||||||
buffered = False, labeled = False)
|
buffered = False, labeled = False)
|
||||||
table.croak('\033[1m'+scriptName+'\033[0m'+(': '+name if name != 'STDIN' else ''))
|
except: continue
|
||||||
|
table.croak('\033[1m'+scriptName+'\033[0m'+(': '+name if name else ''))
|
||||||
|
|
||||||
# --- read image ------------------------------------------------------------------------------------
|
# --- read image ------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -14,21 +14,9 @@ scriptName = os.path.splitext(scriptID.split()[1])[0]
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# MAIN
|
# MAIN
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
identifiers = {
|
|
||||||
'grid': ['a','b','c'],
|
|
||||||
'size': ['x','y','z'],
|
|
||||||
'origin': ['x','y','z'],
|
|
||||||
}
|
|
||||||
mappings = {
|
|
||||||
'grid': lambda x: int(x),
|
|
||||||
'size': lambda x: float(x),
|
|
||||||
'origin': lambda x: float(x),
|
|
||||||
'homogenization': lambda x: int(x),
|
|
||||||
'microstructures': lambda x: int(x),
|
|
||||||
}
|
|
||||||
|
|
||||||
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
|
||||||
Generate geometry description and material configuration from position, phase, and orientation data.
|
Generate geometry description and material configuration from position, phase, and orientation (or microstructure) data.
|
||||||
|
|
||||||
""", version = scriptID)
|
""", version = scriptID)
|
||||||
|
|
||||||
|
@ -40,6 +28,10 @@ parser.add_option('--phase',
|
||||||
dest = 'phase',
|
dest = 'phase',
|
||||||
type = 'string', metavar = 'string',
|
type = 'string', metavar = 'string',
|
||||||
help = 'phase label')
|
help = 'phase label')
|
||||||
|
parser.add_option('--microstructure',
|
||||||
|
dest = 'microstructure',
|
||||||
|
type = 'string', metavar = 'string',
|
||||||
|
help = 'microstructure label')
|
||||||
parser.add_option('-t', '--tolerance',
|
parser.add_option('-t', '--tolerance',
|
||||||
dest = 'tolerance',
|
dest = 'tolerance',
|
||||||
type = 'float', metavar = 'float',
|
type = 'float', metavar = 'float',
|
||||||
|
@ -106,9 +98,10 @@ input = [options.eulers != None,
|
||||||
options.quaternion != None,
|
options.quaternion != None,
|
||||||
]
|
]
|
||||||
|
|
||||||
if np.sum(input) != 1: parser.error('needs exactly one orientation input format...')
|
if np.sum(input) != 1 and options.microstructure == None:
|
||||||
|
parser.error('need either microstructure label or exactly one orientation input format.')
|
||||||
if options.axes != None and not set(options.axes).issubset(set(['x','+x','-x','y','+y','-y','z','+z','-z'])):
|
if options.axes != None and not set(options.axes).issubset(set(['x','+x','-x','y','+y','-y','z','+z','-z'])):
|
||||||
parser.error('invalid axes {axes[0]} {axes[1]} {axes[2]}'.format(axes=options.axes))
|
parser.error('invalid axes {} {} {}.'.format(*options.axes))
|
||||||
|
|
||||||
(label,dim,inputtype) = [(options.eulers,3,'eulers'),
|
(label,dim,inputtype) = [(options.eulers,3,'eulers'),
|
||||||
([options.a,options.b,options.c],[3,3,3],'frame'),
|
([options.a,options.b,options.c],[3,3,3],'frame'),
|
||||||
|
@ -120,13 +113,14 @@ options.tolerance *= toRadians
|
||||||
|
|
||||||
# --- loop over input files -------------------------------------------------------------------------
|
# --- loop over input files -------------------------------------------------------------------------
|
||||||
|
|
||||||
if filenames == []: filenames = ['STDIN']
|
if filenames == []: filenames = [None]
|
||||||
|
|
||||||
for name in filenames:
|
for name in filenames:
|
||||||
if not (name == 'STDIN' or os.path.exists(name)): continue
|
try:
|
||||||
table = damask.ASCIItable(name = name, outname = os.path.splitext(name)[0] + '.geom',
|
table = damask.ASCIItable(name = name, outname = os.path.splitext(name)[0] + '.geom',
|
||||||
buffered = False)
|
buffered = False)
|
||||||
table.croak('\033[1m'+scriptName+'\033[0m'+(': '+name if name != 'STDIN' else ''))
|
except: continue
|
||||||
|
table.croak('\033[1m'+scriptName+'\033[0m'+(': '+name if name else ''))
|
||||||
|
|
||||||
# ------------------------------------------ read head ---------------------------------------
|
# ------------------------------------------ read head ---------------------------------------
|
||||||
|
|
||||||
|
@ -135,8 +129,8 @@ for name in filenames:
|
||||||
# ------------------------------------------ sanity checks ---------------------------------------
|
# ------------------------------------------ sanity checks ---------------------------------------
|
||||||
|
|
||||||
errors = []
|
errors = []
|
||||||
if table.label_dimension(options.coordinates) != 2:
|
if not 3 >= table.label_dimension(options.coordinates) >= 2: # TODO need to deal with 3D case!!
|
||||||
errors.append('coordinates {} need to have two dimensions.'.format(options.coordinates))
|
errors.append('coordinates {} need to have two or three dimensions.'.format(options.coordinates))
|
||||||
if not np.all(table.label_dimension(label) == dim):
|
if not np.all(table.label_dimension(label) == dim):
|
||||||
errors.append('orientation {} needs to have dimension {}.'.format(label,dim))
|
errors.append('orientation {} needs to have dimension {}.'.format(label,dim))
|
||||||
if options.phase != None and table.label_dimension(options.phase) != 1:
|
if options.phase != None and table.label_dimension(options.phase) != 1:
|
||||||
|
@ -185,23 +179,19 @@ for name in filenames:
|
||||||
myData = table.data[index[myRank]]
|
myData = table.data[index[myRank]]
|
||||||
mySym = options.symmetry[min(int(myData[colPhase]),len(options.symmetry))-1] # select symmetry from option (take last specified option for all with higher index)
|
mySym = options.symmetry[min(int(myData[colPhase]),len(options.symmetry))-1] # select symmetry from option (take last specified option for all with higher index)
|
||||||
if inputtype == 'eulers':
|
if inputtype == 'eulers':
|
||||||
o = damask.Orientation(Eulers=toRadians*\
|
o = damask.Orientation(Eulers = np.array(map(float,myData[colOri:colOri+3]))*toRadians,
|
||||||
np.array(map(float,myData[colOri:colOri+3])),
|
|
||||||
symmetry = mySym).reduced()
|
symmetry = mySym).reduced()
|
||||||
elif inputtype == 'matrix':
|
elif inputtype == 'matrix':
|
||||||
o = damask.Orientation(matrix=\
|
o = damask.Orientation(matrix = np.array([map(float,myData[colOri:colOri+9])]).reshape(3,3).transpose(),
|
||||||
np.array([map(float,myData[colOri:colOri+9])]).reshape(3,3).transpose(),
|
|
||||||
symmetry = mySym).reduced()
|
symmetry = mySym).reduced()
|
||||||
elif inputtype == 'frame':
|
elif inputtype == 'frame':
|
||||||
o = damask.Orientation(matrix=\
|
o = damask.Orientation(matrix = np.array([map(float,myData[colOri[0]:colOri[0]+3] + \
|
||||||
np.array([map(float,myData[colOri[0]:colOri[0]+3] + \
|
|
||||||
myData[colOri[1]:colOri[1]+3] + \
|
myData[colOri[1]:colOri[1]+3] + \
|
||||||
myData[colOri[2]:colOri[2]+3]
|
myData[colOri[2]:colOri[2]+3]
|
||||||
)]).reshape(3,3),
|
)]).reshape(3,3),
|
||||||
symmetry = mySym).reduced()
|
symmetry = mySym).reduced()
|
||||||
elif inputtype == 'quaternion':
|
elif inputtype == 'quaternion':
|
||||||
o = damask.Orientation(quaternion=\
|
o = damask.Orientation(quaternion = np.array(map(float,myData[colOri:colOri+4])),
|
||||||
np.array(map(float,myData[colOri:colOri+4])),
|
|
||||||
symmetry = mySym).reduced()
|
symmetry = mySym).reduced()
|
||||||
|
|
||||||
oInv = o.quaternion.conjugated()
|
oInv = o.quaternion.conjugated()
|
||||||
|
|
Loading…
Reference in New Issue