easysnowdata.stations.clients.HydroQuebecClient#
- class easysnowdata.stations.clients.HydroQuebecClient(base_url: str = 'https://donnees.hydroquebec.com/api/explore/v2.1', timeout: int = 120, max_retries: int = 3, backoff: int = 4, session: Session | None = None)[source]#
Bases:
objectClient for Hydro-Québec’s open hydrometeorological feed (Opendatasoft).
No credentials are needed. The feed is a rolling ~10-day window of hourly data; see the module docstring for why history must be accumulated by the caller (or taken from CanSWE). Data are licensed CC BY-NC 4.0 (non-commercial).
- Parameters:
base_url (
str) – Opendatasoft API root (.../api/explore/v2.1).timeout (
int) – HTTP settings for the shared retry loop.max_retries (
int) – HTTP settings for the shared retry loop.backoff (
int) – HTTP settings for the shared retry loop.session (
requests.SessionorNone) – Optional pre-configured session.
- get_stations(variables: list[str] | str | None = None, active_only: bool = False, bbox: tuple[float, float, float, float] | None = None) list[dict][source]#
Stations listing any of
variablesin the current window.- Parameters:
- Returns:
list[dict]–station_id(e.g."1-10613"),name,latitude,longitude,elevation_m,status,region,region_code,hq_code(code in the name, e.g.CM3V),operator,network,measurement_method,commissioned,decommissioned,has_swe,has_snwd,variables({label: {n_obs, first, last}}),begin_date/end_date(the window held, not the period of record),latest_observation,license,station_url.
- get_all_stations(active_only: bool = False, bbox: tuple[float, float, float, float] | None = None) list[dict][source]#
All stations listing SWE or snow depth.
statusis"Active"when the station has at least one valid (non-999) value of any variable in the rolling window.- Parameters:
- Returns:
list[dict]– Same schema asget_stations()(which also lists non-snow stations).- Raises:
HydroQuebecError – On a portal failure.
- get_metadata(station_id: str) dict[source]#
Metadata and variable inventory for one station.
- Parameters:
station_id (
str) – Hydro-Québecidentifiant, e.g."1-10613".- Returns:
dict– Theget_stations()dict plusdata_variables: one entry per variable the station lists, withname,type,interval("hourly"),units(emitted),description,notes, andbegin_date/end_date/n_obsdescribing the current rolling window only (valid hourly values).- Raises:
HydroQuebecError – If the station is not in the feed, or on a portal failure.
- get_raw_records(station_ids: list[str], variables: list[str], begin_utc: datetime | None = None, end_utc: datetime | None = None) list[dict][source]#
Raw portal rows (junk
date = nullrows excluded).- Parameters:
station_ids (
list[str]) – Hydro-Québecidentifiantvalues.variables (
list[str]) – Native French variable labels.begin_utc (
datetime, optional) – Half-open UTC bounds[begin_utc, end_utc).end_utc (
datetime, optional) – Half-open UTC bounds[begin_utc, end_utc).
- Returns:
list[dict]– Portal rows withidentifiant, the variable label, measure kind, unit,date(UTC ISO) andvaleur(text), ordered bydate.- Raises:
HydroQuebecError – On a portal failure.
- 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 = 'hourly', include_flags: bool = False) list[dict][source]#
Standardized data fetch — a flat list of observation records.
Only the last ~10 days exist; dates outside the window simply return nothing. Accumulate history yourself (or use CanSWE).
- Parameters:
station_ids (
list[str]orstrorNone) – Hydro-Québecidentifiantvalues ("1-10613"). Required unlessbboxis given.variables (
list[str]orstrorNone) – Native French labels or standardized types ("swe","temp_max", …).None= SWE and snow depth.bbox (
tuple, optional) –(min_lon, min_lat, max_lon, max_lat).begin_date (
strordate, optional) – InclusiveYYYY-MM-DDbounds — on the UTC date for"hourly"and on the America/Toronto local date for"daily".end_date (
strordate, optional) – InclusiveYYYY-MM-DDbounds — on the UTC date for"hourly"and on the America/Toronto local date for"daily".interval (
str) –"hourly"(native; records carrydatetimein UTC,YYYY-MM-DDTHH:MM:SSZ, anddateis its UTC date) or"daily"(local-day aggregation; see module docstring: SWE/depth = last valid value of the local day, precip = sum, Tmax = max, Tmin = min, others = mean, wind direction = circular mean; sum/mean/max/min need >=MIN_HOURS_DAILYvalid hours).include_flags (
bool) – Addflag: the nativetype_mesurefor hourly records,Nonefor daily ones. The feed has no QC flags.
- Returns:
list[dict]–{station_id, date, variable, type, value, units, interval}(+datetimefor hourly, +flag).- Raises:
ValueError – If neither
station_idsnorbboxis provided.HydroQuebecError – On an unknown variable, unsupported interval or portal error.
Example
>>> client = HydroQuebecClient() >>> records = client.get_data( ... bbox=(-80.0, 45.0, -57.0, 63.0), variables=["swe"], interval="daily" ... ) >>> records[0]["units"] 'cm'