-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyse.pmd
297 lines (235 loc) · 8.76 KB
/
analyse.pmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# Visualisierung von kantonalen Daten zu COVID-19
<p>Update: 2022-01-23 -- 11:30<br/>
Geändert: 2022-01-23 -- 11:30</p>
```{python, echo = False}
import numpy as np
import pandas as pd
import geopandas as gpd
import geoplot as gplt
import matplotlib.pyplot as plt
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()
import math
from datetime import datetime, timedelta
from cycler import cycler
from index import Index
from plot_canton import Plot_canton
from complete_indices import Complete_indices
# Import data provided by Open Data Zurich
dat = pd.read_csv('data/ch.csv',
parse_dates = ['date']
#date_parser = dateparse,
)
dat_inter = pd.read_csv('data/ch_interpolated.csv',
parse_dates = ['date']
)
dat_ffill = pd.read_csv('data/ch_ffill.csv',
parse_dates = ['date']
)
cols = list(dat_ffill.columns[2:10])
dat_last_dates = pd.read_csv('data/ch_last_update_total.csv',parse_dates=['date'])
dat_last_dates.set_index('column', inplace = True)
dat_last_dates
cantons = dat['canton'].drop_duplicates()
dates = dat_inter['date'].drop_duplicates()
ind = Complete_indices(dates, dat_last_dates)
default_cycler = (
cycler( color=['blue','green','orange','red','fuchsia'] )*
cycler( linestyle=['-'])
)
col_cycler = (
cycler( color=['blue','green','orange','red','fuchsia'] )*
cycler( linestyle=['-',':'])
)
```
## Schweizweite Situation
### Karten
Die folgende Karte zeigen, wie viele positiv getestete Fälle und wie viele Tote es in den jeweiligen Kantonen je 10'000 EinwohnerInnen bisher gegeben hat.
```{python Karte Fälle pro Kanton, include = True, echo = False}
# load map of cantonal boundariess of Switzerland
map = gpd.read_file( filename = 'map/' +
'swissBOUNDARIES3D_1_3_TLM_KANTONSGEBIET.shp'
)
# load file containing the nbrs used to encode the cantons
bfs_canton_codes = pd.read_csv(
'data/covid_19/mappingCanton_BFS.csv')
# load the data
nbr_cantonal_cases = pd.read_csv('data/ch_cases_cantons.csv')
map = map.set_index(['KANTONSNUM'])
bfs_canton_codes = bfs_canton_codes.set_index('abk')
nbr_cantonal_cases = nbr_cantonal_cases.set_index('canton')
map['cases'] = np.nan
map['casespercapita'] = np.nan
for canton in cantons:
nbr = bfs_canton_codes.loc[canton]
population = map.loc[nbr,'EINWOHNERZ'].iloc[0]
map.loc[nbr,'cases'] = nbr_cantonal_cases.loc[canton].values
map.loc[
nbr,'casespercapita'
] = nbr_cantonal_cases.loc[canton].values / population * 10000
fig, ax = plt.subplots(1, 1)
map.plot(column = 'casespercapita', ax=ax, legend=True, cmap='OrRd')
map.boundary.plot(ax=ax, color='black',linewidth=0.5)
ax.set_title('Positiv getestete Fälle per 10\'000 EinwohnerInnen')
fig.autofmt_xdate()
```
```{python Karte Tote pro Kanton, include = True, echo = False}
# load map of cantonal boundariess of Switzerland
# load file containing the nbrs used to encode the cantons
# load the data
nbr_cantonal_deaths = pd.read_csv('data/ch_deaths_cantons.csv')
nbr_cantonal_deaths = nbr_cantonal_deaths.set_index('canton')
map['deaths'] = np.nan
map['deathspercapita'] = np.nan
for canton in cantons:
nbr = bfs_canton_codes.loc[canton]
population = map.loc[nbr,'EINWOHNERZ'].iloc[0]
map.loc[nbr,'deaths'] = nbr_cantonal_deaths.loc[canton].values
map.loc[
nbr,'deathspercapita'
] = nbr_cantonal_deaths.loc[canton].values / population * 10000
fig, ax = plt.subplots(1, 1)
map.plot(column = 'deathspercapita', ax=ax, legend=True, cmap='OrRd')
map.boundary.plot(ax=ax, color='black',linewidth=0.5)
ax.set_title('Todesfälle per 10\'000 EinwohnerInnen')
fig.autofmt_xdate()
```
### Verlauf
```{python Totale Anzahl, include = True, echo = False, caption = "Totale Fallzahlen in der Schweiz basierend auf katnonalen Meldungen. Gepunktete Linien bedeuten, dass noch nicht von allen Kantonen Daten vorliegen. Fehlende Daten wurden interpoliert"}
with Index(dat_inter,['canton']) as df_:
zh_vent = df_.loc['ZH','current_vent'].values
with Index(dat_inter,['date','canton']) as df_:
df = df_.sum(level='date',skipna=True)
zh_vent[np.isnan(zh_vent)] = 0
df.loc[:,'current_icu'] = df.loc[:,'current_icu']
df
df.iloc[-len(zh_vent):,4] += zh_vent
fig = plt.figure()
plt.rc('axes', prop_cycle=col_cycler)
ax = fig.subplots()
ax.plot(df['ncumul_conf'].iloc[ind.complete('ncumul_conf')],
label='Positive Testergebnisse')
ax.plot(df['ncumul_conf'].iloc[ind.incomplete('ncumul_conf')],
label='')
ax.plot(df['current_hosp'].iloc[ind.complete('current_hosp')],
label='Hospitalisierungen')
ax.plot(df['current_hosp'].iloc[ind.incomplete('current_hosp')],
label='',linestyle='--')
ax.plot(df['ncumul_deceased'].iloc[ind.complete('ncumul_deceased')],label='Verstorben')
ax.plot(df['ncumul_deceased'].iloc[
ind.incomplete('ncumul_deceased')
],label='')
ax.plot(df['current_icu'].iloc[ind.complete('current_icu')],
label='Intensivstation')
ax.plot(df['current_icu'].iloc[ind.incomplete('current_icu')],
label='')
plt.yscale('log')
plt.grid(which='both')
plt.legend()
ax.set_title('Schweiz (Fallzahlen)')
ax.set_ylabel('Anzahl Fälle')
fig.autofmt_xdate()
```
```{python Neue Fälle Anzahl, include = True, echo = False, caption = "Die Anzahl Fälle, welche jeweils über die letzten 7 Tage durchschnittlich neu hinzugekommen sind. Gepunktete Linien bedeuten, dass noch nicht von allen Kantonen Daten vorliegen. Fehlende Daten wurden interpoliert."}
cantons = dat['canton'].drop_duplicates()
dates = dat['date'].drop_duplicates()
cols = dat.columns[[3,4,5,6,7,8,9]]
df_ = dat.set_index(['canton','date'])
with Index(dat_inter,['canton','date']) as df_:
df = df_.sum(level='date',skipna=True)
#df = df.sum(level='date',skipna=True)
df.loc[:,'current_hosp'] = (
df.loc[:,'current_hosp'] +
df.loc[:,'ncumul_released'] + df.loc[:,'ncumul_deceased']
)
zh_vent = df_.loc['ZH','current_vent'].values
zh_vent[np.isnan(zh_vent)] = 0
df.loc[:,'current_icu'] = (
df.loc[:,'current_icu'] + df.loc[:,'ncumul_deceased']
)
df.values[-len(zh_vent):,4] += zh_vent
df = df.rolling('7D',min_periods=7).mean().diff()
len(zh_vent)
fig = plt.figure()
plt.rc('axes', prop_cycle=col_cycler)
ax = fig.subplots()
ax.plot(df['ncumul_conf'].iloc[ind.complete('ncumul_conf')],
label='Positive Testergebnisse')
ax.plot(df['ncumul_conf'].iloc[ind.incomplete('ncumul_conf')],
label='')
ax.plot(df['current_hosp'].iloc[ind.complete('current_hosp')],
label='Hospitalisierungen')
ax.plot(df['current_hosp'].iloc[ind.incomplete('current_hosp')],
label='',linestyle='--')
ax.plot(df['ncumul_deceased'].iloc[ind.complete('ncumul_deceased')],
label='Verstorben')
ax.plot(df['ncumul_deceased'].iloc[
ind.incomplete('ncumul_deceased')
],label='')
ax.plot(df['current_icu'].iloc[ind.complete('current_icu')],
label='Intensivstation')
ax.plot(df['current_icu'].iloc[ind.incomplete('current_icu')])
plt.grid(which='both')
plt.legend()
ax.set_title('Schweiz (Durchschnittswerte der letzten 7 Tage)')
ax.set_ylabel('Durschnittswert pro Tag')
fig.autofmt_xdate()
```
## Entwicklung in den Kantonen
### Luzern
```{python, include = True, echo = False}
plot_lu = Plot_canton('LU','Luzern')
plot_lu.plot0(dat)
```
### Aargau
```{python, include = True, echo = False}
plot_lu = Plot_canton('AG','Aargau')
plot_lu.plot0(dat)
```
### Basel-Stadt
```{python, include = True, echo = False}
plot_lu = Plot_canton('BS','Basel-Stadt')
plot_lu.plot0(dat)
```
### Basel-Land
```{python, include = True, echo = False}
plot_lu = Plot_canton('BL','Basel-Land')
plot_lu.plot0(dat)
```
### Bern
```{python, include = True, echo = False}
plot_lu = Plot_canton('BE','Bern')
plot_lu.plot0(dat)
```
### Zürich
```{python, include = True, echo = False}
plot_lu = Plot_canton('ZH','Zürich')
plot_lu.plot0(dat)
```
### Graubünden
```{python, include = True, echo = False}
plot_lu = Plot_canton('GR','Graubünden')
plot_lu.plot0(dat)
```
### Wallis
```{python, include = True, echo = False}
plot_lu = Plot_canton('VS','Wallis')
plot_lu.plot0(dat)
```
### Genf
```{python, include = True, echo = False}
plot_lu = Plot_canton('GE','Genf')
plot_lu.plot0(dat)
```
### Waadt
```{python, include = True, echo = False}
plot_lu = Plot_canton('VD','Waadt')
plot_lu.plot0(dat)
```
### Tessin
```{python, include = True, echo = False}
plot_lu = Plot_canton('TI','Tessin')
plot_lu.plot0(dat)
```
## Quelle
Die Grafiken auf dieser Seite beruhen auf den Daten, welche durch das *Statistischen Amt des Kanton Zürichs* gesammelt und zur Verfügung gestellt werden. Die Daten findet ihr [hier](https://github.com/openZH/covid_19/blob/master/README.md).