landlab.graph.object.at_node

Set up data structures for node-to-link connectivity.

Parameters:
  • graph (Graph) – A Graph.

  • nodes_at_link (ndarray of int) – Nodes at either end of a link (tail node, then head node).

  • number_of_nodes (int, optional) – The total number of nodes. If not given, use the largest node in nodes_at_link.

Returns:

Tuple of links_at_node and link_dirs_at_node.

Return type:

tuple of ndarray

Sort links as spokes about a hub.

Parameters:
  • links_at_node (ndarray of int, shape (n_nodes, max_links_per_node)) – Links entering or leaving each node.

  • link_dirs_at_node (ndarray of int, shape (n_nodes, max_links_per_node)) – Direction of links entering or leaving each node.

  • angle_of_link (ndarray of float, shape (n_links, )) – Angle (in radians) of each link as measured from its head to tail.

Returns:

The sorted arrays. If inplace is True, these are the input arrays.

Return type:

tuple of (links_at_node, link_dirs_at_node)

Examples

>>> import numpy as np
>>> from landlab.graph.object.at_node import sort_links_at_node_by_angle
(1) - 1 -> (3)
 |          ^
 2          3
 V          |
(0) - 0 -> (2)
>>> links_at_node = [[2, 0], [1, 2], [3, 0], [3, 1]]
>>> link_dirs_at_node = [[1, -1], [-1, -1], [-1, 1], [1, 1]]
>>> angle_of_link = np.array([0.0, 0.0, -90.0, 90.0]) * np.pi / 180.0
>>> out = sort_links_at_node_by_angle(
...     links_at_node, link_dirs_at_node, angle_of_link
... )

The first item of the returned tuple is links at each node sorted counterclockwise by angle.

>>> out[0]
array([[0, 2], [2, 1], [3, 0],  [1, 3]])

The second item is the direction of the link (entering or leaving).

>>> out[1]
array([[-1,  1], [-1, -1], [-1,  1], [ 1,  1]], dtype=int8)

Because the input arrays are lists, not numpy arrays, the sort is not in-place.

>>> out[0] is not links_at_node
True
>>> links_at_node = np.asarray([[2, 0], [1, 2], [3, 0], [3, 1]], dtype=int)
>>> link_dirs_at_node = np.asarray(
...     [[1, -1], [-1, -1], [-1, 1], [1, 1]], dtype=np.int8
... )
>>> angle_of_link = np.array([0.0, 0.0, -90.0, 90.0]) * np.pi / 180.0
>>> _ = sort_links_at_node_by_angle(
...     links_at_node, link_dirs_at_node, angle_of_link, inplace=True
... )
>>> links_at_node
array([[0, 2], [2, 1], [3, 0],  [1, 3]])
>>> link_dirs_at_node
array([[-1,  1], [-1, -1], [-1,  1], [ 1,  1]], dtype=int8)