mosaic.Descriptor

mosaic.Descriptor#

class mosaic.Descriptor(mesh_ds, projection=None, transform=None, use_latlon=False)#

Data structure describing unstructured MPAS meshes.

Enables visualization of fields defined at cell centers, vertices, and edges within matplotlib through the creation of PolyCollection objects. Separate patch arrays, which are subsequently passed to the PolyCollection class by the polypcolor method, are lazily loaded for each variable location (i.e. cells, edges, and vertices) when attribute is first looked up. We use lazily loaded arrays because we are rarely plotting variables located at all three locations and patch array creation is the most expensive process in our visualization procedure.

The resulting patch arrays properly handle culled mesh boundaries (i.e. culled land boundaries for spherical meshes and/or mesh boundary for planar non-periodic meshes). Additionally, x and/or y periodicity is properly handled for planar periodic mesh and we can correct for patch wrapping over the antimeridian for projected spherical meshes.

Parameters:
  • mesh_ds (DataSet) – A valid MPAS mesh dataset that contains the basic mesh variables (i.e. coordinate and connectivity arrays) needed for creating patch arrays.

  • projection (cartopy.crs.CRS, optional) – The target projection for plotting.

  • transform (cartopy.crs.CRS, optional) – The coordinate system in which the parent mesh coordinates are defined.

  • use_latlon (bool, optional) – Whether to use the lat/lon coordinate arrays to construct the patches.

Notes

If both the projection and transform parameters are passed, then the coordinate arrays in the Descriptor.ds will be transformed prior to patch construction. We do this as matter of efficiency, since transforming the one-dimensional coordinate arrays is much faster than transforming the multi-dimensional patch arrays. This means the Descriptor.transform will not be the values passed to the constructor, but instead will be equal to Descriptor.projection

Examples

>>> import cartopy.crs as ccrs
>>> import mosaic
>>>
>>> ds = mosaic.datasets.open_dataset("QU.240km")
>>>
>>> transform = ccrs.PlateCarree()
>>> projection = ccrs.NorthPolarStereo()
>>>
>>> # set `use_latlon` to True b/c our transform expects lat/lon coords
>>> descriptor = mosaic.Descriptor(
>>>     ds, projection, transform, use_latlon=True
>>> )
__init__(mesh_ds, projection=None, transform=None, use_latlon=False)#

Methods

__init__(mesh_ds[, projection, transform, ...])

Attributes

cell_patches

ndarray of patch coordinates for cell centered values

edge_patches

ndarray of patch coordinates for edge centered values

latlon

Boolean whether the lat/lon coordinate arrays should be used for patch construction.

projection

The target projection for plotting.

vertex_patches

ndarray of patch coordinates for vertex centered values

transform

The coordinate system in which patch coordinates are defined.

is_spherical

Boolean whether parent mesh is spherical

ds

Dataset that contains the minimal subset of coordinate and connectivity arrays from the parent mesh needed to create patches arrays.