Wireframes#

mosaic can draw the connectivity of an MPAS mesh using mosaic.wireframe(). This is useful for visualizing the mesh topology on its own, or for layering it on top of plotted data, as shown in Overlaying Wireframes on Data below.

Plotting a Wireframe#

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

import mosaic

# download and read a coarse, global mesh from lcrc
ds = mosaic.datasets.open_dataset("QU.960km")

projection = ccrs.Geostationary()
descriptor = mosaic.Descriptor(ds, projection)

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

mosaic.wireframe(ax, descriptor, color="black", linewidth=0.5);
../_images/475d10135f7922e04f1ec9af9d834a0449b9e59cb283481147ccb70c1a50890f.svg

Wireframe Locations#

The location keyword selects which part of the mesh is drawn. By default, location="Cell", which draws the boundary of each cell (i.e. the primal mesh). Setting location="Edge" instead draws the boundary of the quadrilateral region associated with each edge, and location="Vertex" draws the boundary of the triangular dual mesh. Passing the marker keyword additionally draws the points that define each of these lines.

fig, axs = plt.subplots(
    1, 3,
    figsize=(12, 4),
    constrained_layout=True,
    subplot_kw={"projection": projection},
)

for ax, location in zip(axs, ["Cell", "Edge", "Vertex"]):
    mosaic.wireframe(
        ax,
        descriptor,
        location,
        marker="o",
        color="black",
        linewidth=0.6,
        markersize=3,
    )
    ax.set_title(location)
../_images/db725e6d45331fb9d23747ecb59780c7846107783030710e5d3e34a29bdc38e9.svg

Overlaying Wireframes on Data#

Because mosaic.wireframe only draws lines and markers, it can be layered on top of an existing plot, such as one created with mosaic.polypcolor(), to show the mesh structure alongside the data:

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

mosaic.polypcolor(ax, descriptor, ds.indexToCellID, cmap='tab20b')

mosaic.wireframe(
    ax,
    descriptor,
    location="Vertex",
    color="black",
    linewidth=0.6,
);
../_images/c8e90b129ac1fd0541e22e9ecfc709677a65156eb3b29db90ee517acd0000466.svg

Current Limitations#

mosaic.wireframe does not yet support planar periodic meshes; calling it with a periodic Descriptor raises NotImplementedError.