Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a contour plot in paraview from a numpy array

I have a large binary file that contains all the information I want to plot. The data is ordered in such a way that its easiest to read into a 3D numpy array, this worked fine when I was using Mayavi to plot it using the contour3d() function. Now I'm using Paraview and I can't find any examples of how I could accomplish the same thing. It seems like the only way to get data in is to read it directly from a file in one of many formats and not a numpy array. Any ideas?

like image 942
pter Avatar asked Jul 11 '26 19:07

pter


1 Answers

As far as I understand, mayavi is build on tvtk, a wrapper of vtk designed for Traits support and an easier handling of NumPy.

ParaView on the other hand is based on pure vtk, which makes it a tad less straightforward to manipulate ndarrays directly. However, some support functions are readily available:

>>> from vtk.util import numpy_support as npvtk
>>> vtkarray = npvtk.numpy_to_vtk(numpy_array)
>>> numpy_array = npvtk.vtk_to_numpy(vtkarray)

More reading:

  • the examples from the vtk wiki are always a good start.
  • the vtk mailing list archive can also help you.
like image 108
Pierre GM Avatar answered Jul 13 '26 12:07

Pierre GM