landlab.utils.channel_network_grid_tools

choose_from_repeated(sorted_array, choose='last')[source]

Mark the first/last element of repeated values in a sorted 1-D array.

Parameters:
  • sorted_array (array_like) – Assumed sorted by the grouping key.

  • choose ({'first','last'}, optional) – Whether to mark the first or last item of each run.

Return type:

ndarray[tuple[Any, …], dtype[bool]]

Examples

>>> array = [0, 0, 0, 2, 2, 5, 6, 6, 6, 6, 6]
>>> is_last = choose_from_repeated(array, choose="last")
>>> is_last.astype(int)
array([0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1])
choose_unique(values, order_by=None, choose='last')[source]

Find indices of unique values, selecting one representative if repeated.

Examples

>>> choose_unique([0, 1, 0, 0, 1], order_by=([10.0, 11.0, 12.0, 13.0, 14],))
array([3, 4])
>>> choose_unique([1, 0, 0, 1, 0], order_by=([10.0, 11.0, 12.0, 13.0, 14],))
array([3, 4])
Parameters:
  • values (ArrayLike)

  • order_by (Sequence[ArrayLike] | None)

  • choose (Literal['first', 'last'])

Return type:

ndarray[tuple[Any, …], dtype[int64]]

extract_channel_nodes(grid, Ct)[source]

interpret which nodes of the DEM represent the channel network as all nodes that have a drainage area >= to the average drainage area at which channels initiate in the DEM (Ct, based on field or remote sensing evidence).

Use Ct = average drainage area at which colluvial channels to get the entire channel network.

Use Ct = the drainage area at which cascade channels typically begin to get a channel network where sediment transport is primarily via fluvial processes

Parameters:
  • grid (raster model grid) – raster model grid with node field “drainage_area”

  • Ct (float) – Channel threshold drainage area

Returns:

cn – array of all node ids included in the channel network

Return type:

np array of int

extract_terrace_nodes(grid, terrace_width, acn, fcn)[source]

Determine which raster model grid nodes coincide with channel terraces, which presently are assumed to be a fixed width (number of nodes) from the channel nodes

Parameters:
  • grid (raster model grid)

  • terrace_width (int) – Width of terrace in number of nodes. If provided as float, will be rounded to nearest int.

  • acn (np array) – array of all node IDs included in the channel network

  • fcn (np array) – array of all node IDs included in the fluvial channel network

Raises:

ValueError – Occurs if terrace width less than 1.

Returns:

terrace_nodes – array of all node IDs included in the terrace

Return type:

np array

Get the downstream (head) and upstream (tail) nodes at a link from flow director. The network model grid nodes_at_link attribute may not be ordered according to flow direction. Output from this function should be used for all channel_network_grid_tools functions that require a link_nodes input

Parameters:

nmgrid (network model grid)

Returns:

link_nodes – for a nmgrid of n nodes, returns a nx2 np array, the ith row of the array is the [downstream node id, upstream node id] of the ith link

Return type:

np.array

Map links of a network model grid to all coincident raster model grid nodes. Each coincident raster model grid node is defined in terms of its x and y coordinates, the link it is mapped to and distance downstream from the upstream (tail) end of the link.

Parameters:
  • grid (raster model grid)

  • nmgrid (network model grid)

  • link_nodes (np array) – head and tail node of each link

  • remove_duplicates (bool) – if True, when two or more links are coincident with the same node, the node is assigned to the link with the largest drainage area. If False, the node is assigned to each coincident link. The default is False.

Returns:

nmg_link_to_rmg_coincident_nodes_mapper – each row of the dataframe lists the link ID, the coincident node ID, the x and y coordinates and the downstream distance of the coincident node and the drainage area of the link

Return type:

pandas dataframe

min_distance_to_network(grid, acn, node_id)[source]

Determine the shortest distance (as the crow flies) from a node to the channel network and the closest channel node

Parameters:
  • grid (raster model grid)

  • acn (list of int) – array of all node ids included in the channel network

  • node_id (int) – ID of node from which the distance will be determined

Returns:

  • offset (float) – distance between node and channel network

  • mdn (int) – ID of channel node that is closest node