コード例 #1
0
def test_two_vaccines(do_plot=False):
    sc.heading('Testing nab decay in simulation...')

    p1 = cv.variant('sa variant',   days=20, n_imports=0)

    nabs = []
    vac1 = cv.vaccinate_num(vaccine='pfizer', sequence=[0], num_doses=1)
    vac2 = cv.vaccinate_num(vaccine='jj', sequence=[1], num_doses=1)

    sim  = cv.Sim(base_pars, n_days=1000, pop_size=2, pop_infected=0, rescale=False, use_waning=True, variants=p1, interventions=[vac1, vac2], analyzers=lambda sim: nabs.append(sim.people.nab.copy()))
    sim.run()

    if do_plot:
        nabs = np.array(nabs)
        print(sim.people.peak_nab)
        pl.figure()
        pl.plot(nabs)
コード例 #2
0
def test_two_vaccines(do_plot=False):
    sc.heading('Testing two vaccines...')

    p1 = cv.variant('beta',   days=20, n_imports=0)

    nabs = []
    vac1 = cv.vaccinate_num(vaccine='pfizer', sequence=[0], num_doses=1)
    vac2 = cv.vaccinate_num(vaccine='jj', sequence=[1], num_doses=1)

    sim  = cv.Sim(base_pars, n_days=1000, pop_size=2, pop_infected=0, variants=p1, interventions=[vac1, vac2], analyzers=lambda sim: nabs.append(sim.people.nab.copy()))

    # No infections, so suppress warnings
    with cv.options.context(warnings='print'):
        sim.run()
        print('↑↑↑ Should print warning about no infections')

    if do_plot:
        nabs = np.array(nabs).sum(axis=1)
        pl.figure()
        pl.plot(nabs)
        pl.show()

    return sim
コード例 #3
0
def test_vaccines_sequential(do_plot=False):
    sc.heading('Testing sequential vaccine...')

    n_days = 60
    p1 = cv.variant('beta', days=20, n_imports=20)
    num_doses = {i:(i**2)*(i%2==0) for i in np.arange(n_days)} # Test subtarget and fluctuating doses

    n_doses = []
    subtarget = dict(inds=np.arange(int(base_pars.pop_size//2)), vals=0.1)
    pfizer = cv.vaccinate_num(vaccine='pfizer', sequence='age', num_doses=num_doses, subtarget=subtarget)
    sim  = cv.Sim(base_pars, n_days=n_days, rescale=False, use_waning=True, variants=p1, interventions=pfizer, analyzers=lambda sim: n_doses.append(sim.people.doses.copy()))
    sim.run()

    n_doses = np.array(n_doses)

    if do_plot:
        fully_vaccinated = (n_doses == 2).sum(axis=1)
        first_dose = (n_doses == 1).sum(axis=1)
        pl.stackplot(sim.tvec, first_dose, fully_vaccinated)

        # Stacked bars by 10 year age

        # At the end of the simulation
        df = pd.DataFrame(n_doses.T)
        df['age_bin'] = np.digitize(sim.people.age,np.arange(0,100,10))
        df['fully_vaccinated'] = df[60]==2
        df['first_dose'] = df[60]==1
        df['unvaccinated'] = df[60]==0
        out = df.groupby('age_bin').sum()
        out[["unvaccinated", "first_dose","fully_vaccinated"]].plot(kind="bar", stacked=True)

        # Part-way through the simulation
        df = pd.DataFrame(n_doses.T)
        df['age_bin'] = np.digitize(sim.people.age,np.arange(0,100,10))
        df['fully_vaccinated'] = df[40]==2
        df['first_dose'] = df[40]==1
        df['unvaccinated'] = df[40]==0
        out = df.groupby('age_bin').sum()
        out[["unvaccinated", "first_dose","fully_vaccinated"]].plot(kind="bar", stacked=True)

    return sim
コード例 #4
0
def test_vaccines_sequential(do_plot=False):
    sc.heading('Testing sequential vaccine...')

    p1 = cv.variant('sa variant',   days=20, n_imports=20)
    def age_sequence(people): return np.argsort(-people.age)

    n_doses = []
    pfizer = cv.vaccinate_num(vaccine='pfizer', sequence=age_sequence, num_doses=lambda sim: sim.t)
    sim  = cv.Sim(base_pars, rescale=False, use_waning=True, variants=p1, interventions=pfizer, analyzers=lambda sim: n_doses.append(sim.people.vaccinations.copy()))
    sim.run()

    n_doses = np.array(n_doses)

    if do_plot:
        fully_vaccinated = (n_doses == 2).sum(axis=1)
        first_dose = (n_doses == 1).sum(axis=1)
        pl.stackplot(sim.tvec, first_dose, fully_vaccinated)

        # Stacked bars by 10 year age

        # At the end of the simulation
        df = pd.DataFrame(n_doses.T)
        df['age_bin'] = np.digitize(sim.people.age,np.arange(0,100,10))
        df['fully_vaccinated'] = df[60]==2
        df['first_dose'] = df[60]==1
        df['unvaccinated'] = df[60]==0
        out = df.groupby('age_bin').sum()
        out[["unvaccinated", "first_dose","fully_vaccinated"]].plot(kind="bar", stacked=True)

        # Part-way through the simulation
        df = pd.DataFrame(n_doses.T)
        df['age_bin'] = np.digitize(sim.people.age,np.arange(0,100,10))
        df['fully_vaccinated'] = df[40]==2
        df['first_dose'] = df[40]==1
        df['unvaccinated'] = df[40]==0
        out = df.groupby('age_bin').sum()
        out[["unvaccinated", "first_dose","fully_vaccinated"]].plot(kind="bar", stacked=True)

    return sim
コード例 #5
0
    beta=0.015,
    n_days=90,
)


# Define the prioritization function
def prioritize_by_age(people):
    return np.argsort(-people.age)


# Record the number of doses each person has received each day so
# that we can plot the rollout in this example. Without a custom
# analyzer, only the total number of doses will be recorded
n_doses = []

# Define sequence based vaccination
pfizer = cv.vaccinate_num(vaccine='pfizer',
                          sequence=prioritize_by_age,
                          num_doses=100)
sim = cv.Sim(pars=pars,
             interventions=pfizer,
             analyzers=lambda sim: n_doses.append(sim.people.doses.copy()))
sim.run()

pl.figure()
n_doses = np.array(n_doses)
fully_vaccinated = (n_doses == 2).sum(axis=1)
first_dose = (n_doses == 1).sum(axis=1)
pl.stackplot(sim.tvec, first_dose, fully_vaccinated)
pl.legend(['First dose', 'Fully vaccinated'])
pl.show()
コード例 #6
0
# Define a function to specify the number of doses
def num_doses(sim):
    if sim.t < 50:
        return sim.t*10
    else:
        return 500

# Define the number of boosters
def num_boosters(sim):
    if sim.t < 50: # None over the first 50 days
        return 0
    else:
        return 50 # Then 100/day thereafter

# Define base vaccine
pfizer = cv.vaccinate_num(vaccine='pfizer', sequence='age', num_doses=num_doses)

# Only give boosters to people who have had 2 doses
booster_target  = {'inds': lambda sim: cv.true(sim.people.doses != 2), 'vals': 0}
booster = cv.vaccinate_num(vaccine='pfizer', sequence='age', subtarget=booster_target, booster=True, num_doses=num_boosters)

# Track doses
n_doses = []
n_doses_boosters = []

# Create simple sim
sim = cv.Sim(
    pars          = pars,
    interventions = pfizer,
)
sim.run()
コード例 #7
0
        def age_sequence(people):
            return np.argsort(people.age)

        if 'extra' in scen:
            total_doses = 2.0e6
        else:
            total_doses = 0.0e5
        extra_days = sc.daterange('2021-07-11', '2021-07-20')
        doses = int(total_doses / len(extra_days))
        for day in extra_days:
            vxdict[day] = doses

        vax = 'az' if 'az' in scen else 'pfizer'
        vx = cv.vaccinate_num(
            vaccine=vax,
            num_doses=vxdict,
            sequence=age_sequence,
            label=f'{scen}')  # Most vaccinations have been AstraZeneca to date

        sim = cv.Sim(
            pars=pars,
            interventions=[vx],
            label=f'{scen}',
        )
        sims.append(sim)

    msim = cv.MultiSim(sims)
    msim.run()
    to_plot = cv.get_default_plots('default', 'scen')
    to_plot['Doses'] = ['cum_doses']
    to_plot['Infections'] = ['cum_infections']