Working with Mesh Data

Note

Several of the operations below rely on the optional dependencies mentioned in Iris’ Mesh Partner Packages.

Operations Summary

Making a Mesh

✨ New

Making a Cube

♻️ Unchanged

Save

♻️ Unchanged

Load

⚠️ Different - UGRID parsing is opt-in

Plotting

⚠️ Different - plot with GeoVista

Region Extraction

⚠️ Different - use GeoVista for mesh analysis

Regridding

⚠️ Different - use iris-esmf-regrid for mesh regridders

Equality

♻️ Unchanged

Combining Cubes

🚧 Support Pending

Arithmetic

🚧 Support Pending

Making a Mesh

✨ New

Already have a file? Consider skipping to Load.

Creating Iris objects from scratch is a highly useful skill for testing code and improving understanding of how Iris works. This knowledge will likely prove particularly useful when converting data into the Iris mesh data model from structured formats and non-UGRID mesh formats.

The objects created in this example will be used where possible in the subsequent example operations on this page.

Making a Cube (with a Mesh)

♻️ Unchanged

Creating a Cube is unchanged; the Mesh is linked via a MeshCoord (see MeshCoords):

Save

♻️ Unchanged

Note

UGRID saving support is limited to the NetCDF file format.

The Iris saving process automatically detects if the Cube has an associated Mesh and automatically saves the file in a UGRID-conformant format:

The iris.experimental.ugrid.save_mesh() function allows Meshes to be saved to file without associated Cubes:

Load

⚠️ Different - UGRID parsing is opt-in

Note

UGRID loading support is limited to the NetCDF file format.

While Iris’ UGRID support remains experimental, parsing UGRID when loading a file remains optional. To load UGRID data from a file into the Iris mesh data model, use the iris.experimental.ugrid.PARSE_UGRID_ON_LOAD context manager:

All the existing loading functionality still operates on UGRID-compliant data - Constraints, callbacks, load_cube() etcetera:

Note

We recommend caution if constraining on coordinates associated with a Mesh. An individual coordinate value might not be shared by any other data points, and using a coordinate range will demand notably higher performance given the size of the dimension versus structured grids (see the data model detail).

The iris.experimental.ugrid.load_mesh() and load_meshes() functions allow only Meshes to be loaded from a file without creating any associated Cubes:

Plotting

⚠️ Different - plot with GeoVista

The Cartopy-Matplotlib combination is not optimised for displaying the high number of irregular shapes associated with meshes. Thankfully mesh visualisation is already popular in many other fields (e.g. CGI, gaming, SEM microscopy), so there is a wealth of tooling available, which GeoVista harnesses for cartographic plotting.

GeoVista’s default behaviour is to convert lat-lon information into full XYZ coordinates so the data is visualised on the surface of a 3D globe. The plots are interactive by default, so it’s easy to explore the data in detail.

2D projections have also been demonstrated in proofs of concept, and will be added to API in the near future.

This first example uses GeoVista to plot the face_cube that we created earlier:

Here’s another example using a global cubed-sphere data set:

Region Extraction

⚠️ Different - use GeoVista for mesh analysis

As described in The Mesh Data Model, indexing for a range along a Cube's mesh_dim() will not provide a contiguous region, since position on the unstructured dimension is unrelated to spatial position. This means that subsetted MeshCoords cannot be reliably interpreted as intended, and subsetting a MeshCoord is therefore set to return an AuxCoord instead - breaking the link between Cube and Mesh:

Extracting a region therefore requires extra steps - to determine the spatial position of the data points before they can be analysed as inside/outside the selected region. The recommended way to do this is using tools provided by GeoVista, which is optimised for performant mesh analysis.

This approach centres around using geovista.geodesic.BBox.enclosed() to get the subset of the original mesh that is inside the BBox. This subset pyvista.PolyData object includes the original indices of each datapoint - the vtkOriginalCellIds array, which can be used to index the original Cube. Since we know that this subset Cube represents a regional mesh, we then reconstruct a Mesh from the Cube's aux_coords using iris.experimental.ugrid.Mesh.from_coords():

Regridding

⚠️ Different - use iris-esmf-regrid for mesh regridders

Regridding to or from a mesh requires different logic than Iris’ existing regridders, which are designed for structured grids. For this we recommend ESMF’s powerful regridding tools, which integrate with Iris’ mesh data model via the iris-esmf-regrid package.

Regridding is achieved via the esmf_regrid.experimental.unstructured_scheme.MeshToGridESMFRegridder and GridToMeshESMFRegridder classes. Regridding from a source Cube to a target Cube involves initialising and then calling one of these classes. Initialising is done by passing in the source and target Cube as arguments. The regridder is then called by passing the source Cube as an argument. We can demonstrate this with the MeshToGridESMFRegridder:

Note

All Cube attributes are retained when regridding, so watch out for any attributes that reference the format (there are several in these examples) - you may want to manually remove them to avoid later confusion.

The initialisation process is computationally expensive so we use caching to improve performance. Once a regridder has been initialised, it can be used on any Cube which has been defined on the same Mesh (or on the same grid in the case of GridToMeshESMFRegridder). Since calling a regridder is usually a lot faster than initialising, reusing regridders can save a lot of time. We can demonstrate the reuse of the previously initialised regridder:

Support also exists for saving and loading previously initialised regridders - esmf_regrid.experimental.io.save_regridder() and load_regridder() - so that they can be re-used by future scripts.

Equality

♻️ Unchanged

Mesh comparison is supported, and comparing two ‘Mesh-Cubes’ will include a comparison of the respective Meshes, with no extra action needed by the user.

Note

Keep an eye on memory demand when comparing large Meshes, but note that Meshequality is enabled for lazy processing (Real and Lazy Data), so if the Meshes being compared are lazy the process will use less memory than their total size.

Combining Cubes

🚧 Support Pending

Merging or concatenating Cubes (described in Merge and Concatenate) with two different Meshes is not possible - a Cube must be associated with just a single Mesh, and merge/concatenate are not yet capable of combining multiple Meshes into one.

Cubes that include MeshCoords can still be merged/concatenated on dimensions other than the mesh_dim(), since such Cubes will by definition share the same Mesh.

See also

You may wish to investigate iris.experimental.ugrid.recombine_submeshes(), which can be used for a very specific type of Mesh combination not detailed here.

Arithmetic

🚧 Support Pending

Cube Arithmetic (described in Cube Maths) has not yet been adapted to handle Cubes that include MeshCoords.