easysnowdata.stations.clients.SNIHClient#
- class easysnowdata.stations.clients.SNIHClient(base_url: str = 'https://snih.hidricosargentina.gob.ar', timeout: int = 120, max_retries: int = 3, backoff: int = 4, session: Session | None = None)[source]#
Bases:
objectClient for the SNIH snow stations of Argentina.
No credentials are needed. By using the data you accept the portal’s terms of use (
TERMS_URL): cite SIPH and the contributing network, keep the original meaning and state the date of the last update.- Parameters:
- get_all_stations(active_only: bool = False, bbox: tuple[float, float, float, float] | None = None) list[dict][source]#
Every SNIH station associated with a snow parameter (codes 70–74).
The first call reads the station list, the network names and the station–parameter associations (about 5 MB), then checks the last 30 days of raw telemetry at each pillow station for
status(one request each, four in parallel). Both are cached on the client.- Parameters:
- Returns:
list[dict]–station_id(SNIHCodigo),name,latitude,longitude(negated from the published positive values),elevation_m(NonewhereCotais −999 or 0),status,last_raw_obs(newest raw pillow record in the last 30 days, ISO time, orNone),network_id,network/operator(the network name),data_provider,country,province/province_code,basin_code,system_code,regional_code,river,place,station_type(Tipoletters) and its description,transmission/transmission_code,snow_codes,variables,variables_since(association start per variable),measurement_method,has_swe,has_snwdandstation_url.- Raises:
SNIHError – On a portal failure.
- get_metadata(station_id: str) dict[source]#
Station metadata plus
data_variables(with period of record).- Parameters:
station_id (
str) – SNIH station code (e.g."19145", Toscas).- Returns:
dict– The station dict plusdata_variables: one entry per variable and interval withname,code,type,interval,units(emitted),description,notes,associated_since(the association start the service gives), andbegin_date/end_date/n_obs. For"daily"and"periodic"those come from the full historical series (n_obscounts days for"daily"); for"sub_daily"end_dateis the newest raw record of the last 30 days andbegin_date/n_obsareNone(counting would mean reading the whole raw record).- Raises:
SNIHError – If the station is not a SNIH snow station, or 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 = 'daily', include_flags: bool = False) list[dict][source]#
Snow data as flat records.
- Parameters:
station_ids (
list[str]orstrorNone) – SNIH station code(s). Required unlessbboxis given.variables (
list[str]orstrorNone) – Native names (VARIABLES), parameter codes ("73"), abbreviations or types.None= the SWE and depth variables ofinterval:SWE_PILLOWfor"daily"and"sub_daily",SWE_COURSE+SNWDfor"periodic".bbox (
tuple, optional) –(min_lon, min_lat, max_lon, max_lat).begin_date (
strordate, optional) – Inclusive local (Argentina) dates. Default: the whole record (raw telemetry: from 2009) to today.end_date (
strordate, optional) – Inclusive local (Argentina) dates. Default: the whole record (raw telemetry: from 2009) to today.interval (
str) –"daily"(validated pillow SWE),"sub_daily"(raw pillow telemetry) or"periodic"(snow-course surveys).include_flags (
bool) – Addflag: theCalificadorqualifier (seeDATA_FLAGS;Nonewhen blank),"unvalidated"for a historical value served withValidado = false, and"raw"on every"sub_daily"record.
- Returns:
list[dict]–{station_id, date, variable, type, value, units, interval}(+datetimein Argentina time for"sub_daily", +flag). An id the portal does not know returns no records.- Raises:
ValueError – If neither
station_idsnorbboxis given.SNIHError – On an unsupported interval, an unknown variable, a variable the interval does not offer, a non-numeric station id or a portal failure.
Example
>>> client = SNIHClient() >>> records = client.get_data( ... station_ids="19145", # Toscas ... begin_date="2015-06-01", ... end_date="2015-09-30", ... ) >>> records[0]["units"], records[0]["interval"] ('cm', 'daily')