easysnowdata.stations.clients.RIHMIClient#
- class easysnowdata.stations.clients.RIHMIClient(data_dir: str | PathLike | None = None, use_nsidc: bool = True, cache_dir: str | PathLike | None = None, base_url: str = 'https://noaadata.apps.nsidc.org/NOAA/G01170', timeout: int = 300, max_retries: int = 3, backoff: int = 4, session: Session | None = None, aisori_username: str | None = None, aisori_password: str | None = None)[source]#
Bases:
objectClient for RIHMI-WDC route snow surveys and daily snow cover.
Route surveys (
interval="periodic") come from АИСОРИ-М exports (scripted withsource="aisori", or local files) and/or the public NSIDC G01170 archive (1966–1996, no credentials). Daily snow cover (interval="daily") comes only from АИСОРИ-М.- Parameters:
data_dir (
strorPath, optional) – Folder of АИСОРИ-М exports, searched recursively for the downloaded*.zipfiles and for extracted*.txt/*.dat/*.csvdata files (an export’sfld*/statlist*files are used, not read as data). See the module docstring for the export steps.use_nsidc (
bool) – Include NSIDC G01170 stations and route-survey data (default True).cache_dir (
strorPath, optional) – Where the G01170 tar files (~50 MB) and scripted АИСОРИ-М exports are cached. Defaults toeasysnowdata.config.cache_dir("stations", "rihmi").base_url (
str) – Root of the NSIDC G01170 archive. Override for a mirror.timeout (
int) – HTTP settings for the NSIDC downloads.max_retries (
int) – HTTP settings for the NSIDC downloads.backoff (
int) – HTTP settings for the NSIDC downloads.session (
requests.Session, optional) – Pre-configured session (NSIDC downloads only; each АИСОРИ-М export opens its own).aisori_username (
str, optional) – АИСОРИ-М account forsource="aisori". Default: theaisoriauth provider (AISORI_USERNAME/AISORI_PASSWORD).aisori_password (
str, optional) – АИСОРИ-М account forsource="aisori". Default: theaisoriauth provider (AISORI_USERNAME/AISORI_PASSWORD).
- fetch_aisori(station_ids: list[str] | str, interval: str = 'periodic', first_year: int = 1966, last_year: int | None = None, refresh: bool = False) Path[source]#
Log in to АИСОРИ-М, export stations and years, return the cached zip.
- Parameters:
station_ids (
list[str]orstr) – WMO indexes. Stations the АИСОРИ-М source does not offer are skipped with a warning; if none is offered,RIHMIError.interval (
{"periodic", "daily"}) – Route surveys (SNMAR) or daily snow cover (SNOW).first_year (
int) – Inclusive year range (last_yeardefaults to this year).last_year (
int) – Inclusive year range (last_yeardefaults to this year).refresh (
bool) – Re-run the export even if a cached copy exists. A cached export whose range reaches the current year is re-run after 7 days.
- Returns:
Path– The export zip, readable withread_aisori_export().
- get_all_stations(active_only: bool = False, bbox: tuple[float, float, float, float] | None = None) list[dict][source]#
Every station in the RIHMI route-survey and snow-cover catalogues and (when
use_nsidc) NSIDC G01170’sstation.loc.- Parameters:
- Returns:
list[dict]–station_id(WMO index),name(Cyrillic from RIHMI, else NSIDC’s Latin),name_latin,latitude,longitude,elevation_m,status,wmo_id,operator,measurement_method,has_swe,has_snwd, catalogue membership flags, start years,public_period,login_period,noteandstation_url.- Raises:
RIHMIError – If NSIDC’s
station.loccannot be downloaded.
- get_metadata(station_id: str) dict[source]#
Station dict plus
data_variables.- Parameters:
station_id (
str) – WMO index, e.g."22113"(zero-padded to 5 digits).- Returns:
dict– Theget_all_stations()dict plusdata_variables, one entry per variable withname,type,interval,units(emitted),description,notes,begin_date,end_dateandn_obs.
Notes
Route-survey variables are listed when the station is in the RIHMI route catalogue or NSIDC (NSIDC-only stations list just the fields NSIDC carries); snow-cover variables when it is in the snow-cover catalogue.
begin_dateis the catalogue start year (route catalogue: start of the dataset at that station; snow-cover catalogue: start of observations at the station),end_dateis1996-12-31for NSIDC-only stations andNoneotherwise (ongoing behind a login).n_obsisNone(unknown without reading the data).- Raises:
RIHMIError – If the station is in none of the catalogues.
- 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 = 'periodic', include_flags: bool = False, route_types: list[str] | str | None = None, files: Iterable[str | PathLike] | str | PathLike | None = None, source: str = 'auto') list[dict][source]#
Standardized data fetch — a flat list of observation records.
- Parameters:
station_ids (
list[str]orstrorNone) – WMO indexes ("22113"). Required unlessbboxis given.variables (
list[str]orstrorNone) – Native names ("SWE","HS_MEAN","H"…) or standardized types ("swe","snwd","density","other") valid for the chosen interval.None= snow only:SWE+HS_MEAN(periodic) orH(daily).bbox (
tuple, optional) –(min_lon, min_lat, max_lon, max_lat).begin_date (
strordate, optional) – InclusiveYYYY-MM-DDbounds.end_date (
strordate, optional) – InclusiveYYYY-MM-DDbounds.interval (
{"periodic", "daily"}) –"periodic"= route snow surveys;"daily"= station snow cover (local exports only).include_flags (
bool) – Addflag(seeDATA_FLAGS).route_types (
list[str]orstr, optional) – Keep only these routes ("field","forest","ravine","unknown"). Periodic only.files (
pathorlistofpaths, optional) – АИСОРИ-М export files; overridesdata_dirfor this call.source (
{"auto", "nsidc", "files", "aisori"}) –"auto"merges local exports (preferred) with NSIDC;"nsidc"/"files"restrict to one."aisori"logs in to АИСОРИ-М and exports the stations and the years ofbegin_date–end_date(default 1966 to this year) withfetch_aisori(); it needs theaisoricredentials.
- Returns:
list[dict]–{station_id, date, variable, type, value, units, interval, route_type, source}(+flag). NSIDC downloads the ~50 MB G01170syn.tarfiles once into the cache.- Raises:
ValueError – If neither
station_idsnorbboxis provided.RIHMIError – Unknown variable, interval, route type or source; daily data requested with no АИСОРИ-М export; download or export failure.
Example
>>> client = RIHMIClient() >>> records = client.get_data( ... station_ids="22113", ... variables=["swe"], ... begin_date="1985-01-01", ... end_date="1985-04-30", ... ) >>> records[0]["units"], records[0]["route_type"] ('cm', 'field')
Examples using easysnowdata.stations.clients.RIHMIClient#
Recent Russian snow surveys and snow cover (RIHMI АИСОРИ-М)