Visualizing Grid Topology#

Authors: Philip Chmielowiec

Overview#

This usage example showcases how to use UXarray’s plotting API to visualize the topology of an unstructured grid (i.e., the elements that make up a grid). The majority of this notebook uses the Primal Mesh of an MPAS Ocean Grid, with the final example using an MPAS Atmosphere Grid.

Note

UXarray’s Plotting API is build around the Holoviews package. For details about customization and accepted parameters, pleases refer to their documentation.

import uxarray as ux
from holoviews import opts
base_path = "../../test/meshfiles/mpas/QU/"
grid_path = base_path + "oQU480.231010.nc"
uxds = ux.open_dataset(grid_path, grid_path)
grid = uxds.uxgrid
/home/docs/checkouts/readthedocs.org/user_builds/uxarray/conda/latest/lib/python3.11/site-packages/uxarray/core/utils.py:22: FutureWarning: The return type of `Dataset.dims` will be changed to return a set of dimension names in future, in order to be more consistent with `DataArray.dims`. To access a mapping from dimension names to lengths, please use `Dataset.sizes`.
  if ds.dims[dim] == grid.n_face:
/home/docs/checkouts/readthedocs.org/user_builds/uxarray/conda/latest/lib/python3.11/site-packages/uxarray/grid/grid.py:435: FutureWarning: The return type of `Dataset.dims` will be changed to return a set of dimension names in future, in order to be more consistent with `DataArray.dims`. To access a mapping from dimension names to lengths, please use `Dataset.sizes`.
  return self._ds.dims["n_face"]
/home/docs/checkouts/readthedocs.org/user_builds/uxarray/conda/latest/lib/python3.11/site-packages/uxarray/core/utils.py:24: FutureWarning: The return type of `Dataset.dims` will be changed to return a set of dimension names in future, in order to be more consistent with `DataArray.dims`. To access a mapping from dimension names to lengths, please use `Dataset.sizes`.
  elif ds.dims[dim] == grid.n_node:
/home/docs/checkouts/readthedocs.org/user_builds/uxarray/conda/latest/lib/python3.11/site-packages/uxarray/grid/grid.py:429: FutureWarning: The return type of `Dataset.dims` will be changed to return a set of dimension names in future, in order to be more consistent with `DataArray.dims`. To access a mapping from dimension names to lengths, please use `Dataset.sizes`.
  return self._ds.dims["n_node"]
/home/docs/checkouts/readthedocs.org/user_builds/uxarray/conda/latest/lib/python3.11/site-packages/uxarray/core/utils.py:26: FutureWarning: The return type of `Dataset.dims` will be changed to return a set of dimension names in future, in order to be more consistent with `DataArray.dims`. To access a mapping from dimension names to lengths, please use `Dataset.sizes`.
  elif ds.dims[dim] == grid.n_edge:
/home/docs/checkouts/readthedocs.org/user_builds/uxarray/conda/latest/lib/python3.11/site-packages/uxarray/grid/grid.py:444: FutureWarning: The return type of `Dataset.dims` will be changed to return a set of dimension names in future, in order to be more consistent with `DataArray.dims`. To access a mapping from dimension names to lengths, please use `Dataset.sizes`.
  return self._ds.dims["n_edge"]

Using the Grid.plot() Accessor#

Each Grid object is initialized with a plotting accessor, which enables plotting routines to be called directly on the object. By default, calling .plot() on a Grid instance plots all the edges of a grid.

grid.plot(title="Default Grid Plot Method", height=350, width=700)
/home/docs/checkouts/readthedocs.org/user_builds/uxarray/conda/latest/lib/python3.11/site-packages/uxarray/grid/grid.py:435: FutureWarning: The return type of `Dataset.dims` will be changed to return a set of dimension names in future, in order to be more consistent with `DataArray.dims`. To access a mapping from dimension names to lengths, please use `Dataset.sizes`.
  return self._ds.dims["n_face"]

Since all of our plotting methods are built around the Holoviews package, you can select between Matplotlib and Bokeh backends if desired (Bokeh is the default and is suggested).

grid.plot(backend="matplotlib", title="Default Grid Plot Method with Matplotlib Backend", fig_size=200)

Since each UxDataArray and UxDataset is paired with a Grid objected through the .uxgrid attribute, the same function calls can be executed

uxds.uxgrid.plot(title="Default Plot Method through uxgrid Accessor", height=350, width=700)