Skip to content

Commit fb8d851

Browse files
authored
Add Fetcher for Norway (#70)
* Add fetcher for Norway * Declare more columns as numeric * Formatting * Add unit tests * Add Norwary fetcher to docs * Change class init to accept api_token. Helps fixing test. * Fix data loading in test * Added support for more variables * Add hourly/instant resolution * Formatting
1 parent 1cf26e1 commit fb8d851

11 files changed

Lines changed: 5933 additions & 0 deletions

File tree

docs/api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ API Reference
1515
fetchers/czech
1616
fetchers/france
1717
fetchers/japan
18+
fetchers/norway
1819
fetchers/poland
1920
fetchers/portugal
2021
fetchers/slovenia

docs/fetchers/norway.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Norway Fetcher
2+
==============
3+
4+
.. automodule:: rivretrieve.norway
5+
:members:

examples/test_norway_fetcher.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import logging
2+
3+
import matplotlib.pyplot as plt
4+
5+
from rivretrieve import NorwayFetcher, constants
6+
7+
logging.basicConfig(level=logging.INFO)
8+
9+
# Replace with a valid Norwegian gauge ID, e.g., "12.210.0"
10+
gauge_ids = [
11+
"1.200.0",
12+
]
13+
variables = [
14+
constants.DISCHARGE_INSTANT,
15+
constants.STAGE_INSTANT,
16+
constants.WATER_TEMPERATURE_INSTANT,
17+
]
18+
19+
fetcher = NorwayFetcher()
20+
21+
for variable in variables:
22+
plt.figure(figsize=(12, 6))
23+
has_data = False
24+
for gauge_id in gauge_ids:
25+
print(f"Fetching {variable} for {gauge_id}...")
26+
# Fetching last 5 years for testing
27+
data = fetcher.get_data(gauge_id=gauge_id, variable=variable, start_date="2020-01-01", end_date="2021-12-31")
28+
if not data.empty:
29+
print(f"Data for {gauge_id} ({variable}):")
30+
print(data.head())
31+
print(f"Time series from {data.index.min()} to {data.index.max()}")
32+
plt.plot(
33+
data.index,
34+
data[variable],
35+
label=f"{gauge_id} - {variable}",
36+
marker=".",
37+
linestyle="-",
38+
)
39+
plt.xlim(data.index.min(), data.index.max())
40+
has_data = True
41+
else:
42+
print(f"No data found for {gauge_id} ({variable})")
43+
44+
if has_data:
45+
plt.xlabel(constants.TIME_INDEX)
46+
plt.ylabel(variable)
47+
plt.title(f"Norway River Data ({gauge_ids[0]})")
48+
plt.legend()
49+
plt.grid(True)
50+
plt.tight_layout()
51+
plot_path = f"norway_{variable}_plot.png"
52+
plt.savefig(plot_path)
53+
print(f"Plot saved to {plot_path}")
54+
else:
55+
print(f"No data to plot for {variable}.")
56+
57+
print("Test finished.")

rivretrieve/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from .czech import CzechFetcher
99
from .france import FranceFetcher
1010
from .japan import JapanFetcher
11+
from .norway import NorwayFetcher
1112
from .poland import PolandFetcher
1213
from .portugal import PortugalFetcher
1314
from .slovenia import SloveniaFetcher

rivretrieve/cached_site_data/norway_sites.csv

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

rivretrieve/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
# List of temporal resolutions.
2424
DAILY = "daily"
25+
HOURLY = "hourly"
2526
INSTANTANEOUS = "instantaneous"
2627

2728
# List of temporal aggregrations.
@@ -36,16 +37,20 @@
3637
DISCHARGE_DAILY_MEAN = f"{DISCHARGE}_{DAILY}_{_MEAN}"
3738
DISCHARGE_DAILY_MAX = f"{DISCHARGE}_{DAILY}_{_MAX}"
3839
DISCHARGE_DAILY_MIN = f"{DISCHARGE}_{DAILY}_{_MIN}"
40+
DISCHARGE_HOURLY_MEAN = f"{DISCHARGE}_{HOURLY}_{_MEAN}"
3941
DISCHARGE_INSTANT = f"{DISCHARGE}_{INSTANTANEOUS}"
4042

4143
# Stage.
4244
STAGE_DAILY_MEAN = f"{STAGE}_{DAILY}_{_MEAN}"
4345
STAGE_DAILY_MAX = f"{STAGE}_{DAILY}_{_MAX}"
4446
STAGE_DAILY_MIN = f"{STAGE}_{DAILY}_{_MIN}"
47+
STAGE_HOURLY_MEAN = f"{STAGE}_{HOURLY}_{_MEAN}"
4548
STAGE_INSTANT = f"{STAGE}_{INSTANTANEOUS}"
4649

4750
# Water temperature.
4851
WATER_TEMPERATURE_DAILY_MEAN = f"{_WATER_TEMPERATURE}_{DAILY}_{_MEAN}"
52+
WATER_TEMPERATURE_HOURLY_MEAN = f"{_WATER_TEMPERATURE}_{HOURLY}_{_MEAN}"
53+
WATER_TEMPERATURE_INSTANT = f"{_WATER_TEMPERATURE}_{INSTANTANEOUS}"
4954

5055
# Precipitation
5156
CATCHMENT_PRECIPITATION_DAILY_SUM = f"{_CATCHMENT_PRECIPITATION}_{DAILY}_{_SUM}"

0 commit comments

Comments
 (0)