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.

Advanced MPAS Analysis & Visualization with UXarray

"MPAS Advanced"

In this section, you’ll learn:

  • Utilizing the UXarray package to perform advanced analysis over MPAS data, such as cross-sections and zonal averages, etc.

  • Using Matplotlib and hvPlot to visualize analysis.

Prerequisites

ConceptsImportanceNotes
UXarrayNecessary
SciPyHelpful
HoloViewsHelpful

Time to learn: 15 minutes


Import packages

CPU times: user 250 ms, sys: 67.4 ms, total: 317 ms
Wall time: 263 ms
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[1], line 1
----> 1 get_ipython().run_cell_magic('time', '', '\n# autoload external python modules if they changed\n%load_ext autoreload\n%autoreload 2\n\n# add ../funcs to the current path\nimport sys, os\nsys.path.append(os.path.join(os.getcwd(), "..")) \n\nimport warnings\nimport math\n\nimport cartopy.crs as ccrs\nimport geoviews as gv\nimport geoviews.feature as gf\nimport matplotlib.pyplot as plt\n\nimport s3fs\n\nimport geopandas as gp\nimport numpy as np\nimport uxarray as ux\nimport xarray as xr\n')

File <timed exec>:13

ModuleNotFoundError: No module named 'geoviews'

UXarray and hvPlot

hvPlot is a high-level API built on HoloViews that provides interactive plots. It is integrated with UXarray with a .hvplot() similar to .plot() in Pandas library, but will produce more interactive figures. Import the relevant packages if you want to use the hvplot API.

Configure visualization tools

Retrieve/load MPAS/JEDI data

The example MPAS/JEDI data are stored at jetstream2. We need to retreive those data first.
There are two ways to retrieve MPAS data:

    1. Download all example data from JetStream2 to local and them load them locally. This approach allows downloading the data once per machine and reuse it in notebooks.

    1. Stream the JetStream2 S3 objects on demand. In this case, each notebook (including restarting a notebook) will retrieve the required data separately as needed.

Method 1: Download all example data once and reuse it in mulptile notebooks

Method 2: Stream the JetStream2 S3 objects on demand

Loading the data into UXarray datasets

We use the UXarray data structures for working with the data. This package supports data defined over unstructured grid and provides utilities for modifying and visualizing it. The available fucntionality are discussed in UxDataset documentation.
For more information about the UXarray and unstructured grid, please go to Working with unstructured grids with UXarray.

basic information of used dataset

Indexing and selecting

Subset a latitudinal or longitudinal band

Vertical cross section

Based on UXarray, we will generate cross-sections:

  • along an arbitrary great‑circle arcs (GCAs) between two point over the sphere surface.

  • along a constant longitude line

  • along a constant latitude line

We will also mark the lines or arcs over a map.

Random Great Circle Arc (GCA)

Let us use UXarray’s vertical cross-section function to get a cross-section over a great circle arc:

UXarray’s cross-section returns an xarray.DataArray that can then be plotted:

Constant Latitude

Constant Longitude

Perspective view of cross-sections

Create geography figures

Create horizontal figures and crossections

Updated the figure

Use go.Mesh3d to create a smoother cross-section. It will take a bit more time to render.

Select and plot figures

Zonal Average

In this session we use the first level and extract its zonal averages at each latitude, with a bin width of 1°:

zonal_mean uses a face-weighted average. It accounts for the area of each grid cell, ensuring that larger cells contribute proportionally more to the mean. This is crucial for MPAS grids, which are unstructured and vary in size.

Decompose into zonal averages and zonal anomalies

The total field θi,j\theta_{i,j} at any grid could be decomposed into the zonal average, θiˉ\bar{\theta_i}, and the deviations from the zonal average θi,j′\theta^\prime_{i,j}, where i,ji,j represent the latitudinal and longitudinal coordinates, correspondinly.

θi,j=θiˉ+θi,j′\theta_{i,j}=\bar{\theta_{i}}+\theta^{\prime}_{i,j}

Why this matters?

The eddy components, or the zonal asymmetrical components, often capture localized variations beyond the zonal mean state. This decomposition is useful when analyzing atmospheric circulation patterns.