meteo_swiss#

Download historical and recent measurement data (10-minute, hourly, daily) of MeteoSwiss stations from the MeteoSwiss open data portal (OGD), get the current measurements of all automatic weather stations, and find the nearest station for a given location and sensor type.

See meteo_swiss for usage examples.

API Reference#

MeteoSwiss station lookup and Open Government Data (OGD) downloads.

SwissMetNet values (collection ch.meteoschweiz.ogd-smn, precipitation-only stations in ch.meteoschweiz.ogd-smn-precip) are available per station as historical, recent and now CSV files in 10-minute, hourly and daily granularity and are downloaded with download_data(). When reproducing or redistributing the data the source must be cited as “Source: MeteoSwiss”.

pyedautils.weather.meteo_swiss.get_current_station_data() → DataFrame[source]#

Gets current measurement data of all Meteo Swiss stations.

Returns:

DataFrame with station data.

Return type:

pd.DataFrame

pyedautils.weather.meteo_swiss.find_nearest_station(lat: float, long: float, altitude: float, sensor: str) → str[source]#

Returns station id of closest meteo swiss station to a coordinate.

Parameters:
  • lat (float) – Latitude in decimal degrees.

  • long (float) – Longitude in decimal degrees.

  • altitude (float) – Altitude in meters above sea level.

  • sensor (str) – temp, globrad, relhum or rain

Returns:

Meteo Swiss station ID

Return type:

str

pyedautils.weather.meteo_swiss.SMN_BASE_URL = 'https://data.geo.admin.ch/ch.meteoschweiz.ogd-smn'#

Base URL of the SwissMetNet OGD files.

pyedautils.weather.meteo_swiss.OGD_STAC_URL = 'https://data.geo.admin.ch/api/stac/v1/collections'#

Root of the STAC collections on data.geo.admin.ch.

pyedautils.weather.meteo_swiss.OGD_COLLECTIONS = ['ch.meteoschweiz.ogd-smn', 'ch.meteoschweiz.ogd-smn-precip']#

SwissMetNet weather stations; precipitation-only stations live in a separate collection.

pyedautils.weather.meteo_swiss.SENSOR_PARAMS = {'d': {'globrad': 'gre000d0', 'rain': 'rre150d0', 'relhum': 'ure200d0', 'temp': 'tre200d0'}, 'h': {'globrad': 'gre000h0', 'rain': 'rre150h0', 'relhum': 'ure200h0', 'temp': 'tre200h0'}, 't': {'globrad': 'gre000z0', 'rain': 'rre150z0', 'relhum': 'ure200s0', 'temp': 'tre200s0'}}#

t = 10 minutes, h = hourly, d = daily.

Type:

MeteoSwiss parameter IDs per granularity

pyedautils.weather.meteo_swiss.get_smn_stations(timeout: int = 60) → DataFrame[source]#

Gets the SwissMetNet station list of the MeteoSwiss OGD.

Parameters:

timeout (int) – Request timeout in seconds. Default 60.

Returns:

Station metadata (station_abbr, station_name, coordinates, altitude, …).

Return type:

pd.DataFrame

pyedautils.weather.meteo_swiss.GRANULARITY_CODES = {'D': 'd', 'H': 'h', 'T': 't'}#

parameter_granularity in the parameter metadata -> granularity of download_data()

pyedautils.weather.meteo_swiss.get_smn_parameters(timeout: int = 60) → DataFrame[source]#

Gets the parameter list (metadata) of the SwissMetNet data of the MeteoSwiss OGD.

Parameters:

timeout (int) – Request timeout in seconds. Default 60.

Returns:

One row per parameter with parameter_shortname (the ID used by download_data(), e.g. “tre200h0”), descriptions and groups in de/fr/it/en, parameter_granularity (T = 10 min, H = hourly, D = daily, M = monthly, Y = yearly), parameter_datatype and parameter_unit.

Return type:

pd.DataFrame

pyedautils.weather.meteo_swiss.get_station_parameters(station: str, granularity: str = None, lang: str = 'en', timeout: int = 60) → DataFrame[source]#

Lists the parameters a SwissMetNet station measures, with description and unit.

Parameters:
  • station (str) – Station abbreviation, e.g. “LUZ”.

  • granularity (str, optional) – Only parameters of this resolution: “t” (10 minutes), “h” (hourly) or “d” (daily). Default: all.

  • lang (str, optional) – Language of description and group: “de”, “fr”, “it” or “en”. Default “en”.

  • timeout (int) – Request timeout in seconds. Default 60.

Returns:

Columns parameter (ID for download_data()), description, group, unit, granularity (“t”, “h”, “d”, “m”, “y”), data_since and data_till (NaT while still measured), sorted by group and description. Empty if the station is unknown.

Return type:

pd.DataFrame

pyedautils.weather.meteo_swiss.download_data(station: str, start_date: str, end_date: str, sensors: list = None, granularity: str = 'h', tz: str = 'UTC') → DataFrame[source]#

Downloads historical measurement data of a MeteoSwiss station from the MeteoSwiss open data portal (OGD, data.geo.admin.ch).

The data is assembled from the historical (per decade), recent (current year) and now (last day) files of the station. MeteoSwiss time stamps are in UTC and mark the end of the measurement interval (e.g. the hourly value at 16:00 covers 15:00-16:00). Daily values are returned with a tz-naive date index (one row per day), e.g. as input for pyedautils.degree_days.reference_degree_days().

Parameters:
  • station (str) – MeteoSwiss station abbreviation, e.g. “KLO” (see find_nearest_station()).

  • start_date (str) – Start date in ‘YYYY-MM-DD’ format (inclusive).

  • end_date (str) – End date in ‘YYYY-MM-DD’ format (inclusive).

  • sensors (list, optional) – Sensor types temp, globrad, relhum, rain, or raw MeteoSwiss parameter IDs (e.g. “tre200hx”). Defaults to [“temp”, “globrad”, “relhum”, “rain”].

  • granularity (str, optional) – “t” (10 minutes), “h” (hourly) or “d” (daily). Defaults to “h”.

  • tz (str, optional) – Time zone of start_date/end_date and of the returned index, e.g. “Europe/Zurich”. Ignored for daily values. Defaults to “UTC”.

Returns:

DataFrame with datetime index (tz-aware for “t” and “h”, tz-naive dates for “d”) and one column per sensor.

Return type:

pd.DataFrame

pyedautils.weather.meteo_swiss.download_data_by_plz(plz: int, start_date: str, end_date: str, sensors: list = None, granularity: str = 'h', tz: str = 'UTC', altitude: float = None) → DataFrame[source]#

Downloads historical measurement data from the nearest MeteoSwiss stations to a Swiss postal code.

For each requested sensor type, finds the nearest station that has that sensor within 150 m altitude difference (see find_nearest_station()) and merges all results into a single DataFrame.

Parameters:
  • plz (int) – Swiss postal code (Postleitzahl).

  • start_date (str) – Start date in ‘YYYY-MM-DD’ format (inclusive).

  • end_date (str) – End date in ‘YYYY-MM-DD’ format (inclusive).

  • sensors (list, optional) – Sensor types temp, globrad, relhum, rain. Defaults to [“temp”, “globrad”, “relhum”, “rain”].

  • granularity (str, optional) – “t” (10 minutes), “h” (hourly) or “d” (daily). Defaults to “h”.

  • tz (str, optional) – Time zone of start_date/end_date and of the returned index. Defaults to “UTC”.

  • altitude (float, optional) – Altitude in meters above sea level used for the station search. Defaults to the terrain altitude at the postal code’s coordinates.

Returns:

DataFrame with datetime index (tz-aware for “t” and “h”, tz-naive dates for “d”) and one column per sensor.

Return type:

pd.DataFrame