Contouring on the MPAS Mesh

Contouring on the MPAS Mesh#

mosaic enables contouring on the native through the mosaic.contour() and mosaic.contourf() functions. All keyword arguments (that apply to our unstructured contouring) are shared with the matplotib implementations of contour and contourf. Please consult the matplotlib docs for more examples of fine grained control.

from __future__ import annotations

import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt

import mosaic

projection = ccrs.Mollweide()

ds = mosaic.datasets.open_dataset("QU.240km")
descriptor = mosaic.Descriptor(ds, projection=projection)

# extract temperature of top vertical layer
top_layer_temp = ds.temperature.isel(nVertLevels=0)

Unfilled Contours#

fig, ax = plt.subplots(
    constrained_layout=True, subplot_kw={"projection": projection}
)

mcs = mosaic.contour(
    ax,
    descriptor,
    top_layer_temp,
)

ax.clabel(mcs)

ax.add_feature(cfeature.LAND, fc="grey", zorder=-1, alpha=0.8);
../_images/6aeda1ce915730e1530bd0a0225ea6f6bfe41b7667c4315914ad8c62af6c00b9.png

Filled Contours#

fig, ax = plt.subplots(
    constrained_layout=True, subplot_kw={"projection": projection}
)

mcs = mosaic.contourf(
    ax,
    descriptor,
    top_layer_temp,
)

mcs2 = mosaic.contour(
    ax, descriptor, top_layer_temp, levels=mcs.levels[::2], colors="k"
)
ax.clabel(mcs2)

ax.add_feature(cfeature.LAND, fc="grey", zorder=-1, alpha=0.8)

# Make a colorbar for the contourf call.
cbar = fig.colorbar(
    mcs, shrink=0.5, label=r"Top Layer Temperature [$^\circ$ C]"
)
# Add the contour line levels to the colorbar
cbar.add_lines(mcs2);
../_images/1b8f2453339fc367903548e309d8cb755ea1e52b173eae5716f4f759cff57165.png