Numpy wrapping of 'where' does not support composite dataset
When trying to use the 3 arguments version of where(condition, [x, y, ]/)
(see doc) from the numpy_interface.algorithms
module with a composite dataset, the returned array cannot be added the dataset.
Details
- create two
FastUniformGrid
- Select both,
GroupDataSet
-
Programmable Filter
to usealgs.where
(see below) -> errorTypeError: Could not find a suitable VTK type for object
script:
import paraview.vtk.numpy_interface.algorithms as algs
X = output.PointData['X']
Xpos = algs.where(X > 0, X, 0)
print('-- dataset')
print(type(Xpos))
print(Xpos)
output.PointData.append(Xpos, 'Xpos')
whole output:
Traceback (most recent call last):
File "<string>", line 22, in <module>
File "<string>", line 10, in RequestData
File "/home/nicolas/ParaView/master/build/lib/python3.10/site-packages/vtkmodules/numpy_interface/dataset_adapter.py", line 809, in append
ds.GetAttributes(self.Association).append(array, name)
File "/home/nicolas/ParaView/master/build/lib/python3.10/site-packages/vtkmodules/numpy_interface/dataset_adapter.py", line 748, in append
arr = numpyTovtkDataArray(copy, name)
File "/home/nicolas/ParaView/master/build/lib/python3.10/site-packages/vtkmodules/numpy_interface/dataset_adapter.py", line 148, in numpyTovtkDataArray
vtkarray = numpy_support.numpy_to_vtk(array, array_type=array_type)
File "/home/nicolas/ParaView/master/build/lib/python3.10/site-packages/vtkmodules/util/numpy_support.py", line 146, in numpy_to_vtk
vtk_typecode = get_vtk_array_type(z.dtype)
File "/home/nicolas/ParaView/master/build/lib/python3.10/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
-- dataset
<class 'paraview.vtk.numpy_interface.dataset_adapter.VTKCompositeDataArray'>
[array([0, 0, 0, ...,
<paraview.vtk.numpy_interface.dataset_adapter.VTKCompositeDataArray object at 0x7fd7d2d22a10>,
<paraview.vtk.numpy_interface.dataset_adapter.VTKCompositeDataArray object at 0x7fd7d2d22a10>,
<paraview.vtk.numpy_interface.dataset_adapter.VTKCompositeDataArray object at 0x7fd7d2d22a10>],
dtype=object), array([0, 0, 0, ...,
<paraview.vtk.numpy_interface.dataset_adapter.VTKCompositeDataArray object at 0x7fd7d2d22a10>,
<paraview.vtk.numpy_interface.dataset_adapter.VTKCompositeDataArray object at 0x7fd7d2d22a10>,
<paraview.vtk.numpy_interface.dataset_adapter.VTKCompositeDataArray object at 0x7fd7d2d22a10>],
dtype=object)]
Investigation
where
is wrapped with _make_ufunc
method that suppose only first arg to be an array. The _make_dfunc
method allows a second array but here we need 3 arguments to be arrays.
Workaround
A workaround is to iterate over meshes with for dataset in output:
and the same processing in it.