Comparison to Xarray

For users coming from an Xarray background, much of UXarray’s design is familiar. This notebook showcases an example of transitioning a Structured Grid Xarray workflow to UXarray.


import matplotlib.pyplot as plt
import uxarray as ux
import xarray as xr
fig_size = 400
plot_kwargs = {"backend": "matplotlib", "aspect": 2, "fig_size": fig_size}


It is common practice to resample unstructured grids to a structured representation for many analysis workflows to utilize familiar and reliable tools.

The datasets used in this example are meant to mimic this workflow, with a source Unstructured Grid and a Structured representation of that same grid.


base_path = "../../meshfiles/"
ds_path = base_path + ""
xrds = xr.open_dataset(ds_path)
<xarray.Dataset> Size: 30kB
Dimensions:  (lat: 45, lon: 80)
  * lat      (lat) int64 360B -90 -86 -82 -78 -74 -70 -66 ... 66 70 74 78 82 86
  * lon      (lon) float64 640B -180.0 -175.5 -171.0 ... 166.5 171.0 175.5
Data variables:
    psi      (lat, lon) float64 29kB ...


base_path = "../../meshfiles/"
grid_filename = base_path + ""
data_filename = base_path + ""
uxds = ux.open_dataset(grid_filename, data_filename)
<xarray.UxDataset> Size: 43kB
Dimensions:  (n_face: 5400)
Dimensions without coordinates: n_face
Data variables:
    psi      (n_face) float64 43kB ...

Example Workflows

Below are two simple visualization workflows that someone would run into

  • Creating a single plot

  • Creating a pair of plots (two different color maps are used to mimic different data)


xrds["psi"].plot(figsize=(12, 5), cmap="inferno")
<matplotlib.collections.QuadMesh at 0x7fde7213cd60>
fig, axs = plt.subplots(nrows=2, figsize=(12, 10))

xrds["psi"].plot(cmap="inferno", ax=axs[0])
xrds["psi"].plot(cmap="cividis", ax=axs[1])
<matplotlib.collections.QuadMesh at 0x7fde71de1cc0>


uxds["psi"].plot(width=1000, height=500, cmap="inferno")