hydrotoolbox 2.0.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hydrotoolbox/__init__.py +11 -0
- hydrotoolbox/baseflow/__init__.py +9 -0
- hydrotoolbox/baseflow/comparison.py +72 -0
- hydrotoolbox/baseflow/example.csv +34004 -0
- hydrotoolbox/baseflow/methods/Boughton.py +29 -0
- hydrotoolbox/baseflow/methods/CM.py +21 -0
- hydrotoolbox/baseflow/methods/Chapman.py +21 -0
- hydrotoolbox/baseflow/methods/EWMA.py +20 -0
- hydrotoolbox/baseflow/methods/Eckhardt.py +30 -0
- hydrotoolbox/baseflow/methods/Fixed.py +26 -0
- hydrotoolbox/baseflow/methods/Furey.py +29 -0
- hydrotoolbox/baseflow/methods/LH.py +32 -0
- hydrotoolbox/baseflow/methods/Local.py +47 -0
- hydrotoolbox/baseflow/methods/Slide.py +25 -0
- hydrotoolbox/baseflow/methods/UKIH.py +46 -0
- hydrotoolbox/baseflow/methods/Willems.py +31 -0
- hydrotoolbox/baseflow/methods/__init__.py +15 -0
- hydrotoolbox/baseflow/methods/five_day.py +32 -0
- hydrotoolbox/baseflow/methods/ihacres.py +24 -0
- hydrotoolbox/baseflow/methods/strict.py +17 -0
- hydrotoolbox/baseflow/param_estimate.py +95 -0
- hydrotoolbox/baseflow/separation.py +98 -0
- hydrotoolbox/baseflow/utils.py +94 -0
- hydrotoolbox/baseflow_sep.py +979 -0
- hydrotoolbox/hydrotoolbox.py +2132 -0
- hydrotoolbox/indices/indices.py +1573 -0
- hydrotoolbox/toolbox_utils/docs/conf.py +309 -0
- hydrotoolbox/toolbox_utils/setup.py +21 -0
- hydrotoolbox/toolbox_utils/src/toolbox_utils/__init__.py +0 -0
- hydrotoolbox/toolbox_utils/src/toolbox_utils/readers/__init__.py +0 -0
- hydrotoolbox/toolbox_utils/src/toolbox_utils/readers/hbn.py +392 -0
- hydrotoolbox/toolbox_utils/src/toolbox_utils/readers/plotgen.py +55 -0
- hydrotoolbox/toolbox_utils/src/toolbox_utils/readers/wdm.py +233 -0
- hydrotoolbox/toolbox_utils/src/toolbox_utils/tssplit/setup.py +38 -0
- hydrotoolbox/toolbox_utils/src/toolbox_utils/tssplit/tssplit/__init__.py +1 -0
- hydrotoolbox/toolbox_utils/src/toolbox_utils/tssplit/tssplit/tssplit.py +47 -0
- hydrotoolbox/toolbox_utils/src/toolbox_utils/tsutils.py +2605 -0
- hydrotoolbox/toolbox_utils/tests/test_asbestfreq.py +72 -0
- hydrotoolbox/toolbox_utils/tests/test_common_kwds.py +23 -0
- hydrotoolbox/toolbox_utils/tests/test_date_slice.py +98 -0
- hydrotoolbox/toolbox_utils/tests/test_dateparse.py +41 -0
- hydrotoolbox/toolbox_utils/tests/test_extract.py +80 -0
- hydrotoolbox/toolbox_utils/tests/test_hbn.py +79 -0
- hydrotoolbox/toolbox_utils/tests/test_make_list.py +92 -0
- hydrotoolbox/toolbox_utils/tests/test_period_timestamp.py +136 -0
- hydrotoolbox/toolbox_utils/tests/test_plotgen.py +760 -0
- hydrotoolbox/toolbox_utils/tests/test_range_to_numlist.py +63 -0
- hydrotoolbox/toolbox_utils/tests/test_read.py +106 -0
- hydrotoolbox/toolbox_utils/tests/test_tssplit.py +23 -0
- hydrotoolbox/toolbox_utils/tests/test_wdm.py +59 -0
- hydrotoolbox/utils.py +28 -0
- hydrotoolbox-2.0.9.dist-info/LICENSE.txt +24 -0
- hydrotoolbox-2.0.9.dist-info/METADATA +158 -0
- hydrotoolbox-2.0.9.dist-info/RECORD +57 -0
- hydrotoolbox-2.0.9.dist-info/WHEEL +5 -0
- hydrotoolbox-2.0.9.dist-info/entry_points.txt +2 -0
- hydrotoolbox-2.0.9.dist-info/top_level.txt +1 -0
hydrotoolbox/__init__.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def strict_baseflow(Q):
|
|
5
|
+
delta_q = (Q[2:] - Q[:-2]) / 2
|
|
6
|
+
|
|
7
|
+
# 1. Flow data associated with positive and zero values of dQ/dt.
|
|
8
|
+
wet1 = np.concatenate([[True], delta_q >= 0, [True]])
|
|
9
|
+
|
|
10
|
+
# 2. Previous 2 points before points with dQ/dt >= 0, as well as the next
|
|
11
|
+
# three points.
|
|
12
|
+
idx_first = np.where(wet1[1:].astype(int) - wet1[:-1].astype(int) == 1)[0] + 1
|
|
13
|
+
idx_last = np.where(wet1[1:].astype(int) - wet1[:-1].astype(int) == -1)[0]
|
|
14
|
+
idx_before = np.repeat([idx_first], 2) - np.tile(range(1, 3), idx_first.shape)
|
|
15
|
+
idx_next = np.repeat([idx_last], 3) + np.tile(range(1, 4), idx_last.shape)
|
|
16
|
+
idx_remove = np.concatenate([idx_before, idx_next])
|
|
17
|
+
wet2 = np.full(Q.shape, False)
|
|
18
|
+
wet2[idx_remove.clip(min=0, max=Q.shape[0] - 1)] = True
|
|
19
|
+
|
|
20
|
+
# 3. Five data points after major events. A major event is identified as
|
|
21
|
+
# greater than the 90th quantile.
|
|
22
|
+
growing = np.concatenate([[True], (Q[1:] - Q[:-1]) >= 0, [True]])
|
|
23
|
+
idx_major = np.where((Q >= np.quantile(Q, 0.9)) & growing[:-1] & ~growing[1:])[0]
|
|
24
|
+
idx_after = np.repeat([idx_major], 5) + np.tile(range(1, 6), idx_major.shape)
|
|
25
|
+
wet3 = np.full(Q.shape, False)
|
|
26
|
+
wet3[idx_after.clip(min=0, max=Q.shape[0] - 1)] = True
|
|
27
|
+
|
|
28
|
+
# 4. Flow data followed by a data point with a larger value of -dQ/dt.
|
|
29
|
+
wet4 = np.concatenate([[True], delta_q[1:] - delta_q[:-1] < 0, [True, True]])
|
|
30
|
+
|
|
31
|
+
return ~(wet1 + wet2 + wet3 + wet4)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def KGE(simulations, evaluation):
|
|
35
|
+
"""Original Kling-Gupta Efficiency (KGE) and its three components
|
|
36
|
+
(r, α, β) as per `Gupta et al., 2009
|
|
37
|
+
<https://doi.org/10.1016/j.jhydrol.2009.08.003>`_.
|
|
38
|
+
Note, all four values KGE, r, α, β are returned, in this order.
|
|
39
|
+
:Calculation Details:
|
|
40
|
+
.. math::
|
|
41
|
+
E_{\\text{KGE}} = 1 - \\sqrt{[r - 1]^2 + [\\alpha - 1]^2
|
|
42
|
+
+ [\\beta - 1]^2}
|
|
43
|
+
.. math::
|
|
44
|
+
r = \\frac{\\text{cov}(e, s)}{\\sigma({e}) \\cdot \\sigma(s)}
|
|
45
|
+
.. math::
|
|
46
|
+
\\alpha = \\frac{\\sigma(s)}{\\sigma(e)}
|
|
47
|
+
.. math::
|
|
48
|
+
\\beta = \\frac{\\mu(s)}{\\mu(e)}
|
|
49
|
+
where *e* is the *evaluation* series, *s* is (one of) the
|
|
50
|
+
*simulations* series, *cov* is the covariance, *σ* is the
|
|
51
|
+
standard deviation, and *μ* is the arithmetic mean.
|
|
52
|
+
"""
|
|
53
|
+
# calculate error in timing and dynamics r
|
|
54
|
+
# (Pearson's correlation coefficient)
|
|
55
|
+
sim_mean = np.mean(simulations, axis=0, dtype=np.float64)
|
|
56
|
+
obs_mean = np.mean(evaluation, axis=0, dtype=np.float64)
|
|
57
|
+
|
|
58
|
+
r_num = np.sum(
|
|
59
|
+
(simulations - sim_mean) * (evaluation - obs_mean), axis=0, dtype=np.float64
|
|
60
|
+
)
|
|
61
|
+
r_den = np.sqrt(
|
|
62
|
+
np.sum((simulations - sim_mean) ** 2, axis=0, dtype=np.float64)
|
|
63
|
+
* np.sum((evaluation - obs_mean) ** 2, axis=0, dtype=np.float64)
|
|
64
|
+
)
|
|
65
|
+
r = r_num / (r_den + 1e-10)
|
|
66
|
+
# calculate error in spread of flow alpha
|
|
67
|
+
alpha = np.std(simulations, axis=0) / (np.std(evaluation, axis=0) + 1e-10)
|
|
68
|
+
# calculate error in volume beta (bias of mean discharge)
|
|
69
|
+
beta = np.sum(simulations, axis=0, dtype=np.float64) / (
|
|
70
|
+
np.sum(evaluation, axis=0, dtype=np.float64) + 1e-10
|
|
71
|
+
)
|
|
72
|
+
return 1 - np.sqrt((r - 1) ** 2 + (alpha - 1) ** 2 + (beta - 1) ** 2)
|