# Temporal derivative

**URL:** https://discourse.paraview.org/t/temporal-derivative/10741
**Category:** ParaView Support
**Created:** [November 13, 2022, 5:42am UTC](https://discourse.paraview.org/t/temporal-derivative/10741 "2022-11-13T05:42:01Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![ebreard](https://discourse.paraview.org/user_avatar/discourse.paraview.org/ebreard/32/2421_2.png) [@ebreard](https://discourse.paraview.org/u/ebreard)
#### Post date: [November 13, 2022, 5:42am UTC](https://discourse.paraview.org/t/temporal-derivative/10741/1 "2022-11-13T05:42:01Z")

</div>

Hi,

I have velocity field data, is there a way to use existing filters to calculate the acceleration field?

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [November 14, 2022, 8:26am UTC](https://discourse.paraview.org/t/temporal-derivative/10741/2 "2022-11-14T08:26:37Z")

</div>

HI @ebreard

This is possible but way complex than it should be.

If the timesteps progression is linear (eg: 0.1, 0.2, 0.3), you can use TemporalShiftScale to shift your timesteps and then PythonCalculator to compare between timesteps and do the computation.

If not, then it can only be done one timestep at a time, using ForceTime or TemporalArrayOperator.

Hth,

---

<div class="post-metadata">

### Author: ![ebreard](https://discourse.paraview.org/user_avatar/discourse.paraview.org/ebreard/32/2421_2.png) [@ebreard](https://discourse.paraview.org/u/ebreard)
#### Post date: [November 16, 2022, 6:39am UTC](https://discourse.paraview.org/t/temporal-derivative/10741/3 "2022-11-16T06:39:49Z")

</div>

Thanks, is there no plan to add this as a filter? Lots of folks would be using it

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [November 16, 2022, 8:02am UTC](https://discourse.paraview.org/t/temporal-derivative/10741/4 "2022-11-16T08:02:37Z")

</div>

Not yet, one would need to invest some time or funding in order to get this going.

> [@How are features and bug fixes incorporated into ParaView?](https://discourse.paraview.org/t/how-are-features-and-bug-fixes-incorporated-into-paraview/4735):
>
> As with all open source projects, adding features and fixing bugs takes developer effort. That effort may originate from volunteer community contributors, or through paid professional services offered by companies like [Kitware](https://www.kitware.com). Features and bug fixes are prioritized by the needs of contributing community members and by professional services customers. Note that contributions are vetted by a rigorous community review and testing process; therefore it is recommended that significant changes are d…

You can also open a feature request here:

> **[Feature Requests](https://discourse.paraview.org/c/feature-requests/14)**
>
> Request features for future versions of ParaView. If a feature you want to see in ParaView has already been added to this category, please vote for it by liking the first post in the topic.

---

<div class="post-metadata">

### Author: ![ebreard](https://discourse.paraview.org/user_avatar/discourse.paraview.org/ebreard/32/2421_2.png) [@ebreard](https://discourse.paraview.org/u/ebreard)
#### Post date: [March 7, 2025, 12:36pm UTC](https://discourse.paraview.org/t/temporal-derivative/10741/5 "2025-03-07T12:36:21Z")

</div>

created this “programmable filter” that calculates the temporal derivative of a Gas\_Velocity vector (acceleration). The input data was cell data, then I used the CelltoPoint data, and to that layer applied the programmable filter with the following code:

```auto
import numpy as np
from vtk.util.numpy_support import numpy_to_vtk

# Current velocity data (vector)
velocity_current = inputs[0].PointData['Gas_Velocity']

# Current simulation time
current_time = self.GetInputDataObject(0, 0).GetInformation().Get(vtk.vtkDataObject.DATA_TIME_STEP())

# Check if previous velocity data is available (not first timestep)
if hasattr(self, 'prev_velocity'):
    dt = current_time - self.prev_time
    if dt <= 0:
        dt = 0.001 # Fallback timestep (1 ms for 1000 Hz data)
    dv_dt = (velocity_current - self.prev_velocity) / dt
else:
    dv_dt = np.zeros_like(velocity_current) # Zero initial derivative

# Add derivative to output
vtk_dv_dt = numpy_to_vtk(dv_dt, deep=True)
vtk_dv_dt.SetName('GasAcceleration')
output.PointData.AddArray(vtk_dv_dt)

# Store current timestep for next iteration
self.prev_velocity = velocity_current.copy()
self.prev_time = current_time

```

works well 🙂

---

<div class="post-metadata">

### Author: ![ebreard](https://discourse.paraview.org/user_avatar/discourse.paraview.org/ebreard/32/2421_2.png) [@ebreard](https://discourse.paraview.org/u/ebreard)
#### Post date: [March 7, 2025, 1:00pm UTC](https://discourse.paraview.org/t/temporal-derivative/10741/6 "2025-03-07T13:00:07Z")

</div>

here is an example of temporal derivative on Cell data for an array:

```auto
import numpy as np
from vtk.util.numpy_support import numpy_to_vtk
import vtk

# Access the current timestep's cell data
P_G_current = inputs[0].CellData['P_G']

# Get current simulation time
current_time = self.GetInputDataObject(0, 0).GetInformation().Get(vtk.vtkDataObject.DATA_TIME_STEP())

if hasattr(self, 'prev_PG'):
    dt = current_time - self.prev_time
    if dt <= 0:
        dt = 0.001 # fallback for 1000Hz data
    dPG_dt = (P_G_current - self.prev_PG) / dt
else:
    dPG_dt = np.zeros_like(P_G_current)

# Convert numpy array explicitly to VTK format
vtk_dPG_dt = numpy_to_vtk(dPG_dt, deep=True)
vtk_dPG_dt.SetName('P_G_TemporalDerivative')

# Add the array as Cell Data (since original data is cell-based)
output.CellData.AddArray(vtk_dPG_dt)

# Store current values for next timestep
self.prev_PG = P_G_current.copy()
self.prev_time = current_time

```

---

<div class="post-metadata">

### Author: ![Vignesh\_K](https://discourse.paraview.org/user_avatar/discourse.paraview.org/vignesh_k/32/17616_2.png) [@Vignesh\_K](https://discourse.paraview.org/u/Vignesh_K)
#### Post date: [April 25, 2026, 5:36am UTC](https://discourse.paraview.org/t/temporal-derivative/10741/7 "2026-04-25T05:36:54Z")

</div>

Hi, I have pressure field in my LES and enthalpy in my particle/lagrangian field. I am trying to calculate the time derivatives of both. I copy pasted the code in programmable filter and changed P\_G to p but I couldn’t see the output. Any help in this matter will be appreciated.
