I mean you could use Python plugin with precompiled binaries from ParaView website (https://www.paraview.org/download/). You need to compile PV from sources if you want to use c++ plugins.
I’m already using the paraview application if that’s what you mean.
I think I’ll just stop using paraview and get back to matplotlib with this script
import numpy as np
def decimate(csvfile, factor=1000):
data = np.recfromcsv(csvfile, dtype=None, names=True, delimiter=',', autostrip=True)
output = np.recarray((np.shape(data)[0] // factor,), dtype=data.dtype)
for name in data.dtype.names:
input_row = np.array(data[name])
output_row = input_row[: len(input_row) // factor * factor].reshape(-1, factor).mean(1)
output[name] = output_row
print("file decimated")
return output
And Python plugin code:
"""
Created on Wed Jan 26 18:33:05 2022
@author: pavel.novikov
"""
from paraview.util.vtkAlgorithm import *
@smproxy.reader(name="CSV_Reader_with_downsampling",
label="Reader for .csv files with signal",
extensions="csv CSV",
file_description="CSV with signal")
class PythonCSVSignalReader(VTKPythonAlgorithmBase):
"""A reader that reads a .csv file"""
def __init__(self):
VTKPythonAlgorithmBase.__init__(self, nInputPorts=0, nOutputPorts=1,
outputType='vtkUnstructuredGrid')
self._filename = None
self._k = 10
self._s = 0.01
@smproperty.stringvector(name="FileName", visibility="hidden")
@smdomain.filelist()
@smhint.filechooser(extensions="csv",
file_description="CSV file with signal")
def SetFileName(self, name):
"""Specify filename for the file to read."""
if self._filename != name:
self._filename = name
self.Modified()
@smproperty.intvector(name="DownsampligCoef", default_values=10)
def SetK(self, k):
if self._k != k:
self._k = k
self.Modified()
@smproperty.doublevector(name="ScaleL", default_values=0.01)
def SetS(self, s):
if self._s != s:
self._s = s
self.Modified()
def RequestInformation(self, request, inInfoVec, outInfoVec):
"""Actions after selecting csv file before pressing Apply button"""
from vtkmodules.vtkCommonExecutionModel import vtkAlgorithm
outInfo = outInfoVec.GetInformationObject(0)
outInfo.Set(vtkAlgorithm.CAN_HANDLE_PIECE_REQUEST(), 1)
if self._filename is None:
raise RuntimeError("No filename specified")
return 1
def RequestData(self, request, inInfoVec, outInfoVec):
"""Actions after pressing Apply button"""
import vtk
import csv
output = self.GetOutputDataObject(0)
if not output.IsA("vtkUnstructuredGrid"):
print("Wrong output data type. Should be vtkUnstructuredGrid.")
raise SystemExit
self.output = output
self.output.Reset()
file = open(self._filename)
csv_reader = csv.reader(file)
h = next(csv_reader)
points = vtk.vtkPoints()
i_local = 0
sum_local_t = 0.0
sum_local_l = 0.0
for row in csv_reader:
i_local += 1
sum_local_l += float(row[0])
sum_local_t += float(row[1])
if i_local >= self._k:
t = sum_local_t / self._k
l = sum_local_l / self._k
points.InsertNextPoint(t, self._s*l, 0.0)
i_local = 0
sum_local_t = 0.0
sum_local_l = 0.0
self.output.SetPoints(points)
return 1
Hope this is a solution for your initial request.