Skip to content

Instantly share code, notes, and snippets.

@oerpli
Last active December 7, 2021 15:01
Show Gist options
  • Save oerpli/b1acde07e64214da815505355a0b7b4c to your computer and use it in GitHub Desktop.
Save oerpli/b1acde07e64214da815505355a0b7b4c to your computer and use it in GitHub Desktop.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["figure.dpi"] = 250
delta_r0 = 1.2
omicron_r0 = 1.35
hosp_fraction = 0.05
icu_fraction = 0.30
icu_shift = 5
hosp_shift = 4
df = pd.DataFrame({"days": list(range(30))}).set_index("days")
# Same formula for ICU fraction for both
hosp = lambda x: x.shift(hosp_shift) * hosp_fraction
icu = lambda x: x.shift(icu_shift) * icu_fraction
def add_columns(df, vr, r0):
df[f"Cases {vr}"] = np.power(r0, df.index)
df[f"Hosp {vr}"] = hosp(df[f"Cases {vr}"])
df[f"ICU {vr}"] = icu(df[f"Hosp {vr}"])
def frac(c1, c2, cum_sum):
if cum_sum:
df[f"{c1} / {c2} {vr}"] = df[f"{c1} {vr}"] / df[f"{c2} {vr}"].cumsum()
else:
df[f"{c1} / {c2} {vr}"] = df[f"{c1} {vr}"] / df[f"{c2} {vr}"]
frac("Hosp", "Cases", True)
frac("ICU", "Hosp", False)
for vr in [("Delta", delta_r0), ("Omicron", omicron_r0)]:
add_columns(df, *vr)
fig, ax = plt.subplots(3, figsize=(7, 9))
df[["Cases Delta", "Cases Omicron"]].plot(ax=ax[0])
df[["ICU Delta", "ICU Omicron"]].plot(ax=ax[0])
df[["Hosp / Cases Delta", "Hosp / Cases Omicron"]].plot(ax=ax[1])
df[["ICU / Hosp Delta", "ICU / Hosp Omicron"]].plot(ax=ax[2])
for a in ax:
a.set_xlabel("Days")
ax[0].set_title(
f"Growth Delta (${delta_r0}^t$) vs Omicron (${omicron_r0}^t$), 5% hosp, 1.5% ICU"
)
ax[1].set_ylim(bottom=0)
ax[2].set_ylim(bottom=0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment