Python Reader Plugin For ParaView Help

Hello,
I’m trying to make a ParaView Reader Plugin using python that can read HDF files. I started working on this code by stripping down a filter template to the bare minimum and tried to turn it into a reader by looking at other reader plugin examples. However, while the stripped down filter works fine when put into ParaView as a filter, when I changed the filter specific lines to turn it into a reader I kept getting the same error.

Whenever I would change the first line from .filter to .reader it wouldn’t work.
@smproxy.filter
@smproxy.reader

This is the error I get.
image

This is the code I have so far.

from paraview.util.vtkAlgorithm import *
from vtkmodules.numpy_interface import dataset_adapter as dsa
from vtkmodules.vtkCommonDataModel import vtkDataSet
import numpy as np

@smproxy.reader(name="MyWRFReader", label="My WRF Reader")
@smproperty.input(name="Input", port_index=0)
@smdomain.datatype(dataTypes=["vtkPointSet"])
@smdomain.xml("""<InputArrayDomain attribute_type="point" name="input_normal" number_of_components="3" />""")
@smhint.filechooser(extensions="csv", file_description="Numpy CSV files")
class MyWRFReader(VTKPythonAlgorithmBase):
    def __init__(self):
        VTKPythonAlgorithmBase.__init__(self, nInputPorts=0, nOutputPorts=1, outputType="vtkPointSet")
        self._filename = None
       

   # def RequestData(self, request, inInfoVec, outInfoVec):
        """inData = self.GetInputData(inInfo, 0, 0)
        outData = self.GetOutputData(outInfo, 0)
        assert inData is not None
        if outData is None or (not outData.IsA(inData.GetClassName())):
            outData = inData.NewInstance()
            outInfo.GetInformationObject(0).Set(outData.DATA_OBJECT(), outData)
        return super().RequestDataObject(request, inInfo, outInfo)"""

    @smproperty.stringvector(name="Normal")
    
    def SetNormalArray(self, name):
        if name != self.NormalArray:
            self.NormalArray = name
            self.Modified()


    @smproperty.doublevector(name="Factor", default_values="1")
    @smdomain.doublerange(min=0, max=10)
    def SetFactor(self, i):
        if i != self.WarpFactor:
            self.WarpFactor = i
            self.Modified()

    def RequestData(self, request, inInfo, outInfo):
       from vtkmodules.vtkCommonDataModel import imageToVTK
       from vtkmodules.numpy_interface import dataset_adapter as dsa
       output = vtkPolyData.GetData(outInfo)

       return 1

MyWRFReader.py (1.8 KB)

This is my first time working with python on a ParaView Plugin so I might be missing other stuff. Is there something wrong or missing with the code for it to not work?

Thanks.

Is your ParaView built with Python ?

Here’s the error when loading the plugin:

Generic Warning: In vtkPVPythonAlgorithmPlugin.cxx, line 184
Failed to load Python plugin:
Failed to call `paraview.detail.pythonalgorithm.load_plugin`.

Traceback (most recent call last):
  File "C:\Users\uayachit\Downloads\ParaView-5.11.0-RC2-Windows-Python3.9-msvc2017-AMD64\ParaView-5.11.0-RC2-Windows-Python3.9-msvc2017-AMD64\bin\Lib\site-packages\paraview\detail\pythonalgorithm.py", line 509, in load_plugin
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "C:\Users\uayachit\Downloads\MyWRFReader.py", line 6, in <module>
    @smproxy.reader(name="MyWRFReader", label="My WRF Reader")
TypeError: reader() missing 1 required positional argument: 'file_description'

You’re missing a required argument to reader() decorator.

When loading Python plugins, the error shown in the popup can be a little confusing. Since the plugin loader attempts first to load it as Python plugin and if that fails attempts to load the same file as a standard plugin – causing a rather cryptic popup message. You can get the full error message by looking at the Output Messages panel.

It is the binary version for Windows from paraview.org 5.11.0

I edited the above code to the following and the pop up error went away.

from vtkmodules.numpy_interface import dataset_adapter as dsa
from vtkmodules.vtkCommonDataModel import vtkDataSet
import numpy as np

@smproxy.reader(name="PythonHDFReader", label="Python-based HDF Reader",
                extensions="hdf", file_description="HDF files")
@smproperty.input(name="Input", port_index=0)
@smdomain.datatype(dataTypes=["vtkPointSet"])
@smdomain.xml("""<InputArrayDomain attribute_type="point" name="input_normal" number_of_components="3" />""")

class HDF5Reader(VTKPythonAlgorithmBase):
    def __init__(self):
        super().__init__(nInputPorts=1, nOutputPorts=1, outputType="vtkPointSet")
        self.WarpFactor = 1.0
        self.NormalArray = ""

        return 1

    def RequestData(self, request, inInfo, outInfo):
        from vtkmodules.vtkCommonDataModel import imageToVTK
        from vtkmodules.numpy_interface import dataset_adapter as dsa
                
        output = vtkPolyData.GetData(outInfo)
          
        return 1