less error prone

This commit is contained in:
Martin Diehl 2020-03-19 18:43:49 +01:00
parent 892b7eee98
commit 0556827f29
4 changed files with 53 additions and 25 deletions

View File

@ -22,18 +22,16 @@ 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)
damask.util.report(scriptName,name)
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
damask.util.croak(geom)
if name is None:
sys.stdout.write(geom.to_vtk())
else:
geom.to_vtk(os.path.splitext(name)[0])
damask.util.croak(geom)
if name:
geom.to_vtk(os.path.splitext(name)[0])
else:
sys.stdout.write(geom.to_vtk())

39
processing/pre/seeds_check.py Executable file
View File

@ -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__())

View File

@ -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

View File

@ -177,8 +177,8 @@ class VTK:
default_ext = writer.GetDefaultFileExtension()
name, ext = os.path.splitext(fname)
if ext and ext != default_ext:
raise ValueError('Given extension {} is not {}'.format(ext,default_ext))
if ext and ext != '.'+default_ext:
raise ValueError('Given extension {} is not .{}'.format(ext,default_ext))
writer.SetFileName('{}.{}'.format(name,default_ext))
writer.SetCompressorTypeToZLib()
writer.SetDataModeToBinary()
@ -196,15 +196,17 @@ class VTK:
if isinstance(data,np.ndarray):
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)
if data.shape[0] == N_cells:
self.geom.GetCellData().AddArray(d)
elif data.shape[0] == N_points:
self.geom.GetPointData().AddArray(d)
elif isinstance(data,pd.DataFrame):
raise NotImplementedError
raise NotImplementedError('pd.DataFrame')
elif isinstance(data,Table):
raise NotImplementedError
raise NotImplementedError('damask.Table')
else:
raise TypeError