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, dataset: Dataset = None, indexes: Dict[str, str] = None, projected: bool = True, crs: Any = None, attrs: Dict[str, str] = None, start_index: int = 0)[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.

  • start_index (int, 0 or 1, default is 0.) – Start index of the connectivity arrays. Must match the start index of the provided face_node_connectivity and edge_node_connectivity.

__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, dataset: Dataset = None, indexes: Dict[str, str] = None, projected: bool = True, crs: Any = None, attrs: Dict[str, str] = None, start_index: int = 0)[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.

bounding_polygon()

Construct the bounding polygon of the grid.

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

Create a deepcopy.

create_data_array(data, facet)

Create a UgridDataArray from this grid and a 1D array of values.

delete_polygon(polygon[, delete_option, ...])

earcut_triangulate_polygons(polygons[, ...])

Break down polygons using mapbox_earcut, and create a mesh from the resulting triangles.

equals(other)

find_ugrid_dim(obj)

Find the UGRID dimension that is present in the object.

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_shapely(geometry[, crs])

Convert an array of shapely polygons to UGRID2D topology.

from_structured(data[, x, y, name, return_dims])

Create a Ugrid2d topology from a structured topology axis-aligned rectilinear, rotated or (approximated) curvilinear topologies.

from_structured_bounds(x_bounds, y_bounds[, ...])

Create a Ugrid2d topology from a structured topology based on 1D bounds.

from_structured_intervals1d(x_intervals, ...)

Create a Ugrid2d topology from a structured topology based on 1D intervals.

from_structured_intervals2d(x_intervals, ...)

Create a Ugrid2d topology from a structured topology based on 2D intervals.

from_structured_multicoord(data[, x, y, name])

get_connectivity_matrix(dim, xy_weights)

Return the connectivity matrix for the specified UGRID dimension.

get_coordinates(dim)

Return the coordinates for the specified UGRID dimension.

intersect_edges(edges)

Find in which face edges are located and compute the intersection with the face edges.

intersect_line(obj, start, end)

Intersect a line with this grid, and fetch the values of the intersected faces.

intersect_linestring(obj, linestring)

Intersect linestrings with this grid, and fetch the values of the intersected faces.

isel([indexers, return_index])

Select based on node, edge, or face.

label_partitions(n_part)

Generate partition labesl for this grid topology using METIS: KarypisLab/METIS

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)

Merge grid partitions into a single whole.

partition(n_part)

Partition this grid topology using METIS: KarypisLab/METIS

plot(**kwargs)

Plot the edges of the mesh.

rasterize(resolution[, bounds])

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[, ...])

reindex_like(other, obj[, tolerance])

Conform a DataArray or Dataset to match the topology of another Ugrid2D topology.

rename(name[, return_name_dict])

Create a new grid with all variables named according to the default naming conventions.

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[, out_of_bounds, ...])

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.

tesselate_circumcenter_voronoi([...])

Create a circumcenter Voronoi tesselation of this UGRID2D topology.

to_crs([crs, epsg])

Transform geometries to a new coordinate reference system.

to_dataset([other, optional_attributes])

to_nonperiodic(xmax[, obj])

Convert this grid from a periodic grid (where the rightmost boundary shares its nodes with the leftmost boundary) to an aperiodic grid, where the leftmost nodes are separate from the rightmost nodes.

to_periodic([obj])

Convert this grid to a periodic grid, where the rightmost nodes are equal to the leftmost nodes.

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.

validate_edge_node_connectivity()

Mark valid edges, by comparing face_node_connectivity and edge_node_connectivity.

Attributes

area

Area of every face.

attrs

boundary_node_connectivity

Boundary node connectivity

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.

circumcenters

Circumenter (x, y) of every face; only works for fully triangular grids.

coords

Dictionary for grid coordinates.

core_dimension

dimensions

Mapping from UGRID dimension names to lengths.

dims

node dimension, edge dimension, face_dimension.

directed_node_node_connectivity

Directed node to node connectivity.

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

fill_value

Fill value for UGRID connectivity arrays.

is_geographic

max_connectivity_dimensions

max_connectivity_sizes

max_face_node_dimension

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.

node_node_connectivity

Node to node connectivity.

perimeter

Perimeter length of every face.

sizes

start_index

Start index for UGRID connectivity arrays.

topology_dimension

2

triangulation

Triangulation of the UGRID2D topology.

voronoi_topology

Centroidal Voronoi tesselation of this UGRID2D topology.