easysnowdata.stations.clients.SLFClient#
- class easysnowdata.stations.clients.SLFClient(dataset: str = 'gcos', cache_dir: str | Path | None = None, cache_ttl_hours: float = 24.0, base_url: str = 'https://measurement-data.slf.ch', timeout: int = 120, max_retries: int = 3, backoff: int = 4, session: Session | None = None)[source]#
Bases:
objectClient for open SLF snow-station datasets (GCOS SWE, new-snow SWE, manual study plots, IMIS).
No credentials are needed.
- Parameters:
dataset (
str) –"gcos"(default),"new_snow","study_plot"or"imis"; seeDATASETSand the module docstring.cache_dir (
strorPathorNone) – Where downloads are cached. Defaults toeasysnowdata.config.cache_dir("stations", "slf").cache_ttl_hours (
float) – Re-download a cached file of a non-static dataset older than this.base_url (
str) – Root of the SLF measurement-data file service (study_plotandimis). The EnviDat datasets are resolved through CKAN.timeout (
int) – HTTP settings passed to the shared retry loop.max_retries (
int) – HTTP settings passed to the shared retry loop.backoff (
int) – HTTP settings passed to the shared retry loop.session (
requests.SessionorNone) – Optional pre-configured session.
- ckan_package(ckan_id: str | None = None) dict[source]#
The EnviDat CKAN
package_showrecord for a dataset.
- get_all_stations(active_only: bool = False, bbox: tuple[float, float, float, float] | None = None) list[dict][source]#
All stations of the selected dataset.
- Parameters:
- Returns:
list[dict]–station_id,name,latitude,longitude,elevation_m,status,operator,dataset,doi,license,measurement_method,period_of_record("first/last"where known),has_swe,has_snwd,station_url;study_plot/imisaddnetworkandstation_type;new_snowadds LV03 coordinates.- Raises:
SLFError – If the station list or data file cannot be fetched or parsed.
- get_data(station_ids: list[str] | str | None = None, variables: list[str] | str | None = None, bbox: tuple[float, float, float, float] | None = None, begin_date: str | date | None = None, end_date: str | date | None = None, interval: str | None = None, include_flags: bool = False) list[dict][source]#
Standardized data fetch — a flat list of observation records.
- Parameters:
station_ids (
list[str]orstrorNone) – Dataset station code(s), e.g."5WJ"(gcos),"5WJ0"(study_plot),"WFJ2"(imis). Required unlessbbox.variables (
list[str]orstrorNone) – Native names ("SWE","HS","HN_1D"…) or standardized types ("swe","snwd").None= snow only (SWE + snow depth where the dataset has them).bbox (
tuple, optional) –(min_lon, min_lat, max_lon, max_lat).begin_date (
strordate, optional) – InclusiveYYYY-MM-DDbounds (files are fetched whole).end_date (
strordate, optional) – InclusiveYYYY-MM-DDbounds (files are fetched whole).interval (
strorNone) –None= each variable at its native cadence ("periodic"for biweekly snow pits,"daily"otherwise)."periodic","daily"or (imis)"sub_hourly"select explicitly; anything the dataset lacks raisesSLFError.include_flags (
bool) – Addsflag(alwaysNone— SLF publishes no flags).
- Returns:
list[dict]–{station_id, date, variable, type, value, units, interval}(+datetimefor sub-hourly, +flag).- Raises:
ValueError – If neither
station_idsnorbboxis given.SLFError – On an unknown variable / interval, or a source failure.
Example
>>> client = SLFClient("gcos") >>> records = client.get_data( ... station_ids="5WJ", ... variables=["swe"], ... begin_date="2024-01-01", ... end_date="2024-05-31", ... ) >>> records[0]["units"], records[0]["interval"] ('cm', 'periodic')
- get_metadata(station_id: str) dict[source]#
Station dict plus
data_variablesfor one station.- Parameters:
station_id (
str) – Dataset station code, e.g."5WJ"(gcos).- Returns:
dict– Theget_all_stations()dict plusterms_urlanddata_variables: one entry per variable × interval withname,type,interval,units(emitted),description,notes,begin_date,end_dateandn_obs. These are computed from the data file (non-missing values; variables without any are omitted) except for IMIS 30-minute variables, whose files are large; those reportNone.- Raises:
SLFError – If the station is not in the dataset.