Skip to content
Snippets Groups Projects
Unverified Commit d5ad80af authored by Rok Roškar's avatar Rok Roškar
Browse files

chore: fix up zh notebook

parent f274f293
No related branches found
No related tags found
Loading
%% Cell type:code id: tags:
``` python
%load_ext autoreload
%autoreload 2
```
%% Cell type:code id: tags:
``` python
from pathlib import Path
import altair as alt
import pandas as pd
from IPython.display import display, HTML
from covid_19_utils import helper, plotting
from covid_19_utils.converters import CaseConverter
```
%% Cell type:code id: tags:parameters
``` python
save_figures = False
data_path = '../data/openzh-covid-19'
atlas_path = '../data/atlas'
```
%% Cell type:code id: tags:
``` python
html_credits=HTML('''
<p style="font-size: smaller">Data Sources:
<a href="https://github.com/openZH/covid_19">OpenData Zuerich</a>,
<a href="https://www.bfs.admin.ch">Federal Statistical Office</a>
<br>
Analysis:
<a href="https://renkulab.io/projects/covid-19/covid-19-public-data">Covid-19 Public Data Collaboration Project</a>
</p>''')
```
%% Cell type:markdown id: tags:
## Summary data for Covid-19 cases in Switzerland
The data for Switzerland comes from the effort initiated by [OpenData Zürich](https://github.com/openZH/covid_19) and collected during the [Case data #covid19mon hackathon challenge](https://db.schoolofdata.ch/project/73).
Below we make plots of total cases, total cases per 10k population and total deaths. You can click on the canton abbreviations in the legend to highlight individual lines.
%% Cell type:code id: tags:
``` python
# read in cantonal data and produce one dataframe
converter = CaseConverter(atlas_path)
df = converter.read_convert(data_path)
df["canton"] = df.apply(lambda row: row["region_iso"][3:], axis=1)
```
%% Cell type:markdown id: tags:
### Total cases
%% Cell type:code id: tags:
``` python
startdate = "2021-06-01"
```
%% Cell type:code id: tags:
``` python
base = alt.Chart(df[df['date'] > startdate])
base.configure_header(titleFontSize=25)
base.configure_axis(labelFontSize=15, titleFontSize=15)
# cumul = generate_canton_chart(base, 'positive', 'Cases', 'Cases')
cumul = plotting.generate_region_chart(
base,
column='positive',
region_column='canton',
ytitle='Cases',
legend_title='Canton',
tooltip_title='Cases')
cumul_100k = plotting.generate_region_chart(
base,
column='positive_100k',
region_column='canton',
ytitle='Cases per 100k population',
legend_title='Canton',
tooltip_title='Cases/100k')
chart = alt.hconcat(
cumul, cumul_100k, title='Covid-19 cases in Switzerland by Canton'
).configure_title(
anchor='middle'
)
display(chart)
if save_figures:
chart.save(str(Path(figures_path) / 'switzerland-cases-by-canton.html'))
display(html_credits)
```
%% Cell type:markdown id: tags:
### Deaths
%% Cell type:code id: tags:
``` python
base = alt.Chart(df[df['date'] > startdate])
base.configure_header(titleFontSize=25)
base.configure_axis(labelFontSize=15, titleFontSize=15)
deaths = plotting.generate_region_chart(
base,
column='deceased',
region_column='canton',
ytitle='Deaths',
tooltip_title='Deaths',
legend_title='Canton'
)
deaths_10k = plotting.generate_region_chart(
base,
column='deceased_100k',
region_column='canton',
ytitle='Deaths per 100k population',
tooltip_title='Deaths/100k',
legend_title='Canton'
)
chart = alt.hconcat(
deaths, deaths_10k, title='Covid-19 deaths in Switzerland by Canton'
).configure_title(
anchor='middle'
)
display(chart)
display(html_credits)
if save_figures:
chart.save(str(Path(figures_path) / 'switzerland-deaths-by-canton.html'))
```
%% Cell type:code id: tags:
``` python
since_100th_case = helper.make_since_df(df, 'positive', 'canton', start_case=15000)
since_100th_case = helper.make_since_df(df, 'positive', 'canton', start_case=20000)
base = alt.Chart(since_100th_case, title="Switzerland: total cases since 1000th case").encode(alt.Y(scale=alt.Scale(type='log')))
lineChart = plotting.make_region_since_chart(
base,
'positive',
'sinceDay0',
'canton',
'Days since 1000th case',
'Cumulative positive cases',
'Cases',
'Canton'
).properties(
width=450,
height=450
)
lineChart
```
%% Cell type:code id: tags:
``` python
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment