<div dir="ltr">Hello,<div>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<br> ds.CopyStructure(dataset.VTKObject). The code is below and the terminal output follows. <div><br></div><div>Any help would be greatly appreciated. Also, any other suggestions for calculating the volume of cells in an VTKStructuredGrid would also be appreciated. </div><div><br></div><div>Thanks,</div><div><br></div><div>Rich<br><div><br></div><div><pre style="color:rgb(0,0,0);font-family:'Courier New';font-size:9pt"><span style="color:rgb(0,0,128);font-weight:bold">import </span>vtk<br><span style="color:rgb(0,0,128);font-weight:bold">import </span>vtk.numpy_interface.algorithms <span style="color:rgb(0,0,128);font-weight:bold">as </span>algs<br><span style="color:rgb(0,0,128);font-weight:bold">from </span>vtk.numpy_interface <span style="color:rgb(0,0,128);font-weight:bold">import </span>dataset_adapter <span style="color:rgb(0,0,128);font-weight:bold">as </span>dsa<br><span style="color:rgb(0,0,128);font-weight:bold">import </span>numpy <span style="color:rgb(0,0,128);font-weight:bold">as </span>np<br><span style="color:rgb(0,0,128);font-weight:bold">import </span>vtk.util.numpy_support <span style="color:rgb(0,0,128);font-weight:bold">as </span>nps<br><br>file_name3Da = <span style="color:rgb(0,128,0);font-weight:bold">r'E:\RMCD_KOOTENAI_DRIVE_BACKUP\Arcrom\PartTrack\Result_VTK_3D_ASCII1.vtk'<br></span>file_name2Da = <span style="color:rgb(0,128,0);font-weight:bold">r'E:\RMCD_KOOTENAI_DRIVE_BACKUP\Arcrom\PartTrack\Result_VTK_2D_ASCII1.vtk'<br></span>vtkSGrid3D = vtk.vtkStructuredGrid()<br>reader3D = vtk.vtkStructuredGridReader()<br>reader3D.SetFileName(file_name3Da)<br>reader3D.SetOutput(vtkSGrid3D)<br>reader3D.Update() <span style="color:rgb(128,128,128);font-style:italic"># Needed because of GetScalarRange<br></span>output3D = reader3D.GetOutput()<br><br><span style="color:rgb(128,128,128);font-style:italic">#use vtk.numpy interface<br></span><span style="color:rgb(128,128,128);font-style:italic">#ds = dsa.WrapDataObject(reader3D.GetOutput())<br></span><span style="color:rgb(128,128,128);font-style:italic"><br></span>ds = reader3D.GetOutput()<br>pd = ds.GetPointData()<br>Velocity = pd.GetArray(<span style="color:rgb(0,128,0);font-weight:bold">"Velocity (magnitude)"</span>)<br>np_Velocity = nps.vtk_to_numpy(Velocity)<br>min_v = np.min(np_Velocity)<br>max_v = np.max(np_Velocity)<br><br><span style="color:rgb(0,0,128);font-weight:bold">print </span>min_v, max_v<br><br>cell_volumes = algs.volume(ds)<br><span style="color:rgb(0,0,128);font-weight:bold">print </span>cell_volumes<br></pre><div>Terminal output:</div><div><br></div><div><div>"C:\VTK 6.3.0\bin\python.exe" "C:/Python Projects/Arcrom/TestVTKNumpy.py"</div><div>Traceback (most recent call last):</div><div> File "C:/Python Projects/Arcrom/TestVTKNumpy.py", line 29, in <module></div><div> cell_volumes = algs.volume(ds)</div><div>0.0 1.64687</div><div> File "C:\Python27\Lib\site-packages\vtk\numpy_interface\algorithms.py", line 130, in new_dsfunc2</div><div> return dsfunc(ds)</div><div> File "C:\Python27\Lib\site-packages\vtk\numpy_interface\internal_algorithms.py", line 484, in volume</div><div> return _cell_quality(dataset, "volume")</div><div> File "C:\Python27\Lib\site-packages\vtk\numpy_interface\internal_algorithms.py", line 90, in _cell_quality</div><div> ds.CopyStructure(dataset.VTKObject)</div><div>AttributeError: VTKObject</div></div><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">Richard McDonald<div>Hydrologist<br><div>U.S. Geological Survey</div><div>Geomorphology and Sediment Transport Laboratory</div><div>4620 Technology Drive, Golden, CO 80403</div><div><a href="mailto:rmcd@usgs.gov" target="_blank">rmcd@usgs.gov</a></div><div>303-278-7952</div></div></div></div>
</div></div></div></div>