MPAS Atmosphere¶
This recipe demonstrates how to create visualizations using 30km MPAS Atmosphere model output. We’ll explore techniques for visualizing atmospheric variables on both the primal and dual MPAS grids, focusing on relative humidity and vorticity at the 200hPa pressure level.
Visualization Objectives¶
This recipe will guide you through:
Creating polygon plots using the MPAS primal grid to visualize relative humidity at 200hPa
Developing polygon plots using the MPAS dual grid to visualize vorticity at 200hPa
Understanding the differences between primal and dual grid visualizations in MPAS
import uxarray as ux
import cartopy.crs as ccrsRelative Humidity¶
For visualizing relative humidity, we use the Primal MPAS grid, which is composed of hexagons.
grid_path = "../../meshfiles/x1.655362.grid.nc"
data_path = "../../meshfiles/x1.655362.data.nc"
uxds_primal = ux.open_dataset(grid_path, data_path)
uxds_primal---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[2], line 4
1 grid_path = "../../meshfiles/x1.655362.grid.nc"
2 data_path = "../../meshfiles/x1.655362.data.nc"
3
----> 4 uxds_primal = ux.open_dataset(grid_path, data_path)
5 uxds_primal
File ~/micromamba/envs/unstructured-grid-viz-cookbook-dev/lib/python3.14t/site-packages/uxarray/core/api.py:194, in open_dataset(grid_filename_or_obj, filename_or_obj, latlon, use_dual, grid_kwargs, **kwargs)
191 # map each dimension to its UGRID equivalent
192 ds = _map_dims_to_ugrid(ds, uxgrid._source_dims_dict, uxgrid)
--> 194 uxds = UxDataset(ds, uxgrid=uxgrid, source_datasets=str(filename_or_obj))
196 return uxds
File ~/micromamba/envs/unstructured-grid-viz-cookbook-dev/lib/python3.14t/site-packages/uxarray/core/dataset.py:82, in UxDataset.__init__(self, uxgrid, source_datasets, *args, **kwargs)
79 else:
80 self._uxgrid = uxgrid
---> 82 super().__init__(*args, **kwargs)
File ~/micromamba/envs/unstructured-grid-viz-cookbook-dev/lib/python3.14t/site-packages/xarray/core/dataset.py:389, in Dataset.__init__(self, data_vars, coords, attrs)
385 ) -> None:
386 if data_vars is None:
387 data_vars = {}
388 if isinstance(data_vars, Dataset):
--> 389 raise TypeError(
390 "Passing a Dataset as `data_vars` to the Dataset constructor is"
391 " not supported. Use `ds.copy()` to create a copy of a Dataset."
392 )
TypeError: Passing a Dataset as `data_vars` to the Dataset constructor is not supported. Use `ds.copy()` to create a copy of a Dataset.uxds_primal['relhum_200hPa'][0].plot(projection=ccrs.Robinson(), backend='matplotlib', pixel_ratio=4.0, features=['coastline'], width=1000, height=500, cmap='viridis', title="30km Relative Humidity (MPAS Primal Grid)")Vorticity¶
For visualizing relative humidity, we use the Dual MPAS grid, which is composed of triangles.
grid_path = "../../meshfiles/x1.655362.grid.nc"
data_path = "../../meshfiles/x1.655362.data.nc"
uxds_dual = ux.open_dataset(grid_path, data_path, use_dual=True)
uxds_dual['vorticity_200hPa']uxds_dual['vorticity_200hPa'][0].plot(projection=ccrs.Robinson(), rasterize=True, backend='matplotlib', pixel_ratio=4.0, features=['coastline'], width=1000, height=500, cmap='coolwarm', title="30km Vorticity (MPAS Dual Grid)", clim=(-0.0001,0.0001))MPAS Dual & Primal Grids¶
The Model for Prediction Across Scales (MPAS) utilizes two complementary grid structures for atmospheric modeling: the primal grid and the dual grid. The primal grid consists of hexagonal cells that form the primary computational mesh, while the dual grid is composed of triangular cells that connect the centers of the primary hexagons.
In the primal grid structure, scalar quantities like relative humidity are naturally represented at the centers of the hexagonal cells. The dual grid, with its triangular elements, is particularly well-suited for vector quantities and derived fields such as vorticity.
Below, we visualize both grid structures to illustrate their complementary nature.
(uxds_primal.uxgrid.subset.bounding_box(lon_bounds = (-1, 1), lat_bounds=(-0.5, 0.5)).plot(title="MPAS Primal Grid Structure", ) +
uxds_dual.uxgrid.subset.bounding_box(lon_bounds = (-1, 1), lat_bounds=(-0.5, 0.5)).plot(title="MPAS Dual Grid Structure")).cols(1).opts(fig_size=200)The visualization below demonstrates the intricate geometric relationship between MPAS primal and dual grids. By overlaying both grid structures, we can observe how the vertices of each hexagonal cell in the primal grid serve as the cell centers for the triangular elements of the dual grid. Conversely, the vertices of the triangular cells in the dual grid correspond to the centers of the hexagonal cells in the primal grid.
(uxds_primal.uxgrid.subset.bounding_box(lon_bounds = (-1, 1), lat_bounds=(-0.5, 0.5)).plot() *
uxds_dual.uxgrid.subset.bounding_box(lon_bounds = (-1, 1), lat_bounds=(-0.5, 0.5)).plot()).opts(fig_size=200, title="Primal & Dual Grid Together")3.75km Visualization¶
For another example of MPAS grid visualization, readers can refer to the UXarray documentation showcasing a 3.75km resolution grid
This example demonstrates MPAS visualization at a higher resolution compared to the 30km grid shown in this recipe.