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.
compute_face_areas([quadrature_rule, order, ...])Face areas calculation function for grid class, calculates area of all faces in the grid.
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 anxarray.Dataset.from_face_vertices(face_vertices[, latlon])Constructs a
Gridobject from user-defined face vertices.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 nodes (
node_lon,node_lat) or face centers (face_lon,face_lat).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 nodes (
node_x,node_y,node_z) or face centers (face_x,face_y,face_z).isel(**dim_kwargs)Indexes an unstructured grid along a given dimension (
n_node,n_edge, orn_face) and returns a new grid.to_geodataframe([override, cache, ...])Constructs a
spatialpandas.GeoDataFramewith a "geometry" column, containing a collection of Shapely Polygons or MultiPolygons representing the geometry of the unstructured grid.to_linecollection([override, cache])Constructs a
matplotlib.collections.LineCollectionobject with line segments representing the geometry of the unstructured grid, corrected near the antimeridian.to_polycollection([override, cache, ...])Constructs a
matplotlib.collections.PolyCollectionobject with polygons representing the geometry of the unstructured grid, with polygons that cross the antimeridian split.validate()Validate a grid object check for common errors, such as:
Attributes
Mesh2UGRID Attribute
Mesh2, which indicates the topology data of a 2D unstructured mesh.Index of each face that crosses the antimeridian.
Connectivity Variable
edge_edge_connectivity.Connectivity Variable
edge_face_connectivity, which contains the index of the faces that saddle a given edge.edge_face_distancesContains the distance between the faces that saddle a given edge.
Coordinate
edge_lat, which contains the latitude of each edge in degrees.Coordinate
edge_lon, which contains the longitude of each edge in degrees.Connectivity Variable
edge_node_connectivity, which maps every edge to the two nodes that it connects.edge_node_distancesContains the distance between the nodes that saddle a given edge.
Coordinate
edge_x, which contains the Cartesian x location of each edge in meters.Coordinate
edge_y, which contains the Cartesian y location of each edge in meters.Coordinate
edge_z, which contains the Cartesian z location of each edge in meters.Declare face_areas as a property.
Connectivity Variable
face_edge_connectivity, which maps every face to its edges.Connectivity Variable
face_face_connectivity.face_jacobianDeclare face_jacobian as a property.
Coordinate
face_lat, which contains the latitude of each face in degrees.Coordinate
face_lon, which contains the longitude of each face in degrees.Connectivity Variable
face_node_connectivity, which maps each face to its corner nodes.Coordinate
face_x, which contains the Cartesian x location of each face in meters.Coordinate
face_y, which contains the Cartesian y location of each face in meters.Coordinate
face_z, which contains the Cartesian z location of each face in meters.Dimension
n_edge, which represents the total number of unique edges.Dimension
n_face, which represents the total number of unique faces.Dimension
n_max_face_edges, which represents the maximum number of edges per face.Dimension
n_max_face_nodes, which represents the maximum number of nodes that a face may contain.Dimension
n_node, which represents the total number of unique corner nodes.Dimension Variable
n_nodes_per_face, which contains the number of non-fill-value nodes per face.Connectivity Variable
node_edge_connectivity.Connectivity Variable
node_face_connectivity, which maps every node to its faces.Coordinate
node_lat, which contains the latitude of each node in degrees.Coordinate
node_lon, which contains the longitude of each node in degrees.Connectivity Variable
node_node_connectivity.Coordinate
node_x, which contains the Cartesian x location of each node in meters.Coordinate
node_y, which contains the Cartesian y location of each node in meters.Coordinate
node_z, which contains the Cartesian y location of each node in meters.Dictionary of parsed attributes from the source grid.