# Unable to change filter timestep in python/pvbatch

**URL:** https://discourse.paraview.org/t/unable-to-change-filter-timestep-in-python-pvbatch/5725
**Category:** ParaView Support
**Tags:** python
**Created:** [November 5, 2020, 11:10am UTC](https://discourse.paraview.org/t/unable-to-change-filter-timestep-in-python-pvbatch/5725 "2020-11-05T11:10:51Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![lhcamilo](https://discourse.paraview.org/user_avatar/discourse.paraview.org/lhcamilo/32/5249_2.png) [@lhcamilo](https://discourse.paraview.org/u/lhcamilo)
#### Post date: [November 5, 2020, 11:10am UTC](https://discourse.paraview.org/t/unable-to-change-filter-timestep-in-python-pvbatch/5725/1 "2020-11-05T11:10:51Z")

</div>

I have been trying to write a batch script in python/pvbatch that would

- probe a location from an openfoam case.
- Read its velocity and pressure data
- Save the data onto a numpy array
- loop over all time steps of the case

Though for some reason I am not able to loop over all the time steps.

Here is a simplified version of my code: [https://pastebin.com/8iyyqibC](https://pastebin.com/8iyyqibC)

I would have thought that using

` TimeKeeper.Time = 0.33`

Note in the code that is written tk.Time = 0.33

Would be enough to change the probeLocation1 dataset to a new time step… but apparently that does not seem to be the case.

What am I missing? I thought this would be a trivial script but I am at my wit’s end.

Thanks in advance for your help

---

<div class="post-metadata">

### Author: ![theodorebaltis](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/t/e480ec/32.png) [@theodorebaltis](https://discourse.paraview.org/u/theodorebaltis)
#### Post date: [November 5, 2020, 4:20pm UTC](https://discourse.paraview.org/t/unable-to-change-filter-timestep-in-python-pvbatch/5725/2 "2020-11-05T16:20:41Z")

</div>

I know you said that was a simplified case but the first thing that jumps out at me is that you are explicitly setting the time. You already have a handle to the timesteps through `times = tk.TimestepValues` so you should set the time like `tk.Time = times[1]`

As far as the time looping goes, the full code shouldn’t be much different from a simplified version. Just some code pushed under a for loop.

You might need a general `UpdatePipeline()` or `Render()` call as well.

---

<div class="post-metadata">

### Author: ![lhcamilo](https://discourse.paraview.org/user_avatar/discourse.paraview.org/lhcamilo/32/5249_2.png) [@lhcamilo](https://discourse.paraview.org/u/lhcamilo)
#### Post date: [November 5, 2020, 4:54pm UTC](https://discourse.paraview.org/t/unable-to-change-filter-timestep-in-python-pvbatch/5725/3 "2020-11-05T16:54:56Z")

</div>

Hi,

thanks for takijng the time to answer.

This bit of code was a based off a trace I took.

I have not yet implemented a loop, as I thought I would not add any more complexity if I could not even manually switch the time affectively. The trace seemed to suggest that `tk.Time = ` was the way to go. But either this is not the case or there is a bug.

I have `probeLocation1.UpdatePipeline()` on line 55, so I doubt it will do anything or maybe I am using it wrong.

As for `Render()`, I thought that was just used to force a redraw/render to a viewport. Since this is strictly in the command line with no viewport, I thought it would not do anything. In fact, I just tested it and it gives an error if used.

So, the question still remains, how would I go about changing the time to location probe data?

---

<div class="post-metadata">

### Author: ![theodorebaltis](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/t/e480ec/32.png) [@theodorebaltis](https://discourse.paraview.org/u/theodorebaltis)
#### Post date: [November 5, 2020, 4:57pm UTC](https://discourse.paraview.org/t/unable-to-change-filter-timestep-in-python-pvbatch/5725/4 "2020-11-05T16:57:15Z")

</div>

I’ve never used the OpenFOAMReader but can you set the time on the reader itself?

---

<div class="post-metadata">

### Author: ![lhcamilo](https://discourse.paraview.org/user_avatar/discourse.paraview.org/lhcamilo/32/5249_2.png) [@lhcamilo](https://discourse.paraview.org/u/lhcamilo)
#### Post date: [November 5, 2020, 5:05pm UTC](https://discourse.paraview.org/t/unable-to-change-filter-timestep-in-python-pvbatch/5725/5 "2020-11-05T17:05:26Z")

</div>

I don’t think so, if it is possible, it is not obvious to me.

> **[paraview.simple.OpenFOAMReader — ParaView/Python 5.8.1 documentation](https://kitware.github.io/paraview-docs/latest/python/paraview.simple.OpenFOAMReader.html)**

---

<div class="post-metadata">

### Author: ![theodorebaltis](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/t/e480ec/32.png) [@theodorebaltis](https://discourse.paraview.org/u/theodorebaltis)
#### Post date: [November 5, 2020, 5:05pm UTC](https://discourse.paraview.org/t/unable-to-change-filter-timestep-in-python-pvbatch/5725/6 "2020-11-05T17:05:27Z")

</div>

You could also try using the animation scene like:

```python
scene = GetAnimationScene()
scene.GoToNext()

```

---

<div class="post-metadata">

### Author: ![lhcamilo](https://discourse.paraview.org/user_avatar/discourse.paraview.org/lhcamilo/32/5249_2.png) [@lhcamilo](https://discourse.paraview.org/u/lhcamilo)
#### Post date: [November 5, 2020, 5:09pm UTC](https://discourse.paraview.org/t/unable-to-change-filter-timestep-in-python-pvbatch/5725/7 "2020-11-05T17:09:44Z")

</div>

I am afraid that did not work

---

<div class="post-metadata">

### Author: ![lizliv](https://discourse.paraview.org/user_avatar/discourse.paraview.org/lizliv/32/9725_2.png) [@lizliv](https://discourse.paraview.org/u/lizliv)
#### Post date: [August 8, 2022, 4:10pm UTC](https://discourse.paraview.org/t/unable-to-change-filter-timestep-in-python-pvbatch/5725/8 "2022-08-08T16:10:10Z")

</div>

Did you ever figure this problem out? I am having a similar issue. I can loop over time to get data with this code:

```auto
visualiseInParaview_pht = PhastaReader(FileName=fPath+meshPath)
renderView1 = GetActiveViewOrCreate('RenderView')
objectDisplay = Show(visualiseInParaview_pht, renderView1)
view = GetActiveView()
reader = GetActiveSource()
tsteps = reader.TimestepValues
view.ViewTime = tsteps[-1]

view.Update()
reader.UpdatePipeline()
print(f' Time step: {view.ViewTime}')

mergedBlock = MergeBlocks(reader)
data = servermanager.Fetch(mergedBlock)
vtk_data = dsa.WrapDataObject(data)

lastPressArr = vtk_data.PointData[1]
lastVelocityArr = vtk_data.PointData[2]

```

However, applying similar code to an IntegrateVariables filter, it fails to properly update the pipeline/render:

```auto
paraviewReader = PhastaReader(FileName=phtPath)
renderView1 = GetActiveViewOrCreate('RenderView')
...
integrateVariables1 = IntegrateVariables(Input=slice1)
        tIdx = 0
        for t in tsteps:
            renderView1.ViewTime = t
            renderView1.Update()
            slice1.UpdatePipeline()
            integrateVariables1.UpdatePipeline()
            print('At Time:',renderView1.ViewTime )

            intPointData = servermanager.Fetch(integrateVariables1).GetPointData()
            sliceVelocityX = intPointData.GetArray('velocity').GetValue(0)

```

The time will loop appropriately, but the data fetched from the server is always the first time step. When trying to use

```auto
animationScene.GoToNext()

```

the result did not loop one time step at a time.

---

<div class="post-metadata">

### Author: ![theodorebaltis](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/t/e480ec/32.png) [@theodorebaltis](https://discourse.paraview.org/u/theodorebaltis)
#### Post date: [August 8, 2022, 4:30pm UTC](https://discourse.paraview.org/t/unable-to-change-filter-timestep-in-python-pvbatch/5725/9 "2022-08-08T16:30:58Z")

</div>

@lizliv I couldn’t dig up the code, but I feel like I’ve run into that issue before and solved it by adding a call to the `UpdateVTKObjects` property of the client-side source of interest.

So for you it would be `integrateVariables1.UpdateVTKObjects()` before the `Fetch` call.

This is just based off of fuzzy memory so I apologize if it doesn’t help.

[UpdateVTKObjects](https://kitware.github.io/paraview-docs/latest/cxx/classvtkSMProxy.html#a3d22d7cd275d1241b1137845afa4cb18)

---

<div class="post-metadata">

### Author: ![lizliv](https://discourse.paraview.org/user_avatar/discourse.paraview.org/lizliv/32/9725_2.png) [@lizliv](https://discourse.paraview.org/u/lizliv)
#### Post date: [August 8, 2022, 4:48pm UTC](https://discourse.paraview.org/t/unable-to-change-filter-timestep-in-python-pvbatch/5725/10 "2022-08-08T16:48:04Z")

</div>

Unfortunately that did not work. Maybe I should use a different method to `Fetch` the data that I want?

It works if I set the time before all of the filters, its just extremely slow re-slicing my data for each timestep.

---

<div class="post-metadata">

### Author: ![lizliv](https://discourse.paraview.org/user_avatar/discourse.paraview.org/lizliv/32/9725_2.png) [@lizliv](https://discourse.paraview.org/u/lizliv)
#### Post date: [August 8, 2022, 5:28pm UTC](https://discourse.paraview.org/t/unable-to-change-filter-timestep-in-python-pvbatch/5725/11 "2022-08-08T17:28:26Z")

</div>

I found a solution! I ran `Trace` with “Skip Rendering Components” enabled and found the command `UpdatePipeline()` without any render/source input, it acts on the proxy. This is my code snippet that worked to loop over time within a filter:

```auto
tsteps = paraviewReader.TimestepValues
...
integrateVariables1 = IntegrateVariables(Input=slice1)

for t in tsteps:            
     UpdatePipeline(time=t, proxy=integrateVariables1)
...

```

---

<div class="post-metadata">

### Author: ![amiraslanpour](https://discourse.paraview.org/user_avatar/discourse.paraview.org/amiraslanpour/32/5827_2.png) [@amiraslanpour](https://discourse.paraview.org/u/amiraslanpour)
#### Post date: [September 11, 2023, 8:26pm UTC](https://discourse.paraview.org/t/unable-to-change-filter-timestep-in-python-pvbatch/5725/12 "2023-09-11T20:26:37Z")

</div>

This worked!!

Thank you Liz for providing the solution. I was struggling with this for days.
