Skip to article frontmatterSkip to article content

UXarray logo

UXarray Grid

In this tutorial, you’ll learn:

  • What is a UXarray Grid?
  • How to load a Grid
  • How to access Grid attributes

Prerequisites

ConceptsImportanceNotes
Unstructured GridsNecessary
Python programmingNecessary
Introduction to XarrayHelpful

Time to learn: 10 minutes


Overview

In the previous section, we briefly introduced the Grid class, which stores unstructured grid variables such as coordinates and connectivity. This class is the foundation of UXarray, which ensures awareness of the unstructured grid topology between operations. Exploring the grid geometry can be helpful throughout analysis and visualization workflows.

Note:

In most cases, checking the ``Grid`` object of either ``UxDataset`` or ``UxDataArray`` is anticipated be the common scenario since majority of the UXarray workflows will rely on a data set and its variable(s) of interest. Such cases will be showcased as part of many of the following notebooks; thus, this tutorial will focus on the latter where we explore a standalone ``Grid`` object.

Unstructured Grid Files

In the following sections, we will look into loading a standalone grid-specific file. The coordinates and connectivity variables of an unstructured grid are often stored as a separate unstructured grid file.

grid_path = "../../meshfiles/outCSne30.grid.ug"

Loading a Grid

The suggested way to construct a standalone Grid is by using the uxarray.open_grid() method. When constructing a standalone grid, only topology variables such as coordinates and connectivity are used to construct the grid. This means that any data variables that reside on the unstructured grid, such as temperature, would not be stored in a Grid. Pairing the grid definiton with data variables will be covered in the next notebook.

import uxarray as ux

uxgrid = ux.open_grid(grid_path)
uxgrid
Loading...

Printing a Grid displays the contents of our newly created grid object. If you are coming from an Xarray background, this output will look very similar to what one might see when constructing an xarray.Dataset.

Coordinates

Different types of coordinates for the geometric elements of a Grid are either constructed upfront during the grid instantiation or generated at the time of use.

Spherical Coordinates

The spherical node coordinates are always instantiated upfront with the grid initialization and can be examined through the grid attributes such as node_lon, node_lat, etc:

uxgrid.node_lon
Loading...

However, the spherical face and edge coordinates might not be readily available in the grid definition (see the original Grid object above for reference) and would need to be generated by UXarray when prompted; for instance:

uxgrid.face_lon
Loading...

Cartesian coordinates

The original uxgrid object above shows no Cartesian coordinates; however, UXarray is able to generate those as soon as the user tries to access one of them; for instance:

uxgrid.node_x
Loading...

Connectivity

In unstructured grid geometry, connectivity information between each type of geometric elements can be defined, e.g. face-node, node-edge, edge-face, etc. UXarray requires only the face-node connectivity, either coming from the grid definition or being constructed by UXarray in special cases, in addition to the node coordinates to represent the topology.

UXarray can also generate all the other connectivity information when prompted.

Let us look at the face-node connectivity, for example:

uxgrid.face_node_connectivity
Loading...

Descriptors

UXarray provides descriptors for further information about the geometry. For instance, an array that shows the number of nodes for each face can be helpful to determine if the grid is uniformly constructed of a single shape or multiple n-gons, and simplify some of the grid-specific calculations as well.

uxgrid.n_nodes_per_face
Loading...

What is next?

The next section will cover the other core data structures of UXarray, UxDataset and UxDataArray classes and how to open unstructured grid datasets for data analysis and visualization purposes.