update to changes in Result class
This commit is contained in:
parent
1e1fb35e14
commit
17e7b32b31
|
@ -36,39 +36,34 @@ if options.con is None: options.con=[]
|
||||||
# --- loop over input files ------------------------------------------------------------------------
|
# --- loop over input files ------------------------------------------------------------------------
|
||||||
|
|
||||||
for filename in options.filenames:
|
for filename in options.filenames:
|
||||||
results = damask.DADF5(filename)
|
results = damask.Result(filename)
|
||||||
|
|
||||||
if not results.structured: continue
|
if not results.structured: continue
|
||||||
if results.version_major == 0 and results.version_minor >= 5:
|
|
||||||
coords = damask.grid_filters.cell_coord0(results.grid,results.size,results.origin)
|
coords = damask.grid_filters.cell_coord0(results.grid,results.size,results.origin)
|
||||||
else:
|
|
||||||
coords = damask.grid_filters.cell_coord0(results.grid,results.size)
|
|
||||||
|
|
||||||
N_digits = int(np.floor(np.log10(int(results.increments[-1][3:]))))+1
|
N_digits = int(np.floor(np.log10(int(results.increments[-1][3:]))))+1
|
||||||
N_digits = 5 # hack to keep test intact
|
N_digits = 5 # hack to keep test intact
|
||||||
for i,inc in enumerate(results.iter_visible('increments')):
|
for inc in damask.util.show_progress(results.iter_visible('increments'),len(results.increments)):
|
||||||
print('Output step {}/{}'.format(i+1,len(results.increments)))
|
table = damask.Table(np.ones(np.product(results.grid),dtype=int)*int(inc[3:]),{'inc':(1,)})
|
||||||
|
table.add('pos',coords.reshape((-1,3)))
|
||||||
|
|
||||||
table = damask.Table(np.ones(np.product(results.grid),dtype=int)*int(inc[3:]),{'inc':(1,)})
|
results.pick('materialpoints',False)
|
||||||
table.add('pos',coords.reshape((-1,3)))
|
results.pick('constituents', True)
|
||||||
|
for label in options.con:
|
||||||
|
x = results.get_dataset_location(label)
|
||||||
|
if len(x) != 0:
|
||||||
|
table.add(label,results.read_dataset(x,0,plain=True).reshape((results.grid.prod(),-1)))
|
||||||
|
|
||||||
results.pick('materialpoints',False)
|
results.pick('constituents', False)
|
||||||
results.pick('constituents', True)
|
results.pick('materialpoints',True)
|
||||||
for label in options.con:
|
for label in options.mat:
|
||||||
x = results.get_dataset_location(label)
|
x = results.get_dataset_location(label)
|
||||||
if len(x) != 0:
|
if len(x) != 0:
|
||||||
table.add(label,results.read_dataset(x,0,plain=True).reshape((results.grid.prod(),-1)))
|
table.add(label,results.read_dataset(x,0,plain=True).reshape((results.grid.prod(),-1)))
|
||||||
|
|
||||||
results.pick('constituents', False)
|
dirname = os.path.abspath(os.path.join(os.path.dirname(filename),options.dir))
|
||||||
results.pick('materialpoints',True)
|
if not os.path.isdir(dirname):
|
||||||
for label in options.mat:
|
os.mkdir(dirname,0o755)
|
||||||
x = results.get_dataset_location(label)
|
file_out = '{}_inc{}.txt'.format(os.path.splitext(os.path.split(filename)[-1])[0],
|
||||||
if len(x) != 0:
|
inc[3:].zfill(N_digits))
|
||||||
table.add(label,results.read_dataset(x,0,plain=True).reshape((results.grid.prod(),-1)))
|
table.to_ASCII(os.path.join(dirname,file_out))
|
||||||
|
|
||||||
dirname = os.path.abspath(os.path.join(os.path.dirname(filename),options.dir))
|
|
||||||
if not os.path.isdir(dirname):
|
|
||||||
os.mkdir(dirname,0o755)
|
|
||||||
file_out = '{}_inc{}.txt'.format(os.path.splitext(os.path.split(filename)[-1])[0],
|
|
||||||
inc[3:].zfill(N_digits))
|
|
||||||
table.to_ASCII(os.path.join(dirname,file_out))
|
|
||||||
|
|
|
@ -55,94 +55,88 @@ parser.add_argument('-d','--dir', dest='dir',default='postProc',metavar='string'
|
||||||
|
|
||||||
options = parser.parse_args()
|
options = parser.parse_args()
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
|
||||||
# loop over input files
|
|
||||||
for filename in options.filenames:
|
for filename in options.filenames:
|
||||||
f = damask.DADF5(filename) #DAMASK output file
|
f = damask.Result(filename)
|
||||||
for increment in options.inc:
|
f.pick('increments',options.inc)
|
||||||
f.set_by_increment(increment,increment)
|
for increment in damask.util.show_progress(f.iter_selection('increments'),len(f.selection['increments'])):
|
||||||
if len(f.visible['increments']) == 0:
|
#-------output file creation-------------------------------------
|
||||||
continue
|
dirname = os.path.abspath(os.path.join(os.path.dirname(filename),options.dir))
|
||||||
|
try:
|
||||||
|
os.mkdir(dirname)
|
||||||
|
except FileExistsError:
|
||||||
|
pass
|
||||||
|
|
||||||
#-------output file creation-------------------------------------
|
o = h5py.File(dirname + '/' + os.path.splitext(filename)[0] + '_{}.dream3D'.format(increment),'w')
|
||||||
dirname = os.path.abspath(os.path.join(os.path.dirname(filename),options.dir))
|
#-----------------------------------------------------------------
|
||||||
try:
|
o.attrs['DADF5toDREAM3D'] = '1.0'
|
||||||
os.mkdir(dirname)
|
o.attrs['FileVersion'] = '7.0'
|
||||||
except FileExistsError:
|
#-----------------------------------------------------------------
|
||||||
pass
|
|
||||||
|
|
||||||
o = h5py.File(dirname + '/' + os.path.splitext(filename)[0] + '_{}.dream3D'.format(increment),'w')
|
for g in ['DataContainerBundles','Pipeline']: # empty groups (needed)
|
||||||
#-----------------------------------------------------------------
|
o.create_group(g)
|
||||||
o.attrs['DADF5toDREAM3D'] = '1.0'
|
|
||||||
o.attrs['FileVersion'] = '7.0'
|
data_container_label = 'DataContainers/ImageDataContainer'
|
||||||
#-----------------------------------------------------------------
|
cell_data_label = data_container_label + '/CellData'
|
||||||
|
|
||||||
|
|
||||||
for g in ['DataContainerBundles','Pipeline']: # empty groups (needed)
|
# Phase information of DREAM.3D is constituent ID in DAMASK
|
||||||
o.create_group(g)
|
o[cell_data_label + '/Phases'] = f.get_constituent_ID().reshape(tuple(f.grid)+(1,))
|
||||||
|
# Data quaternions
|
||||||
|
DAMASK_quaternion = f.read_dataset(f.get_dataset_location('orientation'))
|
||||||
|
# Convert: DAMASK uses P = -1, DREAM.3D uses P = +1. Also change position of imagninary part
|
||||||
|
DREAM_3D_quaternion = np.hstack((-DAMASK_quaternion['x'],-DAMASK_quaternion['y'],-DAMASK_quaternion['z'],
|
||||||
|
DAMASK_quaternion['w'])).astype(np.float32)
|
||||||
|
o[cell_data_label + '/Quats'] = DREAM_3D_quaternion.reshape(tuple(f.grid)+(4,))
|
||||||
|
|
||||||
data_container_label = 'DataContainers/ImageDataContainer'
|
# Attributes to CellData group
|
||||||
cell_data_label = data_container_label + '/CellData'
|
o[cell_data_label].attrs['AttributeMatrixType'] = np.array([3],np.uint32)
|
||||||
|
o[cell_data_label].attrs['TupleDimensions'] = f.grid.astype(np.uint64)
|
||||||
|
|
||||||
|
# Common Attributes for groups in CellData
|
||||||
|
for group in ['/Phases','/Quats']:
|
||||||
|
o[cell_data_label + group].attrs['DataArrayVersion'] = np.array([2],np.int32)
|
||||||
|
o[cell_data_label + group].attrs['Tuple Axis Dimensions'] = 'x={},y={},z={}'.format(*f.grid)
|
||||||
|
|
||||||
|
# phase attributes
|
||||||
|
o[cell_data_label + '/Phases'].attrs['ComponentDimensions'] = np.array([1],np.uint64)
|
||||||
|
o[cell_data_label + '/Phases'].attrs['ObjectType'] = 'DataArray<int32_t>'
|
||||||
|
o[cell_data_label + '/Phases'].attrs['TupleDimensions'] = f.grid.astype(np.uint64)
|
||||||
|
|
||||||
|
# Quats attributes
|
||||||
|
o[cell_data_label + '/Quats'].attrs['ComponentDimensions'] = np.array([4],np.uint64)
|
||||||
|
o[cell_data_label + '/Quats'].attrs['ObjectType'] = 'DataArray<float>'
|
||||||
|
o[cell_data_label + '/Quats'].attrs['TupleDimensions'] = f.grid.astype(np.uint64)
|
||||||
|
|
||||||
|
# Create EnsembleAttributeMatrix
|
||||||
|
ensemble_label = data_container_label + '/EnsembleAttributeMatrix'
|
||||||
|
|
||||||
|
# Data CrystalStructures
|
||||||
|
o[ensemble_label + '/CrystalStructures'] = np.uint32(np.array([999,\
|
||||||
|
Crystal_structures[f.get_crystal_structure()]])).reshape((2,1))
|
||||||
|
o[ensemble_label + '/PhaseTypes'] = np.uint32(np.array([999,Phase_types['Primary']])).reshape((2,1)) # ToDo
|
||||||
|
|
||||||
|
# Attributes Ensemble Matrix
|
||||||
|
o[ensemble_label].attrs['AttributeMatrixType'] = np.array([11],np.uint32)
|
||||||
|
o[ensemble_label].attrs['TupleDimensions'] = np.array([2], np.uint64)
|
||||||
|
|
||||||
|
# Attributes for data in Ensemble matrix
|
||||||
|
for group in ['CrystalStructures','PhaseTypes']: # 'PhaseName' not required MD: But would be nice to take the phase name mapping
|
||||||
|
o[ensemble_label+'/'+group].attrs['ComponentDimensions'] = np.array([1],np.uint64)
|
||||||
|
o[ensemble_label+'/'+group].attrs['Tuple Axis Dimensions'] = 'x=2'
|
||||||
|
o[ensemble_label+'/'+group].attrs['DataArrayVersion'] = np.array([2],np.int32)
|
||||||
|
o[ensemble_label+'/'+group].attrs['ObjectType'] = 'DataArray<uint32_t>'
|
||||||
|
o[ensemble_label+'/'+group].attrs['TupleDimensions'] = np.array([2],np.uint64)
|
||||||
|
|
||||||
|
|
||||||
# Phase information of DREAM.3D is constituent ID in DAMASK
|
# Create geometry info
|
||||||
o[cell_data_label + '/Phases'] = f.get_constituent_ID().reshape(tuple(f.grid)+(1,))
|
geom_label = data_container_label + '/_SIMPL_GEOMETRY'
|
||||||
# Data quaternions
|
|
||||||
DAMASK_quaternion = f.read_dataset(f.get_dataset_location('orientation'))
|
|
||||||
# Convert: DAMASK uses P = -1, DREAM.3D uses P = +1. Also change position of imagninary part
|
|
||||||
DREAM_3D_quaternion = np.hstack((-DAMASK_quaternion['x'],-DAMASK_quaternion['y'],-DAMASK_quaternion['z'],
|
|
||||||
DAMASK_quaternion['w'])).astype(np.float32)
|
|
||||||
o[cell_data_label + '/Quats'] = DREAM_3D_quaternion.reshape(tuple(f.grid)+(4,))
|
|
||||||
|
|
||||||
# Attributes to CellData group
|
o[geom_label + '/DIMENSIONS'] = np.int64(f.grid)
|
||||||
o[cell_data_label].attrs['AttributeMatrixType'] = np.array([3],np.uint32)
|
o[geom_label + '/ORIGIN'] = np.float32(np.zeros(3))
|
||||||
o[cell_data_label].attrs['TupleDimensions'] = f.grid.astype(np.uint64)
|
o[geom_label + '/SPACING'] = np.float32(f.size)
|
||||||
|
|
||||||
# Common Attributes for groups in CellData
|
o[geom_label].attrs['GeometryName'] = 'ImageGeometry'
|
||||||
for group in ['/Phases','/Quats']:
|
o[geom_label].attrs['GeometryTypeName'] = 'ImageGeometry'
|
||||||
o[cell_data_label + group].attrs['DataArrayVersion'] = np.array([2],np.int32)
|
o[geom_label].attrs['GeometryType'] = np.array([0],np.uint32)
|
||||||
o[cell_data_label + group].attrs['Tuple Axis Dimensions'] = 'x={},y={},z={}'.format(*f.grid)
|
o[geom_label].attrs['SpatialDimensionality'] = np.array([3],np.uint32)
|
||||||
|
o[geom_label].attrs['UnitDimensionality'] = np.array([3],np.uint32)
|
||||||
# phase attributes
|
|
||||||
o[cell_data_label + '/Phases'].attrs['ComponentDimensions'] = np.array([1],np.uint64)
|
|
||||||
o[cell_data_label + '/Phases'].attrs['ObjectType'] = 'DataArray<int32_t>'
|
|
||||||
o[cell_data_label + '/Phases'].attrs['TupleDimensions'] = f.grid.astype(np.uint64)
|
|
||||||
|
|
||||||
# Quats attributes
|
|
||||||
o[cell_data_label + '/Quats'].attrs['ComponentDimensions'] = np.array([4],np.uint64)
|
|
||||||
o[cell_data_label + '/Quats'].attrs['ObjectType'] = 'DataArray<float>'
|
|
||||||
o[cell_data_label + '/Quats'].attrs['TupleDimensions'] = f.grid.astype(np.uint64)
|
|
||||||
|
|
||||||
# Create EnsembleAttributeMatrix
|
|
||||||
ensemble_label = data_container_label + '/EnsembleAttributeMatrix'
|
|
||||||
|
|
||||||
# Data CrystalStructures
|
|
||||||
o[ensemble_label + '/CrystalStructures'] = np.uint32(np.array([999,\
|
|
||||||
Crystal_structures[f.get_crystal_structure()]])).reshape((2,1))
|
|
||||||
o[ensemble_label + '/PhaseTypes'] = np.uint32(np.array([999,Phase_types['Primary']])).reshape((2,1)) # ToDo
|
|
||||||
|
|
||||||
# Attributes Ensemble Matrix
|
|
||||||
o[ensemble_label].attrs['AttributeMatrixType'] = np.array([11],np.uint32)
|
|
||||||
o[ensemble_label].attrs['TupleDimensions'] = np.array([2], np.uint64)
|
|
||||||
|
|
||||||
# Attributes for data in Ensemble matrix
|
|
||||||
for group in ['CrystalStructures','PhaseTypes']: # 'PhaseName' not required MD: But would be nice to take the phase name mapping
|
|
||||||
o[ensemble_label+'/'+group].attrs['ComponentDimensions'] = np.array([1],np.uint64)
|
|
||||||
o[ensemble_label+'/'+group].attrs['Tuple Axis Dimensions'] = 'x=2'
|
|
||||||
o[ensemble_label+'/'+group].attrs['DataArrayVersion'] = np.array([2],np.int32)
|
|
||||||
o[ensemble_label+'/'+group].attrs['ObjectType'] = 'DataArray<uint32_t>'
|
|
||||||
o[ensemble_label+'/'+group].attrs['TupleDimensions'] = np.array([2],np.uint64)
|
|
||||||
|
|
||||||
|
|
||||||
# Create geometry info
|
|
||||||
geom_label = data_container_label + '/_SIMPL_GEOMETRY'
|
|
||||||
|
|
||||||
o[geom_label + '/DIMENSIONS'] = np.int64(f.grid)
|
|
||||||
o[geom_label + '/ORIGIN'] = np.float32(np.zeros(3))
|
|
||||||
o[geom_label + '/SPACING'] = np.float32(f.size)
|
|
||||||
|
|
||||||
o[geom_label].attrs['GeometryName'] = 'ImageGeometry'
|
|
||||||
o[geom_label].attrs['GeometryTypeName'] = 'ImageGeometry'
|
|
||||||
o[geom_label].attrs['GeometryType'] = np.array([0],np.uint32)
|
|
||||||
o[geom_label].attrs['SpatialDimensionality'] = np.array([3],np.uint32)
|
|
||||||
o[geom_label].attrs['UnitDimensionality'] = np.array([3],np.uint32)
|
|
||||||
|
|
Loading…
Reference in New Issue