Beispiel #1
0
def examplev2():
    pars = {'use_waning': True}
    variants = [cv.variant('b117', days=30, n_imports=10)]
    sim = cv.Sim(pars=pars, variants=variants)

    # length of our base campaign
    duration = 30
    # estimate per-day probability needed for a coverage of 30%
    prob = cv.historical_vaccinate_prob.estimate_prob(duration=duration,
                                                      coverage=0.30)
    print('using per-day probability of ', prob)

    # estimate per-day probability needed for a coverage of 30%
    prob2 = cv.historical_vaccinate_prob.estimate_prob(duration=2 * duration,
                                                       coverage=0.30)

    scenarios = {
        'base': {
            'name': 'baseline',
            'pars': {}
        },
        'scen1': {
            'name': 'historical_vaccinate',
            'pars': {
                'interventions': [
                    cv.historical_vaccinate_prob(vaccine='pfizer',
                                                 days=np.arange(-duration, 0),
                                                 prob=prob)
                ]
            }
        },
        'scen2': {
            'name': 'vaccinate',
            'pars': {
                'interventions': [
                    cv.vaccinate_prob(vaccine='pfizer',
                                      days=np.arange(0, 30),
                                      prob=prob)
                ]
            }
        },
        'scen3': {
            'name': 'historical_vaccinate into sim',
            'pars': {
                'interventions': [
                    cv.historical_vaccinate_prob(vaccine='pfizer',
                                                 days=np.arange(-30, 30),
                                                 prob=prob2)
                ]
            }
        },
    }

    scens = cv.Scenarios(sim=sim, scenarios=scenarios)

    scens.run()

    scens.plot()
Beispiel #2
0
def test_vaccines(do_plot=False):
    sc.heading('Testing vaccines...')

    p1 = cv.variant('sa variant',   days=20, n_imports=20)
    pfizer = cv.vaccinate_prob(vaccine='pfizer', days=30)
    sim  = cv.Sim(base_pars, use_waning=True, variants=p1, interventions=pfizer)
    sim.run()

    if do_plot:
        sim.plot('overview-variant')

    return sim
Beispiel #3
0
def test_vaccine_1variant(do_plot=False, do_show=True, do_save=False):
    sc.heading('Test vaccination with a single variant')

    pars = sc.mergedicts(base_pars, {
        'beta': 0.015,
        'n_days': 120,
    })

    pfizer = cv.vaccinate_prob(days=[20], vaccine='pfizer')
    sim = cv.Sim(use_waning=True, pars=pars, interventions=pfizer)
    sim.run()

    return sim
Beispiel #4
0
def test_vaccine_1variant_scen(do_plot=False, do_show=True, do_save=False):
    sc.heading('Run a basic sim with 1 variant, pfizer vaccine')

    # Define baseline parameters
    n_runs = 3
    base_sim = cv.Sim(use_waning=True, pars=base_pars)

    # Vaccinate 75+, then 65+, then 50+, then 18+ on days 20, 40, 60, 80
    base_sim.vxsubtarg = sc.objdict()
    base_sim.vxsubtarg.age = [75, 65, 50, 18]
    base_sim.vxsubtarg.prob = [.05, .05, .05, .05]
    base_sim.vxsubtarg.days = subtarg_days = [20, 40, 60, 80]
    pfizer = cv.vaccinate_prob(days=subtarg_days,
                               vaccine='pfizer',
                               subtarget=vacc_subtarg)

    # Define the scenarios

    scenarios = {
        'baseline': {
            'name': 'No Vaccine',
            'pars': {}
        },
        'pfizer': {
            'name': 'Pfizer starting on day 20',
            'pars': {
                'interventions': [pfizer],
            }
        },
    }

    metapars = {'n_runs': n_runs}
    scens = cv.Scenarios(sim=base_sim, metapars=metapars, scenarios=scenarios)
    scens.run()

    to_plot = sc.objdict({
        'New infections': ['new_infections'],
        'Cumulative infections': ['cum_infections'],
        'New reinfections': ['new_reinfections'],
        # 'Cumulative reinfections': ['cum_reinfections'],
    })
    if do_plot:
        scens.plot(do_save=do_save,
                   do_show=do_show,
                   fig_path='results/test_basic_vaccination.png',
                   to_plot=to_plot)

    return scens
Beispiel #5
0
def test_vaccine_1dose(do_plot=False, do_show=True, do_save=False):
    # Create some base parameters
    pars = sc.mergedicts(base_pars, {
        'beta': 0.015,
        'n_days': 120,
    })
    janssen = cv.vaccinate_prob(vaccine='janssen', days=[0])
    sim = cv.Sim(use_waning=True, pars=pars, interventions=janssen)
    sim.run()
    to_plot = sc.objdict({
        'New infections': ['new_infections'],
        'Cumulative infections': ['cum_infections'],
        'New reinfections': ['new_reinfections'],
    })
    if do_plot:
        sim.plot(do_save=do_save,
                 do_show=do_show,
                 fig_path='results/test_reinfection.png',
                 to_plot=to_plot)
Beispiel #6
0
def make_sim(use_defaults=False, do_plot=False, **kwargs):
    '''
    Define a default simulation for testing the baseline -- use hybrid and include
    interventions to increase coverage. If run directly (not via pytest), also
    plot the sim by default.
    '''

    # Define the interventions
    tp = cv.test_prob(start_day=20, symp_prob=0.1, asymp_prob=0.01)
    vx = cv.vaccinate_prob('pfizer', days=30, prob=0.1)
    cb = cv.change_beta(days=40, changes=0.5)
    ct = cv.contact_tracing(trace_probs=0.3, start_day=50)

    # Define the parameters
    pars = dict(
        use_waning=True,  # Whether or not to use waning and NAb calculations
        pop_size=20e3,  # Population size
        pop_infected=
        100,  # Number of initial infections -- use more for increased robustness
        pop_type=
        'hybrid',  # Population to use -- "hybrid" is random with household, school,and work structure
        n_days=60,  # Number of days to simulate
        verbose=0,  # Don't print details of the run
        rand_seed=2,  # Set a non-default seed
        interventions=[cb, tp, ct,
                       vx],  # Include the most common interventions
    )
    pars = sc.mergedicts(pars, kwargs)

    # Create the sim
    if use_defaults:
        sim = cv.Sim()
    else:
        sim = cv.Sim(pars)

    # Optionally plot
    if do_plot:
        s2 = sim.copy()
        s2.run()
        s2.plot()

    return sim
Beispiel #7
0
def test_synthpops():
    sim = cv.Sim(use_waning=True,
                 **sc.mergedicts(base_pars,
                                 dict(pop_size=5000, pop_type='synthpops')))
    sim.popdict = cv.make_synthpop(sim,
                                   with_facilities=True,
                                   layer_mapping={'LTCF': 'f'})
    sim.reset_layer_pars()

    # Vaccinate 75+, then 65+, then 50+, then 18+ on days 20, 40, 60, 80
    sim.vxsubtarg = sc.objdict()
    sim.vxsubtarg.age = [75, 65, 50, 18]
    sim.vxsubtarg.prob = [.05, .05, .05, .05]
    sim.vxsubtarg.days = subtarg_days = [20, 40, 60, 80]
    pfizer = cv.vaccinate_prob(days=subtarg_days,
                               vaccine='pfizer',
                               subtarget=vacc_subtarg)
    sim['interventions'] += [pfizer]

    sim.run()
    return sim
Beispiel #8
0
def test_vaccine_target_eff():

    sc.heading('Testing vaccine with pre-specified efficacy...')
    target_eff_1 = 0.7
    target_eff_2 = 0.95

    default_pars = cv.parameters.get_vaccine_dose_pars(default=True)
    test_pars = dict(doses=2, interval=21, target_eff=[target_eff_1, target_eff_2])
    vacc_pars = sc.mergedicts(default_pars, test_pars)

    # construct analyzer to select placebo arm
    class placebo_arm(cv.Analyzer):
        def __init__(self, day, trial_size, **kwargs):
            super().__init__(**kwargs)
            self.day = day
            self.trial_size = trial_size
            return

        def initialize(self, sim=None):
            self.placebo_inds = []
            self.initialized = True
            return

        def apply(self, sim):
            if sim.t == self.day:
                eligible = cv.true(~np.isfinite(sim.people.date_exposed) & ~sim.people.vaccinated)
                self.placebo_inds = eligible[cv.choose(len(eligible), min(self.trial_size, len(eligible)))]
            return

    pars = dict(
        rand_seed  = 1, # Note: results may be sensitive to the random seed
        pop_size   = 20_000,
        beta       = 0.01,
        n_days     = 90,
        verbose    = -1,
        use_waning = True,
    )

    # Define vaccine arm
    trial_size = 4_000
    start_trial = 20

    def subtarget(sim):
        ''' Select people who are susceptible '''
        if sim.t == start_trial:
            eligible = cv.true(~np.isfinite(sim.people.date_exposed))
            inds = eligible[cv.choose(len(eligible), min(trial_size // 2, len(eligible)))]
        else:
            inds = []
        return {'vals': [1.0 for ind in inds], 'inds': inds}

    # Initialize
    vx = cv.vaccinate_prob(vaccine=vacc_pars, days=[start_trial], label='target_eff', prob=0.0, subtarget=subtarget)
    sim = cv.Sim(
        pars          = pars,
        interventions = vx,
        analyzers     = placebo_arm(day=start_trial, trial_size=trial_size // 2)
    )

    # Run
    sim.run()

    print('Vaccine efficiency:')
    results = sc.objdict()
    vacc_inds = cv.true(sim.people.vaccinated)  # Find trial arm indices, those who were vaccinated
    placebo_inds = sim['analyzers'][0].placebo_inds
    assert (len(set(vacc_inds).intersection(set(placebo_inds))) == 0)  # Check that there is no overlap
    # Calculate vaccine efficacy against infection
    VE_inf = 1 - (np.isfinite(sim.people.date_exposed[vacc_inds]).sum() /
                  np.isfinite(sim.people.date_exposed[placebo_inds]).sum())
    # Calculate vaccine efficacy against symptoms
    VE_symp = 1 - (np.isfinite(sim.people.date_symptomatic[vacc_inds]).sum() /
                   np.isfinite(sim.people.date_symptomatic[placebo_inds]).sum())
    # Calculate vaccine efficacy against severe disease
    VE_sev = 1 - (np.isfinite(sim.people.date_severe[vacc_inds]).sum() /
                  np.isfinite(sim.people.date_severe[placebo_inds]).sum())
    results['inf'] = VE_inf
    results['symp'] = VE_symp
    results['sev'] = VE_sev
    print(f'Against: infection: {VE_inf * 100:0.2f}%, symptoms: {VE_symp * 100:0.2f}%, severity: {VE_sev * 100:0.2f}%')

    # Check that actual efficacy is within 6 %age points of target
    errormsg = f'Expected VE to be about {target_eff_2}, but it is {VE_symp}. Check different random seeds; this test is highly sensitive.'
    assert round(abs(VE_symp-target_eff_2),2)<=0.1, errormsg

    nab_init = sim['vaccine_pars']['target_eff']['nab_init']
    boost = sim['vaccine_pars']['target_eff']['nab_boost']
    print(f'Initial NAbs: {nab_init}')
    print(f'Boost: {boost}')

    return sim
Beispiel #9
0
'''
Illustrate simple vaccine usage
'''

import covasim as cv

# Create some base parameters
pars = dict(
    beta   = 0.015,
    n_days = 90,
)

# Define probability based vaccination
pfizer = cv.vaccinate_prob(vaccine='pfizer', days=20, prob=0.8)

# Create and run the sim
sim = cv.Sim(pars=pars, interventions=pfizer)
sim.run()
sim.plot(['new_infections', 'cum_infections', 'new_doses', 'cum_doses'])
Beispiel #10
0
def make_sim(seed,
             beta,
             calibration=True,
             future_symp_test=None,
             scenario=None,
             vx_scenario=None,
             end_day='2021-08-31',
             verbose=0):

    # Set the parameters
    #total_pop    = 67.86e6 # UK population size
    total_pop = 55.98e6  # UK population size
    pop_size = 100e3  # Actual simulated population
    pop_scale = int(total_pop / pop_size)
    pop_type = 'hybrid'
    pop_infected = 1000
    beta = beta
    asymp_factor = 2
    contacts = {'h': 3.0, 's': 20, 'w': 20, 'c': 20}
    beta_layer = {'h': 3.0, 's': 1.0, 'w': 0.6, 'c': 0.3}
    if end_day is None: end_day = '2021-05-05'

    pars = sc.objdict(
        use_waning=True,
        pop_size=pop_size,
        pop_infected=pop_infected,
        pop_scale=pop_scale,
        pop_type=pop_type,
        start_day=start_day,
        end_day=end_day,
        beta=beta,
        asymp_factor=asymp_factor,
        contacts=contacts,
        rescale=True,
        rand_seed=seed,
        verbose=verbose,
    )

    sim = cv.Sim(pars=pars, datafile=data_path, location='uk')
    #sim['prognoses']['sus_ORs'][0] = 0.5 # ages 0-10
    #sim['prognoses']['sus_ORs'][1] = 1.0 # ages 11-20

    # ADD BETA INTERVENTIONS
    #sbv is transmission in schools and assumed to be 63%=0.7*90% assuming that masks are used and redyce it by 30%
    #from June 2021 we will asume that it is 50% as a combination of large scale isolation of bubbles - found via seeking optimal value
    sbv = 0.63
    sbv_new = 0.63
    beta_past = sc.odict({
        '2020-02-14': [1.00, 1.00, 0.90, 0.90],
        '2020-03-16': [1.00, 0.90, 0.80, 0.80],
        #first lockdown starts
        '2020-03-23': [1.00, 0.02, 0.20, 0.20],
        #first lockdown ends
        '2020-06-01': [1.00, 0.23, 0.40, 0.40],
        '2020-06-15': [1.00, 0.38, 0.50, 0.50],
        '2020-07-22': [1.15, 0.00, 0.30, 0.50],
        '2020-07-29': [1.15, 0.00, 0.30, 0.70],
        '2020-08-12': [1.15, 0.00, 0.30, 0.70],
        '2020-07-19': [1.15, 0.00, 0.30, 0.70],
        '2020-07-26': [1.15, 0.00, 0.30, 0.70],
        #schools start in Sep 2020
        '2020-09-02': [1.15, sbv, 0.50, 0.70],
        '2020-10-01': [1.15, sbv, 0.40, 0.70],
        '2020-10-16': [1.15, sbv, 0.40, 0.70],
        #schools holiday Oct 2020
        '2020-10-26': [1.15, 0.00, 0.30, 0.60],
        #2nd lockdown starts
        '2020-11-05': [1.15, sbv, 0.30, 0.40],
        '2020-11-14': [1.15, sbv, 0.30, 0.40],
        '2020-11-21': [1.15, sbv, 0.30, 0.40],
        '2020-11-30': [1.15, sbv, 0.30, 0.40],
        '2020-12-05': [1.15, sbv, 0.30, 0.40],
        #2nd lockdown ends and opening for Christmas
        '2020-12-10': [1.50, sbv, 0.40, 0.80],
        '2020-12-17': [1.50, sbv, 0.40, 0.80],
        '2020-12-24': [1.50, 0.00, 0.40, 0.60],
        '2020-12-26': [1.50, 0.00, 0.40, 0.70],
        '2020-12-31': [1.50, 0.00, 0.20, 0.70],
        '2021-01-01': [1.50, 0.00, 0.20, 0.70],
        #3rd lockdown starts
        '2021-01-04': [1.10, 0.14, 0.20, 0.40],
        '2021-01-11': [1.05, 0.14, 0.20, 0.40],
        '2021-01-18': [1.05, 0.14, 0.30, 0.30],
        '2021-01-30': [1.05, 0.14, 0.30, 0.30],
        '2021-02-08': [1.05, 0.14, 0.30, 0.30],
        '2021-02-15': [1.05, 0.00, 0.20, 0.20],
        '2021-02-22': [1.05, 0.14, 0.30, 0.30],
        #3rd lockdown ends and reopening starts in 4 steps
        #schools open in March 2021 - step 1 part 1
        '2021-03-08': [1.05, sbv, 0.30, 0.40],
        '2021-03-15': [1.05, sbv, 0.30, 0.40],
        '2021-03-22': [1.05, sbv, 0.30, 0.40],
        #stay at home rule finishes - step 1 part 2
        '2021-03-29': [1.05, 0.00, 0.40, 0.50],
        '2021-04-01': [1.05, 0.00, 0.30, 0.50],
        #further relaxation measures - step 2
        '2021-04-12': [1.05, 0.00, 0.30, 0.40],
        '2021-04-19': [1.05, sbv, 0.30, 0.40],
        '2021-04-26': [1.05, sbv, 0.30, 0.40],
        '2021-05-03': [1.05, sbv, 0.30, 0.40],
        '2021-05-10': [1.05, sbv, 0.30, 0.40],
        #some further relaxation  - step 3
        '2021-05-17': [1.05, sbv, 0.30, 0.50],
        '2021-05-21': [1.05, sbv, 0.30, 0.50],
        #May half-term
        '2021-05-31': [1.05, 0.00, 0.30, 0.40],
        #slight relaxation after Spring half-term
        #but delay Step 3 until 19/07/2021
        '2021-06-07': [1.05, sbv, 0.30, 0.50],
        '2021-06-14': [1.05, sbv, 0.30, 0.50],
        '2021-06-21': [1.05, sbv, 0.30, 0.50],
        '2021-06-28': [1.05, sbv, 0.30, 0.50],
        '2021-07-05': [1.25, sbv, 0.30, 0.50],
        '2021-07-12': [1.25, sbv, 0.30, 0.50],
        '2021-07-19': [1.25, 0.00, 0.30, 0.50],
        '2021-07-26': [1.25, 0.00, 0.30, 0.50],
        '2021-08-02': [1.25, 0.00, 0.30, 0.50],
    })

    if not calibration:
        ##no schools until 8th March but assue 20% (1 in 5) in schools between 04/01-22/02;
        ##model transmission remaining at schools as 14% (to account for 30% reduction due to school measures)
        ## reopening schools on 8th March, society stage 1 29th March, society stage 2 12th April,
        ## society some more (stage 3) 17th May and everything (stage 4) 21st June 2021.
        ## Projecting until end of August 2021.
        if scenario == 'Roadmap_Step3':

            beta_scens = sc.odict({
                '2021-06-21': [1.05, sbv, 0.40, 0.80],
                '2021-06-28': [1.25, sbv, 0.40, 0.80],
                '2021-07-05': [1.25, sbv, 0.40, 0.80],
                '2021-07-12': [1.25, sbv, 0.40, 0.80],
                '2021-07-19': [1.25, 0.00, 0.40, 0.80],
                '2021-07-26': [1.25, 0.00, 0.40, 0.80],
                '2021-08-02': [1.25, 0.00, 0.40, 0.80],
            })

        elif scenario == 'Roadmap_delayed_Step3':
            beta_scens = sc.odict({
                '2021-06-21': [1.25, sbv, 0.30, 0.50],
                '2021-06-28': [1.25, sbv, 0.30, 0.50],
                '2021-07-05': [1.25, sbv, 0.30, 0.50],
                '2021-07-12': [1.25, sbv, 0.30, 0.50],
                '2021-07-19': [1.25, 0.00, 0.40, 0.80],
                '2021-07-26': [1.25, 0.00, 0.40, 0.80],
                '2021-08-02': [1.25, 0.00, 0.40, 0.80],
            })
        beta_dict = sc.mergedicts(beta_past, beta_scens)
    else:
        beta_dict = beta_past

    beta_days = list(beta_dict.keys())
    h_beta = cv.change_beta(days=beta_days,
                            changes=[c[0] for c in beta_dict.values()],
                            layers='h')
    s_beta = cv.change_beta(days=beta_days,
                            changes=[c[1] for c in beta_dict.values()],
                            layers='s')
    w_beta = cv.change_beta(days=beta_days,
                            changes=[c[2] for c in beta_dict.values()],
                            layers='w')
    c_beta = cv.change_beta(days=beta_days,
                            changes=[c[3] for c in beta_dict.values()],
                            layers='c')

    # Add B.1.1351 strain from August 2020; n_imports, rel_beta and rel_severe_beta from calibration
    b1351 = cv.variant('b1351',
                       days=np.arange(sim.day('2020-08-10'),
                                      sim.day('2020-08-20')),
                       n_imports=3000)
    b1351.p['rel_beta'] = 1.2
    b1351.p['rel_severe_prob'] = 0.4
    sim['variants'] += [b1351]

    # Add Alpha strain from October 2020; n_imports, rel_beta and rel_severe_beta from calibration
    b117 = cv.variant('b117',
                      days=np.arange(sim.day('2020-10-20'),
                                     sim.day('2020-10-30')),
                      n_imports=3000)
    b117.p['rel_beta'] = 1.8
    b117.p['rel_severe_prob'] = 0.4
    sim['variants'] += [b117]

    # Add Delta strain starting middle of April 2021; n_imports, rel_beta and rel_severe_beta from calibration
    b16172 = cv.variant('b16172',
                        days=np.arange(sim.day('2021-04-15'),
                                       sim.day('2021-04-20')),
                        n_imports=4000)
    b16172.p['rel_beta'] = 2.9
    b16172.p['rel_severe_prob'] = 0.2
    sim['variants'] += [b16172]

    interventions = [h_beta, w_beta, s_beta, c_beta]

    # ADD TEST AND TRACE INTERVENTIONS
    tc_day = sim.day(
        '2020-03-16'
    )  #intervention of some testing (tc) starts on 16th March and we run until 1st April when it increases
    te_day = sim.day(
        '2020-04-01'
    )  #intervention of some testing (te) starts on 1st April and we run until 1st May when it increases
    tt_day = sim.day(
        '2020-05-01'
    )  #intervention of increased testing (tt) starts on 1st May
    tti_day = sim.day(
        '2020-06-01'
    )  #intervention of tracing and enhanced testing (tti) starts on 1st June
    tti_day_july = sim.day(
        '2020-07-01'
    )  #intervention of tracing and enhanced testing (tti) at different levels starts on 1st July
    tti_day_august = sim.day(
        '2020-08-01'
    )  #intervention of tracing and enhanced testing (tti) at different levels starts on 1st August
    tti_day_sep = sim.day('2020-09-01')
    tti_day_oct = sim.day('2020-10-01')
    tti_day_nov = sim.day('2020-11-01')
    tti_day_dec = sim.day('2020-12-01')
    tti_day_jan = sim.day('2021-01-01')
    tti_day_feb = sim.day('2021-02-01')
    tti_day_march = sim.day('2021-03-08')
    tti_day_june21 = sim.day('2021-06-20')
    tti_day_july21 = sim.day('2021-07-19')
    tti_day_august21 = sim.day('2021-08-02')
    tti_day_sep21 = sim.day('2021-09-07')

    s_prob_april = 0.012
    s_prob_may = 0.012
    s_prob_june = 0.04769
    s_prob_july = 0.04769
    s_prob_august = 0.04769
    s_prob_sep = 0.07769
    s_prob_oct = 0.07769
    s_prob_nov = 0.07769
    s_prob_dec = 0.07769
    s_prob_jan = 0.08769
    s_prob_march = 0.08769
    #for reopening in June
    #s_prob_june21 = 0.19769
    #for reopening in July
    s_prob_june21 = 0.08769
    #for reopening in July
    #s_prob_july21 = 0.195069
    s_prob_july21 = 0.08769
    s_prob_august21 = 0.08769
    s_prob_sep21 = 0.03769

    #0.114=70%; 0.149=80%; 0.205=90%

    if future_symp_test is None: future_symp_test = s_prob_jan
    t_delay = 1.0

    #isolation may-june
    iso_vals = [{k: 0.2 for k in 'hswc'}]
    #isolation july
    iso_vals1 = [{k: 0.4 for k in 'hswc'}]
    #isolation september
    iso_vals2 = [{k: 0.6 for k in 'hswc'}]
    #isolation october
    iso_vals3 = [{k: 0.6 for k in 'hswc'}]
    #isolation november
    iso_vals4 = [{k: 0.2 for k in 'hswc'}]
    #isolation december
    iso_vals5 = [{k: 0.5 for k in 'hswc'}]
    #isolation March 2021
    ####changed to 0.2 for fitting
    iso_vals6 = [{k: 0.5 for k in 'hswc'}]
    #isolation from 20 June 2021 reduced
    iso_vals7 = [{k: 0.7 for k in 'hswc'}]
    #isolation from 16 July 2021 increased
    ####chnaged to 0.2 for fitting
    iso_vals8 = [{k: 0.3 for k in 'hswc'}]
    #isolation from August 2021
    iso_vals9 = [{k: 0.5 for k in 'hswc'}]
    #isolation from Sep 2021
    iso_vals10 = [{k: 0.5 for k in 'hswc'}]

    #testing and isolation intervention
    interventions += [
        cv.test_prob(symp_prob=0.009,
                     asymp_prob=0.0,
                     symp_quar_prob=0.0,
                     start_day=tc_day,
                     end_day=te_day - 1,
                     test_delay=t_delay),
        cv.test_prob(symp_prob=s_prob_april,
                     asymp_prob=0.0,
                     symp_quar_prob=0.0,
                     start_day=te_day,
                     end_day=tt_day - 1,
                     test_delay=t_delay),
        cv.test_prob(symp_prob=s_prob_may,
                     asymp_prob=0.00076,
                     symp_quar_prob=0.0,
                     start_day=tt_day,
                     end_day=tti_day - 1,
                     test_delay=t_delay),
        cv.test_prob(symp_prob=s_prob_june,
                     asymp_prob=0.00076,
                     symp_quar_prob=0.0,
                     start_day=tti_day,
                     end_day=tti_day_july - 1,
                     test_delay=t_delay),
        cv.test_prob(symp_prob=s_prob_july,
                     asymp_prob=0.00076,
                     symp_quar_prob=0.0,
                     start_day=tti_day_july,
                     end_day=tti_day_august - 1,
                     test_delay=t_delay),
        cv.test_prob(symp_prob=s_prob_august,
                     asymp_prob=0.0028,
                     symp_quar_prob=0.0,
                     start_day=tti_day_august,
                     end_day=tti_day_sep - 1,
                     test_delay=t_delay),
        cv.test_prob(symp_prob=s_prob_sep,
                     asymp_prob=0.0028,
                     symp_quar_prob=0.0,
                     start_day=tti_day_sep,
                     end_day=tti_day_oct - 1,
                     test_delay=t_delay),
        cv.test_prob(symp_prob=s_prob_oct,
                     asymp_prob=0.0028,
                     symp_quar_prob=0.0,
                     start_day=tti_day_oct,
                     end_day=tti_day_nov - 1,
                     test_delay=t_delay),
        cv.test_prob(symp_prob=s_prob_nov,
                     asymp_prob=0.0063,
                     symp_quar_prob=0.0,
                     start_day=tti_day_nov,
                     end_day=tti_day_dec - 1,
                     test_delay=t_delay),
        cv.test_prob(symp_prob=s_prob_dec,
                     asymp_prob=0.0063,
                     symp_quar_prob=0.0,
                     start_day=tti_day_dec,
                     end_day=tti_day_jan - 1,
                     test_delay=t_delay),
        cv.test_prob(symp_prob=s_prob_jan,
                     asymp_prob=0.0063,
                     symp_quar_prob=0.0,
                     start_day=tti_day_jan,
                     end_day=tti_day_feb - 1,
                     test_delay=t_delay),
        cv.test_prob(symp_prob=s_prob_jan,
                     asymp_prob=0.008,
                     symp_quar_prob=0.0,
                     start_day=tti_day_feb,
                     end_day=tti_day_march - 1,
                     test_delay=t_delay),
        cv.test_prob(symp_prob=s_prob_march,
                     asymp_prob=0.008,
                     symp_quar_prob=0.0,
                     start_day=tti_day_march,
                     end_day=tti_day_june21 - 1,
                     test_delay=t_delay),
        cv.test_prob(symp_prob=s_prob_june21,
                     asymp_prob=0.008,
                     symp_quar_prob=0.0,
                     start_day=tti_day_june21,
                     end_day=tti_day_july21 - 1,
                     test_delay=t_delay),
        cv.test_prob(symp_prob=s_prob_july21,
                     asymp_prob=0.004,
                     symp_quar_prob=0.0,
                     start_day=tti_day_july21,
                     end_day=tti_day_august21 - 1,
                     test_delay=t_delay),
        cv.test_prob(symp_prob=s_prob_august21,
                     asymp_prob=0.004,
                     symp_quar_prob=0.0,
                     start_day=tti_day_august21,
                     end_day=tti_day_sep21 - 1,
                     test_delay=t_delay),
        cv.test_prob(symp_prob=s_prob_sep21,
                     asymp_prob=0.008,
                     symp_quar_prob=0.0,
                     start_day=tti_day_sep21,
                     test_delay=t_delay),
        cv.contact_tracing(trace_probs={
            'h': 1,
            's': 0.8,
            'w': 0.8,
            'c': 0.1
        },
                           trace_time={
                               'h': 0,
                               's': 1,
                               'w': 1,
                               'c': 2
                           },
                           start_day='2020-06-01',
                           end_day='2023-07-12',
                           quar_period=10),
        #cv.contact_tracing(trace_probs={'h': 1, 's': 0.8, 'w': 0.8, 'c': 0.1},
        #                   trace_time={'h': 0, 's': 1, 'w': 1, 'c': 2},
        #                   start_day='2021-07-12', end_day='2021-07-20',
        #                   quar_period=10),
        #cv.contact_tracing(trace_probs={'h': 1, 's': 0.8, 'w': 0.8, 'c': 0.1},
        #                   trace_time={'h': 0, 's': 1, 'w': 1, 'c': 2},
        #                   start_day='2021-07-20', end_day='2022-07-19',
        #                   quar_period=10),
        #cv.contact_tracing(trace_probs={'h': 1, 's': 0.5, 'w': 0.5, 'c': 0.05},
        #                   trace_time={'h': 0, 's': 1, 'w': 1, 'c': 2},
        #                   start_day='2021-03-08',
        #                   quar_period=5),
        cv.dynamic_pars({'iso_factor': {
            'days': te_day,
            'vals': iso_vals
        }}),
        cv.dynamic_pars(
            {'iso_factor':
             {
                 'days': tti_day_july,
                 'vals': iso_vals1
             }}),
        cv.dynamic_pars(
            {'iso_factor':
             {
                 'days': tti_day_sep,
                 'vals': iso_vals2
             }}),
        cv.dynamic_pars(
            {'iso_factor':
             {
                 'days': tti_day_oct,
                 'vals': iso_vals3
             }}),
        cv.dynamic_pars(
            {'iso_factor':
             {
                 'days': tti_day_nov,
                 'vals': iso_vals4
             }}),
        cv.dynamic_pars(
            {'iso_factor':
             {
                 'days': tti_day_dec,
                 'vals': iso_vals5
             }}),
        cv.dynamic_pars(
            {'iso_factor':
             {
                 'days': tti_day_march,
                 'vals': iso_vals6
             }}),
        cv.dynamic_pars(
            {'iso_factor':
             {
                 'days': tti_day_june21,
                 'vals': iso_vals7
             }}),
        cv.dynamic_pars(
            {'iso_factor':
             {
                 'days': tti_day_july21,
                 'vals': iso_vals8
             }}),
        cv.dynamic_pars(
            {'iso_factor':
             {
                 'days': tti_day_august21,
                 'vals': iso_vals9
             }}),
        cv.dynamic_pars(
            {'iso_factor':
             {
                 'days': tti_day_sep21,
                 'vals': iso_vals10
             }})
    ]
    #cv.dynamic_pars({'rel_crit_prob': {'days': tti_day_vac, 'vals': 1.2}}),
    #cv.dynamic_pars({'rel_severe_prob': {'days': tti_day_dec, 'vals': 0.7}}),
    #cv.dynamic_pars({'rel_death_prob': {'days': tti_day_dec, 'vals': 1.2}})]
    #cv.vaccine(days=[0,14], rel_sus=0.4, rel_symp=0.2, cumulative=[0.7, 0.3])]

    dose_pars = cvp.get_vaccine_dose_pars()['az']
    dose_pars['interval'] = 7 * 8
    variant_pars = cvp.get_vaccine_variant_pars()['az']
    az_vaccine = sc.mergedicts({'label': 'az_uk'},
                               sc.mergedicts(dose_pars, variant_pars))

    dose_pars = cvp.get_vaccine_dose_pars()['pfizer']
    dose_pars['interval'] = 7 * 8
    variant_pars = cvp.get_vaccine_variant_pars()['pfizer']
    pfizer_vaccine = sc.mergedicts({'label': 'pfizer_uk'},
                                   sc.mergedicts(dose_pars, variant_pars))

    # Loop over vaccination in different ages
    for age in vx_ages:
        vaccine = az_vaccine if (age > 40 and age < 65) else pfizer_vaccine
        subtarget = subtargets[vx_scen][age]
        vx_start_day = sim.day(vx_rollout[age]['start_day'])
        vx_end_day = vx_start_day + vx_duration
        days = np.arange(vx_start_day, vx_end_day)
        #vx = cv.vaccinate(vaccine=vaccine, subtarget=subtarget, days=days)
        vx = cv.vaccinate_prob(vaccine=vaccine, days=days, prob=0.01)
        interventions += [vx]

    analyzers = []

    # add daily age stats analyzer
    analyzers += [cv.daily_age_stats(edges=[0, 30, 65, 80, 100])]
    #analyzers +=  [cv.age_histogram(datafile='uk_stats_by_age.xlsx', edges=np.concatenate([np.linspace(0, 90, 19),np.array([100])]))]

    # Finally, update the parameters
    sim.update_pars(interventions=interventions, analyzers=analyzers)

    # Change death and critical probabilities
    #    interventions += [cv.dynamic_pars({'rel_death_prob':{'days':sim.day('2020-07-01'), 'vals':0.6}})]

    # Finally, update the parameters
    #sim.update_pars(interventions=interventions)
    for intervention in sim['interventions']:
        intervention.do_plot = False

    sim.initialize()

    return sim
trial_size = 4000
start_trial = 20

def subtarget(sim):
    ''' Select people who are susceptible '''
    if sim.t == start_trial:
        eligible = cv.true(~np.isfinite(sim.people.date_exposed))
        inds = eligible[cv.choose(len(eligible), min(trial_size//2, len(eligible)))]
    else:
        inds = []
    return {'vals': [1.0 for ind in inds], 'inds': inds}

# Initialize
sims = []
for vaccine in vaccines:
    vx = cv.vaccinate_prob(vaccine=vaccine, days=[start_trial], prob=0.0, subtarget=subtarget)
    sim = cv.Sim(
        label=vaccine,
        use_waning=True,
        pars=pars,
        interventions=vx,
        analyzers=placebo_arm(day=start_trial, trial_size=trial_size//2)
    )
    sims.append(sim)

# Run
# Run
msim = cv.MultiSim(sims)
msim.run(keep_people=True)

results = sc.objdict()
Beispiel #12
0
def test_vaccine_2variants_scen(do_plot=False, do_show=True, do_save=False):
    sc.heading(
        'Run a basic sim with b117 variant on day 10, pfizer vaccine day 20')

    # Define baseline parameters
    n_runs = 3
    base_sim = cv.Sim(use_waning=True, pars=base_pars)

    # Vaccinate 75+, then 65+, then 50+, then 18+ on days 20, 40, 60, 80
    base_sim.vxsubtarg = sc.objdict()
    base_sim.vxsubtarg.age = [75, 65, 50, 18]
    base_sim.vxsubtarg.prob = [.01, .01, .01, .01]
    base_sim.vxsubtarg.days = subtarg_days = [60, 150, 200, 220]
    jnj = cv.vaccinate_prob(days=subtarg_days,
                            vaccine='j&j',
                            subtarget=vacc_subtarg)
    b1351 = cv.variant('b1351', days=10, n_imports=20)
    p1 = cv.variant('p1', days=100, n_imports=100)

    # Define the scenarios

    scenarios = {
        'baseline': {
            'name': 'B1351 on day 10, No Vaccine',
            'pars': {
                'variants': [b1351]
            }
        },
        'b1351': {
            'name': 'B1351 on day 10, J&J starting on day 60',
            'pars': {
                'interventions': [jnj],
                'variants': [b1351],
            }
        },
        'p1': {
            'name': 'B1351 on day 10, J&J starting on day 60, p1 on day 100',
            'pars': {
                'interventions': [jnj],
                'variants': [b1351, p1],
            }
        },
    }

    metapars = {'n_runs': n_runs}
    scens = cv.Scenarios(sim=base_sim, metapars=metapars, scenarios=scenarios)
    scens.run(debug=debug)

    to_plot = sc.objdict({
        'New infections': ['new_infections'],
        'Cumulative infections': ['cum_infections'],
        'New reinfections': ['new_reinfections'],
        # 'Cumulative reinfections': ['cum_reinfections'],
    })
    if do_plot:
        scens.plot(do_save=do_save,
                   do_show=do_show,
                   fig_path='results/test_vaccine_b1351.png',
                   to_plot=to_plot)

    return scens