Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xarray-to-vtk #106

Open
3 of 4 tasks
johnkit opened this issue Aug 20, 2024 · 7 comments
Open
3 of 4 tasks

Xarray-to-vtk #106

johnkit opened this issue Aug 20, 2024 · 7 comments
Assignees

Comments

@johnkit
Copy link
Collaborator

johnkit commented Aug 20, 2024

Using vtkNetCDFCFReader as described in #99

  • to netcdf file to paraview
  • to netcdf file to Python (PyVista Plotter for display)
  • Xarray direct (no netcdf file)
  • Xarray slice feature
@danlipsa
Copy link
Collaborator

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
Copy link
Collaborator

danlipsa commented Aug 25, 2024

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
Copy link
Collaborator Author

johnkit commented Aug 27, 2024

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
Copy link
Collaborator Author

johnkit commented Aug 30, 2024

(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

This was referenced Sep 4, 2024
@aashish24 aashish24 changed the title Xarray-to-vtk Prototypes Xarray-to-vtk for rectilinear grid Sep 10, 2024
@danlipsa
Copy link
Collaborator

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

@aashish24
Copy link
Collaborator

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

@danlipsa danlipsa changed the title Xarray-to-vtk for rectilinear grid Xarray-to-vtk Oct 14, 2024
@danlipsa
Copy link
Collaborator

danlipsa commented Oct 14, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants