X-Git-Url: https://git.njae.me.uk/?p=covid19.git;a=blobdiff_plain;f=covid.md;h=e86f0ed5e62e5037ca833da38741694937b12bcd;hp=b06cd354a8c39f61c6211a29f188af2d2b82dc1f;hb=HEAD;hpb=0fa9dcb25b4a7ee4e28c28f9c350add4f61f21ee diff --git a/covid.md b/covid.md deleted file mode 100644 index b06cd35..0000000 --- a/covid.md +++ /dev/null @@ -1,721 +0,0 @@ ---- -jupyter: - jupytext: - formats: ipynb,md - text_representation: - extension: .md - format_name: markdown - format_version: '1.2' - jupytext_version: 1.3.4 - kernelspec: - display_name: Python 3 - language: python - name: python3 ---- - -Data from [European Centre for Disease Prevention and Control](https://www.ecdc.europa.eu/en/publications-data/download-todays-data-geographic-distribution-covid-19-cases-worldwide) - -```python -import itertools -import collections -import json -import pandas as pd -import numpy as np -from scipy.stats import gmean -import datetime - -import matplotlib as mpl -import matplotlib.pyplot as plt -%matplotlib inline -``` - -```python -DEATH_COUNT_THRESHOLD = 10 -COUNTRIES_CORE = 'IT DE UK ES IE FR'.split() -COUNTRIES_NORDIC = 'SE NO DK FI UK'.split() -COUNTRIES_FRIENDS = 'IT UK ES BE SI MX'.split() -COUNTRIES_OF_INTEREST = list(set(COUNTRIES_CORE + COUNTRIES_FRIENDS)) -COUNTRIES_ALL = list(set(COUNTRIES_CORE + COUNTRIES_FRIENDS + COUNTRIES_NORDIC)) -``` - -```python -!curl https://opendata.ecdc.europa.eu/covid19/casedistribution/csv/ > covid.csv -``` - -```python -# First col is a date, treat geoId of NA as 'Namibia', not "NA" value -raw_data = pd.read_csv('covid.csv', parse_dates=[0], keep_default_na=False, dayfirst=True) -``` - -```python -raw_data.size -``` - -```python -raw_data.head() -``` - -```python -raw_data.dtypes -``` - -```python -base_data = raw_data.set_index(['geoId', 'dateRep']) -base_data.sort_index(inplace=True) -base_data -``` - -```python -base_data.loc['UK'] -``` - -```python -base_data.loc['UK', '2020-04-17'] -``` - -```python -countries = raw_data[['geoId', 'countriesAndTerritories', 'popData2018']] -countries = countries[countries['popData2018'] != ''] -countries = countries.drop_duplicates() -countries.set_index('geoId', inplace=True) -countries = countries.astype({'popData2018': 'int64'}) -countries.head() -``` - -```python -countries.shape -``` - -```python -countries[countries.countriesAndTerritories == 'Finland'] -``` - -```python -countries.loc[COUNTRIES_OF_INTEREST] -``` - -```python -data_by_date = base_data[['cases', 'deaths']] -data_by_date.head() -``` - -```python -data_by_date.loc['UK'] -``` - -```python -data_by_date.groupby(level=0).cumsum() -``` - -```python -data_by_date = data_by_date.merge( - data_by_date.groupby(level=0).cumsum(), - suffixes=('', '_culm'), - left_index=True, right_index=True) -data_by_date -``` - -```python -data_by_date = data_by_date.merge( - data_by_date[['cases', 'deaths']].groupby(level=0).diff(), - suffixes=('', '_diff'), - left_index=True, right_index=True) -data_by_date -``` - -```python -data_by_date.loc['UK', '2020-04-17'] -``` - -```python -data_by_date.loc['UK'] -``` - -```python -# data_by_date[data_by_date.deaths_culm > DEATH_COUNT_THRESHOLD] -``` - -```python -# days_since_threshold = data_by_date[data_by_date.deaths_culm > DEATH_COUNT_THRESHOLD].groupby(level=0).cumcount() -# days_since_threshold.rename('since_threshold', inplace=True) -``` - -```python -dbd = data_by_date[data_by_date.deaths_culm > DEATH_COUNT_THRESHOLD].reset_index(level=1) -dbd['since_threshold'] = dbd.dateRep -dbd.set_index('dateRep', append=True, inplace=True) -dbd.sort_index(inplace=True) -days_since_threshold = dbd.groupby(level=0).diff().since_threshold.dt.days.fillna(0).astype(int).groupby(level=0).cumsum() -# days_since_threshold.groupby(level=0).cumsum() - -# days_since_threshold = dbd.rename('since_threshold') -days_since_threshold -``` - -```python -# days_since_threshold = (data_by_date[data_by_date.deaths_culm > DEATH_COUNT_THRESHOLD] -# .reset_index(level=1).groupby(level=0) -# .diff().dateRep.dt.days -# .groupby(level=0).cumcount() -# ) -# days_since_threshold.rename('since_threshold', inplace=True) -# days_since_threshold -``` - -```python -data_since_threshold = data_by_date.merge(days_since_threshold, - left_index=True, right_index=True) -data_since_threshold -``` - -```python -data_since_threshold = data_since_threshold.set_index('since_threshold', append=True - ).reorder_levels(['since_threshold', 'geoId', 'dateRep'] - ).reset_index('dateRep') -data_since_threshold -``` - -```python -data_since_threshold.loc[(slice(None), ['UK', 'DE', 'IT']), :] -``` - -```python -data_since_threshold.loc[(slice(None), ['UK', 'DE', 'IT']), ['deaths_culm']].unstack().plot(logy=True) -``` - -```python -# deaths = data_since_threshold.loc[(slice(None), ['UK', 'DE', 'IT', 'IE']), ['deaths_culm']].unstack().xs('deaths_culm', axis=1, drop_level=True) -``` - -```python -deaths = data_since_threshold.loc[(slice(None), COUNTRIES_ALL), ['deaths_culm']].unstack().sort_index().xs('deaths_culm', axis=1, drop_level=True) -``` - -```python -data_since_threshold.reset_index().merge(countries, on='geoId').set_index(['since_threshold', 'geoId']) -``` - -```python -data_since_threshold.reset_index().merge(countries, on='geoId').set_index(['since_threshold', 'geoId']).sort_index(inplace=True) -``` - -```python -data_since_threshold_per_capita = data_since_threshold.reset_index().merge(countries, on='geoId').set_index(['since_threshold', 'geoId']) -data_since_threshold_per_capita['cases_culm_pc'] = data_since_threshold_per_capita.cases_culm / data_since_threshold_per_capita.popData2018 -data_since_threshold_per_capita['deaths_culm_pc'] = data_since_threshold_per_capita.deaths_culm / data_since_threshold_per_capita.popData2018 -data_since_threshold_per_capita -``` - -```python -deaths_pc = data_since_threshold_per_capita.loc[(slice(None), ['UK', 'DE', 'IT', 'IE']), ['deaths_culm_pc']].unstack().sort_index().xs('deaths_culm_pc', axis=1, drop_level=True) -``` - -```python -deaths_pc -``` - -```python -deaths_pc.index -``` - -```python -deaths_pc = data_since_threshold_per_capita.loc[(slice(None), COUNTRIES_ALL), ['deaths_culm_pc']].unstack().xs('deaths_culm_pc', axis=1, drop_level=True) -``` - -```python -deaths[COUNTRIES_CORE].plot() -``` - -```python -deaths[COUNTRIES_FRIENDS].plot() -``` - -```python -ax = deaths[COUNTRIES_CORE].plot(figsize=(10, 6), title="Total deaths, linear") -for c in COUNTRIES_CORE: - lvi = deaths[c].last_valid_index() - ax.text(x = lvi + 1, y = deaths[c][lvi], s = c) -plt.savefig('covid_deaths_total_linear.png') -``` - -```python -ax = deaths[COUNTRIES_NORDIC].plot(figsize=(10, 6), title="Total deaths, linear") -for c in COUNTRIES_NORDIC: - lvi = deaths[c].last_valid_index() - ax.text(x = lvi + 1, y = deaths[c][lvi], s = c) -# plt.savefig('covid_deaths_total_linear.png') -``` - -```python -ax = deaths[COUNTRIES_OF_INTEREST].plot(figsize=(10, 6), title="Total deaths, linear") -for c in COUNTRIES_OF_INTEREST: - lvi = deaths[c].last_valid_index() - ax.text(x = lvi + 1, y = deaths[c][lvi], s = c) -# plt.savefig('covid_deaths_total_linear.png') -``` - -```python -ax = deaths[COUNTRIES_CORE].plot(logy=True, figsize=(10, 6), title="Total deaths, log") -for c in COUNTRIES_CORE: - lvi = deaths[c].last_valid_index() - ax.text(x = lvi + 1, y = deaths[c][lvi], s = c) - -plt.savefig('covid_deaths_total_log.png') -``` - -```python -ylim = (5*10**3, 5*10**4) -ax = deaths[COUNTRIES_CORE].plot(logy=True, figsize=(10, 6), ylim=ylim, title="Total deaths, log") -for c in COUNTRIES_CORE: - lvi = deaths[c].last_valid_index() - if ylim[0] < deaths[c][lvi] < ylim[1]: - ax.text(x = lvi + 1, y = deaths[c][lvi], s = c) - -# plt.savefig('covid_deaths_total_log.png') -``` - -```python -ax = deaths[COUNTRIES_FRIENDS].plot(logy=True, figsize=(10, 6), title="Total deaths, log") -for c in COUNTRIES_FRIENDS: - lvi = deaths[c].last_valid_index() - ax.text(x = lvi + 1, y = deaths[c][lvi], s = c) - -# plt.savefig('covid_deaths_total_log.png') -``` - -```python -ax = deaths[COUNTRIES_NORDIC].plot(logy=True, figsize=(10, 6), title="Total deaths, log") -for c in COUNTRIES_NORDIC: - lvi = deaths[c].last_valid_index() - ax.text(x = lvi + 1, y = deaths[c][lvi], s = c) - -# plt.savefig('covid_deaths_total_log.png') -``` - -```python -ax = deaths[COUNTRIES_OF_INTEREST].plot(logy=True, figsize=(10, 6), title="Total deaths, log") -for c in COUNTRIES_OF_INTEREST: - lvi = deaths[c].last_valid_index() - ax.text(x = lvi + 1, y = deaths[c][lvi], s = c) - -plt.savefig('covid_deaths_total_log.png') -``` - -```python -ax = deaths_pc.plot(figsize=(10, 6), title="Deaths per capita, linear") -for c in deaths_pc.columns: - lvi = deaths_pc[c].last_valid_index() - ax.text(x = lvi + 1, y = deaths_pc[c][lvi], s = c) -plt.savefig('covid_deaths_per_capita_linear.png') -``` - -```python -ax = deaths_pc.plot(logy=True, figsize=(10, 6), title="Deaths per capita, log") -for c in deaths_pc.columns: - lvi = deaths_pc[c].last_valid_index() - ax.text(x = lvi + 1, y = deaths_pc[c][lvi], s = c) -``` - -```python -deaths_pc[['UK', 'IE']].plot( figsize=(10, 6), title="Deaths per capita, linear") -``` - -```python -deaths_pc[['UK', 'IE']].plot(logy=True, figsize=(10, 6), title="Deaths per capita, log") -``` - -```python -deaths[['UK', 'ES', 'IT']].plot(logy=True, figsize=(10, 6), title="Deaths, log") -plt.savefig('covid_deaths_selected_log.png') -``` - -```python -deaths[['UK', 'ES', 'IT', 'MX']].plot(logy=True, figsize=(10, 6), title="Deaths, log") -``` - -```python -data_since_threshold.loc[(slice(None), ['UK', 'DE', 'IT']), :] -``` - -```python -data_since_threshold['deaths_m4'] = data_since_threshold.groupby(level=1)['deaths'].transform(lambda x: x.rolling(4, 1).mean()) -data_since_threshold['deaths_m7'] = data_since_threshold.groupby(level=1)['deaths'].transform(lambda x: x.rolling(7, 1).mean()) -# data_since_threshold['deaths_diff_m4'] = data_since_threshold.groupby(level=1)['deaths_diff'].transform(lambda x: x.rolling(4, 1).mean()) -# data_since_threshold['deaths_diff_m7'] = data_since_threshold.groupby(level=1)['deaths_diff'].transform(lambda x: x.rolling(7, 1).mean()) -data_since_threshold.loc[(slice(None), ['UK', 'DE', 'IT']), :] -``` - -```python -deaths_m4 = (data_since_threshold.loc[(slice(None), COUNTRIES_ALL), ['deaths_m4']] - .unstack().sort_index().xs('deaths_m4', axis=1, drop_level=True)) -``` - -```python -deaths_m7 = (data_since_threshold.loc[(slice(None), COUNTRIES_ALL), ['deaths_m7']] - .unstack().sort_index().xs('deaths_m7', axis=1, drop_level=True)) -``` - -```python -ax = deaths_m4.plot(figsize=(10, 6), title="Deaths per day, 4 day moving average") -for c in deaths_m4.columns: - lvi = deaths_m4[c].last_valid_index() - ax.text(x = lvi + 1, y = deaths_m4[c][lvi], s = c) -plt.savefig('covid_deaths_per_day.png') -``` - -```python -ax = deaths_m4[COUNTRIES_CORE].plot(figsize=(10, 6), title="Deaths per day, 4 day moving average") -for c in COUNTRIES_CORE: - lvi = deaths_m4[c].last_valid_index() - ax.text(x = lvi + 1, y = deaths_m4[c][lvi], s = c) -plt.savefig('covid_deaths_per_day-core.png') -``` - -```python -ax = deaths_m4[COUNTRIES_FRIENDS].plot(figsize=(10, 6), title="Deaths per day, 4 day moving average") -for c in COUNTRIES_FRIENDS: - lvi = deaths_m4[c].last_valid_index() - ax.text(x = lvi + 1, y = deaths_m4[c][lvi], s = c) -plt.savefig('covid_deaths_per_day-friends.png') -``` - -```python -C7s = 'ES FR IT UK'.split() -ax = deaths_m7[C7s].plot(figsize=(10, 6), title="Deaths per day, 7 day moving average") -for c in C7s: - lvi = deaths_m7[c].last_valid_index() - ax.text(x = lvi + 1, y = deaths_m7[c][lvi], s = c) -# plt.savefig('covid_deaths_per_day-friends.png') -``` - -```python -ax = deaths_m7[COUNTRIES_CORE].plot(figsize=(10, 6), title="Deaths per day, 7 day moving average") -for c in COUNTRIES_CORE: - lvi = deaths_m7[c].last_valid_index() - ax.text(x = lvi + 1, y = deaths_m7[c][lvi], s = c) -plt.savefig('covid_deaths_per_day_7.png') -``` - -```python -ax = deaths_m7[COUNTRIES_FRIENDS].plot(figsize=(10, 6), title="Deaths per day, 7 day moving average") -for c in COUNTRIES_FRIENDS: - lvi = deaths_m7[c].last_valid_index() - ax.text(x = lvi + 1, y = deaths_m7[c][lvi], s = c) -plt.savefig('covid_deaths_per_day_friends_7.png') -``` - -```python -def gmean_scale(items): - return gmean(items) / items[-1] -``` - -```python -def doubling_time(df): - return np.log(2) / np.log((df.deaths_culm + df.deaths_g4) / df.deaths_culm) - -def doubling_time_7(df): - return np.log(2) / np.log((df.deaths_culm + df.deaths_g7) / df.deaths_culm) -``` - -```python -# data_since_threshold['deaths_g4'] = data_since_threshold.groupby(level=1)['deaths'].transform(lambda x: x.rolling(4, 1).apply(gmean_scale, raw=True)) -# data_since_threshold.loc[(slice(None), ['UK', 'DE', 'IT']), :] -``` - -```python -data_since_threshold['deaths_g4'] = data_since_threshold.groupby(level=1)['deaths'].transform(lambda x: x.rolling(4, 1).apply(gmean, raw=True)) -data_since_threshold['deaths_g7'] = data_since_threshold.groupby(level=1)['deaths'].transform(lambda x: x.rolling(7, 1).apply(gmean, raw=True)) -data_since_threshold.loc[(slice(None), ['UK', 'DE', 'IT']), :] -``` - -```python -data_since_threshold['doubling_time'] = data_since_threshold.groupby(level=1).apply(doubling_time).reset_index(level=0, drop=True) -data_since_threshold['doubling_time_7'] = data_since_threshold.groupby(level=1).apply(doubling_time_7).reset_index(level=0, drop=True) -# data_since_threshold.loc[(slice(None), 'UK'), :] -``` - -```python -doubling_times = (data_since_threshold.loc[(slice(None), COUNTRIES_OF_INTEREST), ['doubling_time']] - .unstack().sort_index().xs('doubling_time', axis=1, drop_level=True)) -doubling_times.replace([np.inf, -np.inf], np.nan, inplace=True) -``` - -```python -doubling_times_7 = (data_since_threshold.loc[(slice(None), COUNTRIES_OF_INTEREST), ['doubling_time_7']] - .unstack().sort_index().xs('doubling_time_7', axis=1, drop_level=True)) -doubling_times_7.replace([np.inf, -np.inf], np.nan, inplace=True) -``` - -```python -ax = doubling_times.plot(figsize=(10, 6), title="Doubling times, 4 day average") -for c in doubling_times.columns: - lvi = doubling_times[c].last_valid_index() - ax.text(x = lvi + 1, y = doubling_times[c][lvi], s = c) -# plt.savefig('covid_deaths_per_day.png') -``` - -```python -ax = doubling_times_7[COUNTRIES_CORE].plot(figsize=(10, 6), title="Doubling times, 7 day average") -for c in COUNTRIES_CORE: - lvi = doubling_times_7[c].last_valid_index() - ax.text(x = lvi + 1, y = doubling_times_7[c][lvi], s = c) -plt.savefig('covid_doubling_times_7.png') -``` - -```python -ax = doubling_times[COUNTRIES_CORE].plot(figsize=(10, 6), title="Doubling times, 4 day average") -for c in COUNTRIES_CORE: - lvi = doubling_times[c].last_valid_index() - ax.text(x = lvi + 1, y = doubling_times[c][lvi], s = c) -plt.savefig('covid_doubling_times.png') -``` - -```python -ax = doubling_times[COUNTRIES_FRIENDS].plot(figsize=(10, 6), title="Doubling times") -for c in COUNTRIES_FRIENDS: - lvi = doubling_times[c].last_valid_index() - ax.text(x = lvi + 1, y = doubling_times[c][lvi], s = c) -plt.savefig('covid_doubling_times_friends.png') -``` - -```python -ax = doubling_times[C7s].plot(figsize=(10, 6), title="Doubling times") -for c in C7s: - lvi = doubling_times[c].last_valid_index() - ax.text(x = lvi + 1, y = doubling_times[c][lvi], s = c) -# plt.savefig('covid_doubling_times_friends.png') -``` - -```python -# deaths_diff_m4 = (data_since_threshold.loc[(slice(None), COUNTRIES_ALL), ['deaths_diff_m4']] -# .unstack().sort_index().xs('deaths_diff_m4', axis=1, drop_level=True)) -``` - -```python -# deaths_diff_m7 = (data_since_threshold.loc[(slice(None), COUNTRIES_ALL), ['deaths_diff_m7']] -# .unstack().sort_index().xs('deaths_diff_m7', axis=1, drop_level=True)) -``` - -```python -# deaths_diff_m7 -``` - -```python -data_since_threshold.replace([np.inf, -np.inf], np.nan).groupby(level=1).last().loc[COUNTRIES_ALL]#, [doubling_time]] -``` - -```python -data_since_threshold.replace([np.inf, -np.inf], np.nan).groupby(level=1).last().loc[['UK', 'DE', 'IT']]#, [doubling_time]] -``` - -```python -it_since_threshold = data_since_threshold.replace([np.inf, -np.inf], np.nan).loc[(slice(None), ['IT']), :] -s_end = it_since_threshold.index.max()[0] -s_end -``` - -```python -uk_projection = data_since_threshold.replace([np.inf, -np.inf], np.nan).loc[(slice(None), ['UK']), :] -s_start = uk_projection.index.max()[0] + 1 -s_start -``` - -```python -proj = it_since_threshold.loc[(slice(s_start, s_end), slice(None)), ['cases', 'deaths']] -proj.index = pd.MultiIndex.from_tuples([(n, 'UK') for n, _ in proj.index], names=proj.index.names) -proj -``` - -Projected deaths, UK following IT trend from now. - -```python -uk_projection = uk_projection.append(proj, sort=True) -uk_projection.deaths.sum() -``` - -```python -it_since_threshold.deaths.sum() -``` - -```python -with open('excess_deaths.json') as f: - excess_deaths_data = json.load(f) -excess_deaths_data -``` - -```python -excess_deaths_upto = '2020-05-08' -excess_deaths = 54500 -``` - -```python -excess_deaths_upto = excess_deaths_data['end_date'] -excess_deaths = excess_deaths_data['excess_deaths'] -``` - -Recorded deaths in period where ONS has reported total deaths - -```python -reported_deaths = base_data.loc['UK'][:excess_deaths_upto]['deaths'].sum() -reported_deaths -``` - -```python -excess_deaths / reported_deaths -``` - -True deaths to date, if we follow the scaling of excess deaths over reported deaths so far. - -```python -uk_covid_deaths = data_since_threshold.replace([np.inf, -np.inf], np.nan).loc[(slice(None), ['UK']), 'deaths_culm'].iloc[-1] -uk_covid_deaths -``` - -```python -data_since_threshold.replace([np.inf, -np.inf], np.nan).loc[(slice(None), ['IT']), 'dateRep'].iloc[-1] + pd.Timedelta(s_end - s_start, unit='days') -``` - -```python -data_since_threshold.replace([np.inf, -np.inf], np.nan).loc[(slice(None), ['UK']), 'dateRep'].iloc[-1].strftime("%Y-%m-%d") -``` - -```python -uk_covid_deaths * excess_deaths / reported_deaths -``` - -```python -uk_projection.deaths.sum() * excess_deaths / reported_deaths -``` - -# Write results to summary file - -```python -with open('covid_summary.md', 'w') as f: - f.write('% Covid death data summary\n') - f.write('% Neil Smith\n') - f.write(f'% Created on {datetime.datetime.now().strftime("%Y-%m-%d")}\n') - f.write('\n') - - last_uk_date = data_since_threshold.replace([np.inf, -np.inf], np.nan).loc[(slice(None), ['UK']), 'dateRep'].iloc[-1] - f.write(f'> Last UK data from {last_uk_date.strftime("%Y-%m-%d")}\n') -``` - -```python -with open('covid_summary.md', 'a') as f: - f.write('\n') - f.write('## Headlines\n') - f.write('\n') - f.write('| []() | |\n') - f.write('|:---|---:|\n') - f.write(f'| Deaths reported so far | {reported_deaths} | \n') - f.write(f'| Total Covid deaths to date | {uk_covid_deaths * excess_deaths / reported_deaths:.0f} |\n') - projection_date = data_since_threshold.replace([np.inf, -np.inf], np.nan).loc[(slice(None), ['IT']), 'dateRep'].iloc[-1] + pd.Timedelta(s_end - s_start, unit='days') - f.write(f'| Projected total deaths up to {projection_date.strftime("%Y-%m-%d")} | {uk_projection.deaths.sum() * excess_deaths / reported_deaths:.0f} | \n') - f.write('\n') -``` - -```python -with open('covid_summary.md', 'a') as f: - f.write('\n') - f.write('## Total deaths\n') - f.write(f'Time based on days since {DEATH_COUNT_THRESHOLD} deaths\n') - f.write('\n') - f.write('![Total deaths](covid_deaths_total_linear.png)\n') - f.write('\n') - f.write('| Country ID | Country name | Total deaths |\n') - f.write('|:-----------|:-------------|-------------:|\n') - for c in sorted(COUNTRIES_CORE): - lvi = deaths[c].last_valid_index() - f.write(f'| {c} | {countries.loc[c].countriesAndTerritories} | {int(deaths[c][lvi])} |\n') - f.write('\n') -``` - -```python -with open('covid_summary.md', 'a') as f: - f.write('\n') - f.write('## All-causes deaths, UK\n') - f.write('\n') - f.write('![All-causes deaths](deaths-radar.png)\n') - f.write('\n') - f.write('### Excess deaths\n') - f.write('\n') - f.write(f'From week ending 20 March 2020, there have been approximately **{excess_deaths:.0f}** excess deaths, over the average for the previous five years.\n') - f.write('\n') -``` - -```python -with open('covid_summary.md', 'a') as f: - f.write(f'In that period, the UK reported {reported_deaths} Covid deaths.\n') - f.write(f'That means the actual number of Covid death is about {excess_deaths / reported_deaths:.2f} times higher than the reported figures.\n') - f.write('\n') - f.write(f'The UK has reported {uk_covid_deaths} deaths so far.\n') - f.write(f'Using the scaling factor above, I infer that there have been **{uk_covid_deaths * excess_deaths / reported_deaths:.0f}** total deaths so far.\n') - f.write('\n') -``` - -```python -with open('covid_summary.md', 'a') as f: - f.write('\n') - f.write('## Deaths per day\n') - f.write(f'Based on a 7-day moving average\n') - f.write('\n') - f.write('![Deaths per day](covid_deaths_per_day_7.png)\n') - f.write('\n') -``` - -```python -with open('covid_summary.md', 'a') as f: - f.write('\n') - f.write('## Projected deaths\n') - f.write(f"The UK's daily deaths data is very similar to Italy's.\n") - f.write(f'If I use the Italian data for the next {s_end - s_start - 1} days,') - f.write(f' the UK will report {uk_projection.deaths.sum()} deaths on day {s_end} of the epidemic.\n') - f.write('\n') - f.write('Using the excess deaths scaling from above, that will translate into ') - f.write(f'**{(uk_projection.deaths.sum() * excess_deaths / reported_deaths):.0f}** Covid deaths total.\n') - f.write('\n') -``` - -```python -with open('covid_summary.md', 'a') as f: - f.write('\n') - f.write('## Deaths doubling times\n') - f.write(f'Based on a 7-day moving average\n') - f.write('\n') - f.write('![Deaths doubling times](covid_doubling_times_7.png)\n') - f.write('\n') -``` - -```python -with open('covid_summary.md', 'a') as f: - f.write('# Data sources\n') - f.write('\n') - f.write('> Covid data from [European Centre for Disease Prevention and Control](https://www.ecdc.europa.eu/en/publications-data/download-todays-data-geographic-distribution-covid-19-cases-worldwide)\n') - f.write('\n') - f.write("""> Population data from: - -* [Office of National Statistics](https://www.ons.gov.uk/peoplepopulationandcommunity/birthsdeathsandmarriages/deaths/datasets/weeklyprovisionalfiguresondeathsregisteredinenglandandwales) (Endland and Wales) Weeks start on a Saturday. -* [Northern Ireland Statistics and Research Agency](https://www.nisra.gov.uk/publications/weekly-deaths) (Northern Ireland). Weeks start on a Saturday. Note that the week numbers don't match the England and Wales data. -* [National Records of Scotland](https://www.nrscotland.gov.uk/statistics-and-data/statistics/statistics-by-theme/vital-events/general-publications/weekly-and-monthly-data-on-births-and-deaths/weekly-data-on-births-and-deaths) (Scotland). Note that Scotland uses ISO8601 week numbers, which start on a Monday.""") - - f.write('\n\n') - f.write('> [Souce code available](https://git.njae.me.uk/?p=covid19.git;a=tree)\n') - f.write('\n') - -``` - -```python -!pandoc -s covid_summary.md > covid_summary.html -``` - -```python -!scp covid_summary.html neil@ogedei:/var/www/scripts.njae.me.uk/covid/index.html -!scp covid_deaths_total_linear.png neil@ogedei:/var/www/scripts.njae.me.uk/covid/ -!scp deaths-radar.png neil@ogedei:/var/www/scripts.njae.me.uk/covid/ -!scp covid_deaths_per_day_7.png neil@ogedei:/var/www/scripts.njae.me.uk/covid/ -!scp covid_doubling_times_7.png neil@ogedei:/var/www/scripts.njae.me.uk/covid/ -``` - -```python - -```