Question on vtkParticleTracer Filter using vtkPythonAlgorithmBase

Hi, I have been trying to add vtkParticleTracer in external python script based on vtkPythonAlgorithmBase.

Paraview Version: 5.11.1

So far what I have understood is:

  1. vtkParticleTracer requires two inputs: A dataset containing ‘velocity’ field and Seeds.
  2. Time related information such as TIME_STEPS, TIME_RANGE, UPDATE_TIME_STEPS and DATA_TIME_STEPS must be present in both inputs.
  3. Then Update() method of vtkParticleTracer() should move particles given in the ‘Seed’ object.

What I have done:

  1. I have a dataset from which I am manually calculating ‘velocity’ field, copying old dataset onto a vtkPolyData object named ‘output_velocity_field’ using ShallowCopy() and then appending ‘velocity’ field to this vtkPolyData object. I am doing same for Seeds with name ‘output_seeds’.
  2. I also set ‘velocity’ field: tracer.SetInputArrayToProcess(0, 0, 0, vtk.vtkDataObject.FIELD_ASSOCIATION_POINTS, “velocity”).
  3. Now, when I ran Update() of vtkParticleTracer(), it gives error: Input Data does not have TIME_STEPS.
  4. So, I manually copy all four above mentioned time related fields to both: using ‘Set’ method which looks like Set(SDSP.TIME_STEPS(), time_steps, len(time_steps)). where SDSP = vtkStreamingDemandDrivenPipeline.
  5. I connect input to vtkParticleTracer(): tracer.SetInputData(0, output_velocity_field.VTKObject) and tracer.SetInputData(1, output_seeds) where tracer = vtkParticleTracer(). Particles were not moving.
  6. Then after copying, I wrap both of these object in TrivialProducer() objects and also again copy all four time related field onto both producers.
  7. Then, I use different method to set input to vtkParticleTracer: self.particle_tracer.SetInputConnection(0, velocity_field_producer.GetOutputPort()) and self.particle_tracer.SetInputConnection(1, self.seed_producer.GetOutputPort()).
  8. Particles were still not moving.
  9. I compared results by manually adding ParticleTracer from Paraview’s Filter menu with the external script and I found that ParticleAge is NOT incrementing at all when I use script but increments when I use filter from Paraview’s menu.
  10. I print the output of ‘GetIntegrator()’ method of vtkParticleTracer():
    vtkRungeKutta4 (0x2745fe10)
    Debug: Off
    Modified Time: 8761737
    Reference Count: 2
    Registered Events: (none)
    Function set : 0
    Function values : 0
    Function derivatives: 0
    Initialized: No
    Runge-Kutta 4 function derivatives: 0 0 0

What could be issue here? I want an external filter which applies Particle Tracer filter and then Temporal Particles to Pathlines filter using vtkPythonAlgorithmBase. Both of these filter works perfectly when using Paraview within GUI from filters menu. But I want to apply them using external script.

Please share your data.

Sure.

Data: DataSet

Either of the NetCDF file works.

Path Lines Script: https://pastebin.com/iP6TiURG

I have also uploaded picture of what I want using script and I already got it using Filter from Paraview GUI but I want using external script.

What do you mean by external script ? You mention vtkPythonAlgorithmBase, are you writing a python plugin ?

Yes. I am writing a plugin which I can load from Tools → Manage Plugins menu and then select dataset in the pipeline and apply over it.

Writing a temporal filter in a python plugin can be really chalenging. If your objective is to simplify the process and reduce the number of clicks, I’d suggest using state files, python macros or default settings instead.

If you want to keep making this work as a python plugin, then please share your full code.

Oh, I see. If possible, I want make a python plugin for this. I did same for vtkStreamTracer and it works perfectly, however it does not involve temporal data I guess.

Here’s the code what I am currently using: New_Pathlines.py

    def RequestInformation(self, request, inInfo, outInfo):
        return 1
    
    def RequestUpdateExtent(self, request, inInfo, outInfo):
        return 1

You definitely need to implement these, I dont have an example on hand for temporal implement though.

So, right now I am manually coping TIME_STEPS, TIME_RANGE, UPDATE_TIME_STEP to the input from dataset.

I believe these functions does that automatically. I tried earlier using these functions before manually copying everything. vtkParticleTracer() still complained Input not having TIME_STEPS.

Well, I have decided to use Macro. It works perfectly.

1 Like