Skip to content

Commit 24a65df

Browse files
authored
Add CHMI fetcher, fixes #47 (#55)
1 parent 88b835d commit 24a65df

6 files changed

Lines changed: 1156 additions & 0 deletions

File tree

examples/test_czech_fetcher.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import logging
2+
3+
import matplotlib.pyplot as plt
4+
5+
from rivretrieve import CzechFetcher, constants
6+
7+
logging.basicConfig(level=logging.INFO)
8+
9+
gauge_ids = [
10+
"0-203-1-016000", # Example gauge_id from issue #47
11+
]
12+
variable = constants.DISCHARGE_DAILY_MEAN
13+
start_date = "2020-01-01"
14+
end_date = "2020-01-31"
15+
16+
plt.figure(figsize=(12, 6))
17+
18+
fetcher = CzechFetcher()
19+
for gauge_id in gauge_ids:
20+
print(f"Fetching {variable} for {gauge_id} from {start_date} to {end_date}...")
21+
data = fetcher.get_data(gauge_id=gauge_id, variable=variable, start_date=start_date, end_date=end_date)
22+
if not data.empty:
23+
print(f"Data for {gauge_id}:")
24+
print(data.head())
25+
print(f"Time series from {data.index.min()} to {data.index.max()}")
26+
plt.plot(
27+
data.index,
28+
data[variable],
29+
label=gauge_id,
30+
marker=".",
31+
linestyle="-",
32+
)
33+
else:
34+
print(f"No data found for {gauge_id}")
35+
36+
if "data" in locals() and not data.empty:
37+
plt.xlabel(constants.TIME_INDEX)
38+
plt.ylabel(f"{variable} (m3/s)")
39+
plt.title(f"Czech River Discharge ({gauge_ids[0]} - {start_date} to {end_date})")
40+
plt.legend()
41+
plt.grid(True)
42+
plt.tight_layout()
43+
plot_path = "czech_discharge_plot.png"
44+
plt.savefig(plot_path)
45+
print(f"Plot saved to {plot_path}")
46+
else:
47+
print("No data to plot.")
48+
49+
print("Test finished.")

rivretrieve/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from .brazil import BrazilFetcher
66
from .canada import CanadaFetcher
77
from .chile import ChileFetcher
8+
from .czech import CzechFetcher
89
from .france import FranceFetcher
910
from .japan import JapanFetcher
1011
from .poland import PolandFetcher

0 commit comments

Comments
 (0)