landlab.grid.unstructured.links¶
- class LinkGrid[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])
- __new__(**kwargs)¶
- 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])