2019-02-24 17:27:57 +05:30
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2019-05-30 17:00:38 +05:30
|
|
|
import os
|
|
|
|
import sys
|
2019-02-24 17:27:57 +05:30
|
|
|
from optparse import OptionParser
|
2019-05-30 17:00:38 +05:30
|
|
|
|
|
|
|
import h5py
|
|
|
|
import numpy as np
|
|
|
|
|
2019-02-24 17:27:57 +05:30
|
|
|
import damask
|
|
|
|
|
2019-05-30 17:00:38 +05:30
|
|
|
|
2019-02-24 17:27:57 +05:30
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
|
|
|
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
#--------------------------------------------------------------------------------------------------
|
|
|
|
|
2019-05-30 17:00:38 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [DREAM.3Dfile(s)]', description = """
|
|
|
|
Converts DREAM.3D file. Input can be cell data (direct pointwise takeover) or grain data (individual
|
|
|
|
grains are segmented). Requires orientation data as quaternion.
|
2019-02-24 17:27:57 +05:30
|
|
|
|
|
|
|
""", version = scriptID)
|
|
|
|
|
|
|
|
parser.add_option('-b','--basegroup',
|
2019-05-30 17:00:38 +05:30
|
|
|
dest = 'basegroup',
|
|
|
|
metavar = 'string',
|
2019-03-05 15:28:57 +05:30
|
|
|
help = 'name of the group in "DataContainers" containing the pointwise (and, if applicable grain average) data')
|
2019-02-24 17:27:57 +05:30
|
|
|
parser.add_option('-p','--pointwise',
|
2019-05-30 17:00:38 +05:30
|
|
|
dest = 'pointwise',
|
|
|
|
metavar = 'string',
|
2019-03-05 15:28:57 +05:30
|
|
|
help = 'name of the group in "DataContainers/<basegroup>" containing pointwise data [%default]')
|
2019-02-24 17:27:57 +05:30
|
|
|
parser.add_option('-a','--average',
|
2019-05-30 17:00:38 +05:30
|
|
|
dest = 'average',
|
|
|
|
metavar = 'string',
|
2019-03-05 15:28:57 +05:30
|
|
|
help = 'name of the group in "DataContainers</basegroup>" containing grain average data. '\
|
2019-02-24 17:27:57 +05:30
|
|
|
+ 'Leave empty for pointwise data')
|
|
|
|
parser.add_option('--phase',
|
|
|
|
dest = 'phase',
|
2019-05-30 17:00:38 +05:30
|
|
|
type = 'string',
|
|
|
|
metavar = 'string',
|
2019-02-24 17:27:57 +05:30
|
|
|
help = 'name of the dataset containing pointwise/average phase IDs [%default]')
|
|
|
|
parser.add_option('--microstructure',
|
|
|
|
dest = 'microstructure',
|
2019-05-30 17:00:38 +05:30
|
|
|
type = 'string',
|
|
|
|
metavar = 'string',
|
2019-02-24 17:27:57 +05:30
|
|
|
help = 'name of the dataset connecting pointwise and average data [%default]')
|
|
|
|
parser.add_option('-q', '--quaternion',
|
|
|
|
dest = 'quaternion',
|
2019-05-30 17:00:38 +05:30
|
|
|
type = 'string',
|
|
|
|
metavar='string',
|
2019-02-24 17:27:57 +05:30
|
|
|
help = 'name of the dataset containing pointwise/average orientation as quaternion [%default]')
|
2019-05-30 17:00:38 +05:30
|
|
|
parser.add_option('--homogenization',
|
|
|
|
dest = 'homogenization',
|
|
|
|
type = 'int', metavar = 'int',
|
|
|
|
help = 'homogenization index to be used [%default]')
|
2019-02-24 17:27:57 +05:30
|
|
|
|
|
|
|
parser.set_defaults(pointwise = 'CellData',
|
|
|
|
quaternion = 'Quats',
|
|
|
|
phase = 'Phases',
|
|
|
|
microstructure = 'FeatureIds',
|
2019-05-30 17:00:38 +05:30
|
|
|
homogenization = 1,
|
2019-02-24 17:27:57 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
(options, filenames) = parser.parse_args()
|
|
|
|
|
|
|
|
if options.basegroup is None:
|
|
|
|
parser.error('No base group selected')
|
|
|
|
|
|
|
|
rootDir ='DataContainers'
|
|
|
|
|
|
|
|
|
|
|
|
if filenames == []: parser.error('no input file specified.')
|
|
|
|
|
|
|
|
for name in filenames:
|
|
|
|
damask.util.report(scriptName,name)
|
|
|
|
|
|
|
|
errors = []
|
2019-05-30 17:37:49 +05:30
|
|
|
|
2019-02-24 17:27:57 +05:30
|
|
|
inFile = h5py.File(name, 'r')
|
|
|
|
group_geom = os.path.join(rootDir,options.basegroup,'_SIMPL_GEOMETRY')
|
|
|
|
try:
|
2019-05-30 17:00:38 +05:30
|
|
|
size = inFile[os.path.join(group_geom,'DIMENSIONS')][...] \
|
|
|
|
* inFile[os.path.join(group_geom,'SPACING')][...]
|
|
|
|
grid = inFile[os.path.join(group_geom,'DIMENSIONS')][...]
|
|
|
|
origin = inFile[os.path.join(group_geom,'ORIGIN')][...]
|
2019-11-24 23:55:01 +05:30
|
|
|
except KeyError:
|
2019-02-24 17:27:57 +05:30
|
|
|
errors.append('Geometry data ({}) not found'.format(group_geom))
|
2019-05-30 17:37:49 +05:30
|
|
|
|
|
|
|
|
2019-02-24 17:27:57 +05:30
|
|
|
group_pointwise = os.path.join(rootDir,options.basegroup,options.pointwise)
|
|
|
|
if options.average is None:
|
2019-05-30 17:00:38 +05:30
|
|
|
label = 'Point'
|
2019-03-05 15:28:57 +05:30
|
|
|
|
2019-02-24 17:27:57 +05:30
|
|
|
dataset = os.path.join(group_pointwise,options.quaternion)
|
|
|
|
try:
|
2019-05-30 17:00:38 +05:30
|
|
|
quats = np.reshape(inFile[dataset][...],(np.product(grid),4))
|
2020-05-16 14:47:12 +05:30
|
|
|
rot = [damask.Rotation.from_quaternion(q,True,P=+1) for q in quats]
|
2019-11-24 23:55:01 +05:30
|
|
|
except KeyError:
|
2019-03-05 15:28:57 +05:30
|
|
|
errors.append('Pointwise orientation (quaternion) data ({}) not readable'.format(dataset))
|
2019-05-30 17:37:49 +05:30
|
|
|
|
2019-02-24 17:27:57 +05:30
|
|
|
dataset = os.path.join(group_pointwise,options.phase)
|
|
|
|
try:
|
2019-05-30 17:00:38 +05:30
|
|
|
phase = np.reshape(inFile[dataset][...],(np.product(grid)))
|
2019-11-24 23:55:01 +05:30
|
|
|
except KeyError:
|
2019-03-05 15:28:57 +05:30
|
|
|
errors.append('Pointwise phase data ({}) not readable'.format(dataset))
|
2019-05-30 17:37:49 +05:30
|
|
|
|
2019-05-30 17:00:38 +05:30
|
|
|
microstructure = np.arange(1,np.product(grid)+1,dtype=int).reshape(grid,order='F')
|
2019-02-24 17:27:57 +05:30
|
|
|
|
2019-05-30 17:37:49 +05:30
|
|
|
|
2019-02-24 17:27:57 +05:30
|
|
|
else:
|
2019-05-30 17:00:38 +05:30
|
|
|
label = 'Grain'
|
2019-05-30 17:37:49 +05:30
|
|
|
|
2019-02-24 17:27:57 +05:30
|
|
|
dataset = os.path.join(group_pointwise,options.microstructure)
|
|
|
|
try:
|
2019-05-30 17:00:38 +05:30
|
|
|
microstructure = np.transpose(inFile[dataset][...].reshape(grid[::-1]),(2,1,0)) # convert from C ordering
|
2019-11-24 23:55:01 +05:30
|
|
|
except KeyError:
|
2019-03-05 15:28:57 +05:30
|
|
|
errors.append('Link between pointwise and grain average data ({}) not readable'.format(dataset))
|
2019-05-30 17:37:49 +05:30
|
|
|
|
2019-02-24 17:27:57 +05:30
|
|
|
group_average = os.path.join(rootDir,options.basegroup,options.average)
|
2019-05-30 17:37:49 +05:30
|
|
|
|
2019-02-24 17:27:57 +05:30
|
|
|
dataset = os.path.join(group_average,options.quaternion)
|
|
|
|
try:
|
2020-05-16 14:47:12 +05:30
|
|
|
rot = [damask.Rotation.from_quaternion(q,True,P=+1) for q in inFile[dataset][...][1:]] # skip first entry (unindexed)
|
2019-11-24 23:55:01 +05:30
|
|
|
except KeyError:
|
2019-03-05 15:28:57 +05:30
|
|
|
errors.append('Average orientation data ({}) not readable'.format(dataset))
|
2019-05-30 17:37:49 +05:30
|
|
|
|
2019-02-24 17:27:57 +05:30
|
|
|
dataset = os.path.join(group_average,options.phase)
|
|
|
|
try:
|
|
|
|
phase = [i[0] for i in inFile[dataset][...]][1:] # skip first entry (unindexed)
|
2019-11-24 23:55:01 +05:30
|
|
|
except KeyError:
|
2019-03-05 15:28:57 +05:30
|
|
|
errors.append('Average phase data ({}) not readable'.format(dataset))
|
2019-02-24 17:27:57 +05:30
|
|
|
|
|
|
|
if errors != []:
|
|
|
|
damask.util.croak(errors)
|
|
|
|
continue
|
2019-05-30 17:35:45 +05:30
|
|
|
|
|
|
|
config_header = ['<texture>']
|
|
|
|
for i in range(np.nanmax(microstructure)):
|
|
|
|
config_header += ['[{}{}]'.format(label,i+1),
|
2020-05-17 11:31:34 +05:30
|
|
|
'(gauss)\tphi1 {:.2f}\tPhi {:.2f}\tphi2 {:.2f}'.format(*rot[i].as_Eulers(degrees = True)),
|
2019-05-30 17:35:45 +05:30
|
|
|
]
|
|
|
|
config_header += ['<microstructure>']
|
2019-05-30 17:00:38 +05:30
|
|
|
for i in range(np.nanmax(microstructure)):
|
|
|
|
config_header += ['[{}{}]'.format(label,i+1),
|
|
|
|
'(constituent)\tphase {}\ttexture {}\tfraction 1.0'.format(phase[i],i+1),
|
|
|
|
]
|
2019-05-30 17:37:49 +05:30
|
|
|
|
2019-05-30 17:00:38 +05:30
|
|
|
header = [scriptID + ' ' + ' '.join(sys.argv[1:])]\
|
|
|
|
+ config_header
|
|
|
|
geom = damask.Geom(microstructure,size,origin,
|
|
|
|
homogenization=options.homogenization,comments=header)
|
|
|
|
damask.util.croak(geom)
|
|
|
|
|
2020-09-21 00:15:06 +05:30
|
|
|
geom.save_ASCII(os.path.splitext(name)[0]+'.geom',compress=False)
|