Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CircularGreenSimCity
CircularGreenSimCity
Commits
a7a6e0e0
Commit
a7a6e0e0
authored
Apr 17, 2023
by
Eric Duminil
Browse files
monthly_precipitation_variation_wuerzburg
parent
6c7b5e4b
Changes
3
Hide whitespace changes
Inline
Side-by-side
python_scripts/get_dwd_precipitation/Parse Niederschlag.ipynb
View file @
a7a6e0e0
%% Cell type:markdown id:d52465eb tags:
# Niederschlag from DWD
[stundenwerte_RR_05705_hist.zip](https://www.dwd.de/DE/leistungen/_config/leistungsteckbriefPublication.zip?view=nasPublication&nn=16102&imageFilePath=675349470684952943382999480164406894835507349402593906628786280354581421008571928705011438849092751258299962952312473511744392814375916459681379337607540679777573246835730326122056459559982440454207144420355774317891799102452512290249737221071767178890331035105331501334382788925&download=true)
from [Klimadaten Deutschland - Stundenwerte (Archiv)](https://www.dwd.de/DE/leistungen/klimadatendeutschland/klarchivstunden.html) "Würzburg, Niederschlag, Historisch"
%% Cell type:code id:18d75296 tags:
``` python
import pandas as pd
from datetime import datetime
dateparse = lambda x: datetime.strptime(x, '%Y%m%d%H')
df = pd.read_csv('produkt_rr_stunde_19950901_20211231_05705.txt',
sep=';',
skipinitialspace=True,
usecols = [1, 3],
names = ['datetime', 'precipitation'],
skiprows = 1,
parse_dates = ['datetime'],
date_parser=dateparse,
index_col = 'datetime'
)
df
```
%%%% Output: execute_result
precipitation
datetime
1995-09-01 00:00:00 0.0
1995-09-01 01:00:00 0.2
1995-09-01 02:00:00 0.2
1995-09-01 03:00:00 0.1
1995-09-01 04:00:00 0.0
... ...
2021-12-31 19:00:00 0.0
2021-12-31 20:00:00 0.0
2021-12-31 21:00:00 0.0
2021-12-31 22:00:00 0.0
2021-12-31 23:00:00 0.0
[230227 rows x 1 columns]
%% Cell type:code id:52f73e31 tags:
``` python
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = (20, 10)
```
%% Cell type:code id:672300ca tags:
``` python
df2 = df[df.precipitation >= 0]
```
%% Cell type:code id:0fdf4a6f tags:
``` python
df2.resample('d').sum().plot(title='Niederschlag in Würzburg [mm / Tag]');
```
%%%% Output: display_data

%% Cell type:code id:9a68733c tags:
``` python
df2.resample('M').sum().plot(title='Niederschlag in Würzburg [mm / Monat]', ylim=(0, None));
```
%%%% Output: display_data

%% Cell type:code id:929bacb6 tags:
``` python
yearly_values = df2[df2.index.year >= 1996].resample('Y').sum()
```
%% Cell type:code id:c4dd7535 tags:
``` python
yearly_values.describe()
```
%%%% Output: execute_result
precipitation
count 26.000000
mean 568.538462
std 96.303059
min 410.500000
25% 516.575000
50% 548.900000
75% 614.400000
max 807.100000
%% Cell type:code id:0a1cc458 tags:
``` python
yearly_values.plot.bar(title='Niederschlag in Würzburg [mm / Jahr]', ylim=(0, None));
```
%%%% Output: display_data

%% Cell type:code id:c74631eb tags:
``` python
yearly_values.boxplot()
plt.title("Niederschlag in Würzburg, zwischen 1996 & 2021 [mm / Jahr]")
plt.savefig('wurzburg_yearly_precipitations_1996_2021.png', facecolor='w', bbox_inches='tight')
```
%%%% Output: display_data

%% Cell type:code id:faf431eb tags:
``` python
df3 = df2[df2.index.year == 2021]
```
%% Cell type:code id:2509790f tags:
``` python
rain2021 = pd.pivot_table(df3, values='precipitation', index=df3.index.time, columns=df3.index.dayofyear)
rain2021
```
%%%% Output: execute_result
datetime 1 2 3 4 5 6 7 8 9 10 ... 356 357 \
00:00:00 0.0 0.0 0.0 0.1 0.0 0.0 0.0 0.2 0.0 0.0 ... 0.0 0.0
01:00:00 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.2 0.0 0.0 ... 0.0 0.0
02:00:00 0.0 0.0 0.0 0.0 0.0 0.1 0.0 0.1 0.0 0.0 ... 0.0 0.0
03:00:00 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0
04:00:00 0.0 0.0 0.0 0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 0.0
[24 rows x 365 columns]
%% Cell type:code id:42ddd82d tags:
``` python
import seaborn as sns
```
%% Cell type:code id:f1b17ef2 tags:
``` python
sns.heatmap(rain2021, annot=False, cmap='viridis', vmax=5)
plt.title('mm/h Regen in Würzburg, 2021')
plt.show()
```
%%%% Output: display_data

%% Cell type:code id:29be9114 tags:
``` python
df4 = df2[df2.index.year >= 2010].resample('M').sum()
df4
```
%%%% Output: execute_result
precipitation
datetime
2010-01-31 35.9
2010-02-28 28.5
2010-03-31 29.7
2010-04-30 23.7
2010-05-31 68.4
... ...
2021-08-31 82.0
2021-09-30 6.0
2021-10-31 42.5
2021-11-30 26.3
2021-12-31 60.5
[144 rows x 1 columns]
%% Cell type:code id:
7f474ad
0 tags:
%% Cell type:code id:
283cd89
0 tags:
``` python
import calendar
df4['Year'] = df4.index.year
df4['Month'] = df4.index.month
df4['Month'] = df4['Month'].apply(lambda x: calendar.month_abbr[x])
df4
```
%%%% Output: execute_result
precipitation Year Month
datetime
2010-01-31 35.9 2010 Jan
2010-02-28 28.5 2010 Feb
2010-03-31 29.7 2010 Mar
2010-04-30 23.7 2010 Apr
2010-05-31 68.4 2010 May
... ... ... ...
2021-08-31 82.0 2021 Aug
2021-09-30 6.0 2021 Sep
2021-10-31 42.5 2021 Oct
2021-11-30 26.3 2021 Nov
2021-12-31 60.5 2021 Dec
[144 rows x 3 columns]
%% Cell type:code id:
a1f5385
1 tags:
%% Cell type:code id:
28a0fd6
1 tags:
``` python
df4 = df4.set_index(['Year', 'Month'])
df4
```
%%%% Output: execute_result
precipitation
Year Month
2010 Jan 35.9
Feb 28.5
Mar 29.7
Apr 23.7
May 68.4
... ...
2021 Aug 82.0
Sep 6.0
Oct 42.5
Nov 26.3
Dec 60.5
[144 rows x 1 columns]
%% Cell type:code id:
3c9b3b93
tags:
%% Cell type:code id:
8e3bd7d1
tags: