API Reference - Utils Module
backward(Q, b_LH, a)
Calculates the baseflow time series b from the discharge time series Q and the baseflow time series b_LH using a backward recursive approach.
The function iterates through the discharge time series in reverse order, calculating the baseflow at each time step based on the baseflow at the next time step and the recession coefficient a. If the calculated baseflow exceeds the discharge at the current time step, the baseflow is set to the discharge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q |
ndarray
|
The discharge time series. |
required |
b_LH |
ndarray
|
The baseflow time series. |
required |
a |
float
|
The recession coefficient. |
required |
Returns:
| Type | Description |
|---|---|
|
numpy.ndarray: The baseflow time series. |
Source code in baseflow/utils.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
clean_streamflow(series)
Cleans a streamflow time series by removing invalid values and keeping only years with at least 120 data points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
series |
Series
|
The streamflow time series to be cleaned. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
A tuple containing the cleaned streamflow values and the corresponding dates. |
Source code in baseflow/utils.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | |
exist_ice(date, ice_period)
Checks if a given date falls within an ice period.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date |
datetime
|
The date to check. |
required |
ice_period |
tuple or ndarray
|
The ice period, either as a tuple of (start_month, start_day, end_month, end_day) or as a numpy array of months. |
required |
Returns:
| Type | Description |
|---|---|
|
bool or numpy.ndarray: True if the date falls within the ice period, False otherwise. If |
Source code in baseflow/utils.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
flow_duration_curve(Q, plot=True)
Calculate the Flow Duration Curve (FDC) and optionally plot it.
Parameters: Q (numpy array): Streamflow data as a numpy array. plot (bool): Whether to plot the FDC, default is True.
Returns: percentiles (numpy array): The percentiles corresponding to streamflow. flow_values (numpy array): The sorted streamflow values.
Source code in baseflow/utils.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
format_method(method)
Formats the input method parameter to a list of method names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method |
str or list
|
The input method parameter, which can be a single string or a list of strings. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
A list of method names. |
Source code in baseflow/utils.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
geo2imagexy(x, y)
Converts geographic coordinates (x, y) to image coordinates (col, row).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x |
float
|
The x-coordinate in geographic space. |
required |
y |
float
|
The y-coordinate in geographic space. |
required |
Returns:
| Type | Description |
|---|---|
|
Tuple[int, int]: The corresponding column and row indices in image space. |
Source code in baseflow/utils.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
kge(simulations, evaluation)
Original Kling-Gupta Efficiency (KGE) and its three components
(r, α, β) as per Gupta et al., 2009
<https://doi.org/10.1016/j.jhydrol.2009.08.003>.
Note, all four values KGE, r, α, β are returned, in this order.
:Calculation Details:
.. math::
E{\text{KGE}} = 1 - \sqrt{[r - 1]^2 + [\alpha - 1]^2
+ [\beta - 1]^2}
.. math::
r = \frac{\text{cov}(e, s)}{\sigma({e}) \cdot \sigma(s)}
.. math::
\alpha = \frac{\sigma(s)}{\sigma(e)}
.. math::
\beta = \frac{\mu(s)}{\mu(e)}
where e is the evaluation series, s is (one of) the
simulations series, cov is the covariance, σ is the
standard deviation, and μ is the arithmetic mean.
Source code in baseflow/utils.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
multi_arange(starts, stops)
Generates a 1D numpy array containing all integers between the given start and stop values for each element in the input arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
starts |
ndarray
|
A 1D numpy array of start values. |
required |
stops |
ndarray
|
A 1D numpy array of stop values, where each stop value corresponds to the start value at the same index. |
required |
Returns:
| Type | Description |
|---|---|
|
numpy.ndarray: A 1D numpy array containing all integers between the given start and stop values for each element in the input arrays. |
Source code in baseflow/utils.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |