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.UxDataArray
orux.UxDataset
and accessed through the.uxgrid
attribute.For constructing a grid from non-UGRID datasets or other types of supported data, see our
ux.open_grid
method or specific class methods (Grid.from_dataset
,Grid.from_face_verticies
, etc.)- Parameters:
grid_ds (xr.Dataset) –
xarray.Dataset
encoded 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 : nMesh2_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
Grid
object from anxarray.Dataset
.from_face_vertices
(face_vertices[, latlon])Constructs a
Grid
object from user-defined face vertices.get_ball_tree
([tree_type])Get the BallTree data structure of this Grid that allows for nearest neighbor queries (k nearest or within some radius) on either the nodes (
Mesh2_node_x
,Mesh2_node_y
) or face centers (Mesh2_face_x
,Mesh2_face_y
).get_kd_tree
([tree_type])Get the KDTree data structure of this Grid that allows for nearest neighbor queries (k nearest or within some radius) on either the nodes (
Mesh2_node_cart_x
,Mesh2_node_cart_y
,Mesh2_node_cart_z
) or face centers (Mesh2_face_cart_x
,Mesh2_face_cart_y
,Mesh2_face_cart_z
).to_geodataframe
([override, cache, ...])Constructs a
spatialpandas.GeoDataFrame
with 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.LineCollection
object with line segments representing the geometry of the unstructured grid, corrected near the antimeridian.to_polycollection
([override, cache, ...])Constructs a
matplotlib.collections.PolyCollection
object with polygons representing the geometry of the unstructured grid, with polygons that cross the antimeridian split.to_shapely_polygons
([...])Constructs an array of Shapely Polygons representing each face, with antimeridian polygons split according to the GeoJSON standards.
Attributes
UGRID Attribute
Mesh2
, which indicates the topology data of a 2D unstructured mesh.Mesh2_edge_cart_x
Coordinate
Mesh2_edge_cart_x
, which contains the Cartesian x of each edge center in meters.Mesh2_edge_cart_y
Coordinate
Mesh2_edge_cart_y
, which contains the Cartesian y location of each edge center in meters.Mesh2_edge_cart_z
Coordinate
Mesh2_edge_cart_z
, which contains the Cartesian z location of each edge center in meters.Mesh2_edge_face_distances
Contains the distance between the faces that saddle a given edge.
UGRID Connectivity Variable
Mesh2_edge_faces
, which contains the index of the faces that saddle a given edge.Mesh2_edge_node_distances
Contains the distance between the nodes that saddle a given edge.
UGRID Connectivity Variable
Mesh2_edge_nodes
, which maps every edge to the two nodes that it connects.Mesh2_edge_x
Coordinate
Mesh2_edge_x
, which contains the longitude of the center of each edge in degrees.Mesh2_edge_y
Coordinate
Mesh2_node_cart_z
, which contains the latitude on each edge center in degrees.Mesh2_face_cart_x
Coordinate
Mesh2_face_cart_x
, which contains the Cartesian x location of each face center in meters.Mesh2_face_cart_y
Coordinate
Mesh2_face_cart_y
, which contains the Cartesian y location of each face center in meters.Mesh2_face_cart_z
Coordinate
Mesh2_face_cart_z
, which contains the Cartesian z location of each face center in meters.UGRID Connectivity Variable
Mesh2_face_edges
, which maps every face to its edges.UGRID Connectivity Variable
Mesh2_face_nodes
, which maps each face to its corner nodes.Coordinate
Mesh2_face_x
, which contains the longitude of each face center in degrees.Coordinate
Mesh2_face_y
, which contains the latitude of each face center in degrees.Coordinate
Mesh2_node_cart_x
, which contains the Cartesian x of each node in meters.Coordinate
Mesh2_node_cart_y
, which contains the Cartesian y location of each node in meters.Coordinate
Mesh2_node_cart_z
, which contains the Cartesian z location of each node in meters.Mesh2_node_faces
UGRID Connectivity Variable
Mesh2_node_faces
, which maps every node to its faces.Coordinate
Mesh2_node_x
, which contains the longitude of each node in degrees.Coordinate
Mesh2_node_y
, which contains the latitude of each node in degrees.Index of each face that crosses the antimeridian.
face_areas
Declare face_areas as a property.
Dimension
nMaxMesh2_face_edges
, which represents the maximum number of edges per face.UGRID Dimension
nMaxMesh2_face_nodes
, which represents the maximum number of nodes that a face may contain.UGRID Dimension
nMesh2_edge
, which represents the total number of edges.UGRID Dimension
nMesh2_face
, which represents the total number of faces.UGRID Dimension
nMesh2_node
, which represents the total number of nodes.Dimension Variable
nNodes_per_face
, which contains the number of non-fill-value nodes per face.Dictionary of parsed attributes from the source grid.