less error prone
This commit is contained in:
parent
892b7eee98
commit
0556827f29
|
@ -22,8 +22,6 @@ Writes vtk file for visualization.
|
||||||
""", version = scriptID)
|
""", version = scriptID)
|
||||||
|
|
||||||
(options, filenames) = parser.parse_args()
|
(options, filenames) = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
if filenames == []: filenames = [None]
|
if filenames == []: filenames = [None]
|
||||||
|
|
||||||
for name in filenames:
|
for name in filenames:
|
||||||
|
@ -33,7 +31,7 @@ for name in filenames:
|
||||||
|
|
||||||
damask.util.croak(geom)
|
damask.util.croak(geom)
|
||||||
|
|
||||||
if name is None:
|
if name:
|
||||||
sys.stdout.write(geom.to_vtk())
|
|
||||||
else:
|
|
||||||
geom.to_vtk(os.path.splitext(name)[0])
|
geom.to_vtk(os.path.splitext(name)[0])
|
||||||
|
else:
|
||||||
|
sys.stdout.write(geom.to_vtk())
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from io import StringIO
|
||||||
|
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 [seedfile(s)]', description = """
|
||||||
|
Writes vtk file for visualization.
|
||||||
|
|
||||||
|
""", version = scriptID)
|
||||||
|
|
||||||
|
(options, filenames) = parser.parse_args()
|
||||||
|
if filenames == []: filenames = [None]
|
||||||
|
|
||||||
|
for name in filenames:
|
||||||
|
damask.util.report(scriptName,name)
|
||||||
|
|
||||||
|
seeds = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
||||||
|
v = damask.VTK.from_polyData(seeds.get('pos'))
|
||||||
|
for label in seeds.shapes.keys():
|
||||||
|
if label == 'pos': pass
|
||||||
|
v.add(seeds.get(label),label)
|
||||||
|
|
||||||
|
if name:
|
||||||
|
v.write(os.path.splitext(name)[0])
|
||||||
|
else:
|
||||||
|
sys.stdout.write(v.__repr__())
|
|
@ -1,11 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
for seeds in "$@"
|
|
||||||
do
|
|
||||||
vtk_pointCloud $seeds
|
|
||||||
|
|
||||||
vtk_addPointCloudData $seeds \
|
|
||||||
--data microstructure,weight \
|
|
||||||
--vtk ${seeds%.*}.vtp \
|
|
||||||
|
|
||||||
done
|
|
|
@ -177,8 +177,8 @@ class VTK:
|
||||||
|
|
||||||
default_ext = writer.GetDefaultFileExtension()
|
default_ext = writer.GetDefaultFileExtension()
|
||||||
name, ext = os.path.splitext(fname)
|
name, ext = os.path.splitext(fname)
|
||||||
if ext and ext != default_ext:
|
if ext and ext != '.'+default_ext:
|
||||||
raise ValueError('Given extension {} is not {}'.format(ext,default_ext))
|
raise ValueError('Given extension {} is not .{}'.format(ext,default_ext))
|
||||||
writer.SetFileName('{}.{}'.format(name,default_ext))
|
writer.SetFileName('{}.{}'.format(name,default_ext))
|
||||||
writer.SetCompressorTypeToZLib()
|
writer.SetCompressorTypeToZLib()
|
||||||
writer.SetDataModeToBinary()
|
writer.SetDataModeToBinary()
|
||||||
|
@ -196,15 +196,17 @@ class VTK:
|
||||||
|
|
||||||
if isinstance(data,np.ndarray):
|
if isinstance(data,np.ndarray):
|
||||||
d = np_to_vtk(num_array=data.reshape(data.shape[0],-1),deep=True)
|
d = np_to_vtk(num_array=data.reshape(data.shape[0],-1),deep=True)
|
||||||
|
if not label:
|
||||||
|
raise ValueError('No label defined for numpy.ndarray')
|
||||||
d.SetName(label)
|
d.SetName(label)
|
||||||
if data.shape[0] == N_cells:
|
if data.shape[0] == N_cells:
|
||||||
self.geom.GetCellData().AddArray(d)
|
self.geom.GetCellData().AddArray(d)
|
||||||
elif data.shape[0] == N_points:
|
elif data.shape[0] == N_points:
|
||||||
self.geom.GetPointData().AddArray(d)
|
self.geom.GetPointData().AddArray(d)
|
||||||
elif isinstance(data,pd.DataFrame):
|
elif isinstance(data,pd.DataFrame):
|
||||||
raise NotImplementedError
|
raise NotImplementedError('pd.DataFrame')
|
||||||
elif isinstance(data,Table):
|
elif isinstance(data,Table):
|
||||||
raise NotImplementedError
|
raise NotImplementedError('damask.Table')
|
||||||
else:
|
else:
|
||||||
raise TypeError
|
raise TypeError
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue