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 rivretrieve/australia.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class AustraliaFetcher(base.RiverDataFetcher):
BOM_URL = "http://www.bom.gov.au/waterdata/services"

@staticmethod
def get_gauge_ids() -> pd.DataFrame:
"""Retrieves a DataFrame of available Australian gauge IDs."""
return utils.load_sites_csv("australia")
def get_cached_metadata() -> pd.DataFrame:
"""Retrieves a DataFrame of available Australian gauge IDs and metadata."""
return utils.load_cached_metadata_csv("australia")

@staticmethod
def get_available_variables() -> tuple[str, ...]:
Expand Down
8 changes: 2 additions & 6 deletions rivretrieve/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,8 @@ def get_data(

@staticmethod
@abc.abstractmethod
def get_gauge_ids() -> pd.DataFrame:
"""Retrieves a DataFrame of available gauge IDs.

Returns:
A pandas DataFrame containing gauge ID information.
"""
def get_cached_metadata() -> pd.DataFrame:
"""Retrieves a DataFrame of available gauge IDs and metadata from a cached file."""
pass

def get_metadata(self) -> pd.DataFrame:
Expand Down
6 changes: 3 additions & 3 deletions rivretrieve/brazil.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def __init__(self, username: Optional[str] = None, password: Optional[str] = Non
)

@staticmethod
def get_gauge_ids() -> pd.DataFrame:
"""Retrieves a DataFrame of available Brazilian gauge IDs."""
return utils.load_sites_csv("brazil")
def get_cached_metadata() -> pd.DataFrame:
"""Retrieves a DataFrame of available Brazilian gauge IDs and metadata."""
return utils.load_cached_metadata_csv("brazil")

@staticmethod
def get_available_variables() -> tuple[str, ...]:
Expand Down
6 changes: 3 additions & 3 deletions rivretrieve/canada.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class CanadaFetcher(base.RiverDataFetcher):
HYDAT_PATH = DATA_DIR / "Hydat.sqlite3"

@staticmethod
def get_gauge_ids() -> pd.DataFrame:
"""Retrieves a DataFrame of available Canadian gauge IDs."""
return utils.load_sites_csv("canada")
def get_cached_metadata() -> pd.DataFrame:
"""Retrieves a DataFrame of available Canadian gauge IDs and metadata."""
return utils.load_cached_metadata_csv("canada")

@staticmethod
def get_available_variables() -> tuple[str, ...]:
Expand Down
6 changes: 3 additions & 3 deletions rivretrieve/chile.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class ChileFetcher(base.RiverDataFetcher):
"""Fetches river gauge data from Chile's CR2 explorador."""

@staticmethod
def get_gauge_ids() -> pd.DataFrame:
"""Retrieves a DataFrame of available Chilean gauge IDs."""
return utils.load_sites_csv("chile")
def get_cached_metadata() -> pd.DataFrame:
"""Retrieves a DataFrame of available Chilean gauge IDs and metadata."""
return utils.load_cached_metadata_csv("chile")

@staticmethod
def get_available_variables() -> tuple[str, ...]:
Expand Down
6 changes: 3 additions & 3 deletions rivretrieve/france.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class FranceFetcher(base.RiverDataFetcher):
BASE_URL = "https://hubeau.eaufrance.fr/api/v2/hydrometrie/obs_elab"

@staticmethod
def get_gauge_ids() -> pd.DataFrame:
"""Retrieves a DataFrame of available French gauge IDs."""
return utils.load_sites_csv("french") # Note: CSV file name is french_sites.csv
def get_cached_metadata() -> pd.DataFrame:
"""Retrieves a DataFrame of available French gauge IDs and metadata."""
return utils.load_cached_metadata_csv("french") # Note: CSV file name is french_sites.csv

@staticmethod
def get_available_variables() -> tuple[str, ...]:
Expand Down
6 changes: 3 additions & 3 deletions rivretrieve/japan.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class JapanFetcher(base.RiverDataFetcher):
BASE_URL = "http://www1.river.go.jp/cgi-bin/DspWaterData.exe"

@staticmethod
def get_gauge_ids() -> pd.DataFrame:
"""Retrieves a DataFrame of available Japanese gauge IDs."""
return utils.load_sites_csv("japan")
def get_cached_metadata() -> pd.DataFrame:
"""Retrieves a DataFrame of available Japanese gauge IDs and metadata."""
return utils.load_cached_metadata_csv("japan")

@staticmethod
def get_available_variables() -> tuple[str, ...]:
Expand Down
6 changes: 3 additions & 3 deletions rivretrieve/poland.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class PolandFetcher(base.RiverDataFetcher):
CACHE_FILE = Path(os.path.dirname(__file__)) / "data" / "poland.zarr"

@staticmethod
def get_gauge_ids() -> pd.DataFrame:
"""Retrieves a DataFrame of available Polish gauge IDs."""
return utils.load_sites_csv("poland")
def get_cached_metadata() -> pd.DataFrame:
"""Retrieves a DataFrame of available Polish gauge IDs and metadata."""
return utils.load_cached_metadata_csv("poland")

@staticmethod
def get_available_variables() -> tuple[str, ...]:
Expand Down
6 changes: 3 additions & 3 deletions rivretrieve/slovenia.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class SloveniaFetcher(base.RiverDataFetcher):
BASE_URL = "https://vode.arso.gov.si/hidarhiv/pov_arhiv_tab.php"

@staticmethod
def get_gauge_ids() -> pd.DataFrame:
"""Retrieves a DataFrame of available Slovenian gauge IDs."""
return utils.load_sites_csv("slovenia")
def get_cached_metadata() -> pd.DataFrame:
"""Retrieves a DataFrame of available Slovenian gauge IDs and metadata."""
return utils.load_cached_metadata_csv("slovenia")

@staticmethod
def get_available_variables() -> tuple[str, ...]:
Expand Down
6 changes: 3 additions & 3 deletions rivretrieve/southafrica.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class SouthAfricaFetcher(base.RiverDataFetcher):
BASE_URL = "https://www.dws.gov.za/Hydrology/Verified/HyData.aspx"

@staticmethod
def get_gauge_ids() -> pd.DataFrame:
"""Retrieves a DataFrame of available South African gauge IDs."""
return utils.load_sites_csv("southAfrican")
def get_cached_metadata() -> pd.DataFrame:
"""Retrieves a DataFrame of available South African gauge IDs and metadata."""
return utils.load_cached_metadata_csv("southAfrican")

@staticmethod
def get_available_variables() -> tuple[str, ...]:
Expand Down
6 changes: 3 additions & 3 deletions rivretrieve/uk_ea.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class UKEAFetcher(base.RiverDataFetcher):
}

@staticmethod
def get_gauge_ids() -> pd.DataFrame:
"""Retrieves a DataFrame of available UK gauge IDs."""
return utils.load_sites_csv("uk_ea")
def get_cached_metadata() -> pd.DataFrame:
"""Retrieves a DataFrame of available UK gauge IDs and metadata."""
return utils.load_cached_metadata_csv("uk_ea")

@staticmethod
def get_available_variables() -> tuple[str, ...]:
Expand Down
4 changes: 2 additions & 2 deletions rivretrieve/uk_nrfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class UKNRFAFetcher(base.RiverDataFetcher):
}

@staticmethod
def get_gauge_ids() -> pd.DataFrame:
def get_cached_metadata() -> pd.DataFrame:
"""Retrieves a DataFrame of available NRFA gauge IDs from the cached CSV."""
return utils.load_sites_csv("uk_nrfa")
return utils.load_cached_metadata_csv("uk_nrfa")

def get_metadata(self) -> pd.DataFrame:
"""Fetches site metadata from the NRFA API and renames columns."""
Expand Down
6 changes: 3 additions & 3 deletions rivretrieve/usa.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class USAFetcher(base.RiverDataFetcher):
"""Fetches river gauge data from USGS NWIS."""

@staticmethod
def get_gauge_ids() -> pd.DataFrame:
"""Retrieves a DataFrame of available USA gauge IDs."""
return utils.load_sites_csv("usa")
def get_cached_metadata() -> pd.DataFrame:
"""Retrieves a DataFrame of available USA gauge IDs and metadata."""
return utils.load_cached_metadata_csv("usa")

@staticmethod
def get_available_variables() -> tuple[str, ...]:
Expand Down
7 changes: 3 additions & 4 deletions rivretrieve/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

logger = logging.getLogger(__name__)

DEFAULT_HEADERS = {"User-Agent": "Mozilla/5.0"}


def format_start_date(start_date: Optional[str]) -> str:
"""Formats the start date, defaulting to 1900-01-01 if None."""
Expand Down Expand Up @@ -60,12 +58,13 @@ def requests_retry_session(
return session


def load_sites_csv(country_code: str) -> pd.DataFrame:
def load_cached_metadata_csv(country_code: str) -> pd.DataFrame:
"""Loads site data from a CSV file in the data directory."""
current_dir = os.path.dirname(__file__)
file_path = os.path.join(current_dir, "cached_site_data", f"{country_code}_sites.csv")
try:
return pd.read_csv(file_path, dtype={constants.GAUGE_ID: str})
df = pd.read_csv(file_path, dtype={constants.GAUGE_ID: str})
return df.set_index(constants.GAUGE_ID)
except FileNotFoundError:
logger.error(f"Site file not found: {file_path}")
raise