vaccination state corrected (first vs second dose), small cleanup

This commit is contained in:
fordprefect
2021-02-17 13:50:18 +01:00
parent aa8faf634e
commit 15784f7e72
3 changed files with 43 additions and 31 deletions

View File

@@ -34,6 +34,7 @@ def plot(data, countries, pop, metadata={}, **kwargs):
continue
name = basename+loc
time, new_cases, new_deaths, total_cases, total_deaths, total_vaccinations, stringency_index, new_vaccinations = data[loc]['time'], data[loc]['new_cases'], data[loc]['new_deaths'], data[loc]['total_cases'], data[loc]['total_deaths'], data[loc]['total_vaccinations'], data[loc]['stringency_index'], data[loc]['new_vaccinations']
people_fully_vaccinated = data[loc]['people_fully_vaccinated']
fig, ax1 = pp.subplots(num=name, figsize=figsize)
@@ -54,19 +55,8 @@ def plot(data, countries, pop, metadata={}, **kwargs):
if np.isnan(total_vaccinations[-2]):
print(f"{loc} starts vaccinating, adding to plot")
ax2.plot(time, np.array(total_vaccinations), label=f"Total vaccinations", marker="", linestyle="-.", color="crimson")
if False:
# plot detailed vaccination plot for all_countries.py
rfig, rax = pp.subplots(1,1,num=f"{loc}_vacc")
rax2 = rax.twinx()
rax.plot(time, new_vaccinations, linestyle="--", color="green", label="new vac")
rax2.plot(time, total_vaccinations, linestyle="-.", color="red", label="total vac")
rax.set_ylabel("new vaccinatios")
rax2.set_ylabel("total vaccinations")
rax.legend(frameon=False, loc=2)
rfig.savefig("img/"+f"{loc}".replace(" ", "_").replace("'", "").replace("/", "") + "/vaccs.png")
ax2.plot(time, np.array(total_vaccinations), label=f"Total vaccination doses", marker="", linestyle="-.", color="crimson")
ax2.plot(time, np.array(people_fully_vaccinated), label="fully vaccinated", marker="", linestyle="-", color="crimson")
# fix lower bound of plot
for ax in (ax1, ax2):
@@ -145,9 +135,9 @@ def plot(data, countries, pop, metadata={}, **kwargs):
if loc in pop:
#pp.title(f"{loc}", population = "+f"{pop[loc]['pop']:,}".replace(",","."))
title += ", population = "+f"{pop[loc]['pop']:,}".replace(",",".")
if not np.isnan(total_vaccinations[-1]):
title += ", vac rate: "+f"{total_vaccinations[-1]/pop[loc]['pop']*100:1.3f}%"
vaccs.append([loc, total_vaccinations[-1], total_vaccinations[-1]/pop[loc]['pop']*100]) # bookkeeping for overview
if not np.isnan(people_fully_vaccinated[-1]):
title += ", vac rate: "+f"{people_fully_vaccinated[-1]/pop[loc]['pop']*100:1.3f}%"
vaccs.append([loc, people_fully_vaccinated[-1], people_fully_vaccinated[-1]/pop[loc]['pop']*100]) # bookkeeping for overview
ax1.set_title(title)
fig.tight_layout()
pp.text(0.002,0.005, f"plot generated {time_module.strftime('%Y-%m-%d %H:%M')}, CC-by-sa-nc, origin: dukun.de/corona, datasource: ourworldindata.org/coronavirus-source-data", color="dimgrey", fontsize=8, transform=fig.transFigure)
@@ -167,7 +157,7 @@ def plot(data, countries, pop, metadata={}, **kwargs):
# data
for loc, tvac, rvac in vaccs:
line = f"<tr><td>{loc}</td><td>" + \
f"{tvac:,d}".replace(",",".") + \
f"{int(tvac):,d}".replace(",",".") + \
f"</td><td>{rvac:3.3f}%</td>".replace(".", ",")
if "vaccines" in metadata[loc]:
line += f"<td>{metadata[loc]['vaccines']}</td></tr>\n"

View File

@@ -224,6 +224,10 @@ def get_data():
for n in range(1, len(total_vaccinations)):
if np.isnan(total_vaccinations[n]) and not np.isnan(total_vaccinations[n-1]):
total_vaccinations[n] = total_vaccinations[n-1]
# fix vaccination data: not all countries report fully vaccinated
for n in range(1, len(people_fully_vaccinated)):
if np.isnan(people_fully_vaccinated[n]) and not np.isnan(people_fully_vaccinated[n-1]):
people_fully_vaccinated[n] = people_fully_vaccinated[n-1]
###
@@ -254,7 +258,7 @@ def get_data():
if loc in vaccines_country_dict:
metadata[loc]['vaccines'] = vaccines_country_dict[loc]
# cast population to int
if loc not in ("International", "Africa", "European Union", "Europe", "Asia", "North America", "South America", "Oceania"):
if loc not in ("International", "Africa", "European Union", "Europe", "Asia", "North America", "South America", "Oceania", "Northern Cyprus"):
try: metadata[loc]['population'] = int(float(metadata[loc]['population']))
except: metadata[loc][loc]['population'] = np.nan

View File

@@ -30,17 +30,32 @@ def plot(data, countries, pop, metadata, **kwargs):
# is this country vaccinating?
is_vaccinating = True if data[loc]['total_vaccinations'][-1] > 0 else False
if is_vaccinating:
first_vac_report = np.argwhere(np.isnan(data[loc]['total_vaccinations']))[-1][0] + 1
vac_text = f"<tr><td>Impfstart</td><td>{data[loc]['time'][first_vac_report]}</td></tr>"
vac_text = ""
try:
vac_rate = data[loc]['total_vaccinations'][-1]/metadata[loc]['population']*100
first_vac_report = np.argwhere(np.isnan(data[loc]['total_vaccinations']))[-1][0] + 1
vac_text += f"<tr><td>Impfstart</td><td>{data[loc]['time'][first_vac_report]}</td></tr>"
except:
print("------> country details: strange error, ignoring")
try:
if not (np.isnan(data[loc]['people_fully_vaccinated'])).all():
vac_rate = data[loc]['people_fully_vaccinated'][-1]/metadata[loc]['population']*100
vac_text += f"<tr><td>Impfrate</td><td>{vac_rate:1.3f} %</td></tr>"
else:
vac_text += f"<tr><td>Impfrate</td><td>n/a</td></tr>"
except:
pass
try:
immune_rate = (data[loc]['total_vaccinations'][-1] + data[loc]['total_cases'][-1])/metadata[loc]['population']*100
if not (np.isnan(data[loc]['people_fully_vaccinated'])).all():
immune_rate = (data[loc]['people_fully_vaccinated'][-1] + data[loc]['total_cases'][-1])/metadata[loc]['population']*100
vac_text += f"<tr><td>Immunrate</td><td>{immune_rate:1.3f} %</td></tr>"
vac_text += f"<tr><td>Geimpfte</td><td>{data[loc]['total_vaccinations'][-1]}</td></tr>"
vac_text += f"<tr><td>verabreichte Impfdosen</td><td>{data[loc]['total_vaccinations'][-1]}</td></tr>"
vac_text += f"<tr><td>vollständig Geimpfte</td><td>{int(data[loc]['people_fully_vaccinated'][-1])}</td></tr>"
else:
vac_text += f"<tr><td>Immunrate</td><td>n/a %</td></tr>"
vac_text += f"<tr><td>verabreichte Impfdosen</td><td>{data[loc]['total_vaccinations'][-1]}</td></tr>"
vac_text += f"<tr><td>vollständig Geimpfte</td><td>n/a</td></tr>"
except:
pass
try:
@@ -103,7 +118,10 @@ Letztes Update: {datetime.datetime.strftime(datetime.datetime.now(), "%Y-%m-%d")
<details open><summary>Testsituation</summary><img src=https://dukun.de/corona/{path}/tests.png />
<br>
Testing dataset: Hasell, J., Mathieu, E., Beltekian, D. et al. A cross-country database of COVID-19 testing. Sci Data 7, 345 (2020). <a href=https://doi.org/10.1038/s41597-020-00688-8>DOI:10.1038/s41597-020-00688-8</a></details>
<details open><summary>Impfsituation</summary><img src=https://dukun.de/corona/{path}/vaccinations.png /></details>
<details open><summary>Impfsituation</summary><img src=https://dukun.de/corona/{path}/vaccinations.png />
<br>
Immunität: Vollständige Impfung oder durchgemachte Erkrankung. Unterschätzung durch vernachlässigte Schutzwirkung der ersten Impfung. Überschätzung durch noch nicht beendete Erkrankungen.
</details>
<br><br>
<a href=https://dukun.de/corona>Zurück</a><br>
@@ -221,13 +239,13 @@ Ein Infoservice von <a href=dukun.de>dukun.de</a>; Anregungen gern <a href="mail
if not np.isnan(new_vaccinations).all():
ax1.plot(np.array(time), new_vaccinations, color="grey", linestyle="--", linewidth=1, label="new vaccinations")
if not np.isnan(total_vaccinations).all():
ax2.plot(np.array(time), total_vaccinations, color="blue", linestyle="-", linewidth=1, label="total vaccinations")
ax2.plot(np.array(time), total_vaccinations, color="blue", linestyle="-", linewidth=1, label="total vaccination doses")
if not np.isnan(people_fully_vaccinated).all():
ax2.plot(np.array(time), people_fully_vaccinated, color="black", linestyle="-", linewidth=1, label="people fully vaccinated")
immune_mask = ~np.isnan(total_vaccinations) & ~np.isnan(total_cases)
assert len(total_vaccinations) == len(total_cases)
total_immune = np.array(total_vaccinations) + np.array(total_cases)
immune_mask = ~np.isnan(people_fully_vaccinated) & ~np.isnan(total_cases)
assert len(people_fully_vaccinated) == len(total_cases)
total_immune = np.array(people_fully_vaccinated) + np.array(total_cases)
ax2.plot(np.array(time)[immune_mask], total_immune[immune_mask], color="green", linestyle="-", linewidth=1, label="total immune")
ax1.set_ylabel(f"new vaccinations")