landlab.grid.unstructured package#
Submodules#
landlab.grid.unstructured.base module#
- class BaseGrid([coord0, coord1, ..., ]axis_name=None, axis_units=None)[source]#
Bases:
object
- Parameters:
coord0 (sequence of array-like) – Coordinates of grid nodes
coord1 (sequence of array-like) – Coordinates of grid nodes
... (sequence of array-like) – Coordinates of grid nodes
axis_name (sequence of strings, optional) – Names of coordinate axes
axis_units (sequence of strings, optional) – Units of coordinate axes
- Returns:
A newly-created BaseGrid
- Return type:
Examples
>>> from landlab.grid.unstructured.base import BaseGrid >>> ngrid = BaseGrid(([0, 0, 1, 1], [0, 1, 0, 1])) >>> ngrid.number_of_nodes 4 >>> ngrid.x_at_node array([ 0., 1., 0., 1.]) >>> ngrid.x_at_node[2] 0.0 >>> ngrid.point_at_node[2] array([ 1., 0.]) >>> ngrid.coord_at_node[:, [2, 3]] array([[ 1., 1.], [ 0., 1.]])
>>> cells = ([0, 1, 2, 1, 3, 2], [3, 3], [0, 1]) >>> ngrid = BaseGrid(([0, 0, 1, 1], [0, 1, 0, 1]), cells=cells) >>> ngrid.number_of_cells 2 >>> ngrid.node_at_cell array([0, 1])
>>> links = [(0, 2), (1, 3), (0, 1), (1, 2), (0, 3)] >>> ngrid = BaseGrid(([0, 0, 1, 1], [0, 1, 0, 1]), links=zip(*links)) >>> ngrid.number_of_links 5 >>> ngrid.links_leaving_at_node(0) array([0, 2, 4]) >>> len(ngrid.links_entering_at_node(0)) == 0 True
>>> tails, heads = zip(*links) >>> grid = BaseGrid(([0, 0, 1, 1], [0, 1, 0, 1]), ... node_status=[0, 0, 0, 4], links=[tails, heads]) >>> grid.status_at_node array([0, 0, 0, 4]) >>> len(grid.active_links_entering_at_node(0)) == 0 True >>> grid.active_links_leaving_at_node(0) array([0, 2])
__init__([coord0, coord1, …], axis_name=None, axis_units=None)
- Parameters:
coord0 (sequence of array-like) – Coordinates of grid nodes
coord1 (sequence of array-like) – Coordinates of grid nodes
... (sequence of array-like) – Coordinates of grid nodes
axis_name (sequence of strings, optional) – Names of coordinate axes
axis_units (sequence of strings, optional) – Units of coordinate axes
- Returns:
A newly-created BaseGrid
- Return type:
Examples
>>> from landlab.grid.unstructured.base import BaseGrid >>> ngrid = BaseGrid(([0, 0, 1, 1], [0, 1, 0, 1])) >>> ngrid.number_of_nodes 4 >>> ngrid.x_at_node array([ 0., 1., 0., 1.]) >>> ngrid.x_at_node[2] 0.0 >>> ngrid.point_at_node[2] array([ 1., 0.]) >>> ngrid.coord_at_node[:, [2, 3]] array([[ 1., 1.], [ 0., 1.]])
>>> cells = ([0, 1, 2, 1, 3, 2], [3, 3], [0, 1]) >>> ngrid = BaseGrid(([0, 0, 1, 1], [0, 1, 0, 1]), cells=cells) >>> ngrid.number_of_cells 2 >>> ngrid.node_at_cell array([0, 1])
>>> links = [(0, 2), (1, 3), (0, 1), (1, 2), (0, 3)] >>> ngrid = BaseGrid(([0, 0, 1, 1], [0, 1, 0, 1]), links=zip(*links)) >>> ngrid.number_of_links 5 >>> ngrid.links_leaving_at_node(0) array([0, 2, 4]) >>> len(ngrid.links_entering_at_node(0)) == 0 True
>>> tails, heads = zip(*links) >>> grid = BaseGrid(([0, 0, 1, 1], [0, 1, 0, 1]), ... node_status=[0, 0, 0, 4], links=[tails, heads]) >>> grid.status_at_node array([0, 0, 0, 4]) >>> len(grid.active_links_entering_at_node(0)) == 0 True >>> grid.active_links_leaving_at_node(0) array([0, 2])
- __init__([coord0, coord1, ..., ]axis_name=None, axis_units=None)[source]#
- Parameters:
coord0 (sequence of array-like) – Coordinates of grid nodes
coord1 (sequence of array-like) – Coordinates of grid nodes
... (sequence of array-like) – Coordinates of grid nodes
axis_name (sequence of strings, optional) – Names of coordinate axes
axis_units (sequence of strings, optional) – Units of coordinate axes
- Returns:
A newly-created BaseGrid
- Return type:
Examples
>>> from landlab.grid.unstructured.base import BaseGrid >>> ngrid = BaseGrid(([0, 0, 1, 1], [0, 1, 0, 1])) >>> ngrid.number_of_nodes 4 >>> ngrid.x_at_node array([ 0., 1., 0., 1.]) >>> ngrid.x_at_node[2] 0.0 >>> ngrid.point_at_node[2] array([ 1., 0.]) >>> ngrid.coord_at_node[:, [2, 3]] array([[ 1., 1.], [ 0., 1.]])
>>> cells = ([0, 1, 2, 1, 3, 2], [3, 3], [0, 1]) >>> ngrid = BaseGrid(([0, 0, 1, 1], [0, 1, 0, 1]), cells=cells) >>> ngrid.number_of_cells 2 >>> ngrid.node_at_cell array([0, 1])
>>> links = [(0, 2), (1, 3), (0, 1), (1, 2), (0, 3)] >>> ngrid = BaseGrid(([0, 0, 1, 1], [0, 1, 0, 1]), links=zip(*links)) >>> ngrid.number_of_links 5 >>> ngrid.links_leaving_at_node(0) array([0, 2, 4]) >>> len(ngrid.links_entering_at_node(0)) == 0 True
>>> tails, heads = zip(*links) >>> grid = BaseGrid(([0, 0, 1, 1], [0, 1, 0, 1]), ... node_status=[0, 0, 0, 4], links=[tails, heads]) >>> grid.status_at_node array([0, 0, 0, 4]) >>> len(grid.active_links_entering_at_node(0)) == 0 True >>> grid.active_links_leaving_at_node(0) array([0, 2])
- property axis_name#
Name of each axis.
- Returns:
Names of each axis.
- Return type:
tuple of strings
Examples
>>> from landlab.grid.unstructured.base import BaseGrid >>> ngrid = BaseGrid(([0, 1, 0], [1, 1, 0])) >>> ngrid.axis_name ('y', 'x')
>>> ngrid = BaseGrid(([0, 1, 0], [1, 1, 0]), axis_name=['lat', 'lon']) >>> ngrid.axis_name ('lat', 'lon')
- property axis_units#
Coordinate units of each axis.
- Returns:
Coordinate units of each axis.
- Return type:
tuple of strings
Examples
>>> from landlab.grid.unstructured.base import BaseGrid >>> ngrid = BaseGrid(([0, 1, 0], [1, 1, 0])) >>> ngrid.axis_units ('-', '-')
>>> ngrid = BaseGrid(([0, 1, 0], [1, 1, 0]), ... axis_units=['degrees_north', 'degrees_east']) >>> ngrid.axis_units ('degrees_north', 'degrees_east')
- property cell_at_node#
- property coord_at_node#
- length_of_link(link=None)[source]#
Length of grid links.
- Parameters:
link (array-like, optional) – Link IDs
Examples
>>> from landlab.grid.unstructured.base import BaseGrid >>> links = [(0, 2), (1, 3), (0, 1), (2, 3), (0, 3)] >>> grid = BaseGrid(([0, 0, 4, 4], [0, 3, 0, 3]), links=links) >>> grid.length_of_link() array([ 4., 4., 3., 3., 5.]) >>> grid.length_of_link(0) array([ 4.])
>>> grid.length_of_link().min() 3.0 >>> grid.length_of_link().max() 5.0
- property ndim#
- property node_at_cell#
- property node_at_link_end#
- property node_at_link_start#
- node_to_node_distance(node0, node1, out=None)[source]#
Distance between nodes.
- Parameters:
node0 (array-like) – Node ID of start
node1 (array-like) – Node ID of end
- Returns:
Distances between nodes.
- Return type:
array
Examples
>>> from landlab.grid.unstructured.base import BaseGrid >>> grid = BaseGrid(([0, 0, 4, 4], [0, 3, 0, 3])) >>> grid.node_to_node_distance(0, 3) array([ 5.]) >>> grid.node_to_node_distance(0, [0, 1, 2, 3]) array([ 0., 3., 4., 5.])
- property number_of_cells#
Number of cells.
- property number_of_links#
Number of links.
- property number_of_nodes#
Number of nodes.
- property point_at_node#
- point_to_node_angle(point, node=None, out=None)[source]#
Angle from a point to a node.
- Parameters:
point (tuple) – Coordinates of point
node (array-like) – Node IDs
- Returns:
Angles from point to node as radians.
- Return type:
array
Examples
>>> from landlab.grid.unstructured.base import BaseGrid >>> grid = BaseGrid(([0, 0, 1, 1], [0, 1, 0, 1])) >>> grid.point_to_node_angle((0., 0.), [1, 2, 3]) / np.pi array([ 0. , 0.5 , 0.25]) >>> grid.point_to_node_angle((0., 0.)) / np.pi array([ 0. , 0. , 0.5 , 0.25]) >>> out = np.empty(4) >>> out is grid.point_to_node_angle((0., 0.), out=out) True >>> out / np.pi array([ 0. , 0. , 0.5 , 0.25])
- point_to_node_azimuth(point, node=None, out=None)[source]#
Azimuth from a point to a node.
- Parameters:
point (tuple) – Coordinates of point
node (array-like) – Node IDs
- Returns:
Azimuths from point to node.
- Return type:
array
Examples
>>> from landlab.grid.unstructured.base import BaseGrid >>> grid = BaseGrid(([0, 0, 1, 1], [0, 1, 0, 1])) >>> grid.point_to_node_azimuth((0., 0.), [1, 2, 3]) array([ 90., 0., 45.]) >>> grid.point_to_node_azimuth((0., 0.)) array([ 90., 90., 0., 45.]) >>> grid.point_to_node_azimuth((0., 0.), 1) array([ 90.]) >>> out = np.empty(4) >>> out is grid.point_to_node_azimuth((0., 0.), out=out) True >>> out array([ 90., 90., 0., 45.])
- point_to_node_distance(point, node=None, out=None)[source]#
Distance from a point to a node.
- Parameters:
point (tuple) – Coordinates of point
node (array-like) – Node IDs
- Returns:
Distances from point to node.
- Return type:
array
Examples
>>> from landlab.grid.unstructured.base import BaseGrid >>> grid = BaseGrid(([0, 0, 4, 4], [0, 3, 0, 3])) >>> grid.point_to_node_distance((0., 0.), [1, 2, 3]) array([ 3., 4., 5.]) >>> grid.point_to_node_distance((0., 0.)) array([ 0., 3., 4., 5.]) >>> out = np.empty(4) >>> out is grid.point_to_node_distance((0., 0.), out=out) True >>> out array([ 0., 3., 4., 5.])
- point_to_node_vector(point, node=None, out=None)[source]#
Azimuth from a point to a node.
- Parameters:
point (tuple) – Coordinates of point
node (array-like) – Node IDs
- Returns:
Vector from point to node.
- Return type:
array
Examples
>>> from landlab.grid.unstructured.base import BaseGrid >>> grid = BaseGrid(([0, 0, 1, 1], [0, 1, 0, 1])) >>> grid.point_to_node_vector((0., 0.), [1, 2, 3]) array([[ 0., 1., 1.], [ 1., 0., 1.]]) >>> grid.point_to_node_vector((0., 0.)) array([[ 0., 0., 1., 1.], [ 0., 1., 0., 1.]]) >>> grid.point_to_node_vector((0., 0.), 1) array([[ 0.], [ 1.]]) >>> out = np.empty((2, 1)) >>> out is grid.point_to_node_vector((0., 0.), 1, out=out) True >>> out array([[ 0.], [ 1.]])
- property status_at_node#
- property x_at_node#
- property y_at_node#
- point_to_point_angle(point0, point1, out=None)[source]#
Angle of vector that joins two points.
- Parameters:
- Returns:
a – Angle of vector joining points; if out is provided, v will be equal to out.
- Return type:
array_like
- point_to_point_azimuth(point0, point1, out=None)[source]#
Azimuth of vector that joins two points.
- Parameters:
- Returns:
azimuth – Azimuth of vector joining points; if out is provided, v will be equal to out.
- Return type:
array_like
Examples
>>> from landlab.grid.unstructured.base import point_to_point_azimuth >>> point_to_point_azimuth((0, 0), (1, 0)) array([ 0.]) >>> point_to_point_azimuth([(0, 1), (0, 1)], (1, 0)) array([ 0., -90.]) >>> point_to_point_azimuth([(0, 1, 0), (0, 1, 2)], [(1, 1, 2), (0, 0, 4)]) array([ 0., -90., 45.])
- point_to_point_distance(point0, point1, out=None)[source]#
Length of vector that joins two points.
- Parameters:
- Returns:
l – Length of vector joining points; if out is provided, v will be equal to out.
- Return type:
array_like
Examples
>>> from landlab.grid.unstructured.base import point_to_point_distance >>> point_to_point_distance((0, 0), (3, 4)) array([ 5.]) >>> point_to_point_distance((0, 0), ([3, 6], [4, 8])) array([ 5., 10.])
- point_to_point_vector(point0, point1, out=None)[source]#
Vector that joins two points.
- Parameters:
- Returns:
(dy, dx) – Vectors between points; if out is provided, v will be equal to out.
- Return type:
tuple of array_like
Examples
>>> from landlab.grid.unstructured.base import point_to_point_vector >>> point_to_point_vector((0, 0), (1, 2)) array([[1], [2]]) >>> point_to_point_vector([(0, 1), (0, 1)], (1, 2)) array([[1, 0], [2, 1]]) >>> point_to_point_vector([(0, 0, 0), (0, 1, 2)], [(1, 2, 2), (2, 4, 4)]) array([[1, 2, 2], [2, 3, 2]])
landlab.grid.unstructured.cells module#
- class CellGrid(vertices, vertices_per_cell, node_at_cell=None)[source]#
Bases:
object
- Parameters:
vertices (array-like) – Vertex IDs at each grid cell
vertices_per_cell (array-like) – Number of vertices per grid cell
- Returns:
A newly-created CellGrid
- Return type:
Examples
Create a grid of two cells where the first cell has four vertices and the second has three.
>>> from landlab.grid.unstructured.cells import CellGrid >>> cgrid = CellGrid([0, 1, 3, 2, 1, 4, 3], [4, 3]) >>> cgrid.number_of_cells 2 >>> cgrid.number_of_vertices_at_cell(0) 4 >>> cgrid.number_of_vertices_at_cell(1) 3 >>> cgrid.vertices_at_cell(0) array([0, 1, 3, 2]) >>> cgrid.vertices_at_cell(1) array([1, 4, 3])
Associate nodes with each cell.
>>> cgrid = CellGrid([0, 1, 2, 3, 1, 3, 4], [4, 3], node_at_cell=[10, 11]) >>> cgrid.node_at_cell array([10, 11]) >>> cgrid.cell_at_node[10] 0 >>> cgrid.cell_at_node[11] 1
- Parameters:
vertices (array-like) – Vertex IDs at each grid cell
vertices_per_cell (array-like) – Number of vertices per grid cell
- Returns:
A newly-created CellGrid
- Return type:
Examples
Create a grid of two cells where the first cell has four vertices and the second has three.
>>> from landlab.grid.unstructured.cells import CellGrid >>> cgrid = CellGrid([0, 1, 3, 2, 1, 4, 3], [4, 3]) >>> cgrid.number_of_cells 2 >>> cgrid.number_of_vertices_at_cell(0) 4 >>> cgrid.number_of_vertices_at_cell(1) 3 >>> cgrid.vertices_at_cell(0) array([0, 1, 3, 2]) >>> cgrid.vertices_at_cell(1) array([1, 4, 3])
Associate nodes with each cell.
>>> cgrid = CellGrid([0, 1, 2, 3, 1, 3, 4], [4, 3], node_at_cell=[10, 11]) >>> cgrid.node_at_cell array([10, 11]) >>> cgrid.cell_at_node[10] 0 >>> cgrid.cell_at_node[11] 1
- __init__(vertices, vertices_per_cell, node_at_cell=None)[source]#
- Parameters:
vertices (array-like) – Vertex IDs at each grid cell
vertices_per_cell (array-like) – Number of vertices per grid cell
- Returns:
A newly-created CellGrid
- Return type:
Examples
Create a grid of two cells where the first cell has four vertices and the second has three.
>>> from landlab.grid.unstructured.cells import CellGrid >>> cgrid = CellGrid([0, 1, 3, 2, 1, 4, 3], [4, 3]) >>> cgrid.number_of_cells 2 >>> cgrid.number_of_vertices_at_cell(0) 4 >>> cgrid.number_of_vertices_at_cell(1) 3 >>> cgrid.vertices_at_cell(0) array([0, 1, 3, 2]) >>> cgrid.vertices_at_cell(1) array([1, 4, 3])
Associate nodes with each cell.
>>> cgrid = CellGrid([0, 1, 2, 3, 1, 3, 4], [4, 3], node_at_cell=[10, 11]) >>> cgrid.node_at_cell array([10, 11]) >>> cgrid.cell_at_node[10] 0 >>> cgrid.cell_at_node[11] 1
- property cell_at_node#
- property cell_id#
- iter()[source]#
Iterate over the cells of the grid.
- Returns:
Nodes entering and leaving each node
- Return type:
ndarray
- property node_at_cell#
- property number_of_cells#
landlab.grid.unstructured.links module#
- class LinkGrid(link_ends, number_of_nodes, link_ids=None, node_status=None)[source]#
Bases:
object
Create a grid of links that enter and leave nodes. __init__((node0, node1), number_of_nodes=None)
- Parameters:
node0 (sequence of array-like) – Node ID at link start and end.
node1 (sequence of array-like) – Node ID at link start and end.
number_of_nodes (int, optional) – Number of nodes in the grid
- Returns:
A newly-created grid
- Return type:
Examples
>>> from landlab.grid.unstructured.links import LinkGrid >>> lgrid = LinkGrid([(0, 1, 0, 2, 0), (2, 3, 1, 3, 3)], 4) >>> lgrid.number_of_links 5 >>> lgrid.number_of_nodes 4 >>> lgrid.number_of_in_links_at_node(0) 0 >>> lgrid.number_of_out_links_at_node(0) 3 >>> lgrid.out_link_at_node(0) array([0, 2, 4]) >>> lgrid.nodes_at_link_id(1) array([1, 3])
>>> lgrid = LinkGrid([(0, 1, 0, 2, 0), (2, 3, 1, 3, 3)], 4, ... link_ids=range(1, 6)) >>> lgrid.nodes_at_link array([[0, 2], [1, 3], [0, 1], [2, 3], [0, 3]]) >>> lgrid.out_link_at_node(0) array([1, 3, 5]) >>> lgrid.nodes_at_link_id(1) array([0, 2])
Create a grid of links that enter and leave nodes. __init__((node0, node1), number_of_nodes=None)
- Parameters:
node0 (sequence of array-like) – Node ID at link start and end.
node1 (sequence of array-like) – Node ID at link start and end.
number_of_nodes (int, optional) – Number of nodes in the grid
- Returns:
A newly-created grid
- Return type:
Examples
>>> from landlab.grid.unstructured.links import LinkGrid >>> lgrid = LinkGrid([(0, 1, 0, 2, 0), (2, 3, 1, 3, 3)], 4) >>> lgrid.number_of_links 5 >>> lgrid.number_of_nodes 4 >>> lgrid.number_of_in_links_at_node(0) 0 >>> lgrid.number_of_out_links_at_node(0) 3 >>> lgrid.out_link_at_node(0) array([0, 2, 4]) >>> lgrid.nodes_at_link_id(1) array([1, 3])
>>> lgrid = LinkGrid([(0, 1, 0, 2, 0), (2, 3, 1, 3, 3)], 4, ... link_ids=range(1, 6)) >>> lgrid.nodes_at_link array([[0, 2], [1, 3], [0, 1], [2, 3], [0, 3]]) >>> lgrid.out_link_at_node(0) array([1, 3, 5]) >>> lgrid.nodes_at_link_id(1) array([0, 2])
- __init__(link_ends, number_of_nodes, link_ids=None, node_status=None)[source]#
Create a grid of links that enter and leave nodes. __init__((node0, node1), number_of_nodes=None)
- Parameters:
node0 (sequence of array-like) – Node ID at link start and end.
node1 (sequence of array-like) – Node ID at link start and end.
number_of_nodes (int, optional) – Number of nodes in the grid
- Returns:
A newly-created grid
- Return type:
Examples
>>> from landlab.grid.unstructured.links import LinkGrid >>> lgrid = LinkGrid([(0, 1, 0, 2, 0), (2, 3, 1, 3, 3)], 4) >>> lgrid.number_of_links 5 >>> lgrid.number_of_nodes 4 >>> lgrid.number_of_in_links_at_node(0) 0 >>> lgrid.number_of_out_links_at_node(0) 3 >>> lgrid.out_link_at_node(0) array([0, 2, 4]) >>> lgrid.nodes_at_link_id(1) array([1, 3])
>>> lgrid = LinkGrid([(0, 1, 0, 2, 0), (2, 3, 1, 3, 3)], 4, ... link_ids=range(1, 6)) >>> lgrid.nodes_at_link array([[0, 2], [1, 3], [0, 1], [2, 3], [0, 3]]) >>> lgrid.out_link_at_node(0) array([1, 3, 5]) >>> lgrid.nodes_at_link_id(1) array([0, 2])
- in_link_at_node(node)[source]#
Links entering a node.
- Parameters:
node (int) – Node ID
- Returns:
Links entering the node
- Return type:
ndarray
Examples
>>> from landlab.grid.unstructured.links import LinkGrid >>> lgrid = LinkGrid([(0, 1, 0, 2), (2, 3, 1, 3)], 4) >>> len(lgrid.in_link_at_node(0)) == 0 True >>> lgrid.in_link_at_node(3) array([1, 3])
- iter_nodes()[source]#
Iterate of the nodes of the grid.
- Returns:
Links entering and leaving each node
- Return type:
ndarray
Examples
>>> from landlab.grid.unstructured.links import LinkGrid >>> lgrid = LinkGrid([(0, 1, 0, 2), (2, 3, 1, 3)], 4) >>> for link in lgrid.iter_nodes(): link array([0, 2]) array([2, 1]) array([0, 3]) array([1, 3])
- property link_id#
- property node_at_link_end#
- property node_at_link_start#
- property node_status_at_link_end#
- property node_status_at_link_start#
- property nodes_at_link#
- number_of_in_links_at_node(node)[source]#
Number of links entering a node.
Examples
>>> from landlab.grid.unstructured.links import LinkGrid >>> lgrid = LinkGrid([(0, 1, 0, 2), (2, 3, 1, 3)], 4) >>> [lgrid.number_of_in_links_at_node(node) for node in range(4)] [0, 1, 1, 2]
- property number_of_links#
Number of links in the grid.
- number_of_links_at_node(node)[source]#
Number of links entering and leaving a node.
- Parameters:
node (int) – Node ID
- Returns:
Number of links entering and leaving the node.
- Return type:
Examples
>>> from landlab.grid.unstructured.links import LinkGrid >>> lgrid = LinkGrid([(0, 1, 0, 2), (2, 3, 1, 3)], 4) >>> [lgrid.number_of_links_at_node(node) for node in range(4)] [2, 2, 2, 2]
- property number_of_nodes#
Number of nodes in the grid.
- number_of_out_links_at_node(node)[source]#
Number of links leaving a node.
Examples
>>> from landlab.grid.unstructured.links import LinkGrid >>> lgrid = LinkGrid([(0, 1, 0, 2), (2, 3, 1, 3)], 4) >>> [lgrid.number_of_out_links_at_node(node) for node in range(4)] [2, 1, 1, 0]
- out_link_at_node(node)[source]#
Links leaving a node.
- Parameters:
node (int) – Node ID
- Returns:
Links leaving the node
- Return type:
ndarray
Examples
>>> from landlab.grid.unstructured.links import LinkGrid >>> lgrid = LinkGrid([(0, 1, 0, 2), (2, 3, 1, 3)], 4) >>> lgrid.out_link_at_node(0) array([0, 2]) >>> len(lgrid.out_link_at_node(3)) == 0 True
- find_active_links(node_status, node_at_link_ends)[source]#
find_active_links(node_status, (node0, node1)) IDs of active links.
- Parameters:
node_status (ndarray) – Status of nodes.
node0 (sequence of array-like) – Node ID at link start and end.
node1 (sequence of array-like) – Node ID at link start and end.
- Returns:
Links IDs of active links.
- Return type:
ndarray
Examples
>>> from landlab.grid.unstructured.links import find_active_links >>> links = [(0, 2), (1, 3), (0, 1), (1, 2), (0, 3)] >>> status = np.array([0, 0, 0, 0]) >>> find_active_links(status, links) array([0, 1, 2, 3, 4])
- in_link_count_per_node(node_at_link_ends, number_of_nodes=0)[source]#
in_link_count_per_node((node0, node1), number_of_nodes=0) Number of links entering nodes.
- Parameters:
node0 (sequence of array-like) – Node ID at link start and end.
node1 (sequence of array-like) – Node ID at link start and end.
number_of_nodes (int, optional) – Number of nodes in the grid
- Returns:
Number of links entering nodes.
- Return type:
ndarray
Examples
>>> from landlab.grid.unstructured.links import in_link_count_per_node >>> link_ends = [(0, 3), (1, 4), (2, 5), (3, 6), (4, 7), (5, 8)] >>> in_link_count_per_node(zip(*link_ends)) array([0, 0, 0, 1, 1, 1, 1, 1, 1])
- in_link_ids_at_node(node_at_link_ends, link_ids=None, number_of_nodes=0)[source]#
in_link_ids_at_node((node0, node1), number_of_nodes=0) Links entering nodes.
- Parameters:
node0 (sequence of array-like) – Node ID at link start and end.
node1 (sequence of array-like) – Node ID at link start and end.
number_of_nodes (int, optional) – Number of nodes in the grid
- Returns:
Tuple of link id array and offset into link id array.
- Return type:
Examples
>>> from landlab.grid.unstructured.links import in_link_ids_at_node >>> (links, count) = in_link_ids_at_node(([0, 1, 2, 3, 4, 5], ... [3, 4, 5, 6, 7, 8])) >>> links array([0, 1, 2, 3, 4, 5]) >>> count array([0, 0, 0, 1, 1, 1, 1, 1, 1])
>>> (links, count) = in_link_ids_at_node(([0, 1, 2, 3, 4, 5], ... [3, 4, 5, 6, 7, 8]), ... link_ids=range(1, 7)) >>> links array([1, 2, 3, 4, 5, 6]) >>> count array([0, 0, 0, 1, 1, 1, 1, 1, 1])
- link_count_per_node(node_at_link_ends, number_of_nodes=None)[source]#
link_count_per_node((node0, node1), number_of_nodes=None) Number of links per node.
- Parameters:
node0 (sequence of array-like) – Node ID at link start and end.
node1 (sequence of array-like) – Node ID at link start and end.
number_of_nodes (int, optional) – Number of nodes in the grid
- Returns:
Number of links per nodes.
- Return type:
ndarray
Examples
>>> from landlab.grid.unstructured.links import link_count_per_node >>> link_count_per_node(([0, 1, 2, 3, 4, 5], [3, 4, 5, 6, 7, 8])) array([1, 1, 1, 2, 2, 2, 1, 1, 1])
- link_ids_at_node(node_at_link_ends, number_of_nodes=None)[source]#
link_ids_at_node((node0, node1), number_of_nodes=None) Links entering and leaving nodes.
- Parameters:
node0 (sequence of array-like) – Node ID at link start and end.
node1 (sequence of array-like) – Node ID at link start and end.
number_of_nodes (int, optional) – Number of nodes in the grid
- Returns:
Tuple of link id array and offset into link id array.
- Return type:
Examples
>>> from landlab.grid.unstructured.links import link_ids_at_node >>> (links, count) = link_ids_at_node( ... ([0, 1, 2, 3, 4, 5], [3, 4, 5, 6, 7, 8]), number_of_nodes=9) >>> links array([0, 1, 2, 0, 3, 1, 4, 2, 5, 3, 4, 5]) >>> count array([1, 1, 1, 2, 2, 2, 1, 1, 1])
- link_is_active(status_at_link_ends)[source]#
link_is_active((status0, status1)) Check if a link is active.
Links are inactive if they connect two boundary nodes or touch a closed boundary. Otherwise, the link is active.
- Parameters:
status0 (sequence of array-like) – Status at link start and end
status1 (sequence of array-like) – Status at link start and end
- Returns:
Boolean array that indicates if a link is active.
- Return type:
ndarray, boolean
- out_link_count_per_node(node_at_link_ends, number_of_nodes=0)[source]#
out_link_count_per_node((node0, node1), number_of_nodes=0) Number of links leaving nodes.
- Parameters:
node0 (sequence of array-like) – Node ID at link start and end.
node1 (sequence of array-like) – Node ID at link start and end.
number_of_nodes (int, optional) – Number of nodes in the grid
- Returns:
Number of links leaving nodes.
- Return type:
ndarray
Examples
>>> from landlab.grid.unstructured.links import out_link_count_per_node >>> out_link_count_per_node(([0, 1, 2, 3, 4, 5], [3, 4, 5, 6, 7, 8])) array([1, 1, 1, 1, 1, 1]) >>> out_link_count_per_node(([0, 1, 2, 3, 4, 5], [3, 4, 5, 6, 7, 8]), ... number_of_nodes=9) array([1, 1, 1, 1, 1, 1, 0, 0, 0])
- out_link_ids_at_node(node_at_link_ends, link_ids=None, number_of_nodes=None)[source]#
out_link_ids_at_node((node0, node1), number_of_nodes=None) Links leaving nodes.
- Parameters:
node0 (sequence of array-like) – Node ID at link start and end.
node1 (sequence of array-like) – Node ID at link start and end.
number_of_nodes (int, optional) – Number of nodes in the grid
- Returns:
Tuple of link id array and offset into link id array.
- Return type:
Examples
>>> from landlab.grid.unstructured.links import out_link_ids_at_node >>> (links, count) = out_link_ids_at_node( ... ([0, 1, 2, 3, 4, 5], [3, 4, 5, 6, 7, 8]), link_ids=range(-1, 5), ... number_of_nodes=9) >>> links array([-1, 0, 1, 2, 3, 4]) >>> count array([1, 1, 1, 1, 1, 1, 0, 0, 0])
>>> (links, count) = out_link_ids_at_node( ... ([0, 1, 2, 3, 4, 5], [3, 4, 5, 6, 7, 8]), number_of_nodes=9) >>> links array([0, 1, 2, 3, 4, 5]) >>> count array([1, 1, 1, 1, 1, 1, 0, 0, 0])
landlab.grid.unstructured.nodes module#
- class NodeGrid(nodes)[source]#
Bases:
object
__init__((coord0, coord1)) Create a grid of nodes.
- Parameters:
coord0 (sequence of array-like) – Coordinates of grid nodes
coord1 (sequence of array-like) – Coordinates of grid nodes
- Returns:
A newly-created NodeGrid
- Return type:
Examples
>>> from landlab.grid.unstructured.nodes import NodeGrid >>> ngrid = NodeGrid(([0, 0, 1, 1], [0, 1, 0, 1])) >>> ngrid.ndim == 2 True >>> ngrid.number_of_nodes == 4 True >>> ngrid.x array([ 0., 1., 0., 1.]) >>> ngrid.y array([ 0., 0., 1., 1.])
Create a 1D grid.
>>> ngrid = NodeGrid(((0, 1, 3), )) >>> ngrid.ndim == 1 True >>> ngrid.number_of_nodes 3 >>> ngrid.x array([ 0., 1., 3.]) >>> ngrid.y Traceback (most recent call last): AttributeError: Grid has no y-coordinate
__init__((coord0, coord1)) Create a grid of nodes.
- Parameters:
coord0 (sequence of array-like) – Coordinates of grid nodes
coord1 (sequence of array-like) – Coordinates of grid nodes
- Returns:
A newly-created NodeGrid
- Return type:
Examples
>>> from landlab.grid.unstructured.nodes import NodeGrid >>> ngrid = NodeGrid(([0, 0, 1, 1], [0, 1, 0, 1])) >>> ngrid.ndim == 2 True >>> ngrid.number_of_nodes == 4 True >>> ngrid.x array([ 0., 1., 0., 1.]) >>> ngrid.y array([ 0., 0., 1., 1.])
Create a 1D grid.
>>> ngrid = NodeGrid(((0, 1, 3), )) >>> ngrid.ndim == 1 True >>> ngrid.number_of_nodes 3 >>> ngrid.x array([ 0., 1., 3.]) >>> ngrid.y Traceback (most recent call last): AttributeError: Grid has no y-coordinate
- __init__(nodes)[source]#
__init__((coord0, coord1)) Create a grid of nodes.
- Parameters:
coord0 (sequence of array-like) – Coordinates of grid nodes
coord1 (sequence of array-like) – Coordinates of grid nodes
- Returns:
A newly-created NodeGrid
- Return type:
Examples
>>> from landlab.grid.unstructured.nodes import NodeGrid >>> ngrid = NodeGrid(([0, 0, 1, 1], [0, 1, 0, 1])) >>> ngrid.ndim == 2 True >>> ngrid.number_of_nodes == 4 True >>> ngrid.x array([ 0., 1., 0., 1.]) >>> ngrid.y array([ 0., 0., 1., 1.])
Create a 1D grid.
>>> ngrid = NodeGrid(((0, 1, 3), )) >>> ngrid.ndim == 1 True >>> ngrid.number_of_nodes 3 >>> ngrid.x array([ 0., 1., 3.]) >>> ngrid.y Traceback (most recent call last): AttributeError: Grid has no y-coordinate
- property coord#
Examples
>>> from landlab.grid.unstructured.nodes import NodeGrid >>> ngrid = NodeGrid(([0, 0, 1], [0, 1, 0])) >>> ngrid.coord[0] array([ 0., 0., 1.]) >>> ngrid.coord[1] array([ 0., 1., 0.])
- property ndim#
- property number_of_nodes#
Examples
>>> from landlab.grid.unstructured.nodes import NodeGrid >>> ngrid = NodeGrid(([0, 0, 1], [0, 1, 0])) >>> ngrid.number_of_nodes 3
- property point#
Examples
>>> from landlab.grid.unstructured.nodes import NodeGrid >>> ngrid = NodeGrid(([0, 0, 1], [0, 1, 0])) >>> ngrid.point array([[ 0., 0.], [ 0., 1.], [ 1., 0.]]) >>> ngrid.point[1] array([ 0., 1.])
- property x#
Node coordinates of the “fast” dimension.
Examples
>>> from landlab.grid.unstructured.nodes import NodeGrid >>> ngrid = NodeGrid(([0, 0, 1], [0, 1, 0])) >>> ngrid.x array([ 0., 1., 0.])
- property y#
Node y-coordinates.
Examples
>>> from landlab.grid.unstructured.nodes import NodeGrid >>> ngrid = NodeGrid(([0, 0, 1], [0, 1, 0])) >>> ngrid.y array([ 0., 0., 1.])
- property z#
Node z-coordinates.
Examples
>>> from landlab.grid.unstructured.nodes import NodeGrid >>> ngrid = NodeGrid(([0, 0, 1], [0, 1, 0])) >>> ngrid.y array([ 0., 0., 1.])
landlab.grid.unstructured.status module#
- class StatusGrid(node_status)[source]#
Bases:
object
- active_nodes()[source]#
Node IDs of all active (core & open boundary) nodes.
core_nodes will return just core nodes.
- property node_status#
Status of nodes.
Return an array of the status of a grid’s nodes. The node status can be one of the following: -
NodeStatus.CORE
-NodeStatus.FIXED_VALUE
-NodeStatus.FIXED_GRADIENT
-NodeStatus.LOOPED
-NodeStatus.CLOSED