earthkit.hydro.downstream¶
Subpackages¶
Module contents¶
- earthkit.hydro.downstream.max(river_network, field, node_weights=None, edge_weights=None, return_type=None, input_core_dims=None)[source]¶
Computes the weighted maximum of a field over all downstream nodes.
For each node in the river network, this function identifies all downstream nodes in the river network and accumulates their contributions upstream, weighted by both node and edge weights.
The weighted maximum is defined as:
\begin{align*} x'_i &= w'_i \cdot x_i \\ m_j &= \mathrm{max} (x'_j,~\mathrm{max}_{i \in \mathrm{Down}(j)} w_{ij} \cdot m_i) \end{align*}where:
\(x_i\) is the input value at node \(i\) (e.g., rainfall),
\(w'_i\) is the node weight (e.g., pixel area),
\(w_{ij}\) is the edge weight from node \(i\) to node \(j\) (e.g. discharge partitioning ratio),
\(\mathrm{Down}(j)\) is the set of downstream nodes flowing out of node \(j\),
\(m_j\) is the weighted maximum at node \(j\).
Accumulation proceeds in inverse topological order from the sinks to the sources.
- Parameters:
river_network (RiverNetwork) – A river network object.
field (array-like or xarray object) – An array containing field values defined on river network nodes or gridcells.
node_weights (array-like or xarray object, optional) – Array of weights for each river network node or gridcell. Default is None (unweighted).
edge_weights (array-like or xarray object, optional) – Array of weights for each edge. Default is None (unweighted).
return_type (str, optional) – Either “masked”, “gridded” or None. If None (default), uses river_network.return_type.
input_core_dims (sequence of sequence, optional) – List of core dimensions on each input xarray argument that should not be broadcast. Default is None, which attempts to autodetect input_core_dims from the xarray inputs. Ignored if no xarray inputs passed.
- Returns:
Array of maximum values for every river network node or gridcell, depending on return_type.
- Return type:
xarray object
- earthkit.hydro.downstream.mean(river_network, field, node_weights=None, edge_weights=None, return_type=None, input_core_dims=None)[source]¶
Computes the weighted mean of a field over all downstream nodes.
For each node in the river network, this function identifies all downstream nodes in the river network and accumulates their contributions upstream, weighted by both node and edge weights.
The weighted mean is defined as:
\begin{align*} x'_i &= w'_i \cdot x_i \\ n_j &= x'_j + \sum_{i \in \mathrm{Down}(j)} w_{ij} \cdot n_i \\ d_j &= w'_j + \sum_{i \in \mathrm{Down}(j)} w_{ij} \cdot d_i \\ \bar{x}_j &= \frac{n_j}{d_j} \end{align*}where:
\(x_i\) is the input value at node \(i\) (e.g., rainfall),
\(w'_i\) is the node weight (e.g., pixel area),
\(w_{ij}\) is the edge weight from node \(i\) to node \(j\) (e.g. discharge partitioning ratio),
\(\mathrm{Down}(j)\) is the set of downstream nodes flowing out of node \(j\),
\(n_j\) is the accumulated weighted value,
\(d_j\) is the accumulated weight (denominator),
\(\bar{x}_j\) is the weighted mean at node \(j\).
Accumulation proceeds in inverse topological order from the sinks to the sources.
- Parameters:
river_network (RiverNetwork) – A river network object.
field (array-like or xarray object) – An array containing field values defined on river network nodes or gridcells.
node_weights (array-like or xarray object, optional) – Array of weights for each river network node or gridcell. Default is None (unweighted).
edge_weights (array-like or xarray object, optional) – Array of weights for each edge. Default is None (unweighted).
return_type (str, optional) – Either “masked”, “gridded” or None. If None (default), uses river_network.return_type.
input_core_dims (sequence of sequence, optional) – List of core dimensions on each input xarray argument that should not be broadcast. Default is None, which attempts to autodetect input_core_dims from the xarray inputs. Ignored if no xarray inputs passed.
- Returns:
Array of mean values for every river network node or gridcell, depending on return_type.
- Return type:
xarray object
- earthkit.hydro.downstream.min(river_network, field, node_weights=None, edge_weights=None, return_type=None, input_core_dims=None)[source]¶
Computes the weighted minimum of a field over all downstream nodes.
For each node in the river network, this function identifies all downstream nodes in the river network and accumulates their contributions upstream, weighted by both node and edge weights.
The weighted minimum is defined as:
\begin{align*} x'_i &= w'_i \cdot x_i \\ m_j &= \mathrm{min}(x'_j,~\mathrm{min}_{i \in \mathrm{Down}(j)} w_{ij} \cdot m_i) \end{align*}where:
\(x_i\) is the input value at node \(i\) (e.g., rainfall),
\(w'_i\) is the node weight (e.g., pixel area),
\(w_{ij}\) is the edge weight from node \(i\) to node \(j\) (e.g. discharge partitioning ratio),
\(\mathrm{Down}(j)\) is the set of downstream nodes flowing out of node \(j\),
\(m_j\) is the weighted minimum at node \(j\).
Accumulation proceeds in inverse topological order from the sinks to the sources.
- Parameters:
river_network (RiverNetwork) – A river network object.
field (array-like or xarray object) – An array containing field values defined on river network nodes or gridcells.
node_weights (array-like or xarray object, optional) – Array of weights for each river network node or gridcell. Default is None (unweighted).
edge_weights (array-like or xarray object, optional) – Array of weights for each edge. Default is None (unweighted).
return_type (str, optional) – Either “masked”, “gridded” or None. If None (default), uses river_network.return_type.
input_core_dims (sequence of sequence, optional) – List of core dimensions on each input xarray argument that should not be broadcast. Default is None, which attempts to autodetect input_core_dims from the xarray inputs. Ignored if no xarray inputs passed.
- Returns:
Array of minimum values for every river network node or gridcell, depending on return_type.
- Return type:
xarray object
- earthkit.hydro.downstream.std(river_network, field, node_weights=None, edge_weights=None, return_type=None, input_core_dims=None)[source]¶
Computes the weighted standard deviation of a field over all downstream nodes.
For each node in the river network, this function identifies all downstream nodes in the river network and accumulates their contributions upstream, weighted by both node and edge weights.
The weighted standard deviation is defined as:
\begin{align*} x'_i &= w'_i \cdot x_i \\ q'_i &= w'_i \cdot x_i^2 \\ n_j &= x'_j + \sum_{i \in \mathrm{Down}(j)} w_{ij} \cdot n_i \\ q_j &= q'_j + \sum_{i \in \mathrm{Down}(j)} w_{ij} \cdot q_i \\ d_j &= w'_j + \sum_{i \in \mathrm{Down}(j)} w_{ij} \cdot d_i \\ \bar{x}_j &= \frac{n_j}{d_j} \\ \mathrm{Var}(x)_j &= \frac{q_j}{d_j} - \bar{x}_j^2 \\ \mathrm{Std}(x)_j &= \sqrt{\mathrm{Var}(x)_j} \end{align*}where:
\(x_i\) is the input value at node \(i\) (e.g., rainfall),
\(w'_i\) is the node weight (e.g., pixel area),
\(w_{ij}\) is the edge weight from node \(i\) to node \(j\) (e.g., discharge partitioning ratio),
\(\mathrm{Down}(j)\) is the set of downstream nodes flowing out of node \(j\),
\(n_j\) is the accumulated weighted value,
\(q_j\) is the accumulated weighted squared value,
\(d_j\) is the accumulated weight (denominator),
\(\bar{x}_j\) is the weighted average at node \(j\),
\(\mathrm{Var}(x)_j\) is the weighted variance at node \(j\).
\(\mathrm{Std}(x)_j\) is the weighted standard deviation at node \(j\).
Accumulation proceeds in inverse topological order from the sinks to the sources. This formulation computes the population standard deviation.
- Parameters:
river_network (RiverNetwork) – A river network object.
field (array-like or xarray object) – An array containing field values defined on river network nodes or gridcells.
node_weights (array-like or xarray object, optional) – Array of weights for each river network node or gridcell. Default is None (unweighted).
edge_weights (array-like or xarray object, optional) – Array of weights for each edge. Default is None (unweighted).
return_type (str, optional) – Either “masked”, “gridded” or None. If None (default), uses river_network.return_type.
input_core_dims (sequence of sequence, optional) – List of core dimensions on each input xarray argument that should not be broadcast. Default is None, which attempts to autodetect input_core_dims from the xarray inputs. Ignored if no xarray inputs passed.
- Returns:
Array of standard deviation values for every river network node or gridcell, depending on return_type.
- Return type:
xarray object
- earthkit.hydro.downstream.sum(river_network, field, node_weights=None, edge_weights=None, return_type=None, input_core_dims=None)[source]¶
Computes the weighted sum of a field over all downstream nodes.
For each node in the river network, this function identifies all downstream nodes in the river network and accumulates their contributions upstream, weighted by both node and edge weights.
The weighted sum is defined as:
\begin{align*} x'_i &= w'_i \cdot x_i \\ n_j &= x'_j + \sum_{i \in \mathrm{Down}(j)} w_{ij} \cdot n_i \end{align*}where:
\(x_i\) is the input value at node \(i\) (e.g., rainfall),
\(w'_i\) is the node weight (e.g., pixel area),
\(w_{ij}\) is the edge weight from node \(i\) to node \(j\) (e.g. discharge partitioning ratio),
\(\mathrm{Down}(j)\) is the set of downstream nodes flowing out of node \(j\),
\(n_j\) is the weighted sum at node \(j\).
Accumulation proceeds in inverse topological order from the sinks to the sources.
- Parameters:
river_network (RiverNetwork) – A river network object.
field (array-like or xarray object) – An array containing field values defined on river network nodes or gridcells.
node_weights (array-like or xarray object, optional) – Array of weights for each river network node or gridcell. Default is None (unweighted).
edge_weights (array-like or xarray object, optional) – Array of weights for each edge. Default is None (unweighted).
return_type (str, optional) – Either “masked”, “gridded” or None. If None (default), uses river_network.return_type.
input_core_dims (sequence of sequence, optional) – List of core dimensions on each input xarray argument that should not be broadcast. Default is None, which attempts to autodetect input_core_dims from the xarray inputs. Ignored if no xarray inputs passed.
- Returns:
Array of sum values for every river network node or gridcell, depending on return_type.
- Return type:
xarray object
- earthkit.hydro.downstream.var(river_network, field, node_weights=None, edge_weights=None, return_type=None, input_core_dims=None)[source]¶
Computes the weighted variance of a field over all downstream nodes.
For each node in the river network, this function identifies all downstream nodes in the river network and accumulates their contributions upstream, weighted by both node and edge weights.
The weighted variance is defined as:
\begin{align*} x'_i &= w'_i \cdot x_i \\ q'_i &= w'_i \cdot x_i^2 \\ n_j &= x'_j + \sum_{i \in \mathrm{Down}(j)} w_{ij} \cdot n_i \\ q_j &= q'_j + \sum_{i \in \mathrm{Down}(j)} w_{ij} \cdot q_i \\ d_j &= w'_j + \sum_{i \in \mathrm{Down}(j)} w_{ij} \cdot d_i \\ \bar{x}_j &= \frac{n_j}{d_j} \\ \mathrm{Var}(x)_j &= \frac{q_j}{d_j} - \bar{x}_j^2 \end{align*}where:
\(x_i\) is the input value at node \(i\) (e.g., rainfall),
\(w'_i\) is the node weight (e.g., pixel area),
\(w_{ij}\) is the edge weight from node \(i\) to node \(j\) (e.g., discharge partitioning ratio),
\(\mathrm{Down}(j)\) is the set of downstream nodes flowing out of node \(j\),
\(n_j\) is the accumulated weighted value,
\(q_j\) is the accumulated weighted squared value,
\(d_j\) is the accumulated weight (denominator),
\(\bar{x}_j\) is the weighted average at node \(j\),
\(\mathrm{Var}(x)_j\) is the weighted variance at node \(j\).
Accumulation proceeds in inverse topological order from the sinks to the sources. This formulation computes the population variance.
- Parameters:
river_network (RiverNetwork) – A river network object.
field (array-like or xarray object) – An array containing field values defined on river network nodes or gridcells.
node_weights (array-like or xarray object, optional) – Array of weights for each river network node or gridcell. Default is None (unweighted).
edge_weights (array-like or xarray object, optional) – Array of weights for each edge. Default is None (unweighted).
return_type (str, optional) – Either “masked”, “gridded” or None. If None (default), uses river_network.return_type.
input_core_dims (sequence of sequence, optional) – List of core dimensions on each input xarray argument that should not be broadcast. Default is None, which attempts to autodetect input_core_dims from the xarray inputs. Ignored if no xarray inputs passed.
- Returns:
Array of variance values for every river network node or gridcell, depending on return_type.
- Return type:
xarray object