Internal API#

This page shows already-implemented Uxarray internal API functions. You can also check the draft UXarray API documentation to see the tentative whole API and let us know if you have any feedback!

UxDataset#

The uxarray.UxDataset class inherits from xarray.Dataset. Below is a list of features explicitly added to work on Unstructured Grids.

Class#

UxDataset(*args[, uxgrid, source_datasets])

A xarray.Dataset-like, multi-dimensional, in memory, array database.

Attributes#

UxDataset._source_datasets

UxDataset._uxgrid

Methods#

UxDataset.__getitem__(key)

Override to make sure the result is an instance of uxarray.UxDataArray or uxarray.UxDataset.

UxDataset.__setitem__(key, value)

Add an array to this dataset.

UxDataset._calculate_binary_op(*args, **kwargs)

Override to make the result a complete instance of uxarray.UxDataset.

UxDataset._construct_dataarray(name)

Override to make the result an instance of uxarray.UxDataArray.

UxDataset._construct_direct(*args, **kwargs)

Override to make the result an uxarray.UxDataset class.

UxDataset._copy(**kwargs)

Override to make the result a complete instance of uxarray.UxDataset.

UxDataset._replace(*args, **kwargs)

Override to make the result a complete instance of uxarray.UxDataset.

UxDataArray#

The uxarray.UxDataArray class inherits from xarray.DataArray. Below is a list of features explicitly added to work on Unstructured Grids.

Class#

UxDataArray(*args[, uxgrid])

N-dimensional xarray.DataArray-like array.

Attributes#

UxDataArray._uxgrid

Methods#

UxDataArray._construct_direct(*args, **kwargs)

Override to make the result a uxarray.UxDataArray class.

UxDataArray._copy(**kwargs)

Override to make the result a complete instance of uxarray.UxDataArray.

UxDataArray._replace(*args, **kwargs)

Override to make the result a complete instance of uxarray.UxDataArray.

Grid#

Class#

Grid(input_obj, **kwargs)

Unstructured grid topology definition.

Methods#

Grid.__init_grid_var_names__()

Populates a dictionary for storing uxarray's internal representation of xarray object.

Grid.__from_ds__(dataset)

Loads a mesh dataset.

Grid.__from_vert__(dataset)

Create a grid with faces constructed from vertices specified by the given argument.

Attributes#

Grid._Mesh2_node_z

Coordinate Variable _Mesh2_node_z, which contains the level of each node.

Operators#

Grid.__eq__(other)

Two grids are equal if they have matching grid topology variables, coordinates, and dims all of which are equal.

Grid.__ne__(other)

Two grids are not equal if they have differing grid topology variables, coordinates, or dims.

Helpers#

Connectivity#

grid.connectivity._replace_fill_values(...)

Replaces all instances of the the current fill value (original_fill) in (grid_var) with (new_fill) and converts to the dtype defined by (new_dtype)

grid.connectivity._build_nNodes_per_face(grid)

Constructs nNodes_per_face, which contains the number of non- fill- value nodes for each face in Mesh2_face_nodes

grid.connectivity._build_edge_node_connectivity(grid)

Constructs the UGRID connectivity variable (Mesh2_edge_nodes) and stores it within the internal (Grid._ds) and through the attribute (Grid.Mesh2_edge_nodes).

grid.connectivity._build_face_edges_connectivity(grid)

Constructs the UGRID connectivity variable (Mesh2_face_edges) and stores it within the internal (Grid._ds) and through the attribute (Grid.Mesh2_face_edges).

Geometry#

grid.geometry._build_polygon_shells(...)

Constructs the shell of each polygon derived from the closed off face nodes, which can be used to construct Shapely Polygons.

grid.geometry._build_corrected_polygon_shells(...)

Constructs corrected_polygon_shells and ``Grid.original_to_corrected), representing the polygon shells, with antimeridian polygons split.

grid.geometry._build_antimeridian_face_indices(grid)

Constructs antimeridian_face_indices, which represent the indicies of faces that cross the antimeridian.

grid.geometry._grid_to_polygon_geodataframe(grid)

Constructs and returns a spatialpandas.GeoDataFrame

Coordinates#

grid.coordinates._populate_cartesian_xyz_coord(grid)

A helper function that populates the xyz attribute in UXarray.Grid._ds.

grid.coordinates._populate_lonlat_coord(grid)

Helper function that populates the longitude and latitude and store it into the Mesh2_node_x and Mesh2_node_y.

Lines#

grid.lines._angle_of_2_vectors(u, v)

Calculate the angle between two 3D vectors u and v in radians.

Grid Parsing and Encoding#

UGRID#

io._ugrid._read_ugrid(xr_ds, var_names_dict)

UGRID file reader.

io._ugrid._encode_ugrid(ds)

Encodes UGRID file .

io._ugrid._is_ugrid(ds)

Check mesh topology and dimension.

MPAS#

io._mpas._read_mpas(ext_ds[, use_dual])

Function to read in a MPAS Grid dataset and encode either the Primal or Dual Mesh in the UGRID conventions.

io._mpas._primal_to_ugrid(in_ds, out_ds)

Encodes the MPAS Primal-Mesh in the UGRID conventions.

io._mpas._dual_to_ugrid(in_ds, out_ds)

Encodes the MPAS Dual-Mesh in the UGRID conventions.

io._mpas._set_global_attrs(in_ds, out_ds)

Helper to set MPAS global attributes.

io._mpas._replace_padding(verticesOnCell, ...)

Replaces the padded values in verticesOnCell defined by nEdgesOnCell with a fill-value.

io._mpas._replace_zeros(grid_var)

Replaces all instances of a zero (invalid/missing MPAS value) with a fill value.

Exodus#

io._exodus._read_exodus(ext_ds, grid_var_names)

Exodus file reader.

io._exodus._encode_exodus(ds, grid_var_names)

Encodes an Exodus file.

io._exodus._get_element_type(num_nodes)

Helper function to get exodus element type from number of nodes.

SCRIP#

io._scrip._to_ugrid(in_ds, out_ds)

If input dataset (in_ds) file is an unstructured SCRIP file, function will reassign SCRIP variables to UGRID conventions in output file (out_ds).

io._scrip._read_scrip(ext_ds)

Function to reassign lat/lon variables to mesh2_node variables.

io._scrip._encode_scrip(mesh2_face_nodes, ...)

Function to reassign UGRID formatted variables to SCRIP formatted variables.

Shapefile#

io._shapefile._read_shpfile(filepath)

Read shape file.

Utils#

io.utils._parse_grid_type(dataset)

Checks input and contents to determine grid type.