Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/test_australia_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
gauge_ids = [
"403213",
]
variable = constants.DISCHARGE
variable = constants.DISCHARGE_DAILY_MEAN
# Fetch a recent period for testing
start_date = "2023-10-01"
end_date = "2024-03-31"
Expand All @@ -26,15 +26,15 @@
print(f"Time series from {data.index.min()} to {data.index.max()}")
plt.plot(
data.index,
data[constants.DISCHARGE],
data[constants.DISCHARGE_DAILY_MEAN],
label=gauge_id,
marker="o",
)
else:
print(f"No data found for {gauge_id}")

plt.xlabel(constants.TIME_INDEX)
plt.ylabel(f"{constants.DISCHARGE} (m3/s)")
plt.ylabel(f"{constants.DISCHARGE_DAILY_MEAN} (m3/s)")
plt.title(f"Australia River Discharge ({gauge_ids[0]} - Full Time Series)")
plt.legend()
plt.grid(True)
Expand Down
6 changes: 3 additions & 3 deletions examples/test_canada_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
gauge_ids = [
"01AD003",
]
variable = constants.DISCHARGE
variable = constants.DISCHARGE_DAILY_MEAN

plt.figure(figsize=(12, 6))

Expand All @@ -23,7 +23,7 @@
print(f"Time series from {data.index.min()} to {data.index.max()}")
plt.plot(
data.index,
data[constants.DISCHARGE],
data[constants.DISCHARGE_DAILY_MEAN],
label=gauge_id,
marker=".",
linestyle="-",
Expand All @@ -33,7 +33,7 @@

if "data" in locals() and not data.empty:
plt.xlabel(constants.TIME_INDEX)
plt.ylabel(f"{constants.DISCHARGE} (m3/s)")
plt.ylabel(f"{constants.DISCHARGE_DAILY_MEAN} (m3/s)")
plt.title(f"Canada River Discharge ({gauge_ids[0]} - Full Time Series)")
plt.legend()
plt.grid(True)
Expand Down
6 changes: 3 additions & 3 deletions examples/test_chile_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
gauge_ids = [
"01201005",
]
variable = constants.DISCHARGE
variable = constants.DISCHARGE_DAILY_MEAN

plt.figure(figsize=(12, 6))

Expand All @@ -23,7 +23,7 @@
print(f"Time series from {data.index.min()} to {data.index.max()}")
plt.plot(
data.index,
data[constants.DISCHARGE],
data[constants.DISCHARGE_DAILY_MEAN],
label=gauge_id,
marker=".",
linestyle="-",
Expand All @@ -33,7 +33,7 @@

if "data" in locals() and not data.empty:
plt.xlabel(constants.TIME_INDEX)
plt.ylabel(f"{constants.DISCHARGE} (m3/s)")
plt.ylabel(f"{constants.DISCHARGE_DAILY_MEAN} (m3/s)")
plt.title(f"Chile River Discharge ({gauge_ids[0]} - Full Time Series)")
plt.legend()
plt.grid(True)
Expand Down
6 changes: 3 additions & 3 deletions examples/test_france_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
gauge_ids = [
"K027401001",
]
variable = constants.DISCHARGE
variable = constants.STAGE_DAILY_MAX

plt.figure(figsize=(12, 6))

Expand All @@ -23,7 +23,7 @@
print(f"Time series from {data.index.min()} to {data.index.max()}")
plt.plot(
data.index,
data[constants.DISCHARGE],
data[variable],
label=gauge_id,
marker=".",
linestyle="-",
Expand All @@ -34,7 +34,7 @@

if not data.empty:
plt.xlabel(constants.TIME_INDEX)
plt.ylabel(f"{constants.DISCHARGE} (m3/s)")
plt.ylabel(f"{variable} (m3/s)")
plt.title(f"France River Discharge ({gauge_ids[0]} - Full Time Series)")
plt.legend()
plt.grid(True)
Expand Down
6 changes: 3 additions & 3 deletions examples/test_japan_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
gauge_ids = [
"301011281104010",
]
variable = constants.DISCHARGE
variable = constants.DISCHARGE_DAILY_MEAN
start_date = "2019-01-01"
end_date = "2019-12-31" # Fetching a few months to test

Expand All @@ -25,15 +25,15 @@
print(f"Time series from {data.index.min()} to {data.index.max()}")
plt.plot(
data.index,
data[constants.DISCHARGE],
data[constants.DISCHARGE_DAILY_MEAN],
label=gauge_id,
marker="o",
)
else:
print(f"No data found for {gauge_id}")

plt.xlabel(constants.TIME_INDEX)
plt.ylabel(f"{constants.DISCHARGE} (m3/s)")
plt.ylabel(f"{constants.DISCHARGE_DAILY_MEAN} (m3/s)")
plt.title("Japan River Discharge - Full Time Series")
plt.legend()
plt.grid(True)
Expand Down
2 changes: 1 addition & 1 deletion examples/test_poland_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
gauge_ids = [
"149180020", # CHAŁUPKI on Odra
]
variables = [constants.DISCHARGE, constants.STAGE, constants.WATER_TEMPERATURE]
variables = [constants.DISCHARGE_DAILY_MEAN, constants.STAGE_DAILY_MEAN, constants.WATER_TEMPERATURE_DAILY_MEAN]
# Fetch a period from Simon's example
start_date = "1999-01-01"
end_date = "2001-12-31"
Expand Down
6 changes: 3 additions & 3 deletions examples/test_slovenia_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
gauge_ids = [
"1020", # Cmurek on Mura
]
variable = constants.DISCHARGE
variable = constants.DISCHARGE_DAILY_MEAN

plt.figure(figsize=(12, 6))

Expand All @@ -23,7 +23,7 @@
print(f"Time series from {data.index.min()} to {data.index.max()}")
plt.plot(
data.index,
data[constants.DISCHARGE],
data[constants.DISCHARGE_DAILY_MEAN],
label=gauge_id,
marker="o",
)
Expand All @@ -32,7 +32,7 @@

if "data" in locals() and not data.empty:
plt.xlabel(constants.TIME_INDEX)
plt.ylabel(f"{constants.DISCHARGE} (m3/s)")
plt.ylabel(f"{constants.DISCHARGE_DAILY_MEAN} (m3/s)")
plt.title(f"Slovenia River Discharge ({gauge_ids[0]} - Full Time Series)")
plt.legend()
plt.grid(True)
Expand Down
8 changes: 4 additions & 4 deletions examples/test_southafrica_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
gauge_ids = [
"X3H023",
]
variable = constants.DISCHARGE
variable = constants.DISCHARGE_DAILY_MEAN

plt.figure(figsize=(12, 6))

fetcher = SouthAfricaFetcher()
for gauge_id in gauge_ids:
print(f"Fetching data for {gauge_id}...")
data = fetcher.get_data(gauge_id=gauge_id, variable=variable)
data = fetcher.get_data(gauge_id=gauge_id, variable=variable, start_date="2000-01-01", end_date="2005-12-31")
if not data.empty:
print(f"Data for {gauge_id}:")
print(data.head())
print(f"Time series from {data.index.min()} to {data.index.max()}")
plt.plot(
data.index,
data[constants.DISCHARGE],
data[constants.DISCHARGE_DAILY_MEAN],
label=gauge_id,
marker=".",
linestyle="-",
Expand All @@ -33,7 +33,7 @@

if "data" in locals() and not data.empty:
plt.xlabel(constants.TIME_INDEX)
plt.ylabel(f"{constants.DISCHARGE} (m3/s)")
plt.ylabel(f"{constants.DISCHARGE_DAILY_MEAN} (m3/s)")
plt.title(f"South Africa River Discharge ({gauge_ids[0]} - Full Time Series)")
plt.legend()
plt.grid(True)
Expand Down
6 changes: 3 additions & 3 deletions examples/test_uk_ea_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
]
start_date = "2024-01-01"
end_date = "2024-01-31"
variable = constants.DISCHARGE
variable = constants.DISCHARGE_DAILY_MEAN

plt.figure(figsize=(12, 6))

Expand All @@ -20,14 +20,14 @@
print(data.head())
plt.plot(
data.index,
data[constants.DISCHARGE],
data[constants.DISCHARGE_DAILY_MEAN],
label=gauge_id.split("/")[-1],
)
else:
print(f"No data found for {gauge_id}")

plt.xlabel(constants.TIME_INDEX)
plt.ylabel(f"{constants.DISCHARGE} (m3/s)")
plt.ylabel(f"{constants.DISCHARGE_DAILY_MEAN} (m3/s)")
plt.title("UK River Discharge - Full Time Series")
plt.legend()
plt.grid(True)
Expand Down
6 changes: 3 additions & 3 deletions examples/test_uk_nrfa_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
gauge_ids = [
"1001", # Sample gauge from issue #34
]
variable = constants.DISCHARGE
variable = constants.DISCHARGE_DAILY_MEAN
start_date = "2022-01-01"
end_date = "2022-01-31"

Expand All @@ -34,7 +34,7 @@
print(f"Time series from {data.index.min()} to {data.index.max()}")
plt.plot(
data.index,
data[constants.DISCHARGE],
data[constants.DISCHARGE_DAILY_MEAN],
label=gauge_id,
marker=".",
linestyle="-",
Expand All @@ -44,7 +44,7 @@

if "data" in locals() and not data.empty:
plt.xlabel(constants.TIME_INDEX)
plt.ylabel(f"{constants.DISCHARGE} (m3/s)")
plt.ylabel(f"{constants.DISCHARGE_DAILY_MEAN} (m3/s)")
plt.title(f"UK NRFA River Discharge ({gauge_ids[0]} - {start_date} to {end_date})")
plt.legend()
plt.grid(True)
Expand Down
6 changes: 3 additions & 3 deletions examples/test_usa_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
gauge_ids = [
"07374000",
]
variable = constants.DISCHARGE
variable = constants.DISCHARGE_DAILY_MEAN
# Fetch a recent period for testing
start_date = "1950-01-01"
end_date = None
Expand All @@ -26,15 +26,15 @@
print(f"Time series from {data.index.min()} to {data.index.max()}")
plt.plot(
data.index,
data[constants.DISCHARGE],
data[constants.DISCHARGE_DAILY_MEAN],
label=gauge_id,
marker="o",
)
else:
print(f"No data found for {gauge_id}")

plt.xlabel(constants.TIME_INDEX)
plt.ylabel(f"{constants.DISCHARGE} (m3/s)")
plt.ylabel(f"{constants.DISCHARGE_DAILY_MEAN} (m3/s)")
plt.title(f"USA River Discharge ({gauge_ids[0]} - 1950 to Present)")
plt.legend()
plt.grid(True)
Expand Down
6 changes: 3 additions & 3 deletions rivretrieve/australia.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_gauge_ids() -> pd.DataFrame:

@staticmethod
def get_available_variables() -> tuple[str, ...]:
return (constants.DISCHARGE, constants.STAGE)
return (constants.DISCHARGE_DAILY_MEAN, constants.STAGE_DAILY_MEAN)

def _make_bom_request(self, params: Dict[str, Any]) -> Any:
"""Helper function to make requests to the BoM API."""
Expand All @@ -51,10 +51,10 @@ def _make_bom_request(self, params: Dict[str, Any]) -> Any:

def _get_timeseries_id(self, gauge_id: str, variable: str) -> Optional[str]:
"""Retrieves the timeseries ID for the given site and variable."""
if variable == constants.STAGE:
if variable == constants.STAGE_DAILY_MEAN:
bom_variable = "Water Course Level"
# ts_name = "H.Merged.DailyMean"
elif variable == constants.DISCHARGE:
elif variable == constants.DISCHARGE_DAILY_MEAN:
bom_variable = "Water Course Discharge"
# ts_name = "Q.Merged.DailyMean"
else:
Expand Down
6 changes: 3 additions & 3 deletions rivretrieve/canada.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_gauge_ids() -> pd.DataFrame:

@staticmethod
def get_available_variables() -> tuple[str, ...]:
return (constants.DISCHARGE, constants.STAGE)
return (constants.DISCHARGE_DAILY_MEAN, constants.STAGE_DAILY_MEAN)

def _find_latest_hydat_link(self) -> Optional[str]:
s = utils.requests_retry_session()
Expand Down Expand Up @@ -130,8 +130,8 @@ def get_data(
raise ValueError(f"Unsupported variable: {variable}")

var_map = {
constants.DISCHARGE: {"table": "DLY_FLOWS", "prefix": "FLOW"},
constants.STAGE: {"table": "DLY_LEVELS", "prefix": "LEVEL"},
constants.DISCHARGE_DAILY_MEAN: {"table": "DLY_FLOWS", "prefix": "FLOW"},
constants.STAGE_DAILY_MEAN: {"table": "DLY_LEVELS", "prefix": "LEVEL"},
}

table = var_map[variable]["table"]
Expand Down
11 changes: 5 additions & 6 deletions rivretrieve/chile.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def get_gauge_ids() -> pd.DataFrame:

@staticmethod
def get_available_variables() -> tuple[str, ...]:
return (constants.DISCHARGE,)
return (constants.DISCHARGE_DAILY_MEAN,)

def _download_data(
self,
Expand All @@ -33,9 +33,8 @@ def _download_data(
start_date: str,
end_date: str,
) -> Optional[pd.DataFrame]:
"""Downloads the raw CSV data by first finding the download link."""
if variable != constants.DISCHARGE:
logger.warning(f"ChileFetcher only supports variable='{constants.DISCHARGE}'")
if variable != constants.DISCHARGE_DAILY_MEAN:
logger.warning(f"ChileFetcher only supports variable='{constants.DISCHARGE_DAILY_MEAN}'")
return None

# This long URL was extracted from the R code
Expand Down Expand Up @@ -118,8 +117,8 @@ def get_data(
end_date: Optional[str] = None,
) -> pd.DataFrame:
"""Fetches and parses Chilean river gauge data."""
if variable != constants.DISCHARGE:
logger.warning(f"ChileFetcher only supports variable='{constants.DISCHARGE}'")
if variable != constants.DISCHARGE_DAILY_MEAN:
logger.warning(f"ChileFetcher only supports variable='{constants.DISCHARGE_DAILY_MEAN}'")
return pd.DataFrame(columns=[constants.TIME_INDEX, variable])

start_date = utils.format_start_date(start_date)
Expand Down
Loading