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

Triangulate this UGRID2D topology, breaks more complex polygons down into triangles.

Attributes

area

bounds

xmin, ymin, xmax, ymax

celltree

Initializes the celltree if needed, and returns celltree.

centroid_triangulation

Triangulation of centroidal voronoi tesselation.

centroids

Centroid (x, y) of every face.

core_dimension

dimensions

edge_bounds

Returns a numpy array with columns minx, miny, maxx, maxy, describing the bounds of every edge in the grid.

edge_coordinates

Centroid (x,y) coordinates of every edge in the UGRID topology

edge_dimension

Name of edge dimension

edge_face_connectivity

Edge to face connectivity.

edge_node_connectivity

Edge to node connectivity.

edge_node_coordinates

n_edge, 2, 2.

edge_x

x-coordinate of every edge in the UGRID topology

edge_y

y-coordinate of every edge in the UGRID topology

exterior_edges

Get all exterior edges, i.e. edges with no other face.

exterior_faces

Get all exterior faces, i.e. faces with an unshared edge.

face_bounds

Returns a numpy array with columns minx, miny, maxx, maxy, describing the bounds of every face in the grid.

face_coordinates

Centroid (x, y) of every face.

face_dimension

Return the name of the face dimension.

face_edge_connectivity

Face to edge connectivity.

face_face_connectivity

Face to face connectivity.

face_node_coordinates

Node coordinates of every face.

face_x

x-coordinate of centroid of every face

face_y

y-coordinate of centroid of every face

mesh

Create if needed, and return meshkernel Mesh2d object.

meshkernel

Create if needed, and return meshkernel MeshKernel instance.

n_edge

Number of edges in the UGRID topology

n_face

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.

n_node

Number of nodes (vertices) in the UGRID topology

n_node_per_face

node_coordinates

Coordinates (x, y) of the nodes (vertices)

node_dimension

Name of node dimension

node_edge_connectivity

Node to edge connectivity.

node_face_connectivity

Node to face connectivity.

topology_dimension

2

triangulation

Triangulation of the UGRID2D topology.

voronoi_topology

Centroidal Voronoi tesselation of this UGRID2D topology.