landlab.grid.create_network

Created on Tue Feb 2 17:50:09 2021

@author: sahrendt

class AlongChannelSpacingAtLeast[source]

Bases: SpacingAtLeast

Remove segment nodes to ensure a minimum per-node along-channel spacing.

__init__(xy_of_node, spacing=1.0)
Parameters:
Return type:

None

__new__(**kwargs)
calc_distance_along_segment(segment)

Calculate the along-channel distance of a segment.

Parameters:

segment (iterable of int) – Indices of nodes along a channel.

Returns:

Distances to each node along the channel.

Return type:

ndarray of int

reduce(segment)[source]

Reduce the number of nodes in a channel segment.

spacing: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes] = 1.0
xy_of_node: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]
class AtMostNodes[source]

Bases: SegmentReducer

Reduce a segment to a maximum number of nodes.

__init__(count=3)
Parameters:

count (int)

Return type:

None

__new__(**kwargs)
count: int = 3
reduce(segment)[source]

Reduce the number of nodes in a channel segment.

Parameters:

segment (Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes])

Return type:

Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]

class ChannelSegment[source]

Bases: object

A channel segment.

Parameters:

nodes (iterable of int) – The nodes of the channel, listed from downstream to upstream.

__init__(nodes)[source]
__new__(**kwargs)
add_upstream(segment)[source]

Add an upstream segment.

count_segments(direction='upstream')[source]
property downstream

The downstream segment.

property downstream_node

The most downstream node of the channel segment.

for_each(func)[source]
iter_downstream()[source]
property nodes

The nodes of the segment, from downstream to upstream.

property upstream

The upstream segments.

property upstream_node

The most upstream node of the channel segment.

class ChannelSegmentConnector[source]

Bases: object

Connect channel segments to form a network.

ChannelSegmentConnector(channel1, channel2, …)

__init__(*args)[source]

ChannelSegmentConnector(channel1, channel2, …)

__new__(**kwargs)
add(new_segment)[source]

Add a new segment to the network.

property orphans

Channel segments that are not connected to the main network.

property root

The root (most downstream) channel of the network.

set_root(new_root)[source]
exception DisconnectedSegmentError[source]

Bases: Exception

Raise this exception if a channel segment cannot be connected to a network.

__init__(*args, **kwargs)
__new__(**kwargs)
add_note()

Exception.add_note(note) – add a note to the exception

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class JustEndNodes[source]

Bases: SegmentReducer

Reduce a segment to just its end nodes.

__init__()
__new__(**kwargs)
reduce(segment)[source]

Reduce the number of nodes in a channel segment.

class SegmentFieldCollector[source]

Bases: object

Collect field values for each node along segments.

__call__(segment)[source]

Add field values for nodes along a segment to previously collected values.

__init__(field)[source]
__new__(**kwargs)
property values

Field values of all collected nodes.

class SegmentLinkCollector[source]

Bases: object

Collect links between nodes of segments.

__call__(segment)[source]

Add links between segment nodes to those previously collected.

__init__(links=None)[source]
__new__(**kwargs)

Head and tail nodes of all collected links.

class SegmentNodeCoordinateCollector[source]

Bases: object

Collect xy coordinates for each node along segments.

__call__(segment)[source]

Add coordinates of the nodes of a segment to previously collected coordinates.

__init__(grid)[source]
__new__(**kwargs)
property xy_of_node

Coordinates of all collected nodes.

class SegmentNodeReindexer[source]

Bases: object

Reindex nodes along segments.

__call__(segment)[source]

Reindex nodes of a segment based on previously collected nodes.

__init__(nodes=None)[source]
__new__(**kwargs)
property nodes

Reindexed nodes of all collected nodes.

class SegmentReducer[source]

Bases: object

Base class for reducing the nodes in a segment.

__init__()
__new__(**kwargs)
reduce(segment)[source]

Reduce the number of nodes in a channel segment.

class SpacingAtLeast[source]

Bases: SegmentReducer

Remove segment nodes to ensure a minimum along-channel spacing.

__init__(xy_of_node, spacing=1.0)
Parameters:
Return type:

None

__new__(**kwargs)
calc_distance_along_segment(segment)[source]

Calculate the along-channel distance of a segment.

Parameters:

segment (iterable of int) – Indices of nodes along a channel.

Returns:

Distances to each node along the channel.

Return type:

ndarray of int

reduce(segment)[source]

Reduce the number of nodes in a channel segment.

spacing: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes] = 1.0
xy_of_node: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]
calc_distance_to_point(point, points)[source]

Find the euclidian distance between one point and a set of points.

Create links between nodes of the channels of a network.

Parameters:

network (ChannelSegment) – Channel network to create links for.

Returns:

links – Links for network as (head_node, tail_node).

Return type:

list of tuple

create_xy_of_node(network, grid)[source]

Create an array of coordinates for each node of a channel network.

get_channel_segments(grid, divergent_okay=False, minimum_channel_threshold=0.0)[source]

Extract channel segments from a grid.

Each segment includes nodes within the segment, upstream segments, and downstream segments.

Parameters:
  • grid (RasterModelGrid) – Grid from which to extract channel segments.

  • divergent_okay (bool, optional) – If False, raise an error if the network is divergent (i.e. a channel segment has more than one downstream segments).

Returns:

segments – Channel segments as lists of grid nodes. Nodes are ordered from downstream to upstream.

Return type:

list

get_node_fields(network, grid, include='*', exclude=None)[source]

Get field values for each node of a channel network.

Parameters:
  • network (ChannelSegment) – A channel network to extract fields for.

  • grid (ModelGrid) – Grid from which to extract fields from.

  • include (str or list of str, optional) – Patterns to use for including fields.

  • exclude (str or list of str, optional) – Patterns to use for excluding fields.

Returns:

at_node – Dictionary of node fields for each node of a channel network.

Return type:

dict

network_grid_from_raster(grid, reducer=None, include='*', exclude=None, minimum_channel_threshold=0.0)[source]

Create a NetworkModelGrid from a RasterModelGrid.

The optional reducer keyword is use to pass a function that reduces the number of nodes in each channel segment. The default is to keep all segment nodes.

Parameters:
  • grid (RasterModelGrid object) – A raster grid used to create a network grid

  • reducer (func, optional) – A function used to reduce the number of nodes in each segment. The default is to include all segment nodes in the created NetworkModelGrid.

  • include (str, or iterable of str, optional) – Glob-style pattern for field names to include.

  • exclude (str, or iterable of str, optional) – Glob-style pattern for field names to exclude.

  • minimum_channel_threshold (float, optional) – Value to use for the minimum drainage area associated with a plotted channel segment from the ChannelProfiler. Default values 10000.

Returns:

network – NetworkModelGrid object with .at_node[‘rmg_node_value’] attribute listing the RasterModelGrid node ids at each NetworkModelGrid node.

Return type:

NetworkModelGrid

network_grid_from_segments(grid, nodes_at_segment, include='*', exclude=None)[source]

Create a NetworkModelGrid from channel segments.

reindex_network_nodes(network)[source]

Reindex the nodes of a channel network.

spacing_from_drainage_area(drainage_area, a=9.68, b=0.32, n_widths=20.0)[source]

Calculate channel spacing based on upstream drainage area of each node.

Parameters:

drainage_area (number or ndarray) – Upstream drainage area in km ** 2.

Returns:

Node spacing in meters.

Return type:

ndarray