easysnowdata.stations.clients.DWDClient#
- class easysnowdata.stations.clients.DWDClient(base_url: str = 'https://opendata.dwd.de/climate_environment/CDC/observations_germany/climate/daily', timeout: int = 120, max_retries: int = 3, backoff: int = 4, session: Session | None = None, cache: bool = True, cache_path: str | Path | None = None)[source]#
Bases:
objectClient for DWD CDC daily snow water equivalent and snow depth.
No credentials are needed.
- Parameters:
base_url (
str) – Root of the CDCobservations_germany/climate/dailytree.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.cache (
bool) – Cache historical station zips on disk (they never change for a given file name). Recent zips are never cached.cache_path (
strorPathorNone) – Override the cache directory (defaulteasysnowdata.config.cache_dir("stations", "dwd")).
- get_stations(products: list[str] | tuple[str, ...] | str = ('water_equiv', 'more_precip'), active_only: bool = False, bbox: tuple[float, float, float, float] | None = None) list[dict][source]#
Stations in the given product station lists, merged by id.
- Parameters:
- Returns:
list[dict]–station_id(5-digit),name,latitude,longitude,elevation_m,status,state(Bundesland),operator,measurement_method,release,has_swe,has_snwd,products({product: {begin_date, end_date}}),begin_date,end_date,swe_begin_date,swe_end_dateandstation_url(None— DWD has no per-station page).- Raises:
DWDError – On an unknown product or a failed station-list download.
- get_all_stations(active_only: bool = False, bbox: tuple[float, float, float, float] | None = None) list[dict][source]#
All SWE (water_equiv) and snow-depth (more_precip) stations.
- Parameters:
- Returns:
list[dict]– Same schema asget_stations()(which can also select one product).- Raises:
DWDError – If a station list cannot be downloaded.
- get_metadata(station_id: str | int) dict[source]#
Metadata and variable inventory for one station.
- Parameters:
station_id (
strorint) – DWD station id, with or without zero padding ("00020",20).- Returns:
dict– Theget_stations()dict plusdata_variables: one entry per variable available from the station’s products, withname,type,interval,units(emitted),description,notes,begin_date/end_date(from the product station list: the period of record of the product, not of the individual column) andn_obs(None).- Raises:
DWDError – If the id is not numeric or the station is in neither station list.
- get_station_rows(station_id: str | int, product: str, begin_date: str | date | None = None, end_date: str | date | None = None) dict[str, dict[str, Any]][source]#
Merged historical + recent rows for one station and product.
Historical rows win on overlapping dates. Files that cannot hold the window (by historical file name / recent span) are not downloaded.
- 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]#
Standardized data fetch — returns a flat list of observation records.
- Parameters:
station_ids (
list[str]orstrorNone) – DWD station id(s), with or without zero padding ("00020","20",20). Required unlessbboxis provided.variables (
list[str]orstrorNone) – Native columns ("WASH_6") or standardized types ("swe","snwd","snowfall","precip").Nonemeans snow only:WASH_6andSH_TAG.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 (
str) – Only"daily"is supported.include_flags (
bool) – Addflag= the row’sQN_6quality level.
- Returns:
list[dict]–{station_id, date, variable, type, value, units, interval}records (plusflag), only for dates with a non-missing value. Stations whose files cannot be fetched are logged and skipped.- Raises:
ValueError – If neither
station_idsnorbboxis provided.DWDError – On an unknown variable or interval.
Example
>>> client = DWDClient() >>> records = client.get_data( ... station_ids="00020", ... variables=["snwd"], ... begin_date="2024-01-01", ... end_date="2024-01-15", ... ) >>> records[0]["units"] 'cm'