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);
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);