pythonparaview

ParaView: How to create a new vector based on an existing vector using Programmable Filter


My VTI file loaded in Paraview has a 3D data array named MyVelocity. I want to create a new velocity vector as follows:

unew = -u
vnew = -v
wnew =  w

I am trying to use a Programmable Filter to create this array.

import numpy

u=inputs[0].PointData["MyVelocity"][:,0]
v=inputs[0].PointData["MyVelocity"][:,1]
w=inputs[0].PointData["MyVelocity"][:,2]
output.PointData.append([-u,-v,w], "vector")

However, I am running into the following error.

Traceback (most recent call last):
  File "<string>", line 22, in <module>
  File "<string>", line 7, in RequestData
  File "C:\Program Files\ParaView 5.13.0\bin\Lib\site-packages\vtkmodules\numpy_interface\dataset_adapter.py", line 763, in append
    arr = numpyTovtkDataArray(copy, name)
  File "C:\Program Files\ParaView 5.13.0\bin\Lib\site-packages\vtkmodules\numpy_interface\dataset_adapter.py", line 146, in numpyTovtkDataArray
    vtkarray = numpy_support.numpy_to_vtk(array, array_type=array_type)
  File "C:\Program Files\ParaView 5.13.0\bin\Lib\site-packages\vtkmodules\util\numpy_support.py", line 146, in numpy_to_vtk
    vtk_typecode = get_vtk_array_type(z.dtype)
  File "C:\Program Files\ParaView 5.13.0\bin\Lib\site-packages\vtkmodules\util\numpy_support.py", line 69, in get_vtk_array_type
    raise TypeError(
TypeError: Could not find a suitable VTK type for object

Is this the proper way to create a new 3D vector?


Solution

  • The fist argument of append should be a numpy array, not a list. You can use make_vector(-u, -v, w) I think.

    Also, for this kind of operation you can also use the Python Calculator filter (and multinline expression)

    u = MyVelocity[:,0]
    v = MyVelocity[:,1]
    w = MyVelocity[:,2]
    
    outputArray=make_vector((-u, -v, w))
    return outputArray
    

    Some details in the doc:

    https://docs.paraview.org/en/latest/ReferenceManual/vtkNumPyIntegration.html

    https://docs.paraview.org/en/latest/UsersGuide/filteringData.html#python-calculator