pyvista / pyvista-xarray

xarray DataArray accessors for PyVista
Apache License 2.0
100 stars 7 forks source link

3d viz of rectilinear gridded data - only edges of plot showing values #59

Closed josephko91 closed 1 year ago

josephko91 commented 1 year ago

I was trying to follow one of your examples with my own data, but for some reason only data on the edge of the domain is showing in the plot. I plotted cross sections with xarray plotting functions as a sanity check. The data is there in the original xarray dataset and subsequent dataarray. Any pointers would be appreciated!

Code to reproduce error:

import pyvista as pv
import pvxarray
import xarray as xr

file_path = 'path/to/file/cm1out_000030.nc' # edit path here
ds = xr.open_dataset(file_path)
ds = ds.squeeze('time')
da = ds.qi4
mesh = da.pyvista.mesh(x="xh", y="yh", z="zh")
mesh.plot(opacity='linear', cmap='bone')
image

The file is too big to upload here. So here's a link to it in google drive: https://drive.google.com/file/d/144WYF4Q9WSGC1JW7Qw5OTjlRPyjMatqq/view?usp=sharing


Date: Wed Oct 25 16:42:08 2023 EDT

            OS : Darwin
        CPU(s) : 10
       Machine : arm64
  Architecture : 64bit
           RAM : 16.0 GiB
   Environment : Jupyter
   File system : apfs

Python 3.11.0 | packaged by conda-forge | (main, Jan 14 2023, 12:26:40) [Clang 14.0.6 ]

       pyvista : 0.42.3
        xarray : 2023.10.1
        scooby : 0.7.1
           vtk : 9.2.6
         numpy : 1.26.0
       netcdf4 : 1.6.4

josephko91 commented 1 year ago

I think I've found the solution to my own problem! Posting here for future reference. There is a "volume" parameter in the plot method that needs to be set to True.

Revised code:

import pyvista as pv
import pvxarray
import xarray as xr

file_path = 'path/to/file/cm1out_000030.nc' # edit path here
ds = xr.open_dataset(file_path)
ds = ds.squeeze('time')
da = ds.qi4
mesh = da.pyvista.mesh(x="xh", y="yh", z="zh")
mesh.plot(opacity='linear', cmap='bone', volume=True)