Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Viz

Visualizing native-grid output in Python

Intro

With unstructured-grid data, the grid/coordinate information is usually stored in a separate file from the model output fields. Considerably more information is needed to reconstruct the grid than in the case of a rectangular lat/lon grid, for example, which can be expressed with 1-D coordinate variables (e.g. ERA5).

With MPAS-A, the necessary grid variables are available in multiple files:

  • the grid file (usually ends in .grid.nc)

    • agnostic to simulation

    • note that with the standard limited-area workflow, which involves cutting out a section of a global grid, this can’t be used

  • the static file (usually ends in .static.nc)

    • produced as part of the model initialization/prep process, contains static fields like terrain height

  • initial conditions (usually ends in .init.nc)

    • easier to work with since the connectivity for the primal mesh uses zeros for padding

Some example grid and static files are available at: https://mpas-dev.github.io/atmosphere/atmosphere_meshes.html

Or on Casper/Derecho at:

/glade/campaign/mmm/wmr/duda/mesh/

Data

First we fetch an example global mesh: x1.2562 (~ 480-km resolution; chosen for its small file size and quickness to plot). Note that the uniform global meshes are really quasi-uniform.

Source
<Figure size 630x350 with 1 Axes>

Matplotlib

Although pcolormesh won’t work, we can treat our data as scatter points or take advantage of Matplotlib’s tricontouring support.

<Figure size 640x480 with 1 Axes>
<Figure size 640x480 with 1 Axes>
5096 triangles (real number: 5120)
<Figure size 640x480 with 1 Axes>
5120 triangles
<Figure size 640x480 with 1 Axes>
10217 triangles
<Figure size 640x480 with 1 Axes>

uxarray

uxarray builds on xarray to provide a unified interface for working with unstructured-grid data, including MPAS.

uxarray considers the unit sphere internally.

HoloViz

uxarray provides various routines for visualization with the help of HoloViews. By default, you get interactive plots that use the Bokeh backend. Rasterization, by datashader, can be explicitly turned on or off using the rasterize keyword (and configured using pixel_ratio).

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
CPU times: user 2.13 s, sys: 26 ms, total: 2.16 s
Wall time: 2.16 s
Loading...

Raster

uxarray provides capabilities for generating raster representations of your data on the fly, for plotting with Cartopy/Matplotlib without needing to go through HoloViews. Here we also have pixel_ratio.

CPU times: user 3.63 s, sys: 52 ms, total: 3.68 s
Wall time: 3.39 s
<Figure size 640x480 with 1 Axes>
CPU times: user 2.36 s, sys: 108 ms, total: 2.47 s
Wall time: 1.34 s
<Figure size 640x480 with 2 Axes>
CPU times: user 443 ms, sys: 12 ms, total: 455 ms
Wall time: 236 ms
<Figure size 500x350 with 1 Axes>

Matplotlib Collections

The meshes can also be represented exactly using Matplotlib Collections.

This is a good opportunity to use uxarray’s subsetting support, as Matplotlib Collections may be slow to plot if you provide too many cells.

<Figure size 500x350 with 1 Axes>

GeoVista

Built on PyVista/VTK, GeoVista provides GPU-accelerated interactive visualization of geospatial data and has builtin support for unstructured meshes.

It will still work if a GPU is not available/detected, but it may be much slower to first plot and to respond.

Result
Result

lonboard

lonboard provides GPU-accelerated interactive visualiation of geospatial vector data. We can pass it cell polygons. An easy way to get these is using uxarray.

Loading...
Static preview of the result

For when kernel is not active.

Footnotes
  1. small files by default

  2. Or when this site is built, for that matter, which is why it is currently guarded.