# How to write temporal UnstructuredGrid data to a VTKHDF file with vtkHDFWriter in Python?

**URL:** https://discourse.vtk.org/t/how-to-write-temporal-unstructuredgrid-data-to-a-vtkhdf-file-with-vtkhdfwriter-in-python/16096
**Category:** Support
**Tags:** python, file-formats
**Created:** [October 15, 2025, 2:42pm UTC](https://discourse.vtk.org/t/how-to-write-temporal-unstructuredgrid-data-to-a-vtkhdf-file-with-vtkhdfwriter-in-python/16096 "2025-10-15T14:42:20Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![liblaf](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/l/6de8d8/32.png) [@liblaf](https://discourse.vtk.org/u/liblaf)
#### Post date: [October 15, 2025, 2:42pm UTC](https://discourse.vtk.org/t/how-to-write-temporal-unstructuredgrid-data-to-a-vtkhdf-file-with-vtkhdfwriter-in-python/16096/1 "2025-10-15T14:42:20Z")

</div>

Hi all,

I’m trying to write a time series of `vtkUnstructuredGrid` data to a single VTKHDF (`.vtkhdf`) file using Python. Specifically, the grid topology is constant, but a point data array named “foo” changes over 100 timesteps.

I’ve found several resources that explain how to construct the VTKHDF file format from scratch using `h5py`, such as:

- [Trying to make a temporal vtkhdf polydata using Python](https://discourse.vtk.org/t/trying-to-make-a-temporal-vtkhdf-polydata-using-python/15298)
- [https://gitlab.kitware.com/keu-public/vtkhdf/vtkhdf-scripts/-/blob/main/scripts/generate\_poly\_data.py](https://gitlab.kitware.com/keu-public/vtkhdf/vtkhdf-scripts/-/blob/main/scripts/generate_poly_data.py)
- [https://www.kitware.com/how-to-write-time-dependent-data-in-vtkhdf-files/](https://www.kitware.com/how-to-write-time-dependent-data-in-vtkhdf-files/)

However, I’m wondering if there’s a more direct way to do this using `vtkHDFWriter`. It seems like `vtkHDFWriter` should be able to handle this, which would be much simpler than manually creating the HDF5 structure.

My question is: **How can I use `vtkHDFWriter` to save an `UnstructuredGrid` with 100 timesteps of a “foo” point data array into a single `.vtkhdf` file?**

Here’s a conceptual code snippet of what I’m trying to do:

```python
import numpy as np
from vtkmodules.util import numpy_support
from vtkmodules.vtkCommonDataModel import vtkUnstructuredGrid
from vtkmodules.vtkIOHDF import vtkHDFWriter

# 1. Create a sample UnstructuredGrid
grid = vtkUnstructuredGrid()
# make some structure

# 2. Prepare for time series data
num_timesteps = 100
# Dummy data: 3 points, so we need 3 values at each timestep
foo_data_over_time = [
    np.random.rand(grid.number_of_cells) for _ in range(num_timesteps)
]

# 3. This is where I'm unsure how to proceed
writer = vtkHDFWriter()
writer.SetFileName("temporal_ug.vtkhdf")
writer.SetInputData(grid)

# How do I add the time-varying data?
# Do I add all arrays to the grid and give them special names?
# Or do I call writer.Write() in a loop?
# The writer has Write() and AddInputDataObject(), but it's not clear how to use them for time series.

# I would expect something like this, but this is just a guess:
# writer.Start() # is there a method like this?
# for i in range(num_timesteps):
# foo_array = numpy_support.numpy_to_vtk(foo_data_over_time[i])
# foo_array.SetName("foo")
# grid.GetPointData().SetArrays(None) # Clear previous array
# grid.GetPointData().AddArray(foo_array)
# writer.SetTimeValue(float(i)) # Is there a method like this?
# writer.Write() # Append this timestep
# writer.Stop() # is there a method like this?

```

How can I achieve this correctly so that ParaView or other readers recognize it as a time series?

Any help or examples would be greatly appreciated!

Thanks!

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [October 15, 2025, 2:44pm UTC](https://discourse.vtk.org/t/how-to-write-temporal-unstructuredgrid-data-to-a-vtkhdf-file-with-vtkhdfwriter-in-python/16096/2 "2025-10-15T14:44:09Z")

</div>

@Louis_Gombert @lgivord

---

<div class="post-metadata">

### Author: ![Louis\_Gombert](https://discourse.vtk.org/user_avatar/discourse.vtk.org/louis_gombert/32/7766_2.png) [@Louis\_Gombert](https://discourse.vtk.org/u/Louis_Gombert)
#### Post date: [October 15, 2025, 3:02pm UTC](https://discourse.vtk.org/t/how-to-write-temporal-unstructuredgrid-data-to-a-vtkhdf-file-with-vtkhdfwriter-in-python/16096/3 "2025-10-15T15:02:20Z")

</div>

Hello, the `vtkHDFWriter` is capable of writing multiple time steps when the option `WriteAllTimeSteps` is toggled on. However, for that you need to use the VTK pipeline logic to create a temporal VTK source, by creating a class derived from `VTKPythonAlgorithmBase`and generating time steps with your data, like `vtkGenerateTimeSteps` does for example.

Unfortunately, `vtkHDFWriter` does not currently have the ability to append time steps one by one without using the pipeline logic. That is something we want to tackle in the future.

For your simple use case, it may be easier to write data to the VTKHDF file using h5py. Note that you can only write your points once using the right temporal offsets. You can take a look at the [VTKHDF tutorial](https://gitlab.kitware.com/keu-public/vtkhdf/vtkhdf-scripts/-/tree/main/tutorial?ref_type=heads#time-steps) to learn how to do that.
