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.

UxDataArray._face_centered()

Returns whether the data stored is Face Centered (i.e.

UxDataArray._node_centered()

Returns whether the data stored is Node Centered (i.e.

Grid#

Class#

Grid(grid_ds[, source_grid_spec, ...])

Represents a two-dimensional unstructured grid encoded following the UGRID conventions and provides grid-specific functionality.

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._face_nodes_to_sparse_matrix(...)

Converts a given dense matrix connectivity to a sparse matrix format where the locations of non fill-value entries are stored using COO (coordinate list) standard.

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).

grid.connectivity._build_node_faces_connectivity(grid)

Builds the Grid.Mesh2_node_faces: integer DataArray of size (nMesh2_node, nMaxNumFacesPerNode) (optional) A DataArray of indices indicating faces that are neighboring each node.

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

grid.geometry._grid_to_matplotlib_polycollection(grid)

Constructs and returns a matplotlib.collections.PolyCollection

grid.geometry._grid_to_matplotlib_linecollection(grid)

Constructs and returns a matplotlib.collections.LineCollection

grid.geometry._pole_point_inside_polygon(...)

Determines if a pole point is inside a polygon.

grid.geometry._classify_polygon_location(...)

Classify the location of the polygon relative to the hemisphere.

grid.geometry._check_intersection(ref_edge, ...)

Check the number of intersections of the reference edge with the given edges.

Coordinates#

grid.coordinates._get_lonlat_from_xyz(x, y, z)

grid.coordinates._get_xyz_from_lonlat(...)

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.

grid.coordinates._populate_centroid_coord(grid)

Finds the centroids using cartesian averaging of faces based off the vertices.

grid.coordinates._construct_xyz_centroids(...)

Constructs the xyz centroid coordinate for each face using Cartesian Averaging.

Lines#

grid.lines._angle_of_2_vectors(u, v)

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

Utils#

grid.utils._fmms(a, b, c, d)

Calculate the difference of products using the FMA (fused multiply-add) operation: (a * b) - (c * d).

grid.utils._newton_raphson_solver_for_gca_constLat(...)

Solve for the intersection point between a great circle arc and a constant latitude.

grid.utils._inv_jacobian(x0, x1, y0, y1, z0, ...)

Calculate the inverse Jacobian matrix for a given set of parameters.

Grid Parsing and Encoding#

UGRID#

io._ugrid._read_ugrid(xr_ds)

UGRID file reader.

io._ugrid._encode_ugrid(ds)

Encodes UGRID file .

io._ugrid._is_ugrid(ds)

Check mesh topology and dimension.

io._ugrid._validate_minimum_ugrid(grid_ds)

Checks whether a given grid_ds meets the requirements for a minimum unstructured grid encoded in the UGRID conventions, containing a set of (x, y) latlon coordinates and face node connectivity.

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._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)

Exodus file reader.

io._exodus._encode_exodus(ds[, outfile])

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.

Vertices#

io._vertices._read_face_vertices(...)

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

Utils#

io.utils._parse_grid_type(dataset)

Checks input and contents to determine grid type.

Core Utils#

core.utils._map_dims_to_ugrid(ds, ...)

Given a dataset containing variables residing on an unstructured grid, remaps the original dimension name to match the UGRID conventions (i.e.