Skip to content

Commit aa89e45

Browse files
authored
Add Portugal fetcher, fixes #40 (#52)
* Refactor: Rename method that loads cached sites file * Add fetcher for portugal, fixes #40 * Shorten portugal test data file
1 parent 2138fb0 commit aa89e45

5 files changed

Lines changed: 1104 additions & 0 deletions

File tree

examples/test_portugal_fetcher.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import logging
2+
3+
import matplotlib.pyplot as plt
4+
5+
from rivretrieve import PortugalFetcher, constants
6+
7+
logging.basicConfig(level=logging.INFO)
8+
9+
# Example gauge IDs from the SITE_MAP in portugal.py
10+
gauge_ids = [
11+
"19B/01H", # A known gauge ID from the map
12+
]
13+
variables = [constants.STAGE_DAILY_MEAN]
14+
start_date = "1980-01-01"
15+
end_date = None # Defaults to today
16+
17+
fetcher = PortugalFetcher()
18+
19+
for variable in variables:
20+
plt.figure(figsize=(12, 6))
21+
print(f"\n--- Testing variable: {variable} ---")
22+
for gauge_id in gauge_ids:
23+
print(f"Fetching {variable} for {gauge_id} from {start_date} to {end_date}...")
24+
data = fetcher.get_data(gauge_id=gauge_id, variable=variable, start_date=start_date, end_date=end_date)
25+
if not data.empty:
26+
print(f"Data for {gauge_id}:")
27+
print(data.head())
28+
print(f"Time series from {data.index.min()} to {data.index.max()}")
29+
plt.plot(
30+
data.index,
31+
data[variable],
32+
label=f"{gauge_id} - {variable}",
33+
marker=".",
34+
linestyle="-",
35+
)
36+
else:
37+
print(f"No {variable} data found for {gauge_id}")
38+
39+
if plt.gca().has_data():
40+
plt.xlabel(constants.TIME_INDEX)
41+
plt.ylabel(variable)
42+
plt.title(f"Portugal River Data ({start_date} to {end_date})")
43+
plt.legend()
44+
plt.grid(True)
45+
plt.tight_layout()
46+
plot_path = f"portugal_{variable}_plot.png"
47+
plt.savefig(plot_path)
48+
print(f"Plot saved to {plot_path}")
49+
else:
50+
print(f"No data to plot for {variable}.")
51+
52+
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 .france import FranceFetcher
99
from .japan import JapanFetcher
1010
from .poland import PolandFetcher
11+
from .portugal import PortugalFetcher
1112
from .slovenia import SloveniaFetcher
1213
from .southafrica import SouthAfricaFetcher
1314
from .uk_ea import UKEAFetcher

0 commit comments

Comments
 (0)