use 4 space indentation
This commit is contained in:
parent
87b857d307
commit
1f01dce862
|
@ -33,44 +33,44 @@ scriptID = ' '.join([scriptName,damask.version])
|
||||||
|
|
||||||
# ----- helper function ----- #
|
# ----- helper function ----- #
|
||||||
def get_rectMshVectors(xyz_array, posNum):
|
def get_rectMshVectors(xyz_array, posNum):
|
||||||
"""take in a xyz array from rectangular mesh and figure out Vx, Vy, Vz"""
|
"""take in a xyz array from rectangular mesh and figure out Vx, Vy, Vz"""
|
||||||
# need some improvement, and only works for rectangular grid
|
# need some improvement, and only works for rectangular grid
|
||||||
v = sorted(list(set(xyz_array[:, posNum])))
|
v = sorted(list(set(xyz_array[:, posNum])))
|
||||||
v_interval = (v[2]+v[1])/2.0 - (v[1]+v[0])/2.0
|
v_interval = (v[2]+v[1])/2.0 - (v[1]+v[0])/2.0
|
||||||
v_start = (v[1]+v[0])/2.0 - v_interval
|
v_start = (v[1]+v[0])/2.0 - v_interval
|
||||||
v_end = (v[-1]+v[-2])/2.0 + v_interval
|
v_end = (v[-1]+v[-2])/2.0 + v_interval
|
||||||
V = np.linspace(v_start, v_end, len(v)+1)
|
V = np.linspace(v_start, v_end, len(v)+1)
|
||||||
return V
|
return V
|
||||||
|
|
||||||
|
|
||||||
# ----- MAIN ---- #
|
# ----- MAIN ---- #
|
||||||
desp_msg = "Convert DAMASK ascii table to HDF5 file"
|
desp_msg = "Convert DAMASK ascii table to HDF5 file"
|
||||||
parser = OptionParser(option_class=damask.extendableOption,
|
parser = OptionParser(option_class=damask.extendableOption,
|
||||||
usage='%prog options [file[s]]',
|
usage='%prog options [file[s]]',
|
||||||
description = desp_msg,
|
description = desp_msg,
|
||||||
version = scriptID)
|
version = scriptID)
|
||||||
parser.add_option('-D', '--DefinitionFile',
|
parser.add_option('-D', '--DefinitionFile',
|
||||||
dest = 'storage definition file',
|
dest = 'storage definition file',
|
||||||
type = 'string',
|
type = 'string',
|
||||||
metavar = 'string',
|
metavar = 'string',
|
||||||
help = 'definition file for H5 data storage')
|
help = 'definition file for H5 data storage')
|
||||||
parser.add_option('-p',
|
parser.add_option('-p',
|
||||||
'--pos', '--position',
|
'--pos', '--position',
|
||||||
dest = 'pos',
|
dest = 'pos',
|
||||||
type = 'string', metavar = 'string',
|
type = 'string', metavar = 'string',
|
||||||
help = 'label of coordinates [%default]')
|
help = 'label of coordinates [%default]')
|
||||||
|
|
||||||
parser.set_defaults(DefinitionFile='default',
|
parser.set_defaults(DefinitionFile='default',
|
||||||
pos='pos')
|
pos='pos')
|
||||||
|
|
||||||
(options,filenames) = parser.parse_args()
|
(options,filenames) = parser.parse_args()
|
||||||
|
|
||||||
filename = filenames[0]
|
filename = filenames[0]
|
||||||
|
|
||||||
if options.DefinitionFile == 'default':
|
if options.DefinitionFile == 'default':
|
||||||
defFile = None
|
defFile = None
|
||||||
else:
|
else:
|
||||||
defFile = options.DefinitionFile
|
defFile = options.DefinitionFile
|
||||||
|
|
||||||
# ----- read in data using DAMASK ASCII table class ----- #
|
# ----- read in data using DAMASK ASCII table class ----- #
|
||||||
asciiTable = damask.ASCIItable(name=filename, buffered=False)
|
asciiTable = damask.ASCIItable(name=filename, buffered=False)
|
||||||
|
@ -96,9 +96,9 @@ mshGridDim = [len(Vx)-1, len(Vy)-1, len(Vz)-1]
|
||||||
# force remove existing HDF5 file
|
# force remove existing HDF5 file
|
||||||
h5fName = filename.replace(".txt", ".h5")
|
h5fName = filename.replace(".txt", ".h5")
|
||||||
try:
|
try:
|
||||||
os.remove(h5fName)
|
os.remove(h5fName)
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
h5f = damask.H5Table(h5fName,
|
h5f = damask.H5Table(h5fName,
|
||||||
new_file=True,
|
new_file=True,
|
||||||
dsXMLFile=defFile)
|
dsXMLFile=defFile)
|
||||||
|
@ -112,24 +112,29 @@ h5f.add_data("Vz", Vz)
|
||||||
# add the rest of data from table
|
# add the rest of data from table
|
||||||
labelsProcessed = ['inc']
|
labelsProcessed = ['inc']
|
||||||
for fi in xrange(len(labels)):
|
for fi in xrange(len(labels)):
|
||||||
featureName = labels[fi]
|
featureName = labels[fi]
|
||||||
# remove trouble maker "("" and ")" from label/feature name
|
# remove trouble maker "("" and ")" from label/feature name
|
||||||
if "(" in featureName: featureName = featureName.replace("(", "")
|
if "(" in featureName:
|
||||||
if ")" in featureName: featureName = featureName.replace(")", "")
|
featureName = featureName.replace("(", "")
|
||||||
# skip increment and duplicated columns in the ASCII table
|
if ")" in featureName:
|
||||||
if featureName in labelsProcessed: continue
|
featureName = featureName.replace(")", "")
|
||||||
|
# skip increment and duplicated columns in the ASCII table
|
||||||
|
if featureName in labelsProcessed:
|
||||||
|
continue
|
||||||
|
|
||||||
featureIdx = labels_idx[fi]
|
featureIdx = labels_idx[fi]
|
||||||
featureDim = featuresDim[fi]
|
featureDim = featuresDim[fi]
|
||||||
# grab the data hook
|
# grab the data hook
|
||||||
dataset = fullTable[:, featureIdx:featureIdx+featureDim]
|
dataset = fullTable[:, featureIdx:featureIdx+featureDim]
|
||||||
# mapping 2D data onto a 3D rectangular mesh to get 4D data
|
# mapping 2D data onto a 3D rectangular mesh to get 4D data
|
||||||
# WARNING: In paraview, the data for a recmesh is mapped as:
|
# WARNING: In paraview, the data for a recmesh is mapped as:
|
||||||
# --> len(z), len(y), len(x), size(data)
|
# --> len(z), len(y), len(x), size(data)
|
||||||
# dataset = dataset.reshape((mshGridDim[0], mshGridDim[1], mshGridDim[2],
|
# dataset = dataset.reshape((mshGridDim[0],
|
||||||
# dataset.shape[1]))
|
# mshGridDim[1],
|
||||||
# write out data
|
# mshGridDim[2],
|
||||||
print "adding {}...".format(featureName)
|
# dataset.shape[1]))
|
||||||
h5f.add_data(featureName, dataset)
|
# write out data
|
||||||
# write down the processed label
|
print "adding {}...".format(featureName)
|
||||||
labelsProcessed.append(featureName)
|
h5f.add_data(featureName, dataset)
|
||||||
|
# write down the processed label
|
||||||
|
labelsProcessed.append(featureName)
|
||||||
|
|
Loading…
Reference in New Issue