agroweather#

Fetch weather data from agrometeo.ch stations across Switzerland.

See agroweather for usage examples.

API Reference#

pyedautils.weather.agroweather.get_station_data() → DataFrame[source]#

Fetches all agrometeo.ch weather stations.

Returns:

DataFrame with station info (id, name, lat, lon, altitude, sensors).

Return type:

pd.DataFrame

pyedautils.weather.agroweather.find_nearest_station(lat: float, lon: float, sensor: str = None) → int[source]#

Returns station ID of the closest agrometeo.ch station to a coordinate.

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

  • lon (float) – Longitude in decimal degrees.

  • sensor (str, optional) – Filter by sensor type: temp, globrad, relhum, or rain.

Returns:

Agrometeo station ID.

Return type:

int

pyedautils.weather.agroweather.download_data(station_id: int, start_date: str, end_date: str, sensors: list = None) → DataFrame[source]#

Downloads hourly weather data from agrometeo.ch for a station.

Parameters:
  • station_id (int) – Agrometeo station ID.

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

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

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

Returns:

DataFrame with datetime index and sensor columns.

Return type:

pd.DataFrame

pyedautils.weather.agroweather.download_data_by_plz(plz: int, start_date: str, end_date: str, sensors: list = None) → DataFrame[source]#

Downloads hourly weather data from agrometeo.ch for the nearest station to a Swiss postal code.

For each requested sensor type, finds the nearest station that has that sensor 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.

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

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

Returns:

DataFrame with datetime index and sensor columns.

Return type:

pd.DataFrame