xugrid.Ugrid2d#
- class xugrid.Ugrid2d(node_x: ndarray, node_y: ndarray, fill_value: int, face_node_connectivity: ndarray | coo_matrix | csr_matrix, name: str = 'mesh2d', edge_node_connectivity: ndarray | None = None, dataset: Dataset | None = None, indexes: Dict[str, str] | None = None, projected: bool = True, crs: Any | None = None, attrs: Dict[str, str] | None = None)[source]#
This class stores the topological data of a 2-D unstructured grid.
- Parameters:
node_x (ndarray of floats) –
node_y (ndarray of floats) –
fill_value (int) –
face_node_connectivity (ndarray of integers) –
name (string, optional) – Mesh name. Defaults to “mesh2d”.
edge_node_connectivity (ndarray of integers, optional) –
dataset (xr.Dataset, optional) –
indexes (Dict[str, str], optional) – When a dataset is provided, a mapping from the UGRID role to the dataset variable name. E.g. {“face_x”: “mesh2d_face_lon”}.
projected (bool, optional) – Whether node_x and node_y are longitude and latitude or projected x and y coordinates. Used to write the appropriate standard_name in the coordinate attributes.
crs (Any, optional) – Coordinate Reference System of the geometry objects. Can be anything accepted by
pyproj.CRS.from_user_input()
, such as an authority string (eg “EPSG:4326”) or a WKT string.attrs (Dict[str, str], optional) – UGRID topology attributes. Should not be provided together with dataset: if other names are required, update the dataset instead. A name entry is ignored, as name is given explicitly.
- __init__(node_x: ndarray, node_y: ndarray, fill_value: int, face_node_connectivity: ndarray | coo_matrix | csr_matrix, name: str = 'mesh2d', edge_node_connectivity: ndarray | None = None, dataset: Dataset | None = None, indexes: Dict[str, str] | None = None, projected: bool = True, crs: Any | None = None, attrs: Dict[str, str] | None = None)[source]#
Methods
__init__
(node_x, node_y, fill_value, ...[, ...])assign_edge_coords
(obj)Assign node coordinates from the grid to the object.
assign_face_coords
(obj)Assign face coordinates from the grid to the object.
assign_node_coords
(obj)Assign node coordinates from the grid to the object.
clip_box
(xmin, ymin, xmax, ymax)compute_barycentric_weights
(points)Find in which face the points are located, and compute the barycentric weight for every vertex of the face.
copy
()Creates deepcopy
delete_polygon
(polygon[, delete_option, ...])equals
(other)from_dataset
(dataset[, topology])Extract the 2D UGRID topology information from an xarray Dataset.
from_geodataframe
(geodataframe)Convert a geodataframe of polygons to UGRID2D topology.
from_meshkernel
(mesh[, name, projected, crs])Create a 2D UGRID topology from a MeshKernel Mesh2d object.
from_polygon
(polygon)from_structured
(data[, x_bounds, y_bounds])intersect_edges
(edges)Find in which face edges are located and compute the intersection with the face edges.
isel
([indexers, return_index])Select based on node, edge, or face.
locate_bounding_box
(xmin, ymin, xmax, ymax)Find which faces are located in the bounding box.
locate_points
(points)Find in which face points are located.
merge_partitions
(grids)plot
(**kwargs)Plots the edges of the mesh.
rasterize
(resolution)Rasterize unstructured grid by sampling.
rasterize_like
(x, y)Rasterize unstructured grid by sampling on the x and y coordinates.
refine_polygon
(polygon, min_face_size[, ...])reverse_cuthill_mckee
([dimension])Reduces bandwith of the connectivity matrix.
sel
(obj[, x, y])Find selection in the UGRID x and y coordinates.
sel_points
(obj, x, y)Select points in the unstructured grid.
set_crs
([crs, epsg, allow_override])Set the Coordinate Reference System (CRS) of a UGRID topology.
set_node_coords
(node_x, node_y, obj[, projected])Given names of x and y coordinates of the nodes of an object, set them as the coordinates in the grid.
tesselate_centroidal_voronoi
([add_exterior, ...])Create a centroidal Voronoi tesselation of this UGRID2D topology.
to_crs
([crs, epsg])Transform geometries to a new coordinate reference system.
to_dataset
([other])to_shapely
(dim)Convert UGRID topology to shapely objects.
topology_subset
(face_index[, return_index])Create a new UGRID1D topology for a subset of this topology.
Triangulate this UGRID2D topology, breaks more complex polygons down into triangles.
Attributes
xmin, ymin, xmax, ymax
Initializes the celltree if needed, and returns celltree.
Triangulation of centroidal voronoi tesselation.
Centroid (x, y) of every face.
core_dimension
Returns a numpy array with columns
minx, miny, maxx, maxy
, describing the bounds of every edge in the grid.Centroid (x,y) coordinates of every edge in the UGRID topology
Name of edge dimension
edge_face_connectivity
Edge to face connectivity.
Edge to node connectivity.
edge_node_coordinates
n_edge, 2, 2
.x-coordinate of every edge in the UGRID topology
y-coordinate of every edge in the UGRID topology
Get all exterior edges, i.e. edges with no other face.
Get all exterior faces, i.e. faces with an unshared edge.
Returns a numpy array with columns
minx, miny, maxx, maxy
, describing the bounds of every face in the grid.Centroid (x, y) of every face.
Return the name of the face dimension.
Face to edge connectivity.
Face to face connectivity.
face_node_coordinates
Node coordinates of every face.
x-coordinate of centroid of every face
y-coordinate of centroid of every face
Create if needed, and return meshkernel Mesh2d object.
Create if needed, and return meshkernel MeshKernel instance.
Number of edges in the UGRID topology
Return the number of faces in the UGRID2D topology.
n_max_node_per_face
Return the maximum number of nodes that a face can contain in the UGRID2D topology.
Number of nodes (vertices) in the UGRID topology
n_node_per_face
Coordinates (x, y) of the nodes (vertices)
Name of node dimension
Node to edge connectivity.
Node to face connectivity.
2
Triangulation of the UGRID2D topology.
Centroidal Voronoi tesselation of this UGRID2D topology.