|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 1, |
| 6 | + "id": "c93fb23f", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [], |
| 9 | + "source": [ |
| 10 | + "# Wetterdienst: https://pypi.org/project/wetterdienst/\n", |
| 11 | + "from wetterdienst import Settings\n", |
| 12 | + "from wetterdienst.provider.dwd.observation import DwdObservationRequest, DwdObservationMetadata" |
| 13 | + ] |
| 14 | + }, |
| 15 | + { |
| 16 | + "cell_type": "markdown", |
| 17 | + "id": "6906bc4d", |
| 18 | + "metadata": {}, |
| 19 | + "source": [ |
| 20 | + "DWD - Stations with station IDs: https://www.dwd.de/DE/leistungen/klimadatendeutschland/stationsuebersicht.html\n" |
| 21 | + ] |
| 22 | + }, |
| 23 | + { |
| 24 | + "cell_type": "code", |
| 25 | + "execution_count": 2, |
| 26 | + "id": "c15656a2", |
| 27 | + "metadata": {}, |
| 28 | + "outputs": [ |
| 29 | + { |
| 30 | + "name": "stdout", |
| 31 | + "output_type": "stream", |
| 32 | + "text": [ |
| 33 | + "<class 'pandas.core.frame.DataFrame'>\n", |
| 34 | + "DatetimeIndex: 91315 entries, 1975-01-01 to 2024-12-31\n", |
| 35 | + "Data columns (total 15 columns):\n", |
| 36 | + " # Column Non-Null Count Dtype \n", |
| 37 | + "--- ------ -------------- ----- \n", |
| 38 | + " 0 station_id 91315 non-null object \n", |
| 39 | + " 1 wind_gust_max 86857 non-null float64\n", |
| 40 | + " 2 wind_speed 90284 non-null float64\n", |
| 41 | + " 3 precipitation_height 90913 non-null float64\n", |
| 42 | + " 4 precipitation_form 91086 non-null float64\n", |
| 43 | + " 5 sunshine_duration 91054 non-null float64\n", |
| 44 | + " 6 snow_depth 89281 non-null float64\n", |
| 45 | + " 7 cloud_cover_total 91179 non-null float64\n", |
| 46 | + " 8 pressure_vapor 91260 non-null float64\n", |
| 47 | + " 9 pressure_air_site 91289 non-null float64\n", |
| 48 | + " 10 temperature_air_mean_2m 91304 non-null float64\n", |
| 49 | + " 11 humidity 91260 non-null float64\n", |
| 50 | + " 12 temperature_air_max_2m 91304 non-null float64\n", |
| 51 | + " 13 temperature_air_min_2m 91304 non-null float64\n", |
| 52 | + " 14 temperature_air_min_0_05m 72718 non-null float64\n", |
| 53 | + "dtypes: float64(14), object(1)\n", |
| 54 | + "memory usage: 11.1+ MB\n" |
| 55 | + ] |
| 56 | + } |
| 57 | + ], |
| 58 | + "source": [ |
| 59 | + "# Load daily climate summary data from ...\n", |
| 60 | + "# 183 - Arkona\n", |
| 61 | + "# 722 - Brocken\n", |
| 62 | + "# 2667 - Köln-Bonn\n", |
| 63 | + "# 2932 - Leipzig\n", |
| 64 | + "# 5792 - Zugspitze\n", |
| 65 | + "# ... for years 1975-2024 \n", |
| 66 | + "request = DwdObservationRequest(\n", |
| 67 | + " parameters=DwdObservationMetadata.daily.climate_summary,\n", |
| 68 | + " start_date=\"1975-01-01\",\n", |
| 69 | + " end_date=\"2024-12-31\",\n", |
| 70 | + " settings=Settings(\n", |
| 71 | + " ts_shape=\"wide\", # tidy data\n", |
| 72 | + " ts_humanize=True, # humanized parameters\n", |
| 73 | + " ts_convert_units=False # do not convert values to SI units\n", |
| 74 | + " )\n", |
| 75 | + ").filter_by_station_id([183, 722, 2667, 2932, 5792])\n", |
| 76 | + "\n", |
| 77 | + "# Load values\n", |
| 78 | + "df = request.values.all().df.to_pandas().set_index(\"date\")\n", |
| 79 | + "# Drop columns with quality flags and just on distinct value\n", |
| 80 | + "df_selected = df.loc[:, ~df.columns.str.startswith(\"qn_\") & (df.nunique() != 1)]\n", |
| 81 | + "# Remove timezone from datetime index, this triggers warnings in some tsa libraries\n", |
| 82 | + "df_selected.index = df_selected.index.tz_convert(None)\n", |
| 83 | + "df_selected.info()" |
| 84 | + ] |
| 85 | + }, |
| 86 | + { |
| 87 | + "cell_type": "code", |
| 88 | + "execution_count": 4, |
| 89 | + "id": "0d5d838c", |
| 90 | + "metadata": {}, |
| 91 | + "outputs": [], |
| 92 | + "source": [ |
| 93 | + "# Save data station-wise\n", |
| 94 | + "for station_id in df_selected.station_id.unique():\n", |
| 95 | + " station_data = df_selected[df_selected.station_id == station_id]\n", |
| 96 | + " station_data = station_data.drop(columns=[\"station_id\"])\n", |
| 97 | + " station_data.to_csv(f\"data/dwd_{station_id}_climate.csv\", sep=';', index=True)" |
| 98 | + ] |
| 99 | + } |
| 100 | + ], |
| 101 | + "metadata": { |
| 102 | + "kernelspec": { |
| 103 | + "display_name": "tsa-overview (3.14.0)", |
| 104 | + "language": "python", |
| 105 | + "name": "python3" |
| 106 | + }, |
| 107 | + "language_info": { |
| 108 | + "codemirror_mode": { |
| 109 | + "name": "ipython", |
| 110 | + "version": 3 |
| 111 | + }, |
| 112 | + "file_extension": ".py", |
| 113 | + "mimetype": "text/x-python", |
| 114 | + "name": "python", |
| 115 | + "nbconvert_exporter": "python", |
| 116 | + "pygments_lexer": "ipython3", |
| 117 | + "version": "3.13.0" |
| 118 | + } |
| 119 | + }, |
| 120 | + "nbformat": 4, |
| 121 | + "nbformat_minor": 5 |
| 122 | +} |
0 commit comments