pastastore 1.7.0__py3-none-any.whl → 1.7.2__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.
@@ -0,0 +1,181 @@
1
+ # ruff: noqa: D100 D103
2
+ import numpy as np
3
+ import pandas as pd
4
+ import pytest
5
+ from conftest import requires_pkg
6
+
7
+ import pastastore as pst
8
+
9
+ # %% write
10
+
11
+ # data
12
+ rng = np.random.default_rng()
13
+ data = rng.random(int(1e5))
14
+ s = pd.Series(index=pd.date_range("1970", periods=int(1e5), freq="h"), data=data)
15
+ metadata = {"x": 100000.0, "y": 300000.0}
16
+
17
+
18
+ def series_write(conn):
19
+ conn.add_oseries(s, "oseries1", metadata=metadata, overwrite=True)
20
+
21
+
22
+ # @pytest.mark.benchmark(group="write_series")
23
+ # def test_benchmark_write_series_dict(benchmark):
24
+ # conn = pst.DictConnector("test")
25
+ # _ = benchmark(series_write, conn=conn)
26
+
27
+
28
+ @pytest.mark.benchmark(group="write_series")
29
+ def test_benchmark_write_series_pas(benchmark):
30
+ conn = pst.PasConnector("test", "./tests/data/pas")
31
+ _ = benchmark(series_write, conn=conn)
32
+
33
+
34
+ @pytest.mark.benchmark(group="write_series")
35
+ @requires_pkg("arcticdb")
36
+ def test_benchmark_write_series_arcticdb(benchmark):
37
+ uri = "lmdb://./arctic_db/"
38
+ conn = pst.ArcticDBConnector("test", uri)
39
+ _ = benchmark(series_write, conn=conn)
40
+
41
+
42
+ # %% read
43
+
44
+
45
+ def series_read(conn):
46
+ _ = conn.get_oseries("oseries1")
47
+
48
+
49
+ # @pytest.mark.benchmark(group="read_series")
50
+ # def test_benchmark_write_series_dict(benchmark):
51
+ # conn = pst.DictConnector("test")
52
+ # _ = benchmark(series_read, conn=conn)
53
+ #
54
+
55
+
56
+ @pytest.mark.benchmark(group="read_series")
57
+ def test_benchmark_read_series_pas(benchmark):
58
+ conn = pst.PasConnector("test", "./tests/data/pas")
59
+ _ = benchmark(series_read, conn=conn)
60
+
61
+
62
+ @pytest.mark.benchmark(group="read_series")
63
+ @requires_pkg("arcticdb")
64
+ def test_benchmark_read_series_arcticdb(benchmark):
65
+ uri = "lmdb://./arctic_db/"
66
+ conn = pst.ArcticDBConnector("test", uri)
67
+ _ = benchmark(series_read, conn=conn)
68
+
69
+
70
+ # %% write model
71
+
72
+
73
+ def build_model(conn):
74
+ store = pst.PastaStore(conn, "test")
75
+
76
+ # oseries nb1
77
+ if "oseries_nb1" not in store.oseries_names:
78
+ o = pd.read_csv("./tests/data/head_nb1.csv", index_col=0, parse_dates=True)
79
+ store.add_oseries(o, "oseries_nb1", metadata={"x": 100300, "y": 400400})
80
+
81
+ # prec nb1
82
+ if "prec_nb1" not in store.stresses.index:
83
+ s = pd.read_csv("./tests/data/rain_nb1.csv", index_col=0, parse_dates=True)
84
+ store.add_stress(
85
+ s, "prec_nb1", kind="prec", metadata={"x": 100300, "y": 400400}
86
+ )
87
+
88
+ # evap nb1
89
+ if "evap_nb1" not in store.stresses.index:
90
+ s = pd.read_csv("./tests/data/evap_nb1.csv", index_col=0, parse_dates=True)
91
+ store.add_stress(
92
+ s, "evap_nb1", kind="evap", metadata={"x": 100300, "y": 400400}
93
+ )
94
+
95
+ ml = store.create_model("oseries_nb1", add_recharge=True)
96
+
97
+ return ml
98
+
99
+
100
+ def write_model(conn, ml):
101
+ conn.add_model(ml, overwrite=True)
102
+
103
+
104
+ # @pytest.mark.benchmark(group="write_model")
105
+ # def test_benchmark_write_model_dict(benchmark):
106
+ # conn = pst.DictConnector("test")
107
+ # ml = build_model(conn)
108
+ # _ = benchmark(write_model, conn=conn, ml=ml)
109
+
110
+
111
+ @pytest.mark.benchmark(group="write_model")
112
+ def test_benchmark_write_model_pas(benchmark):
113
+ conn = pst.PasConnector("test", "./tests/data/pas")
114
+ ml = build_model(conn)
115
+ _ = benchmark(write_model, conn=conn, ml=ml)
116
+
117
+
118
+ @pytest.mark.benchmark(group="write_model")
119
+ @requires_pkg("arcticdb")
120
+ def test_benchmark_write_model_arcticdb(benchmark):
121
+ uri = "lmdb://./arctic_db/"
122
+ conn = pst.ArcticDBConnector("test", uri)
123
+ ml = build_model(conn)
124
+ _ = benchmark(write_model, conn=conn, ml=ml)
125
+
126
+
127
+ # %%
128
+
129
+
130
+ def write_model_nocheckts(conn, ml):
131
+ conn.set_check_model_series_values(False)
132
+ conn.add_model(ml, overwrite=True)
133
+
134
+
135
+ @pytest.mark.benchmark(group="write_model")
136
+ def test_benchmark_write_model_nocheckts_pas(benchmark):
137
+ conn = pst.PasConnector("test", "./tests/data/pas")
138
+ ml = build_model(conn)
139
+ _ = benchmark(write_model_nocheckts, conn=conn, ml=ml)
140
+
141
+
142
+ @pytest.mark.benchmark(group="write_model")
143
+ @requires_pkg("arcticdb")
144
+ def test_benchmark_write_model_nocheckts_arcticdb(benchmark):
145
+ uri = "lmdb://./arctic_db/"
146
+ conn = pst.ArcticDBConnector("test", uri)
147
+ ml = build_model(conn)
148
+ _ = benchmark(write_model_nocheckts, conn=conn, ml=ml)
149
+
150
+
151
+ # %% read model
152
+
153
+
154
+ def read_model(conn):
155
+ ml = conn.get_models("oseries_nb1")
156
+ return ml
157
+
158
+
159
+ # @pytest.mark.benchmark(group="read_model")
160
+ # def test_benchmark_read_model_dict(benchmark):
161
+ # conn = pst.DictConnector("test")
162
+ # _ = benchmark(read_model, conn=conn, ml=ml)
163
+
164
+
165
+ @pytest.mark.benchmark(group="read_model")
166
+ def test_benchmark_read_model_pas(benchmark):
167
+ conn = pst.PasConnector("test", "./tests/data/pas")
168
+ _ = benchmark(read_model, conn=conn)
169
+ pst.util.delete_pas_connector(conn)
170
+
171
+
172
+ @pytest.mark.benchmark(group="read_model")
173
+ @requires_pkg("arcticdb")
174
+ def test_benchmark_read_model_arcticdb(benchmark):
175
+ uri = "lmdb://./arctic_db/"
176
+ conn = pst.ArcticDBConnector("test", uri)
177
+ _ = benchmark(read_model, conn=conn)
178
+ pst.util.delete_arcticdb_connector(conn=conn)
179
+ import shutil
180
+
181
+ shutil.rmtree("./arctic_db/")
@@ -0,0 +1,85 @@
1
+ # ruff: noqa: D100 D103
2
+ import pytest
3
+ from pandas import Timestamp
4
+
5
+ import pastastore as pst
6
+
7
+
8
+ @pytest.mark.pastas150
9
+ def test_hpd_download_from_bro():
10
+ from pastastore.extensions import activate_hydropandas_extension
11
+
12
+ activate_hydropandas_extension()
13
+ pstore = pst.PastaStore()
14
+ pstore.hpd.download_bro_gmw(
15
+ extent=(117850, 118180, 439550, 439900), tmin="2022-01-01", tmax="2022-01-02"
16
+ )
17
+ assert pstore.n_oseries == 3
18
+
19
+
20
+ @pytest.mark.xfail(reason="KNMI is being flaky, so allow this test to xfail/xpass.")
21
+ @pytest.mark.pastas150
22
+ def test_hpd_download_precipitation_from_knmi():
23
+ from pastastore.extensions import activate_hydropandas_extension
24
+
25
+ activate_hydropandas_extension()
26
+ pstore = pst.PastaStore()
27
+ pstore.hpd.download_knmi_precipitation(
28
+ stns=[260], tmin="2022-01-01", tmax="2022-01-31"
29
+ )
30
+ assert pstore.n_stresses == 1
31
+
32
+
33
+ @pytest.mark.xfail(reason="KNMI is being flaky, so allow this test to xfail/xpass.")
34
+ @pytest.mark.pastas150
35
+ def test_hpd_download_evaporation_from_knmi():
36
+ from pastastore.extensions import activate_hydropandas_extension
37
+
38
+ activate_hydropandas_extension()
39
+ pstore = pst.PastaStore()
40
+ pstore.hpd.download_knmi_evaporation(
41
+ stns=[260], tmin="2022-01-01", tmax="2022-01-31"
42
+ )
43
+ assert pstore.n_stresses == 1
44
+
45
+
46
+ @pytest.mark.pastas150
47
+ def test_update_oseries():
48
+ from pastastore.extensions import activate_hydropandas_extension
49
+
50
+ activate_hydropandas_extension()
51
+
52
+ pstore = pst.PastaStore.from_zip("tests/data/test_hpd_update.zip")
53
+ pstore.hpd.update_bro_gmw(tmax="2024-01-31")
54
+ tmintmax = pstore.get_tmin_tmax("oseries")
55
+ assert tmintmax.loc["GMW000000036319_1", "tmax"] >= Timestamp("2024-01-30")
56
+ assert tmintmax.loc["GMW000000036327_1", "tmax"] >= Timestamp("2024-01-20")
57
+
58
+
59
+ @pytest.mark.xfail(reason="KNMI is being flaky, so allow this test to xfail/xpass.")
60
+ @pytest.mark.pastas150
61
+ def test_update_stresses():
62
+ from pastastore.extensions import activate_hydropandas_extension
63
+
64
+ activate_hydropandas_extension()
65
+
66
+ pstore = pst.PastaStore.from_zip("tests/data/test_hpd_update.zip")
67
+ pstore.hpd.update_knmi_meteo(tmax="2024-01-31", normalize_datetime_index=False)
68
+ tmintmax = pstore.get_tmin_tmax("stresses")
69
+ assert (tmintmax["tmax"] >= Timestamp("2024-01-31")).all()
70
+
71
+
72
+ @pytest.mark.xfail(reason="KNMI is being flaky, so allow this test to xfail/xpass.")
73
+ @pytest.mark.pastas150
74
+ def test_nearest_stresses():
75
+ from pastastore.extensions import activate_hydropandas_extension
76
+
77
+ activate_hydropandas_extension()
78
+
79
+ pstore = pst.PastaStore.from_zip("tests/data/test_hpd_update.zip")
80
+ pstore.hpd.download_nearest_knmi_precipitation(
81
+ "GMW000000036319_1", tmin="2024-01-01"
82
+ )
83
+ assert "RD_GROOT-AMMERS" in pstore.stresses_names
84
+ pstore.hpd.download_nearest_knmi_evaporation("GMW000000036319_1", tmin="2024-01-01")
85
+ assert "EV24_CABAUW-MAST" in pstore.stresses_names
@@ -0,0 +1,128 @@
1
+ # ruff: noqa: D100 D103
2
+ import pastas as ps
3
+ import pytest
4
+
5
+
6
+ def test_stressmodel_time_series_name(pstore):
7
+ pstore.get_stressmodel("evap1")
8
+
9
+
10
+ def test_stressmodel_override_settings(pstore):
11
+ sm = pstore.get_stressmodel("prec1", settings="evap")
12
+ assert sm.stress[0].settings["fill_nan"] == "interpolate"
13
+
14
+ # override settings by passing kind: bit weird, but good to check
15
+ sm = pstore.get_stressmodel("prec1", kind="evap")
16
+ assert sm.stress[0].settings["fill_nan"] == "interpolate"
17
+
18
+
19
+ def test_stressmodel_rfunc_kwargs(pstore):
20
+ sm = pstore.get_stressmodel("well1", rfunc=ps.Hantush, rfunc_kwargs={"quad": True})
21
+ assert sm.rfunc.quad
22
+
23
+
24
+ def test_stressmodel_nearest_kind_no_oseries_specified(pstore):
25
+ with pytest.raises(ValueError, match=r"Getting nearest stress*"):
26
+ pstore.get_stressmodel("nearest evap") # error oseries
27
+
28
+
29
+ def test_stressmodel_nearest_no_kind_specified(pstore):
30
+ with pytest.raises(ValueError, match=r"Could not parse stresses*"):
31
+ pstore.get_stressmodel("nearest", oseries="oseries1")
32
+
33
+ # also in dictionary mode
34
+ with pytest.raises(ValueError, match=r"Could not parse stresses*"):
35
+ pstore.get_stressmodel({"stress": ["nearest"]}, oseries="oseries1")
36
+
37
+
38
+ def test_stressmodel_nearest_kind(pstore):
39
+ # nearest kind
40
+ sm = pstore.get_stressmodel("nearest evap", oseries="oseries1")
41
+ assert sm.stress[0].name == "evap1"
42
+
43
+ # nearest kind in dict
44
+ sm = pstore.get_stressmodel({"stress": "nearest evap"}, oseries="oseries1")
45
+ assert sm.stress[0].name == "evap1"
46
+
47
+ # nearest and kind separate
48
+ sm = pstore.get_stressmodel({"stress": "nearest"}, kind="evap", oseries="oseries1")
49
+ assert sm.stress[0].name == "evap1"
50
+
51
+ # nearest in dict and kind separate
52
+ sm = pstore.get_stressmodel(
53
+ {"stress": ["nearest"]}, kind="evap", oseries="oseries1"
54
+ )
55
+ assert sm.stress[0].name == "evap1"
56
+
57
+
58
+ def test_recharge_model(pstore):
59
+ # test list of stress names
60
+ rm = pstore.get_stressmodel(["prec1", "evap1"], stressmodel="RechargeModel")
61
+ assert rm.stress[0].name == "prec1"
62
+ assert rm.stress[1].name == "evap1"
63
+
64
+ # test list of nearest
65
+ rm = pstore.get_stressmodel(
66
+ ["nearest prec", "nearest evap"],
67
+ stressmodel="RechargeModel",
68
+ oseries="oseries1",
69
+ )
70
+ assert rm.stress[0].name == "prec1"
71
+ assert rm.stress[1].name == "evap1"
72
+
73
+ # test dict, no kind specified
74
+ rm = pstore.get_stressmodel(
75
+ {"prec": "nearest", "evap": "nearest"},
76
+ stressmodel="RechargeModel",
77
+ oseries="oseries1",
78
+ )
79
+ assert rm.stress[0].name == "prec1"
80
+ assert rm.stress[1].name == "evap1"
81
+
82
+ # test list, bare nearest with kind specified
83
+ rm = pstore.get_stressmodel(
84
+ ["nearest", "nearest"],
85
+ kind=["prec", "evap"],
86
+ stressmodel="RechargeModel",
87
+ oseries="oseries1",
88
+ )
89
+ assert rm.stress[0].name == "prec1"
90
+ assert rm.stress[1].name == "evap1"
91
+
92
+
93
+ def test_wellmodel(pstore):
94
+ # test nearest <n> <kind>
95
+ wm = pstore.get_stressmodel(
96
+ "nearest 2 well",
97
+ stressmodel="WellModel",
98
+ oseries="oseries1",
99
+ )
100
+ assert wm.stress[0].name == "well1"
101
+ assert wm.stress[1].name == "well2"
102
+
103
+ # test nearest with no kind specified
104
+ wm = pstore.get_stressmodel(
105
+ "nearest 2",
106
+ stressmodel="WellModel",
107
+ oseries="oseries1",
108
+ )
109
+ assert wm.stress[0].name == "well1"
110
+ assert wm.stress[1].name == "well2"
111
+
112
+ # test nearest n, with non-existing kind specified
113
+ with pytest.raises(ValueError, match=r"Could not find stresses*"):
114
+ pstore.get_stressmodel(
115
+ "nearest 2",
116
+ kind="well2",
117
+ stressmodel="WellModel",
118
+ oseries="oseries1",
119
+ )
120
+
121
+ # test nearest n with n exceeded
122
+ with pytest.raises(ValueError, match=r"Could not find*"):
123
+ pstore.get_stressmodel(
124
+ "nearest 3",
125
+ kind="well",
126
+ stressmodel="WellModel",
127
+ oseries="oseries1",
128
+ )
@@ -1,15 +0,0 @@
1
- pastastore/__init__.py,sha256=l6zRpDO0j6MIrfdljCTbkF70bt-GFlPseBd4IlmaC-o,269
2
- pastastore/base.py,sha256=LLSg8CaKQDoRV0aOWQCSXTYQkBDH9t-xkhgLxiPxQ9Y,67333
3
- pastastore/connectors.py,sha256=YK3I_Jb2uNwzBQvN2VwZvmTRfPeUETW-4ddcFSWkHVw,16820
4
- pastastore/datasets.py,sha256=FHVfmKqb8beEs9NONsWrCoJY37BmlvFLSEQ1VAFmE8A,6415
5
- pastastore/plotting.py,sha256=t6gEeHVGzrwvM6q1l8V3OkklpU75O2Y4h6nKEHRWdjo,46416
6
- pastastore/store.py,sha256=xbv1prv6QqYj8M-2c77CT0ZQejjmNSldpuqu_M4WxoU,60906
7
- pastastore/styling.py,sha256=4xAY0FmhKrvmAGIuoMM7Uucww_X4KAxTpEoHlsxMldc,2280
8
- pastastore/util.py,sha256=iXHoGHfK6VDbUpufNsnzdV71oBVp-koZUD4VJj6MOwo,28250
9
- pastastore/version.py,sha256=lo0Pof9TIeRN4t2EblhGJbu04oz9H0QT_FafAlkwfDE,1205
10
- pastastore/yaml_interface.py,sha256=MddELxWe8_aqJRMUydOCbjoU1-ZodzxFKYnAaqJ5SqA,29947
11
- pastastore-1.7.0.dist-info/LICENSE,sha256=DtHftfUEm99KzgwLr3rQUTg8H3kAS0Z-p5WWJgLf_OY,1082
12
- pastastore-1.7.0.dist-info/METADATA,sha256=GX4vWuy91h3-vjiJxy0oHph1_wPCqeHJ8tTFK3lBiZU,8021
13
- pastastore-1.7.0.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
14
- pastastore-1.7.0.dist-info/top_level.txt,sha256=QKfonr1KJZN46MFsj8eGRBw9Mg-jO-HFvgE2orVX7Sk,11
15
- pastastore-1.7.0.dist-info/RECORD,,