Skip to content

Commit b1df5b7

Browse files
committed
Add Switzerland fetcher
1 parent 3ece6c9 commit b1df5b7

12 files changed

Lines changed: 1461 additions & 1 deletion

docs/api.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ API Reference
2323
fetchers/slovenia
2424
fetchers/southafrica
2525
fetchers/spain
26+
fetchers/switzerland
2627
fetchers/uk_ea
2728
fetchers/uk_nrfa
28-
fetchers/usa
29+
fetchers/usa

docs/fetchers/switzerland.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Switzerland Fetcher
2+
===================
3+
4+
.. automodule:: rivretrieve.switzerland
5+
:members:
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import logging
2+
import os
3+
4+
import matplotlib.pyplot as plt
5+
6+
from rivretrieve import SwitzerlandFetcher, constants
7+
8+
logging.basicConfig(level=logging.INFO)
9+
10+
influx_token = os.environ.get("RIVRETRIEVE_SWITZERLAND_INFLUX_TOKEN")
11+
if not influx_token:
12+
raise SystemExit("Set RIVRETRIEVE_SWITZERLAND_INFLUX_TOKEN before running this example.")
13+
14+
gauge_id = "2016"
15+
variable = constants.DISCHARGE_DAILY_MEAN
16+
start_date = "2020-01-01"
17+
end_date = "2020-01-31"
18+
19+
fetcher = SwitzerlandFetcher(influx_token=influx_token)
20+
data = fetcher.get_data(
21+
gauge_id=gauge_id,
22+
variable=variable,
23+
start_date=start_date,
24+
end_date=end_date,
25+
)
26+
27+
if data.empty:
28+
print(f"No data found for gauge {gauge_id}, variable {variable}")
29+
else:
30+
print(data.head())
31+
print(f"Fetched {len(data)} rows from {data.index.min()} to {data.index.max()}")
32+
33+
plt.figure(figsize=(12, 6))
34+
plt.plot(data.index, data[variable], label=f"{gauge_id} - {variable}", linewidth=1.8)
35+
plt.xlabel(constants.TIME_INDEX)
36+
plt.ylabel("Discharge (m3/s)")
37+
plt.title(f"Switzerland historical series for gauge {gauge_id}")
38+
plt.grid(True, alpha=0.3)
39+
plt.legend()
40+
plt.tight_layout()
41+
42+
output_path = "switzerland_historical_plot.png"
43+
plt.savefig(output_path, dpi=150)
44+
print(f"Saved plot to {output_path}")
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import logging
2+
import os
3+
4+
import matplotlib.pyplot as plt
5+
6+
from rivretrieve import SwitzerlandFetcher, constants
7+
8+
logging.basicConfig(level=logging.INFO)
9+
10+
influx_token = os.environ.get("RIVRETRIEVE_SWITZERLAND_INFLUX_TOKEN")
11+
if not influx_token:
12+
raise SystemExit("Set RIVRETRIEVE_SWITZERLAND_INFLUX_TOKEN before running this example.")
13+
14+
gauge_id = "2016"
15+
variables = [
16+
constants.DISCHARGE_DAILY_MEAN,
17+
constants.WATER_TEMPERATURE_DAILY_MEAN,
18+
]
19+
start_date = "2026-02-01"
20+
end_date = "2026-02-07"
21+
22+
fetcher = SwitzerlandFetcher(influx_token=influx_token)
23+
24+
for variable in variables:
25+
data = fetcher.get_data(gauge_id=gauge_id, variable=variable, start_date=start_date, end_date=end_date)
26+
if data.empty:
27+
print(f"No data found for {gauge_id} ({variable})")
28+
continue
29+
30+
print(data.head())
31+
plt.figure(figsize=(12, 6))
32+
plt.plot(data.index, data[variable], label=f"{gauge_id} - {variable}")
33+
plt.xlabel(constants.TIME_INDEX)
34+
plt.ylabel(variable)
35+
plt.title(f"Switzerland River Data ({gauge_id})")
36+
plt.legend()
37+
plt.grid(True)
38+
plt.tight_layout()
39+
plot_path = f"switzerland_{variable}_plot.png"
40+
plt.savefig(plot_path)
41+
print(f"Plot saved to {plot_path}")

rivretrieve/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from .slovenia import SloveniaFetcher
1717
from .southafrica import SouthAfricaFetcher
1818
from .spain import SpainFetcher
19+
from .switzerland import SwitzerlandFetcher
1920
from .uk_ea import UKEAFetcher
2021
from .uk_nrfa import UKNRFAFetcher
2122
from .usa import USAFetcher

rivretrieve/cached_site_data/switzerland_sites.csv

Lines changed: 247 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)