DAMASK_EICMD/processing/misc/DREAM3D_toTable.py

75 lines
2.8 KiB
Python
Raw Normal View History

2016-08-02 15:00:36 +05:30
#!/usr/bin/env python2.7
# -*- coding: UTF-8 no BOM -*-
import os,h5py,sys
import numpy as np
from optparse import OptionParser
import damask
scriptName = os.path.splitext(os.path.basename(__file__))[0]
scriptID = ' '.join([scriptName,damask.version])
#--------------------------------------------------------------------------------------------------
# MAIN
#--------------------------------------------------------------------------------------------------
parser = OptionParser(option_class=damask.extendableOption, usage='%prog [geomfile[s]]', description = """
Convert DREAM3D file to ASCIItable
""", version = scriptID)
(options, filenames) = parser.parse_args()
rootDir ='DataContainers/ImageDataContainer'
# --- loop over input files -------------------------------------------------------------------------
if filenames == []: parser.error('no input file specified.')
for name in filenames:
try:
table = damask.ASCIItable(outname = os.path.splitext(name)[0]+'.txt',
buffered = False
)
except: continue
damask.util.report(scriptName,name)
inFile = h5py.File(name, 'r')
grid = inFile[rootDir+'/_SIMPL_GEOMETRY/DIMENSIONS'][...]
2016-08-02 15:00:36 +05:30
# --- read comments --------------------------------------------------------------------------------
coords = (np.mgrid[0:grid[2], 0:grid[1], 0: grid[0]]).reshape(3, -1).T
coords = (np.fliplr(coords)*inFile[rootDir+'/_SIMPL_GEOMETRY/SPACING'][...]
+ inFile[rootDir+'/_SIMPL_GEOMETRY/ORIGIN'][...]
+ inFile[rootDir+'/_SIMPL_GEOMETRY/SPACING'][...]*0.5)
table.data = np.hstack( (coords,
inFile[rootDir+'/CellData/EulerAngles'][...].reshape(grid.prod(),3),
inFile[rootDir+'/CellData/Phases'][...].reshape(grid.prod(),1),
inFile[rootDir+'/CellData/Confidence Index'][...].reshape(grid.prod(),1),
inFile[rootDir+'/CellData/Fit'][...].reshape(grid.prod(),1),
inFile[rootDir+'/CellData/Image Quality'][...].reshape(grid.prod(),1)))
labels = ['1_pos','2_pos','3_pos',
'1_Euler','2_Euler','3_Euler',
'PhaseID','CI','Fit','IQ']
try:
table.data = np.hstack((table.data, inFile[rootDir+'/CellData/FeatureIds'][...].reshape(grid.prod(),1)))
labels.append(['FeatureID'])
except Exception:
pass
2016-08-02 15:00:36 +05:30
# ------------------------------------------ assemble header ---------------------------------------
table.labels_clear()
table.labels_append(labels,reset = True)
2016-08-02 15:00:36 +05:30
table.head_write()
2016-08-02 15:00:36 +05:30
# ------------------------------------------ finalize output ---------------------------------------
table.data_writeArray() #(fmt='%e2.2')
2016-08-02 15:00:36 +05:30
table.close()