This is the python based reader i use for testing cobbled together from some of the examples
readertest.py
from paraview.util.vtkAlgorithm import *
from vtk.numpy_interface import algorithms as algs
from vtk.numpy_interface import dataset_adapter as dsa
import numpy as np
import vtk
@smproxy.reader(name="PythonCSVReader", label="Python-based CSV Reader",
extensions="csv", file_description="CSV files")
class PythonCSVReader(VTKPythonAlgorithmBase):
def __init__(self):
VTKPythonAlgorithmBase.__init__(self, nInputPorts=0, nOutputPorts=1, outputType='vtkPolyData')
self._filename = None
@smproperty.stringvector(name="FileName")
@smdomain.filelist()
@smhint.filechooser(extensions="csv", file_description=" CSV files")
def SetFileName(self, name):
"""Specify filename for the file to read."""
print("setname: ",name)
if self._filename != name:
self._filename = name
self.Modified()
def RequestData(self, request, inInfoVec, outInfoVec):
from vtkmodules.vtkCommonDataModel import vtkPolyData
output = vtkPolyData.GetData(outInfoVec, 0)
tt = self._filename
data = np.genfromtxt(tt,dtype=None, names=True,delimiter=',',autostrip=True)
# convert the 3 arrays into a single 3 component array for
# use as the coordinates for the points.
coordinates = algs.make_vector(data["X"],data["Y"],data["Z"])
# create a vtkPoints container to store all the
# point coordinates.
pts = vtk.vtkPoints()
# numpyTovtkDataArray is needed to called directly to convert the NumPy
# to a vtkDataArray which vtkPoints::SetData() expects.
pts.SetData(dsa.numpyTovtkDataArray(coordinates , "Points"))
# set the pts on the output.
output.SetPoints(pts)
# next, we define the cells i.e. the connectivity for this mesh.
# here, we are creating merely a point could, so we’ll add
# that as a single poly vextex cell.
numPts = pts.GetNumberOfPoints()
# ptIds is the list of point ids in this cell
# (which is all the points)
ptIds = vtk.vtkIdList()
ptIds.SetNumberOfIds(numPts )
for a in range( numPts ):
ptIds.SetId(a , a)
# Allocate space for 1 cell.
output.Allocate (1)
output.InsertNextCell( vtk.VTK_POLY_VERTEX , ptIds )
return 1
It reads x,y,z data from a CSV file as single points. An example csv file could be
data_1.csv:
X,Y,Z
1,2,3
4,5,2
8,5,1
4,1,6
3,2,2
This works well in paraview.
My goal is now to wrap this in a FileSeries reader to make use of the automatic time series treatment of numbered input files just as the OP.
As first start i have created a slightly modified version one of the existing reader definitions to make sure this works as i expect. (I changed the extension from vtk to vtka to make sure its actually the new reader being called.)
<ServerManagerConfiguration>
<ProxyGroup name="internal_sources">
<SourceProxy name="readertest"
class="vtkPDataSetReader"
label="Legacy VTK reader aaa">
<StringVectorProperty
name="FileName"
animateable="0"
command="SetFileName"
number_of_elements="1">
<FileListDomain name="files"/>
<Documentation>
This property specifies the file name for the Legacy VTK reader.
</Documentation>
</StringVectorProperty>
<Hints>
<ReaderFactory extensions="vtka"
file_description="Legacy VTK files" />
</Hints>
</SourceProxy>
</ProxyGroup>
<ProxyGroup name="sources">
<SourceProxy name="seriesreadertest"
class="vtkFileSeriesReader"
si_class="vtkSIMetaReaderProxy"
label="Legacy VTK reader aaa"
file_name_method="SetFileName">
<SubProxy>
<Proxy name="Reader"
proxygroup="internal_sources" proxyname="readertest">
</Proxy>
</SubProxy>
<StringVectorProperty name="FileNameInfo"
command="GetCurrentFileName"
information_only="1" >
<SimpleStringInformationHelper />
</StringVectorProperty>
<StringVectorProperty
name="FileNames"
clean_command="RemoveAllFileNames"
command="AddFileName"
animateable="0"
number_of_elements="0"
repeat_command="1">
<FileListDomain name="files"/>
</StringVectorProperty>
<DoubleVectorProperty
name="TimestepValues"
repeatable="1"
information_only="1">
<TimeStepsInformationHelper/>
</DoubleVectorProperty>
<Hints>
<ReaderFactory extensions="vtka"
file_description="Legacy VTK files aaa" />
</Hints>
</SourceProxy>
</ProxyGroup>
</ServerManagerConfiguration>
Saving two cone sources as legacy vtk and naming them cone_1.vtka and cone_2.vtka results in the desired effect.
The problem starts if i try to wrap my python based csv reader from above. I use the following definition:
<ServerManagerConfiguration>
<ProxyGroup name="sources">
<SourceProxy name="TimeTestFileReader"
class="vtkFileSeriesReader"
si_class="vtkSIMetaReaderProxy"
label="time test reader csv"
file_name_method="SetFileName">
<SubProxy>
<Proxy name="Reader"
proxygroup="sources" proxyname="PythonCSVReader">
</Proxy>
</SubProxy>
<StringVectorProperty name="FileNameInfo"
command="GetCurrentFileName"
information_only="1" >
<SimpleStringInformationHelper />
</StringVectorProperty>
<StringVectorProperty
name="FileNames"
clean_command="RemoveAllFileNames"
command="AddFileName"
animateable="0"
number_of_elements="0"
repeat_command="1">
<FileListDomain name="files"/>
</StringVectorProperty>
<DoubleVectorProperty
name="TimestepValues"
repeatable="1"
information_only="1">
<TimeStepsInformationHelper/>
</DoubleVectorProperty>
<Hints>
<ReaderFactory extensions="csv"
file_description="csv timetest" />
</Hints>
</SourceProxy>
</ProxyGroup>
</ServerManagerConfiguration>
Using this definition i get the following error message indicating a filename of none is passed to numpy:
( 20.960s) [paraview ] vtkPythonAlgorithm.cxx:112 ERR| vtkPythonAlgorithm (0x55fbe960c050): Failure when calling method: "ProcessRequest":
Traceback (most recent call last):
File "/mnt/hdd/build/paraview/src/build/lib/python3.7/site-packages/vtkmodules/util/vtkAlgorithm.py", line 152, in ProcessRequest
return vtkself.ProcessRequest(request, inInfo, outInfo)
File "/mnt/hdd/build/paraview/src/build/lib/python3.7/site-packages/vtkmodules/util/vtkAlgorithm.py", line 198, in ProcessRequest
return self.RequestData(request, inInfo, outInfo)
File "paraplugintest/singlereader.py", line 36, in RequestData
data = np.genfromtxt(tt,dtype=None, names=True,delimiter=',',autostrip=True)
File "/usr/lib/python3.7/site-packages/numpy/lib/npyio.py", line 1759, in genfromtxt
fid = np.lib._datasource.open(fname, 'rt', encoding=encoding)
File "/usr/lib/python3.7/site-packages/numpy/lib/_datasource.py", line 269, in open
return ds.open(path, mode, encoding=encoding, newline=newline)
File "/usr/lib/python3.7/site-packages/numpy/lib/_datasource.py", line 623, in open
raise IOError("%s not found." % path)
OSError: None not found.
In the debug output i can see that the SetFileName method of my python reader containing the
print("setname: ",name)
called by the wrapper, it just gets passed a name of None resulting in the above error.
setname: None
This looks to me as the same issue the OP had and as something to do with the interaction of the wrapper and the reader.
Is there anything wrong with the way i have set this up? Maybe I’m missing something?