Title: | Generate Stochastic Branching Networks |
---|---|
Description: | Generate Stochastic Branching Networks ('SBNs'). Used to model the branching structure of rivers. |
Authors: | Finnbar Lee [aut, cre] |
Maintainer: | Finnbar Lee <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.0 |
Built: | 2025-02-20 04:28:48 UTC |
Source: | https://github.com/flee598/sbn |
Change the upstream/downstream direction of an SBN to either, reversed or undirected.
sbn_change_dir(g, method = c("rev", "undir"))
sbn_change_dir(g, method = c("rev", "undir"))
g |
a river network as an igraph object. Must be a downstream directed graph. |
method |
one of "rev" or "undir", determining what to convert the network to. |
A river network as an igraph object.
g <- sbn_create(10, 0.7) sbn_change_dir(g, method = "rev")
g <- sbn_create(10, 0.7) sbn_change_dir(g, method = "rev")
An SBN river network as a downstream directed igraph object.
sbn_create(n, p)
sbn_create(n, p)
n |
desired number of nodes. |
p |
branching probability, from 0 - 1. Passed to |
SBNs are generated using a stochastic branching process. The network generation process starts from an initial downstream node (the river mouth). At each iteration a random node in the network, with no upstream connections is selected, and zero, one or two nodes are added upstream of it, depending on a branching probability (p). This process is repeated until a pre-determined number of nodes across the entire network is attained (n).
A river network as an igraph object.
sbn_create(10, 0.7)
sbn_create(10, 0.7)
Convert an upstream directed or non-directed network to a downstream directed network.
sbn_down_dir(g, mouth)
sbn_down_dir(g, mouth)
g |
a river network as an igraph object. |
mouth |
river mouth vertex id. |
A downstream directed network.
g <- sbn_create(10, 0.7) # to undirected g <- sbn_change_dir(g, method = "undir") # undirected to downstream directed sbn_down_dir(g, mouth = 1)
g <- sbn_create(10, 0.7) # to undirected g <- sbn_change_dir(g, method = "undir") # undirected to downstream directed sbn_down_dir(g, mouth = 1)
Find all nodes downstream of a given node.
sbn_get_downstream(g, node)
sbn_get_downstream(g, node)
g |
a river network as an igraph object. Must be a downstream directed graph. |
node |
target node to get all downstream nodes of. |
a vector of downstream node id's.
g <- sbn_create(10, 0.7) sbn_get_downstream(g, 10)
g <- sbn_create(10, 0.7) sbn_get_downstream(g, 10)
Find all headwater nodes in a network.
sbn_get_hw(g)
sbn_get_hw(g)
g |
a river network as an igraph object. Must be a downstream directed graph. |
A vector of headwater node id's.
g <- sbn_create(10, 0.7) sbn_get_hw(g)
g <- sbn_create(10, 0.7) sbn_get_hw(g)
Find river mouth node from a directed graph.
sbn_get_outlet(g)
sbn_get_outlet(g)
g |
a river network as an igraph object. Must be a downstream directed graph. |
An integer identifying the id of river mouth node.
g <- sbn_create(10, 0.7) sbn_get_outlet(g)
g <- sbn_create(10, 0.7) sbn_get_outlet(g)
Find all nodes upstream of a given node.
sbn_get_upstream(g, node)
sbn_get_upstream(g, node)
g |
a river network as an igraph object. Must be a downstream directed graph. |
node |
target node to get all upstream nodes of. |
A vector of upstream node id's.
g <- sbn_create(10, 0.7) sbn_get_upstream(g, 2)
g <- sbn_create(10, 0.7) sbn_get_upstream(g, 2)
Calculate the reach (node) Strahler for all nodes in a river network. The function will not work if any of the nodes in the network have more than two adjacent upstream reaches (e.g. some networks generated by the OCNet package).
sbn_strahler(g)
sbn_strahler(g)
g |
a river network as an igraph object. Must be a downstream directed graph. |
a vector of stream Strahler orders.
g <- sbn_create(10, 0.7) sbn_strahler(g)
g <- sbn_create(10, 0.7) sbn_strahler(g)
Convert a downstream directed SBN to various adjacency or distance matrix formats.
sbn_to_mtx( g, method = c("dwn_mtx", "undir_mtx", "up_mtx", "n2n_dist_up", "n2n_dist_dwn", "n2n_dist_undir"), unconnected = Inf, weights = NULL )
sbn_to_mtx( g, method = c("dwn_mtx", "undir_mtx", "up_mtx", "n2n_dist_up", "n2n_dist_dwn", "n2n_dist_undir"), unconnected = Inf, weights = NULL )
g |
a river network as an igraph object. Must be a downstream directed graph. |
method |
one of "dwn_mtx", an adjacency matrix for a downstream directed SBN, "up_mtx", an adjacency matrix for a upstream directed SBN, "undir_mtx", an adjacency matrix for a undirected SBN, "n2n_dist_up", "n2n_dist_dwn" or "n2n_dist_undir", an adjacency matrix of upstream, downstream or undirected node to node distances. |
unconnected |
when generating node-to-node distance matrices, what value should be used for unconnected elements. For example, in a downstream directed network, all upstream links are considered unconnected. Default value is |
weights |
passed to |
An adjacency or distance matrix.
g <- sbn_create(10, 0.7) sbn_to_mtx(g, method = "dwn_mtx")
g <- sbn_create(10, 0.7) sbn_to_mtx(g, method = "dwn_mtx")