Skip to article frontmatterSkip to article content

UXarray extends upon Xarray’s core data structures (i.e. Dataset and DataArray) and provides functionality for operating on unstructured (a.k.a. non-regular) grids.

This notebook will showcase the core UXarray data structures and how to interact with them

import uxarray as ux

First, lets specify the paths to our Grid and Data files. As mentioned in the previous notebook, unstructured grids are typically separated into two files: one containing the grid topology and one containing data variables that reside on that grid.

file_dir = "../../meshfiles/"
grid_filename = file_dir + "oQU480.grid.nc"
data_filename = file_dir + "oQU480.data.nc"

Grid Data Structure

An unstructured grid file can be opened standalone using the ux.open_grid method, which is a catch-all method that parses the provided input and returns a Grid object with grid coordinate and connectivity variables represented in the UGRID conventions.

Printing our Grid instance shows all available grid variables and original grid type.

grid = ux.open_grid(grid_filename)
grid

We can access our coordinate, connectivity, and other descriptor variables as attributes through this Grid instance

grid.node_lon
grid.face_node_connectivity

UxDataset & UxDataArray Data Structures

UXarray inherits from Xarray’s two core data structures Dataset & DataArray to provide a grid-informed implementation through the UxDataset & UxDataArray data structures.

The major difference between them is that UXarray’s implementation is paired with a Grid object, accessed through the .uxgrid property.

UXarray also provides an overloaded ux.open_dataset method, which takes in both a Grid and Data file path to construct a UxDataset

uxds = ux.open_dataset(grid_filename, data_filename)
uxds

We can see that our UxDataset has a single data variable bottomDepth, which is mapped to each face (as specified by the n_face dimension).

We can access this variable by indexing our UxDataset to obtain a UxDataArray

uxds["bottomDepth"]

You can access the Grid instance using the .uxgrid attribute, which is linked to every UxDataset and UxDataArray

uxds.uxgrid

Each UxDataArray under a UxDataset is linked to the same Grid object

uxds.uxgrid == uxds["bottomDepth"].uxgrid