Access time dependent PointData in vtkStructuredGrid

Dear vtk-users,

I am using the vtk library in python to importe a netcdf file.
The netcdf file contains data of two variables for different time steps.
It will be converted into a vtkStructuredGrid
The vtkStructuredGrid then should have PointData for different time steps.

reader_nc = vtk.vtkNetCDFCFReader()
source_nc = reader_nc.GetOutput()

How do I access the PointData of the two variabls at the different time steps?


Gives me the data for the 1st variable at the very first time step.
How can I access to remaining time steps?

I would really appreciate some hint.


You’ll need to set the time step when updating the reader and loop through a pipeline calling update for each timestamp with the method .UpdateTimeStep() method on the reader_nc:

This might get really verbose and slow in Python, so I’d recomend just using the
netCDF4 Python package (or another library like xarray that can handle your data format) to load your netCDF files into NumPy arrays.

Then if you want to create a structured grid for visualization, use the vtkStructuredGrid from the vtk.vtkNetCDFCFReader like you have above and simply update the array using the numpy arrays loaded directly using netCDF4.

FYI: PyVista makes managing numpy arrays and VTK datasets super streamlined