UXARRAY / uxarray

Xarray extension for unstructured climate and global weather data analysis and visualization.
https://uxarray.readthedocs.io/
Apache License 2.0
153 stars 31 forks source link

E3SM results visualization #843

Closed evasinha closed 3 months ago

evasinha commented 3 months ago

Proposed new feature or change:

I would like to plot E3SM, eam.h0 output files that are at ne30np4.pg2. As a first step, I am trying to read the grid file:

import uxarray as ux

grid_path = file_path + 'ne30pg2_scrip_c20191218.nc'

uxgrid = ux.open_grid(grid_path)
print(uxgrid)
print(uxgrid.node_lon)

However as shown in the outputs below the lon values being read are all zero:

<uxarray.Grid>
Original Grid Type: Scrip
Grid Dimensions:
  * n_node: 21727
  * n_face: 21600
  * n_max_face_nodes: 4
  * n_nodes_per_face: (21600,)
Grid Coordinates (Spherical):
  * node_lon: (21727,)
  * node_lat: (21727,)
  * face_lon: (21600,)
  * face_lat: (21600,)
Grid Coordinates (Cartesian):
Grid Connectivity Variables:
  * face_node_connectivity: (21600, 4)
Grid Descriptor Variables:

<xarray.DataArray 'node_lon' (n_node: 21727)>
array([0., 0., 0., ..., 0., 0., 0.])
Dimensions without coordinates: n_node

Can you provide a simple example of plotting E3SM unstructured outputs?

rljacob commented 3 months ago

The file can be found here: https://web.lcrc.anl.gov/public/e3sm/inputdata/share/meshes/homme/ne30pg2_scrip_c20191218.nc (Edit: corrected file)

philipc2 commented 3 months ago

Hi @evasinha

The minimal example you provided looks correct to me. The reason the node_lon appears to be all zeros is because it is only printing a handfull of the values for the repr.

image

I'd suggest taking a look at our User Guide section on Plotting

@rytam2 is also working on an E3SM visualuzation notebook in #836

evasinha commented 3 months ago

Thanks @philipc2

When I try to generate a plot using uxarray it show up as blank:

import uxarray as ux
import matplotlib.pyplot as plt

grid_path = file_path + 'ne30pg2_scrip_c20191218.nc'
fname = '20240703_SSP245_ZATM_BGC_ne30pg2_f09_oEC60to30v3.eam.h0.2075-06.nc'

uxds = ux.open_dataset(grid_path, fname)

uxds['SFCO2'][0].plot()
plt.savefig('SFCO2.png')

Is it possible that there are some issues rendering the image and if so how can those be resolved?

evasinha commented 3 months ago

The file mentioned above can be downloaded from - https://web.lcrc.anl.gov/public/e3sm/diagnostic_output/ac.eva.sinha/tmp/

philipc2 commented 3 months ago

@evasinha

Here's a slightly modified example that works for me. Our plotting API is written using HoloViews, so I needed to make a few modifications to the code you provided.

import uxarray as ux
import holoviews as hv
hv.extension('matplotlib')

grid_path = "/Users/philipc/Downloads/ne30pg2_scrip_c20191218.nc"
data_path = "/Users/philipc/Downloads/20240703_SSP245_ZATM_BGC_ne30pg2_f09_oEC60to30v3.eam.h0.2075-06.nc"

uxds = ux.open_dataset(grid_path, data_path)

# generate and store a plot as a variable
out = uxds['SFCO2'][0].plot(backend='matplotlib', 
                            fig_size=350,
                            pixel_ratio=4.0)

# safe plot as a PNG
hv.save(out, 'SFCO2.png', fmt='png')
image
evasinha commented 3 months ago

@philipc2 Thank you very much for the modified working example. The modified script worked effortlessly for me as well.

whannah1 commented 3 months ago

@philipc2 is there a similar example that also specifies a map projection?