Kitware / pan3d

Other
11 stars 2 forks source link

Xarray-to-vtk #106

Open johnkit opened 2 months ago

johnkit commented 2 months ago

Using vtkNetCDFCFReader as described in #99

danlipsa commented 2 months ago

to netcdf file to paraview

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

danlipsa commented 2 months ago

to netcdf file to Python (PyVista Plotter for display) Xarray slice feature

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

test.py.zip

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

johnkit commented 2 months ago

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()

image

johnkit commented 2 months ago

(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 :)

image

danlipsa commented 1 month ago

Here is the WIP MR for the full xarray to vtk: https://gitlab.kitware.com/vtk/vtk/-/merge_requests/11513

aashish24 commented 4 weeks ago

@danlipsa here is link to sample xarray datasets: https://github.com/pydata/xarray-data that we should try to load in your PR

danlipsa commented 2 weeks ago

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.