pearu/pyvtk

unstructured.py example fails with error

rabernat opened this issue · 4 comments

Thanks for creating this very useful package.

I am trying to learn to use it by following the examples. When running unstructured.py, I get the following error

      1 vtk = pyvtk.VtkData(  pyvtk.UnstructuredGrid(points,
----> 2     triangle=tri.simplices
      3     ),
      4   pyvtk.PointData(pyvtk.Scalars(pointPressure,name='Pressure')),
      5   pyvtk.CellData(pyvtk.Scalars(cellTemp,name='Temperature')),

/home/rpa/.conda/envs/lagrangian_vorticity/lib/python2.7/site-packages/pyvtk/UnstructuredGrid.pyc in __init__(self, points, vertex, poly_vertex, line, poly_line, triangle, triangle_strip, polygon, pixel, quad, tetra, voxel, hexahedron, wedge, pyramid, quadratic_tetra)
     71                 self.vertex = r
     72             if self._check_int_seq(getattr(self,k),sz):
---> 73                 raise ValueError('In cell %s: must be (seq of seq|seq) integers less than %s'%(k,sz))
     74 
     75         for k,n in self._vtk_cell_nums_map.items():

ValueError: In cell triangle: must be (seq of seq|seq) integers less than 1000

I am not very familiar with the internals of the package, so it's hard for me to debug what is going on.

Thanks @SteveDoyle2 for your reply.

This is straight from the official examples for the package:
https://github.com/pearu/pyvtk/blob/master/examples/unstructured.py
It is very confusing for a new user to encounter broken examples. I am not in a good position to debug this, given my unfamiliarity with the code.

The problem is in the function:
pyvtk.common.is_int

It checks for integers but not of the type scipy.spatial.Delaunay.simplices contains. In my case, it is numpy.int32, which is not a numpy.int_.
Changing tri.simplices to tri.simplices.astype(int) worked for me. This converts the array to numpy.int64.
I suppose that the pyvtk.common.is_int function should check on numpy.integer instead.

I had the same issue, and submitted this pull request.
The PR was merged into pyVTK but I'm not sure if the pip repository was updated after the pull request.
Doing a pip install might not have the PR, but installing from source will.