Open johnkit opened 2 months ago
File > Open and choose NetCDF Reader Attached is a paraview state file for opening air_temperature.nc also attached. air_temperature.pvsm.zip air_temperature.nc.zip
Build VTK from:
https://gitlab.kitware.com/danlipsa/vtk/-/commits/xarray_quick
then execute the attached script like this:
PYTHONPATH=~/projects/pyvista:~/projects/vtk/xarray/build/lib/python3.10/site-packages/ python test.py
Note PYTHONPATH points to the source code for pyvista and the location where you built VTK
Use n/N to increase/decrease time, l/L to increase/decrease longitude size
Interim example:
def update(pl, xr_ds, time_index):
ds = xr_ds.vtk.dataset(
active_scalars='air', time_index=time_index,
encoding={"air": {"dtype": float}})
print(ds)
mesh = pv.wrap(ds)
pl.add_mesh(mesh, name="air")
time_index = 0
lon_remove = 0
pl = pv.Plotter()
pl.add_key_event('n', next_time_step)
pl.add_key_event('N', prev_time_step)
pl.add_key_event('l', increase_lon)
pl.add_key_event('L', decrease_lon)
xr_ds = xr.tutorial.load_dataset("air_temperature")
print(xr_ds)
lon_length=len(xr_ds['lon'])
update(pl, xr_ds, time_index)
pl.show()
(also in #99) I put a small zarr example (example.zarr.tgz) at https://data.kitware.com/#item/66d225af9eee4150438e24ae. (Github wouldn't let me upload it here for some reason.) Note that you have to untar before trying to load :)
Here is the WIP MR for the full xarray to vtk: https://gitlab.kitware.com/vtk/vtk/-/merge_requests/11513
@danlipsa here is link to sample xarray datasets: https://github.com/pydata/xarray-data that we should try to load in your PR
The attached script works with the xarray MR: https://gitlab.kitware.com/vtk/vtk/-/merge_requests/11513 xarray_vtk.zip
Variables are shallow copied (unless the numpy array needs to be made contiguous: https://numpy.org/devdocs/reference/generated/numpy.ascontiguousarray.html). Coordinates are deep copied at the moment, because the are stored as double array in the netcdf reader so they require a bit more work - they need to be stored as the orginal type in the reader.
Using vtkNetCDFCFReader as described in #99