Build a synthetic DEM using inlet/outlet locations.
Builds a synthetic DEM by considering inlets as “hills” and outlets as
“depressions.” This synthetic is then used to compute the “slope”
of each link, which is added to the links dictionary. Additionally,
direction guesses for each link’s flow are computed.
Parameters:
links (dict) – Network links and associated properties.
nodes (dict) – Network nodes and associated properties.
imshape (tuple) – Shape of binary mask as (nrows, ncols).
Returns:
links (dict) – Network links and associated properties including a ‘slope’.
nodes (dict) – Network nodes and associated properties.
Attempts to resolve a single cycle within a delta network. The general
logic is that all link directions of the cycle are un-set except for those
set by highly-reliable algorithms, and a modified direction-setting
recipe is implemented to re-set these algorithms. This was developed
according to the most commonly-encountered cases for real deltas, but could
certainly be improved.
Parameters:
links (dict) – Network links and associated properties.
nodes (dict) – Network nodes and associated properties.
cyc_links (list) – Link ids comprising the cycle to fix.
imshape (tuple) – Shape of binary mask as (nrows, ncols).
Returns:
links (dict) – Network links and associated properties with cycle fixed, if possible.
nodes (dict) – Network nodes and associated properties with cycle fixed, if possible.
fixed (bool) – True if the cycle was resolved, else False.
Attempts to resolve all cycles within the delta network. This function
is essentially a wrapper for fix_delta_cycle(), which is where the
heavy lifting is actually done. This function finds cycles, calls
fix_delta_cycle() on each one, then aggregates the results.
Parameters:
links (dict) – Network links and associated properties.
nodes (dict) – Network nodes and associated properties.
imshape (tuple) – Shape of binary mask as (nrows, ncols).
Returns:
links (dict) – Network links and associated properties with all possible cycles fixed.
nodes (dict) – Network nodes and associated properties with all possible cycles fixed.
allfixed (bool) – True if all cycles were resolved, else False.
Computes the convex hull of a set of input points. Arranges the convex
hull coordinates in a clockwise manner and removes the longest edge.
This function is required by dir_synthetic_dem().
Parameters:
xy (np.array) – Two element array. First element contains x coordinates, second
contains y coordinates of points to compute a convex hull around.
Returns:
hull_coords – Nx2 array of coordinates defining the convex hull of the input points.
Makes an initial attempt to set all flow directions within the network.
This represents the core of the “delta recipe” described in the following
open access paper:
https://esurf.copernicus.org/articles/8/87/2020/esurf-8-87-2020.pdf
However, note that as RivGraph develops, this recipe may no longer match
the one presented in that paper. The recipe chains together a number of
exploitative algorithms to iteratively set flow directions for the most
certain links first.
Parameters:
links (dict) – Network links and associated properties.
nodes (dict) – Network nodes and associated properties.
imshape (tuple) – Shape of binary mask as (nrows, ncols).
Returns:
links (dict) – Network links and associated properties with initial directions set.
nodes (dict) – Network nodes and associated properties with initial directions set.
This function sets the direction of each link within the network. It
calls a number of helping functions and uses a somewhat-complicated logic
to achieve this. The algorithms and logic is described in this open-access
paper: https://esurf.copernicus.org/articles/8/87/2020/esurf-8-87-2020.pdf
Every time this is run, all directionality information is reset and
recomputed. This includes checking for manually set links via the provided
csv.
Parameters:
links (dict) – Network links and associated properties.
nodes (dict) – Network nodes and associated properties.
imshape (tuple) – Shape of binary mask as (nrows, ncols).
manual_set_csv (str, optional) – Path to a user-provided csv file of known link directions. The default
is None.
Returns:
links (dict) – Network links and associated properties with all directions set.
nodes (dict) – Network nodes and associated properties with all directions set.
If multiple inlets are present, this creates a “super apex” that is
directly upstream of all the inlet nodes. The synthetic links created
have zero length and widths equal to the sum of the widths of the links
connected to their respective inlet node.
Clunky solution (target for optimization) to get QR at bifurcations.
QR is defined as the larger branch Q / smaller branch Q per
Edmonds & Slingerland 2008 [2]. This measure of flux partitioning at a
bifurcation does not scale beyond bifurcations to trifurcations etc.
The graph-based flux partitioning scheme also assumes flow is routed
in a steady-state manner based on the width (or some other attribute)
of the links in the network. Therefore the actual flux value doesn’t
matter, we can calculate QR as larger width / smaller width from the two
branches as that will be the same as if we’d calculated the steady-state
fluxes and taken their ratio.
The function is written flexibly to allow one to assuming flux weighting
by an attribute other than the link width if desired.
Warning
QR values calculated at nodes located at confluences, polyfurcations,
or any other non-bifurcating location will be incorrect!
Parameters:
links (dict) – RivGraph links dictionary
nodes (dict) – RivGraph nodes dictionary
wt (str, optional) – String pointing to the link attribute to use when calculating ratios,
optional, default is ‘wid_adj’ which is the adjusted link widths
new_at (str, optional) – Name of the new attribute to add to the nodes dictionary, optional,
default is ‘graphQR’ to indicate the graph calculated QR value
Returns:
nodes – RivGraph dictionary with new_at attribute added
Compute steady state fluxes through the network graph.
Computes the steady state fluxes through links given a directed, weighted,
NetworkX graph. The network should have only a single inlet (use either
ensure_single_inlet() or add_super_apex() to do this). Additionally,
this method will fail if the network has parallel edges. You should first
run ln_utils artificial_nodes() function to break parallel edges, then
re-compute link widths and lengths. Method after Tejedor et al 2015 [1].
Parameters:
G (networkx.DiGraph) – NetworkX DiGraph object from graphiphy()
links (dict) – RivGraph links dictionary
nodes (dict) – RivGraph nodes dictionary
weight_name (str, optional) – Name to give the new attribute in the links dictionary, is optional,
if not provided will be ‘flux_ss’ (flux steady-state)
Returns:
links – RivGraph links dictionary with new attribute
Compute the nonlocal entrop rate (nER) corresponding to the delta
(including flux partition) represented by adjacency matrix A, and compares
its value with the nER resulting from randomizing the flux partition.
Returns:
pExc – the probability that the value of nER for a randomization of the fluxes
on the topology dictated by A exceeds the actual value of nER. If the
value of pExc is lower than 0.10, we considered that the actual partition
of fluxes is an extreme value of nER
nER_Delta – the nonlinear entropy rate for the provided adjacency matrix
nER_randA – the nonlinear entropy rates for the N randomized deltas
Computes the steady state flux distribution in the delta nodes when the
system is fed with a constant unity influx from the Apex. Also defines the
subnetworks apex-to-outlet.
The SubN is an NxM matrix, where N is number of nodes and M is the number
of outlets. For each mth outlet, its contributing subnetwork is given by
the nonzero entries in SubN. The values in SubN are the degree of
“belongingness” of each node to its subnetwork. If SubN(m,n) = 0, the m’th
node does not belong to the n’th subnetwork; but if SubN(m,n) = 1, the m’th
node belongs only to the n’th subnetwork. The values in SubN may be
interpreted as the percentage of tracers that pass through node m that
eventually make their way to the outlet of subnetwork n.
Does this for nodes. Calculates a normalized distances from apex, ignores
pixel resolution.
Parameters:
nodes (dict) – RivGraph dictionary of nodes
imshape (tuple) – Tuple of the shape of the domain (e.g., Imask.shape)
Returns:
norm_dist – List of normalized straight line distances between each node and the
inlet in the same order as the nodes come in the input nodes
dictionary.
Computes the subnetwork to subnetwork dynamic pairwise dependence (DPD)
which quantifies the overlapping for all pairs of subnetworks in terms of
flux.
Ensure only a single apex node exists. This dumbly just prunes all inlet
nodes+links except the widest one. Recommended to use the super_apex()
approach instead if you want to preserve all inlets.
All the delta metrics here require a single apex node, and that that node
be connected to at least two downstream links. This function ensures these
conditions are met; where there are multiple inlets, the widest is chosen.
This function also ensures that the inlet node is attached to at least two
links–this is important for computing un-biased delta metrics.
The links and nodes dicts are copied so they remain unaltered; the altered
copies are returned.
Converts RivGraph links and nodes into a NetworkX graph object.
Converts the RivGraph links and nodes dictionaries into a NetworkX graph
object.
Parameters:
links (dict) – RivGraph links and their attributes
nodes (dict) – RivGraph nodes and their attributes
weight (str, optional) – Link attribute to use to weight the NetworkX graph. If not provided or
None, the graph will be unweighted (links of 1 and 0)
inletweights (list, optional) – Optional manual weights for the inlets when using the super-apex
functionality. Overrides the weight set by the inlet link attribute
in favor of values from the provided list. List must be in the same
order and have the same length as nodes[‘inlets’].
Returns:
G – Returns a NetworkX DiGraph object weighted by the link attribute
specified in the optional parameter weight
Uses networkx functions to find the shortest path along a graph defined
by A; path is simply defined as the number of links. Actual length not
considered. Number of links in the shortest path is returned.
Computes the intermediate variables and matrices required to compute
delta metrics. This function prevents the re-computation of many matrices
required in the metric functions.
NOTE! TopoDist was not supplied with this function–can use networkX to
compute shortest path but need to know what “shortest” means
This function will not work until TopoDist is resolved.
Computes the resistance distance (RD) from the Apex to each of the
shoreline outlets. The value of RD between two nodes is the effective
resistance between the two nodes when each link in the network is replaced
by a 1 ohm resistor.
This function computes the Subnetwork to Subnetwork Topologic Pairwise
Dependence (TPD) which quantifies the overlapping for all pairs of
subnetworks in terms of links.
Clips links by a provided shoreline shapefile. The largest network is
presumed to be the delta network and is thus retained. The network should
have been de-spurred before running this function.
Parameters:
links (dict) – stores the network’s links and their properties
nodes (dict) – stores the network’s nodes and their properties
shoreline_shp (str) – path to the shapefile of shoreline polyline
gdobj (osgeo.gdal.Dataset) – gdal object corresponding to the georeferenced input binary channel mask
Returns:
links (dict) – links dictionary representing network clipped by the shoreline
nodes (dict) – nodes dictionary representing network clipped by the shoreline.
‘outlets’ has been added to the dictionary to store a list of outlet
node ids