landlab.graph.framed_voronoi package#
Subpackages#
Submodules#
landlab.graph.framed_voronoi.dual_framed_voronoi module#
Implement the DualFramedVoronoiGraph
@author sebastien lenard @date 2022, Aug
- class DualFramedVoronoiGraph(shape, xy_spacing=(1.0, 1.0), xy_of_lower_left=(0.0, 0.0), sort=False, xy_min_spacing=(0.5, 0.5), seed=200)[source]#
Bases:
DualGraph
,FramedVoronoiGraph
Graph of a unstructured grid of Voronoi Delaunay cells and irregular patches. It is a special type of VoronoiDelaunay graph in which the initial set of points is arranged in a fixed lattice (e.g. like a rectangular raster grid) named here “layout” and the core points are then moved aroung their initial position by a random distance, lower than a certain threshold.
Examples
>>> from landlab.graph import DualFramedVoronoiGraph
>>> graph = DualFramedVoronoiGraph((3, 3), seed=200) >>> graph.number_of_nodes 9
>>> graph.x_of_node[2:4] array([ 2., 0.]) >>> graph.y_of_node[2:4] array([ 0. , 0.749]) >>> graph.y_of_node[5] 1.2509999999999999
Create the graph.
- Parameters:
xy_spacing (float or tuple of float, optional) – Node spacing along x and y coordinates. If float, same spacing at x and y.
xy_of_lower_left (tuple, optional) – Minimum x-of-node and y-of-node values. Depending on the grid, there may not be a node present at this location.
sort (bool) – If
True
, nodes, links and patches are re-numbered according to their position.xy_min_spacing (float or tuple of float, optional) – Final minimal spacing between nodes. Random moves of the core nodes around their position cannot be above this threshold:
(xy_spacing - xy_min_spacing) / 2
Iffloat
, same minimal spacing for x and y.seed (int, optional) – Seed used to generate the random x and y moves. When set, controls a pseudo-randomness of moves to ensure reproducibility. When
None
, seed is random and the moves of coordinates are completely random.
- Returns:
A newly-created graph.
- Return type:
Examples
Create a grid with 3 rows and 2 columns of nodes.
>>> from landlab.graph import DualFramedVoronoiGraph >>> graph = DualFramedVoronoiGraph((3, 2), xy_spacing=1.0) >>> graph.number_of_nodes 6
- __init__(shape, xy_spacing=(1.0, 1.0), xy_of_lower_left=(0.0, 0.0), sort=False, xy_min_spacing=(0.5, 0.5), seed=200)[source]#
Create the graph.
- Parameters:
xy_spacing (float or tuple of float, optional) – Node spacing along x and y coordinates. If float, same spacing at x and y.
xy_of_lower_left (tuple, optional) – Minimum x-of-node and y-of-node values. Depending on the grid, there may not be a node present at this location.
sort (bool) – If
True
, nodes, links and patches are re-numbered according to their position.xy_min_spacing (float or tuple of float, optional) – Final minimal spacing between nodes. Random moves of the core nodes around their position cannot be above this threshold:
(xy_spacing - xy_min_spacing) / 2
Iffloat
, same minimal spacing for x and y.seed (int, optional) – Seed used to generate the random x and y moves. When set, controls a pseudo-randomness of moves to ensure reproducibility. When
None
, seed is random and the moves of coordinates are completely random.
- Returns:
A newly-created graph.
- Return type:
Examples
Create a grid with 3 rows and 2 columns of nodes.
>>> from landlab.graph import DualFramedVoronoiGraph >>> graph = DualFramedVoronoiGraph((3, 2), xy_spacing=1.0) >>> graph.number_of_nodes 6
- property adjacent_corners_at_corner#
Get adjacent corners.
See also
adjacent_nodes_at_node
- property adjacent_faces_at_face#
- property angle_of_face#
Get the angle of each face.
See also
angle_of_link
- property area_of_cell#
Get the area of each cell.
See also
area_of_patch
- property cells_at_corner#
Get the cells that touch each corner.
See also
patches_at_node
- property cells_at_face#
Get the cells on either side of each face.
See also
patches_at_link
- property corner_at_face_head#
Get corners at face head.
See also
node_at_link_head
- property corner_at_face_tail#
Get corners at face tail.
See also
node_at_link_tail
- property corner_layout#
- property corner_x#
- property corner_y#
- property corners#
Get identifier for each corner.
See also
nodes
- property corners_at_bottom_edge#
- property corners_at_cell#
Get the corners that define a cell.
See also
nodes_at_patch
- property corners_at_face#
Get corners at either end of faces.
See also
nodes_at_link
- property corners_at_left_edge#
- property corners_at_right_edge#
- property corners_at_top_edge#
- property face_dirs_at_corner#
Return face directions into each corner.
See also
link_dirs_at_node
- property faces_at_cell#
Get the faces that define a cell.
See also
links_at_patch
- property faces_at_corner#
Get faces touching a corner.
See also
links_at_node
- property length_of_face#
Get the length of faces.
See also
length_of_link
- property midpoint_of_face#
Get the middle of faces.
See also
midpoint_of_link
- property number_of_cells#
Get the number of cells.
See also
number_of_patches
- property number_of_corners#
Get total number of corners.
See also
number_of_nodes
- property number_of_faces#
Get corners at face head.
See also
number_of_links
- property perimeter_corners#
- property unit_vector_at_corner#
Get a unit vector for each corner.
See also
unit_vector_at_node
- property unit_vector_at_face#
Make arrays to store the unit vectors associated with each face.
See also
unit_vector_at_link
- property x_of_corner#
Get x-coordinate of corner.
See also
x_of_node
- property xy_of_cell#
Get the centroid of each cell.
See also
xy_of_patch
- property xy_of_corner#
Get x and y-coordinates of corner.
See also
xy_of_node
- property xy_of_face#
- property y_of_corner#
Get y-coordinate of corner.
See also
y_of_node
landlab.graph.framed_voronoi.framed_voronoi module#
Implementation of the FramedVoronoiGraph and its static layout: HorizontalRectVoronoiGraph. This pattern is inspired from the developments of the HexModelGrid
Code author: sebastien lenard
- class FramedVoronoiGraph(shape, xy_spacing=(1.0, 1.0), xy_of_lower_left=(0.0, 0.0), sort=False, xy_min_spacing=(0.5, 0.5), seed=200)[source]#
Bases:
DelaunayGraph
VoronoiDelaunay graph based on a fixed lattice.
Graph of an unstructured grid of Voronoi Delaunay cells and irregular patches. It is a special type of :class`~.VoronoiDelaunayGraph` in which the initial set of points is arranged in a fixed lattice (e.g. like a
RasterModelGrid
) named here “layout” and the core points are then moved from their initial position by a random distance, lower than a certain threshold.Examples
>>> from landlab.graph import FramedVoronoiGraph
>>> graph = FramedVoronoiGraph((3, 3), seed=200) >>> graph.number_of_nodes 9
>>> graph.x_of_node[2:4] array([ 2., 0.]) >>> graph.y_of_node[2:4] array([ 0. , 0.749]) >>> graph.y_of_node[5] 1.2509999999999999
>>> graph.number_of_links 16 >>> graph.number_of_patches 8
Create the graph.
- Parameters:
xy_spacing (float or tuple of float, optional) – Node spacing along x and y coordinates. If
float
, same spacing x and y spacing.xy_of_lower_left (tuple, optional) – Minimum x-of-node and y-of-node values. Depending on the grid, a node may not be present at this location.
sort (bool) – If
True
, nodes, links and patches are re-numbered according certain their positions. Currently not used.xy_min_spacing (float or tuple of float, optional) – Final minimal spacing between nodes. Random moves of the core nodes around their position cannot be above this threshold:
(xy_spacing - xy_min_spacing) / 2
Iffloat
, same minimal spacing for x and y.seed (int, optional) – Seed used to generate the random x and y moves. When set, controls a pseudo-randomness of moves to ensure reproducibility. When
None
, seed is random and the moves of coordinates are completely random.
- Returns:
A newly-created graph.
- Return type:
Examples
Create a grid with 3 rows and 2 columns of nodes.
>>> from landlab.graph import FramedVoronoiGraph >>> graph = FramedVoronoiGraph((3, 2)) >>> graph.number_of_nodes 6
- __init__(shape, xy_spacing=(1.0, 1.0), xy_of_lower_left=(0.0, 0.0), sort=False, xy_min_spacing=(0.5, 0.5), seed=200)[source]#
Create the graph.
- Parameters:
xy_spacing (float or tuple of float, optional) – Node spacing along x and y coordinates. If
float
, same spacing x and y spacing.xy_of_lower_left (tuple, optional) – Minimum x-of-node and y-of-node values. Depending on the grid, a node may not be present at this location.
sort (bool) – If
True
, nodes, links and patches are re-numbered according certain their positions. Currently not used.xy_min_spacing (float or tuple of float, optional) – Final minimal spacing between nodes. Random moves of the core nodes around their position cannot be above this threshold:
(xy_spacing - xy_min_spacing) / 2
Iffloat
, same minimal spacing for x and y.seed (int, optional) – Seed used to generate the random x and y moves. When set, controls a pseudo-randomness of moves to ensure reproducibility. When
None
, seed is random and the moves of coordinates are completely random.
- Returns:
A newly-created graph.
- Return type:
Examples
Create a grid with 3 rows and 2 columns of nodes.
>>> from landlab.graph import FramedVoronoiGraph >>> graph = FramedVoronoiGraph((3, 2)) >>> graph.number_of_nodes 6
- property node_layout#
- property nodes_at_bottom_edge#
- property nodes_at_left_edge#
- property nodes_at_right_edge#
- property nodes_at_top_edge#
- property orientation#
- property perimeter_nodes#
Get nodes on the convex hull of a Graph.
Examples
>>> import numpy as np >>> from landlab.graph import Graph >>> node_x, node_y = [0, 1, 2, 0, 1, 2], [0, 0, 0, 1, 1, 1] >>> graph = Graph((node_y, node_x)) >>> np.sort(graph.perimeter_nodes) array([0, 2, 3, 5])
- property shape#
- property xy_spacing#
- class HorizontalRectVoronoiGraph[source]#
Bases:
object
The horizontal rectangular frame for the FramedVoronoiGraph.
- static corner_nodes(shape)[source]#
- Parameters:
- Returns:
Ids of the corner nodes
- Return type:
ndarray of int
Examples
>>> from landlab.graph.framed_voronoi.framed_voronoi import ( ... HorizontalRectVoronoiGraph, ... ) >>> HorizontalRectVoronoiGraph.corner_nodes((3, 4)) (11, 8, 0, 3)
- static nodes_at_edge(shape)[source]#
- Parameters:
- Returns:
right, top, left, bottom – For each edge give the ids of the nodes present at the edge
- Return type:
ndarray of int
Examples
>>> from landlab.graph.framed_voronoi.framed_voronoi import ( ... HorizontalRectVoronoiGraph, ... ) >>> HorizontalRectVoronoiGraph.nodes_at_edge((3, 3)) (array([2, 5]), array([8, 7]), array([6, 3]), array([0, 1]))
- static number_of_nodes(shape)[source]#
- Parameters:
- Returns:
Number of nodes
- Return type:
Examples
>>> from landlab.graph.framed_voronoi.framed_voronoi import ( ... HorizontalRectVoronoiGraph, ... ) >>> HorizontalRectVoronoiGraph.number_of_nodes((3, 2)) 6
- static number_of_perimeter_nodes(shape)[source]#
- Parameters:
- Returns:
Number of perimeter nodes
- Return type:
Examples
>>> from landlab.graph.framed_voronoi.framed_voronoi import ( ... HorizontalRectVoronoiGraph, ... ) >>> HorizontalRectVoronoiGraph.number_of_perimeter_nodes((3, 4)) 10
- static perimeter_nodes(shape)[source]#
- Parameters:
- Returns:
Ids of the perimeter nodes
- Return type:
ndarray of int
Examples
>>> from landlab.graph.framed_voronoi.framed_voronoi import ( ... HorizontalRectVoronoiGraph, ... ) >>> HorizontalRectVoronoiGraph.perimeter_nodes((3, 3)) array([2, 5, 8, 7, 6, 3, 0, 1])
- static xy_of_node(shape, xy_spacing=(1.0, 1.0), xy_of_lower_left=(0.0, 0.0), xy_min_spacing=(0.5, 0.5), seed=200)[source]#
The x and y coordinates of the graph’s nodes.
Calculation of the x-y coordinates is done following these steps:
Generate a rectangular, regular meshgrid.
Move the coordinates of the core nodes over a random distance around their initial position, within a threshold calculated from xy_spacing and xy_min_spacing.
Rectify the y-coordinates of the nodes of the left and right to ensure that the leftmost node of a row has a lower y than the rightmost node. This ensures that the ids of these nodes are not modified by subsequent sorting operations on the graph and make it possible to get the perimeter nodes in simple way.
- Parameters:
xy_spacing (float or tuple of float, optional) – Node spacing along x and y coordinates. If
float
, same spacing at x and y.xy_of_lower_left (tuple, optional) – Minimum x-of-node and y-of-node values. Depending on the grid, a node may not be present at this location.
xy_min_spacing (float or tuple of float, optional) – Final minimal spacing between nodes. Random moves of the core nodes around their initial positions cannot be above this threshold:
(xy_spacing - xy_min_spacing) / 2
. Iffloat
, same minimal spacing for x and y.seed (int, optional) – Seed used to generate the random x and y moves. When set, controls a pseudo-randomness of moves to ensure reproducibility. When
None
, seed is random and the moves of coordinates are completely random.
- Returns:
x_of_node, y_of_node – The arrays of x and y coordinates.
- Return type:
ndarray of float
Examples
>>> from landlab.graph.framed_voronoi.framed_voronoi import ( ... HorizontalRectVoronoiGraph, ... )
>>> x_of_node, y_of_node = HorizontalRectVoronoiGraph.xy_of_node( ... (3, 3), seed=200 ... )
Coordinates of the lower left node,
>>> x_of_node[0], y_of_node[0] (0.0, 0.0)
x coordinates of the left and right edges,
>>> x_of_node[3], x_of_node[5] (0.0, 2.0)
y coordinate of the middle row of the left edge,
>>> y_of_node[3] 0.749
Module contents#
- class DualFramedVoronoiGraph(shape, xy_spacing=(1.0, 1.0), xy_of_lower_left=(0.0, 0.0), sort=False, xy_min_spacing=(0.5, 0.5), seed=200)[source]#
Bases:
DualGraph
,FramedVoronoiGraph
Graph of a unstructured grid of Voronoi Delaunay cells and irregular patches. It is a special type of VoronoiDelaunay graph in which the initial set of points is arranged in a fixed lattice (e.g. like a rectangular raster grid) named here “layout” and the core points are then moved aroung their initial position by a random distance, lower than a certain threshold.
Examples
>>> from landlab.graph import DualFramedVoronoiGraph
>>> graph = DualFramedVoronoiGraph((3, 3), seed=200) >>> graph.number_of_nodes 9
>>> graph.x_of_node[2:4] array([ 2., 0.]) >>> graph.y_of_node[2:4] array([ 0. , 0.749]) >>> graph.y_of_node[5] 1.2509999999999999
Create the graph.
- Parameters:
xy_spacing (float or tuple of float, optional) – Node spacing along x and y coordinates. If float, same spacing at x and y.
xy_of_lower_left (tuple, optional) – Minimum x-of-node and y-of-node values. Depending on the grid, there may not be a node present at this location.
sort (bool) – If
True
, nodes, links and patches are re-numbered according to their position.xy_min_spacing (float or tuple of float, optional) – Final minimal spacing between nodes. Random moves of the core nodes around their position cannot be above this threshold:
(xy_spacing - xy_min_spacing) / 2
Iffloat
, same minimal spacing for x and y.seed (int, optional) – Seed used to generate the random x and y moves. When set, controls a pseudo-randomness of moves to ensure reproducibility. When
None
, seed is random and the moves of coordinates are completely random.
- Returns:
A newly-created graph.
- Return type:
Examples
Create a grid with 3 rows and 2 columns of nodes.
>>> from landlab.graph import DualFramedVoronoiGraph >>> graph = DualFramedVoronoiGraph((3, 2), xy_spacing=1.0) >>> graph.number_of_nodes 6
- __init__(shape, xy_spacing=(1.0, 1.0), xy_of_lower_left=(0.0, 0.0), sort=False, xy_min_spacing=(0.5, 0.5), seed=200)[source]#
Create the graph.
- Parameters:
xy_spacing (float or tuple of float, optional) – Node spacing along x and y coordinates. If float, same spacing at x and y.
xy_of_lower_left (tuple, optional) – Minimum x-of-node and y-of-node values. Depending on the grid, there may not be a node present at this location.
sort (bool) – If
True
, nodes, links and patches are re-numbered according to their position.xy_min_spacing (float or tuple of float, optional) – Final minimal spacing between nodes. Random moves of the core nodes around their position cannot be above this threshold:
(xy_spacing - xy_min_spacing) / 2
Iffloat
, same minimal spacing for x and y.seed (int, optional) – Seed used to generate the random x and y moves. When set, controls a pseudo-randomness of moves to ensure reproducibility. When
None
, seed is random and the moves of coordinates are completely random.
- Returns:
A newly-created graph.
- Return type:
Examples
Create a grid with 3 rows and 2 columns of nodes.
>>> from landlab.graph import DualFramedVoronoiGraph >>> graph = DualFramedVoronoiGraph((3, 2), xy_spacing=1.0) >>> graph.number_of_nodes 6
- property adjacent_corners_at_corner#
Get adjacent corners.
See also
adjacent_nodes_at_node
- property adjacent_faces_at_face#
- property angle_of_face#
Get the angle of each face.
See also
angle_of_link
- property area_of_cell#
Get the area of each cell.
See also
area_of_patch
- property cells_at_corner#
Get the cells that touch each corner.
See also
patches_at_node
- property cells_at_face#
Get the cells on either side of each face.
See also
patches_at_link
- property corner_at_face_head#
Get corners at face head.
See also
node_at_link_head
- property corner_at_face_tail#
Get corners at face tail.
See also
node_at_link_tail
- property corner_layout#
- property corner_x#
- property corner_y#
- property corners#
Get identifier for each corner.
See also
nodes
- property corners_at_bottom_edge#
- property corners_at_cell#
Get the corners that define a cell.
See also
nodes_at_patch
- property corners_at_face#
Get corners at either end of faces.
See also
nodes_at_link
- property corners_at_left_edge#
- property corners_at_right_edge#
- property corners_at_top_edge#
- property face_dirs_at_corner#
Return face directions into each corner.
See also
link_dirs_at_node
- property faces_at_cell#
Get the faces that define a cell.
See also
links_at_patch
- property faces_at_corner#
Get faces touching a corner.
See also
links_at_node
- property length_of_face#
Get the length of faces.
See also
length_of_link
- property midpoint_of_face#
Get the middle of faces.
See also
midpoint_of_link
- property number_of_cells#
Get the number of cells.
See also
number_of_patches
- property number_of_corners#
Get total number of corners.
See also
number_of_nodes
- property number_of_faces#
Get corners at face head.
See also
number_of_links
- property perimeter_corners#
- property unit_vector_at_corner#
Get a unit vector for each corner.
See also
unit_vector_at_node
- property unit_vector_at_face#
Make arrays to store the unit vectors associated with each face.
See also
unit_vector_at_link
- property x_of_corner#
Get x-coordinate of corner.
See also
x_of_node
- property xy_of_cell#
Get the centroid of each cell.
See also
xy_of_patch
- property xy_of_corner#
Get x and y-coordinates of corner.
See also
xy_of_node
- property xy_of_face#
- property y_of_corner#
Get y-coordinate of corner.
See also
y_of_node
- class FramedVoronoiGraph(shape, xy_spacing=(1.0, 1.0), xy_of_lower_left=(0.0, 0.0), sort=False, xy_min_spacing=(0.5, 0.5), seed=200)[source]#
Bases:
DelaunayGraph
VoronoiDelaunay graph based on a fixed lattice.
Graph of an unstructured grid of Voronoi Delaunay cells and irregular patches. It is a special type of :class`~.VoronoiDelaunayGraph` in which the initial set of points is arranged in a fixed lattice (e.g. like a
RasterModelGrid
) named here “layout” and the core points are then moved from their initial position by a random distance, lower than a certain threshold.Examples
>>> from landlab.graph import FramedVoronoiGraph
>>> graph = FramedVoronoiGraph((3, 3), seed=200) >>> graph.number_of_nodes 9
>>> graph.x_of_node[2:4] array([ 2., 0.]) >>> graph.y_of_node[2:4] array([ 0. , 0.749]) >>> graph.y_of_node[5] 1.2509999999999999
>>> graph.number_of_links 16 >>> graph.number_of_patches 8
Create the graph.
- Parameters:
xy_spacing (float or tuple of float, optional) – Node spacing along x and y coordinates. If
float
, same spacing x and y spacing.xy_of_lower_left (tuple, optional) – Minimum x-of-node and y-of-node values. Depending on the grid, a node may not be present at this location.
sort (bool) – If
True
, nodes, links and patches are re-numbered according certain their positions. Currently not used.xy_min_spacing (float or tuple of float, optional) – Final minimal spacing between nodes. Random moves of the core nodes around their position cannot be above this threshold:
(xy_spacing - xy_min_spacing) / 2
Iffloat
, same minimal spacing for x and y.seed (int, optional) – Seed used to generate the random x and y moves. When set, controls a pseudo-randomness of moves to ensure reproducibility. When
None
, seed is random and the moves of coordinates are completely random.
- Returns:
A newly-created graph.
- Return type:
Examples
Create a grid with 3 rows and 2 columns of nodes.
>>> from landlab.graph import FramedVoronoiGraph >>> graph = FramedVoronoiGraph((3, 2)) >>> graph.number_of_nodes 6
- __init__(shape, xy_spacing=(1.0, 1.0), xy_of_lower_left=(0.0, 0.0), sort=False, xy_min_spacing=(0.5, 0.5), seed=200)[source]#
Create the graph.
- Parameters:
xy_spacing (float or tuple of float, optional) – Node spacing along x and y coordinates. If
float
, same spacing x and y spacing.xy_of_lower_left (tuple, optional) – Minimum x-of-node and y-of-node values. Depending on the grid, a node may not be present at this location.
sort (bool) – If
True
, nodes, links and patches are re-numbered according certain their positions. Currently not used.xy_min_spacing (float or tuple of float, optional) – Final minimal spacing between nodes. Random moves of the core nodes around their position cannot be above this threshold:
(xy_spacing - xy_min_spacing) / 2
Iffloat
, same minimal spacing for x and y.seed (int, optional) – Seed used to generate the random x and y moves. When set, controls a pseudo-randomness of moves to ensure reproducibility. When
None
, seed is random and the moves of coordinates are completely random.
- Returns:
A newly-created graph.
- Return type:
Examples
Create a grid with 3 rows and 2 columns of nodes.
>>> from landlab.graph import FramedVoronoiGraph >>> graph = FramedVoronoiGraph((3, 2)) >>> graph.number_of_nodes 6
- property node_layout#
- property nodes_at_bottom_edge#
- property nodes_at_left_edge#
- property nodes_at_right_edge#
- property nodes_at_top_edge#
- property orientation#
- property perimeter_nodes#
Get nodes on the convex hull of a Graph.
Examples
>>> import numpy as np >>> from landlab.graph import Graph >>> node_x, node_y = [0, 1, 2, 0, 1, 2], [0, 0, 0, 1, 1, 1] >>> graph = Graph((node_y, node_x)) >>> np.sort(graph.perimeter_nodes) array([0, 2, 3, 5])
- property shape#
- property xy_spacing#