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.
Files changed (57) hide show
  1. hydrotoolbox/__init__.py +11 -0
  2. hydrotoolbox/baseflow/__init__.py +9 -0
  3. hydrotoolbox/baseflow/comparison.py +72 -0
  4. hydrotoolbox/baseflow/example.csv +34004 -0
  5. hydrotoolbox/baseflow/methods/Boughton.py +29 -0
  6. hydrotoolbox/baseflow/methods/CM.py +21 -0
  7. hydrotoolbox/baseflow/methods/Chapman.py +21 -0
  8. hydrotoolbox/baseflow/methods/EWMA.py +20 -0
  9. hydrotoolbox/baseflow/methods/Eckhardt.py +30 -0
  10. hydrotoolbox/baseflow/methods/Fixed.py +26 -0
  11. hydrotoolbox/baseflow/methods/Furey.py +29 -0
  12. hydrotoolbox/baseflow/methods/LH.py +32 -0
  13. hydrotoolbox/baseflow/methods/Local.py +47 -0
  14. hydrotoolbox/baseflow/methods/Slide.py +25 -0
  15. hydrotoolbox/baseflow/methods/UKIH.py +46 -0
  16. hydrotoolbox/baseflow/methods/Willems.py +31 -0
  17. hydrotoolbox/baseflow/methods/__init__.py +15 -0
  18. hydrotoolbox/baseflow/methods/five_day.py +32 -0
  19. hydrotoolbox/baseflow/methods/ihacres.py +24 -0
  20. hydrotoolbox/baseflow/methods/strict.py +17 -0
  21. hydrotoolbox/baseflow/param_estimate.py +95 -0
  22. hydrotoolbox/baseflow/separation.py +98 -0
  23. hydrotoolbox/baseflow/utils.py +94 -0
  24. hydrotoolbox/baseflow_sep.py +979 -0
  25. hydrotoolbox/hydrotoolbox.py +2132 -0
  26. hydrotoolbox/indices/indices.py +1573 -0
  27. hydrotoolbox/toolbox_utils/docs/conf.py +309 -0
  28. hydrotoolbox/toolbox_utils/setup.py +21 -0
  29. hydrotoolbox/toolbox_utils/src/toolbox_utils/__init__.py +0 -0
  30. hydrotoolbox/toolbox_utils/src/toolbox_utils/readers/__init__.py +0 -0
  31. hydrotoolbox/toolbox_utils/src/toolbox_utils/readers/hbn.py +392 -0
  32. hydrotoolbox/toolbox_utils/src/toolbox_utils/readers/plotgen.py +55 -0
  33. hydrotoolbox/toolbox_utils/src/toolbox_utils/readers/wdm.py +233 -0
  34. hydrotoolbox/toolbox_utils/src/toolbox_utils/tssplit/setup.py +38 -0
  35. hydrotoolbox/toolbox_utils/src/toolbox_utils/tssplit/tssplit/__init__.py +1 -0
  36. hydrotoolbox/toolbox_utils/src/toolbox_utils/tssplit/tssplit/tssplit.py +47 -0
  37. hydrotoolbox/toolbox_utils/src/toolbox_utils/tsutils.py +2605 -0
  38. hydrotoolbox/toolbox_utils/tests/test_asbestfreq.py +72 -0
  39. hydrotoolbox/toolbox_utils/tests/test_common_kwds.py +23 -0
  40. hydrotoolbox/toolbox_utils/tests/test_date_slice.py +98 -0
  41. hydrotoolbox/toolbox_utils/tests/test_dateparse.py +41 -0
  42. hydrotoolbox/toolbox_utils/tests/test_extract.py +80 -0
  43. hydrotoolbox/toolbox_utils/tests/test_hbn.py +79 -0
  44. hydrotoolbox/toolbox_utils/tests/test_make_list.py +92 -0
  45. hydrotoolbox/toolbox_utils/tests/test_period_timestamp.py +136 -0
  46. hydrotoolbox/toolbox_utils/tests/test_plotgen.py +760 -0
  47. hydrotoolbox/toolbox_utils/tests/test_range_to_numlist.py +63 -0
  48. hydrotoolbox/toolbox_utils/tests/test_read.py +106 -0
  49. hydrotoolbox/toolbox_utils/tests/test_tssplit.py +23 -0
  50. hydrotoolbox/toolbox_utils/tests/test_wdm.py +59 -0
  51. hydrotoolbox/utils.py +28 -0
  52. hydrotoolbox-2.0.9.dist-info/LICENSE.txt +24 -0
  53. hydrotoolbox-2.0.9.dist-info/METADATA +158 -0
  54. hydrotoolbox-2.0.9.dist-info/RECORD +57 -0
  55. hydrotoolbox-2.0.9.dist-info/WHEEL +5 -0
  56. hydrotoolbox-2.0.9.dist-info/entry_points.txt +2 -0
  57. hydrotoolbox-2.0.9.dist-info/top_level.txt +1 -0
@@ -0,0 +1,94 @@
1
+ import numpy as np
2
+
3
+
4
+ def load_streamflow(path):
5
+ """load streamflow into memory
6
+
7
+ Args:
8
+ path (str|DataFrame): path of streamflow csv file, or pandas DataFrame
9
+
10
+ Returns:
11
+ tuple: (date of np.datetime64, streamflow of float)
12
+ """
13
+ if isinstance(path, str):
14
+ date, Q = np.loadtxt(
15
+ path,
16
+ delimiter=",",
17
+ skiprows=1,
18
+ unpack=True,
19
+ dtype=[("date", "datetime64[D]"), ("Q", float)],
20
+ converters={0: np.datetime64},
21
+ encoding="utf8",
22
+ )
23
+ year = date.astype("datetime64[Y]").astype(int) + int(
24
+ str(np.datetime64(0, "Y"))
25
+ )
26
+ month = date.astype("datetime64[M]").astype(int) % 12 + 1
27
+ day = (date - date.astype("datetime64[M]")).astype(int) + 1
28
+ date = np.rec.fromarrays(
29
+ [year, month, day], dtype=[("Y", "i4"), ("M", "i4"), ("D", "i4")]
30
+ )
31
+ else:
32
+ df_date = path.iloc[:, 0].astype("datetime64")
33
+ date = np.rec.fromarrays(
34
+ [df_date.dt.year, df_date.dt.month, df_date.dt.day],
35
+ dtype=[("Y", "i4"), ("M", "i4"), ("D", "i4")],
36
+ )
37
+ Q = path.iloc[:, 1].values.astype(float)
38
+ return clean_streamflow(date, Q)
39
+
40
+
41
+ def clean_streamflow(date, Q):
42
+ Q[np.isnan(Q)] = 0
43
+ Q = np.abs(Q)
44
+ year = date["Y"]
45
+ year_unique = np.unique(year)
46
+ year_delete = clean_streamflow_jit(year, year_unique, Q)
47
+ idx_delete = np.isin(year, year_delete)
48
+ return Q[~idx_delete], date[~idx_delete]
49
+
50
+
51
+ def clean_streamflow_jit(year, year_unique, Q):
52
+ return [y for y in year_unique if (Q[year == y] >= 0).sum() < 120]
53
+
54
+
55
+ def moving_average(x, w):
56
+ res = np.convolve(x, np.ones(w)) / w
57
+ return res[w - 1 : -w + 1]
58
+
59
+
60
+ def multi_arange_steps(starts, stops, steps):
61
+ pos = 0
62
+ cnt = np.sum((stops - starts + steps - np.sign(steps)) // steps, dtype=np.int64)
63
+ res = np.zeros((cnt,), dtype=np.int64)
64
+ for i in range(starts.size):
65
+ v, stop, step = starts[i], stops[i], steps[i]
66
+ if step > 0:
67
+ while v < stop:
68
+ res[pos] = v
69
+ pos += 1
70
+ v += step
71
+ elif step < 0:
72
+ while v > stop:
73
+ res[pos] = v
74
+ pos += 1
75
+ v += step
76
+ assert pos == cnt
77
+ return res
78
+
79
+
80
+ def multi_arange(starts, stops):
81
+ pos = 0
82
+ cnt = np.sum(stops - starts, dtype=np.int64)
83
+ res = np.zeros((cnt,), dtype=np.int64)
84
+ for i in range(starts.size):
85
+ num = stops[i] - starts[i]
86
+ res[pos : pos + num] = np.arange(starts[i], stops[i])
87
+ pos += num
88
+ return res
89
+
90
+
91
+ def NSE(q_obs, q_sim):
92
+ ss_res = np.sum(np.square(q_obs - q_sim))
93
+ ss_tot = np.sum(np.square(q_obs - np.mean(q_obs)))
94
+ return (1 - ss_res / (ss_tot + 1e-10)) - 1e-10