UXARRAY / uxarray

Xarray-styled package for reading and directly operating on unstructured grid datasets following UGRID conventions
https://uxarray.readthedocs.io/
Apache License 2.0
139 stars 30 forks source link

Support GEOS Cube-Sphere Grids #802

Closed philipc2 closed 1 week ago

philipc2 commented 1 month ago

Closes #801

Overview

philipc2 commented 1 month ago

Plot of a ~200,000,000 element grid (CS5760)

image

philipc2 commented 1 month ago

Plot of a ~900 element grid (CS12)

image

philipc2 commented 1 month ago

@mathomp4

Let me know if you have any feedback!

mathomp4 commented 1 month ago

@mathomp4

Let me know if you have any feedback!

Well, I think I need to learn more Python but I decided to try on a stretched grid file I finally got. I first tried plotting the grid but apparently this:

<uxarray.Grid>
Original Grid Type: GEOS-CS
Grid Dimensions:
  * n_node: 440646
  * n_face: 437400
  * n_max_face_nodes: 4
  * n_nodes_per_face: (437400,)
Grid Coordinates (Spherical):
  * node_lon: (440646,)
  * node_lat: (440646,)
  * face_lon: (437400,)
  * face_lat: (437400,)
Grid Coordinates (Cartesian):
Grid Connectivity Variables:
  * face_node_connectivity: (437400, 4)
Grid Descriptor Variables:

was a bit too much for my laptop. I waited a few minutes and in the end it was just solid blue.

But following some of your examples, I did get out:

c270_plot

which is nice! I then tried a plot.polygons() and my computer hated me again. 😄

I think what this demonstrates is that I need to convince my boss to help make a much coarser stretch grid...or learn more UXarray

philipc2 commented 1 month ago

Glad you were able to get it working! Surprised that the Polygon plot took that long. Typically grids of that size should take no longer than a minute maximum for the first run.

mathomp4 commented 1 month ago

Glad you were able to get it working! Surprised that the Polygon plot took that long. Typically grids of that size should take no longer than a minute maximum for the first run.

Hmm. Well, it was on an M3 MacBook Air...if that matters?

Note: it's also possible I called things incorrectly. I was just sort of trying to echo the cookbook. 😄

philipc2 commented 1 month ago

Glad you were able to get it working! Surprised that the Polygon plot took that long. Typically grids of that size should take no longer than a minute maximum for the first run.

Hmm. Well, it was on an M3 MacBook Air...if that matters?

Note: it's also possible I called things incorrectly. I was just sort of trying to echo the cookbook. 😄

Yeah, I've run similar sized meshes on a 32GB M1 and had reasonable performance. Mind sharing the file so I can try to recreate it?

mathomp4 commented 1 month ago

Yeah, I've run similar sized meshes on a 32GB M1 and had reasonable performance. Mind sharing the file so I can try to recreate it?

Yes...if I can figure out how to share it. Can you try:

https://gmao.gsfc.nasa.gov/gmaoftp/gmao_SIteam/test-fixapp-c270.geosgcm_prog_nat.20200415_0000z.nc4

I think that works. If you get it, let me know. It's about 500 MB because I didn't really clean it up

philipc2 commented 1 month ago
import uxarray as ux
import geoviews.feature as gf
import cartopy.crs as ccrs

features = gf.coastline(
    projection=ccrs.PlateCarree(), line_width=1, scale="50m"
) * gf.states(projection=ccrs.PlateCarree(), line_width=1, scale="50m")

file_path = r"C:\Users\chmie\Downloads\test-fixapp-c270.geosgcm_prog_nat.20200415_0000z.nc4"
%%time
uxds = ux.open_dataset(file_path, file_path)

Took about 3s

%%time
uxds['T'][0][-1].plot.rasterize(method='polygon', exclude_antimeridian=True) * features

Took about 3s as well.

image

uxds['RH'][0][0].subset.bounding_circle((-90, 25), 10).plot.rasterize(method='polygon', exclude_antimeridian=True, pixel_ratio=4.0) * features

image

philipc2 commented 1 month ago

I'd like to mention that the white spots are due to an upstream issue with Datashader, which will be fixed in the next release.

https://github.com/holoviz/datashader/pull/1329

mathomp4 commented 1 month ago

Hmm. When I first tried your first block of code, I got:

ValueError: No plotting extension is currently loaded. Ensure you load an plotting extension with hv.extension or import it explicitly from holoviews.plotting before applying any options.

So, I added:

import holoviews as hv
hv.extension("bokeh")

And then the plots took about 2s. So...yeah, I must have really screwed things up in my testing to be ~100x slower. 😄

mathomp4 commented 1 month ago

And I was wondering about the weird white spots, but I figured they were due to just...something.

Now, my laptop was not happy with:

uxgrid = ux.open_grid(file_path,file_path)

%%time
uxgrid.plot()

Actually, my browser sort of crashed before it could render...

philipc2 commented 1 month ago

uxgrid = ux.open_grid(file_path,file_path)

%%time uxgrid.plot()

And I was wondering about the weird white spots, but I figured they were due to just...something.

Now, my laptop was not happy with:

uxgrid = ux.open_grid(file_path,file_path)

%%time
uxgrid.plot()

Actually, my browser sort of crashed before it could render...

The issue here is that you're using open_grid instead of open_dataset. The default plotting for a Grid object is an edge plot of the mesh, which is indeed very slow for any mesh larger than a few thousand elements.

mathomp4 commented 1 month ago

Ohhhh. So:

uxds = ux.open_dataset()
uxds.uxgrid.plot()

would be faster? I'll try that tonight on my laptop!

(I'm learning!)

philipc2 commented 1 month ago

Ohhhh. So:

uxds = ux.open_dataset()
uxds.uxgrid.plot()

would be faster? I'll try that tonight on my laptop!

(I'm learning!)

Plotting a data variable would be faster, since that performs a raster operation as opposed to a vector plot of the geometries.

Our grid (i.e. only mesh) plotting is all vector based, but our data variables can be plotted as rasters.

# defaults to raster plot
uxds['T'].plot()

# can specifically call a raster
uxds['T'].plot.rasterize(method='polygon')
mathomp4 commented 2 weeks ago

Nice work on this!

Doubly so from me and the GEOS community. Nice to have another package that can read our files without need to do all sort of gymnastics!

mathomp4 commented 1 week ago

Woo! Thanks. I eagerly await the next release! 😄