uxarray.Grid#
- class uxarray.Grid(grid_ds, source_grid_spec=None, source_dims_dict={})#
Represents a two-dimensional unstructured grid encoded following the UGRID conventions and provides grid-specific functionality.
Can be used standalone to work with unstructured grids, or can be paired with either a
ux.UxDataArrayorux.UxDatasetand accessed through the.uxgridattribute.For constructing a grid from non-UGRID datasets or other types of supported data, see our
ux.open_gridmethod or specific class methods (Grid.from_dataset,Grid.from_face_verticies, etc.)- Parameters:
grid_ds (xr.Dataset) –
xarray.Datasetencoded in the UGRID conventionssource_grid_spec (str, default="UGRID") – Original unstructured grid format (i.e. UGRID, MPAS, etc.)
source_dims_dict (dict, default={}) – Mapping of dimensions from the source dataset to their UGRID equivalent (i.e. {nCell : n_face})
Examples
>>> import uxarray as ux >>> grid_path = "/path/to/grid.nc" >>> data_path = "/path/to/data.nc"
Open a grid file with uxarray.open_grid():
>>> uxgrid = ux.open_grid(grid_path)
2. Open an unstructured grid dataset file with uxarray.open_dataset(), then access the
Grid.:>>> uxds = ux.open_dataset(grid_path, data_path) >>> uxds.uxgrid
- __init__(grid_ds, source_grid_spec=None, source_dims_dict={})#
Methods
__init__(grid_ds[, source_grid_spec, ...])calculate_total_face_area([quadrature_rule, ...])Function to calculate the total surface area of all the faces in a mesh.
chunk([n_node, n_edge, n_face])Converts all arrays to dask arrays with given chunks across grid dimensions in-place.
compute_face_areas([quadrature_rule, order, ...])Face areas calculation function for grid class, calculates area of all faces in the grid.
construct_face_centers([method])Constructs face centers, this method provides users direct control of the method for constructing the face centers, the default method is "cartesian average", but a more accurate method is "welzl" that is based on the recursive Welzl algorithm.
copy()Returns a deep copy of this grid.
encode_as(grid_type)Encodes the grid as a new xarray.Dataset per grid format supplied in the grid_type argument.
from_dataset(dataset[, use_dual])Constructs a
Gridobject from a dataset.from_face_vertices(face_vertices[, latlon])Constructs a
Gridobject from user-defined face vertices.from_file(filename[, backend])Constructs a
Gridobject from a using the read_file method with a specified backend.from_points(points[, method, boundary_points])Create a grid from unstructured points.
from_structured([ds, lon, lat, tol])Converts a structured
xarray.Datasetor longitude and latitude coordinates into an unstructureduxarray.Grid.from_topology(node_lon, node_lat, ...[, ...])Constructs a
Gridobject from user-defined topology variables provided in the UGRID conventions.get_ball_tree([coordinates, ...])Get the BallTree data structure of this Grid that allows for nearest neighbor queries (k nearest or within some radius) on either the (
node_x,node_y,node_z) and (node_lon,node_lat), edge (edge_x,edge_y,edge_z) and (edge_lon,edge_lat), or center (face_x,face_y,face_z) and (face_lon, ` face_lat`) nodes.get_dual()Compute the dual for a grid, which constructs a new grid centered around the nodes, where the nodes of the primal become the face centers of the dual, and the face centers of the primal become the nodes of the dual.
get_edges_at_constant_latitude(lat[, ...])Identifies the indices of edges that intersect with a line of constant latitude.
get_edges_at_constant_longitude(lon[, ...])Identifies the indices of edges that intersect with a line of constant longitude.
get_faces_at_constant_latitude(lat)Identifies the indices of faces that intersect with a line of constant latitude.
get_faces_at_constant_longitude(lon)Identifies the indices of faces that intersect with a line of constant longitude.
get_kd_tree([coordinates, ...])Get the KDTree data structure of this Grid that allows for nearest neighbor queries (k nearest or within some radius) on either the (
node_x,node_y,node_z) and (node_lon,node_lat), edge (edge_x,edge_y,edge_z) and (edge_lon,edge_lat), or center (face_x,face_y,face_z) and (face_lon,face_lat) nodes.isel(**dim_kwargs)Indexes an unstructured grid along a given dimension (
n_node,n_edge, orn_face) and returns a new grid.Normalizes Cartesian coordinates.
to_geodataframe([periodic_elements, ...])Constructs a
GeoDataFrameconsisting of polygons representing the faces of the currentGridto_linecollection([periodic_elements, ...])Constructs a
matplotlib.collections.LineCollection`consisting of lines representing the edges of the currentGridto_polycollection([periodic_elements, ...])Constructs a
matplotlib.collections.PolyCollection`consisting of polygons representing the faces of the currentGridto_xarray([grid_format])Returns an
xarray.Datasetwith the variables stored under theGridencoded in a specific grid format.validate([check_duplicates])Validates the current
Grid, checking for Duplicate Nodes, Present Connectivity, and Non-Zero Face Areas.Attributes
Index of each face that crosses the antimeridian.
Dictionary of parsed attributes from the source grid.
Indices of edges that border regions not covered by any geometry (holes) in a partial grid.
Indices of faces that border regions not covered by any geometry (holes) in a partial grid.
Indices of nodes that border regions not covered by any geometry (holes) in a partial grid.
Latitude Longitude Bounds for each Face in radians.
Names of all connectivity variables.
coordinatesNames of all coordinate variables.
Names of all descriptor variables.
Names of all unstructured grid dimensions.
Indices of the edges that surround each edge.
Indices of the faces that saddle each edge.
Distances between the centers of the faces that saddle each edge in degrees.
Latitude of the center of each edge in degrees.
Longitude of the center of each edge in degrees.
Indices of the two nodes that make up each edge.
Distances between the two nodes that surround each edge in degrees.
edge_node_xCartesian x location for the two nodes that make up every edge.
edge_node_yCartesian y location for the two nodes that make up every edge.
edge_node_zCartesian z location for the two nodes that make up every edge.
Cartesian x location of the center of each edge in meters.
Cartesian y location of the center of each edge in meters.
Cartesian z location of the center of each edge in meters.
The area of each face.
Latitude bounds for each face in degrees.
Longitude bounds for each face in degrees.
Indices of the edges that surround each face.
Indices of the faces that surround each face.
face_jacobianDeclare face_jacobian as a property.
Latitude of the center of each face in degrees.
Longitude of the center of each face in degrees.
Indices of the nodes that make up each face.
Cartesian x location of the center of each face in meters.
Cartesian y location of the center of each face in meters.
Cartesian z location of the center of each face in meters.
Boolean indicated whether the Grid completely covers the unit sphere (i.e. contains no holes).
Total number of edges.
Total number of faces.
The maximum number of edges that surround a single edge.
The maximum number of edges that surround a single face.
The maximum number of faces that surround a single face.
The maximum number of nodes that can make up a single face.
The maximum number of edges that surround a single node.
The maximum number of faces that surround a single node.
Total number of nodes.
The number of nodes that make up each face.
Indices of the edges that surround each node.
Indices of the faces that surround each node.
Latitude of each node in degrees.
Longitude of each node in degrees.
Indices of the nodes that surround each node.
Cartesian x location of each node in meters.
Cartesian y location of each node in meters.
Cartesian z location of each node in meters.
parsed_attrsDictionary of parsed attributes from the source grid.
Boolean indicated whether the Grid partial covers the unit sphere (i.e. contains holes).
Names and values of all unstructured grid dimensions.
Boolean indicated whether the Grid is strictly composed of triangular faces.