[vtkusers] Error using vtk.numpy_interface.algorithms - volume
Cory Quammen
cory.quammen at kitware.com
Mon Oct 19 10:38:42 EDT 2015
Hi Richard,
It looks like you need to wrap your VTK data object, i.e.,
cell_volumes = algs.volume(dsa.WrapDataObject(ds))
This wraps the VTK object in an object that can be passed into the
functions in the numpy_interface.algorithms module.
It looks like you had this in the code, but commented it out. Did wrapping
the VTK object not work?
Thanks,
Cory
On Fri, Oct 16, 2015 at 8:42 PM, McDonald, Richard <rmcd at usgs.gov> wrote:
> 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
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
>
--
Cory Quammen
R&D Engineer
Kitware, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20151019/fab660f7/attachment.html>
More information about the vtkusers
mailing list