[vtkusers] Error using vtk.numpy_interface.algorithms - volume

McDonald, Richard rmcd at usgs.gov
Fri Oct 16 20:42:48 EDT 2015


Hello,
I've got a short VTK python code that I'm using the test the
vtk.numpy_interface.algorithms.  It follows from an example in a paper Cory
Quammen wrote for 14th Python in Science Conference ("Scientific Data
Analysis and Visualization with Python, VTK, and Paraview").  I've got a
numerical simulation of flow in a river saved as a vtk file.  It's a 3D
solution and I'd really like to get the volume of all the cells in the
grid.  I've tried the following example using the
vtk-6.2.0-cp27-none-win_amd64.whl distribution from the Christoph Gohlke
website and I've also tried it using the VTK 6.3 standalone version of
python.  The error is the same (AttributeError: VTKObject) that occurs in
the internal_algorithms.py", line 90, in _cell_quality
    ds.CopyStructure(dataset.VTKObject).  The code is below and the
terminal output follows.

Any help would be greatly appreciated.   Also, any other suggestions for
calculating the volume of cells in an VTKStructuredGrid would also be
appreciated.

Thanks,

Rich

import vtk
import vtk.numpy_interface.algorithms as algs
from vtk.numpy_interface import dataset_adapter as dsa
import numpy as np
import vtk.util.numpy_support as nps

file_name3Da = r'E:\RMCD_KOOTENAI_DRIVE_BACKUP\Arcrom\PartTrack\Result_VTK_3D_ASCII1.vtk'
file_name2Da = r'E:\RMCD_KOOTENAI_DRIVE_BACKUP\Arcrom\PartTrack\Result_VTK_2D_ASCII1.vtk'
vtkSGrid3D = vtk.vtkStructuredGrid()
reader3D = vtk.vtkStructuredGridReader()
reader3D.SetFileName(file_name3Da)
reader3D.SetOutput(vtkSGrid3D)
reader3D.Update() # Needed because of GetScalarRange
output3D = reader3D.GetOutput()

#use vtk.numpy interface
#ds = dsa.WrapDataObject(reader3D.GetOutput())

ds = reader3D.GetOutput()
pd = ds.GetPointData()
Velocity = pd.GetArray("Velocity (magnitude)")
np_Velocity = nps.vtk_to_numpy(Velocity)
min_v = np.min(np_Velocity)
max_v = np.max(np_Velocity)

print min_v, max_v

cell_volumes = algs.volume(ds)
print cell_volumes

Terminal output:

"C:\VTK 6.3.0\bin\python.exe" "C:/Python Projects/Arcrom/TestVTKNumpy.py"
Traceback (most recent call last):
  File "C:/Python Projects/Arcrom/TestVTKNumpy.py", line 29, in <module>
    cell_volumes = algs.volume(ds)
0.0 1.64687
  File "C:\Python27\Lib\site-packages\vtk\numpy_interface\algorithms.py",
line 130, in new_dsfunc2
    return dsfunc(ds)
  File
"C:\Python27\Lib\site-packages\vtk\numpy_interface\internal_algorithms.py",
line 484, in volume
    return _cell_quality(dataset, "volume")
  File
"C:\Python27\Lib\site-packages\vtk\numpy_interface\internal_algorithms.py",
line 90, in _cell_quality
    ds.CopyStructure(dataset.VTKObject)
AttributeError: VTKObject

-- 
Richard McDonald
Hydrologist
U.S. Geological Survey
Geomorphology and Sediment Transport Laboratory
4620 Technology Drive, Golden, CO 80403
rmcd at usgs.gov
303-278-7952
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20151016/51bea37c/attachment.html>


More information about the vtkusers mailing list