Example #1
0
def test_import2variants(do_plot=False, do_show=True, do_save=False):
    sc.heading('Test introducing 2 new variants partway through a sim')

    b117 = cv.variant('b117', days=1, n_imports=20)
    p1 = cv.variant('sa variant', days=2, n_imports=20)
    sim = cv.Sim(use_waning=True,
                 variants=[b117, p1],
                 label='With imported infections',
                 **base_pars)
    sim.run()

    return sim
Example #2
0
def test_variants(do_plot=False):
    sc.heading('Testing variants...')

    b117 = cv.variant('b117',         days=10, n_imports=20)
    p1   = cv.variant('sa variant',   days=20, n_imports=20)
    cust = cv.variant(label='Custom', days=40, n_imports=20, variant={'rel_beta': 2, 'rel_symp_prob': 1.6})
    sim  = cv.Sim(base_pars, use_waning=True, variants=[b117, p1, cust])
    sim.run()

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

    return sim
Example #3
0
def test_msim(do_plot=False):
    sc.heading('Testing multisim...')

    # basic test for vaccine
    b117 = cv.variant('b117', days=0)
    sim = cv.Sim(use_waning=True, variants=[b117], **base_pars)
    msim = cv.MultiSim(sim, n_runs=2)
    msim.run()
    msim.reduce()

    to_plot = sc.objdict({
        'Total infections': ['cum_infections'],
        'New infections per day': ['new_infections'],
        'New Re-infections per day': ['new_reinfections'],
    })

    if do_plot:
        msim.plot(to_plot=to_plot,
                  do_save=0,
                  do_show=1,
                  legend_args={'loc': 'upper left'},
                  axis_args={'hspace': 0.4},
                  interval=35)

    return msim
Example #4
0
def test_variants(do_plot=False):
    sc.heading('Testing variants...')
    nabs = []
    b117 = cv.variant('b117',         days=10, n_imports=20)
    p1   = cv.variant('beta',   days=20, n_imports=20)
    cust = cv.variant(label='Custom', days=40, n_imports=20, variant={'rel_beta': 2, 'rel_symp_prob': 1.6})
    sim  = cv.Sim(base_pars, use_waning=True, variants=[b117, p1, cust], analyzers=lambda sim: nabs.append(sim.people.nab.copy()))
    sim.run()

    if do_plot:
        nabs = np.array(nabs).sum(axis=1)
        pl.figure()
        pl.plot(nabs)
        pl.show()
        sim.plot('overview-variant')

    return sim
Example #5
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()
Example #6
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
Example #7
0
def examplew1():
    # run single sim
    pars = {'use_waning': True, 'rand_seed': 1}
    variants = [cv.variant('delta', days=15, n_imports=10)]

    sim = cv.Sim(pars=pars, variants=variants)
    sim['interventions'] += [
        cv.historical_wave(variant='wild',
                           prob=[0.05, 0.05],
                           days_prior=[150, 50])
    ]
    sim.run()
    sim.plot()
    sim.plot('variants')
Example #8
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)
Example #9
0
def test_vaccines(do_plot=False):
    sc.heading('Testing vaccines...')

    nabs = []
    p1 = cv.variant('beta',   days=20, n_imports=20)
    pfizer = cv.vaccinate(vaccine='pfizer', days=30)
    sim  = cv.Sim(base_pars, use_waning=True, variants=p1, interventions=pfizer, analyzers=lambda sim: nabs.append(sim.people.nab.copy()))
    sim.run()
    sim.shrink()

    if do_plot:
        nabs = np.array(nabs).sum(axis=1)
        pl.figure()
        pl.plot(nabs)
        pl.show()
        sim.plot('overview-variant')

    return sim
Example #10
0
def examplev3():
    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)

    scenarios = {
        'scen1': {
            'name': 'both doses',
            'pars': {
                'interventions': [
                    cv.historical_vaccinate_prob(vaccine='pfizer',
                                                 days=np.arange(-duration, 0),
                                                 prob=prob)
                ]
            }
        },
        'scen3': {
            'name': 'first dose only',
            'pars': {
                'interventions': [
                    cv.historical_vaccinate_prob(vaccine='pfizer',
                                                 days=np.arange(-duration, 0),
                                                 prob=prob,
                                                 compliance=[1.0, 0.0])
                ]
            }
        },
    }

    scens = cv.Scenarios(sim=sim, scenarios=scenarios)
    scens.run()
    to_plot = cv.get_default_plots(kind='scenarios')
    to_plot.pop(2)
    to_plot.update({'Cumulative doses': ['cum_vaccinated', 'cum_doses']})
    scens.plot(to_plot=to_plot)
Example #11
0
def test_import1variant(do_plot=False, do_show=True, do_save=False):
    sc.heading('Test introducing a new variant partway through a sim')

    variant_pars = {
        'rel_beta': 1.5,
    }
    pars = {'beta': 0.01}
    variant = cv.variant(variant_pars,
                         days=1,
                         n_imports=20,
                         label='Variant 2: 1.5x more transmissible')
    sim = cv.Sim(use_waning=True,
                 pars=pars,
                 variants=variant,
                 analyzers=cv.snapshot(30, 60),
                 **pars,
                 **base_pars)
    sim.run()

    return sim
Example #12
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
Example #13
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
Example #14
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
def make_sim(seed,
             beta,
             calibration=True,
             future_symp_test=None,
             scenario=None,
             end_day='2021-10-30',
             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,
        rel_symp_prob=1.0,
        rel_severe_prob=0.9,
        rel_crit_prob=1.4,
        rel_death_prob=1.2,
    )

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

    # ADD BETA INTERVENTIONS
    sbv = 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],
        '2020-03-23': [1.29, 0.02, 0.20, 0.20],
        '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.29, 0.00, 0.30, 0.50],
        '2020-09-02': [1.25, sbv, 0.50, 0.70],
        '2020-10-01': [1.25, sbv, 0.50, 0.70],
        '2020-10-16': [1.25, sbv, 0.50, 0.70],
        '2020-10-26': [1.00, 0.00, 0.50, 0.70],
        '2020-11-05': [1.25, sbv, 0.30, 0.40],
        '2020-11-14': [1.25, sbv, 0.30, 0.40],
        '2020-11-21': [1.25, sbv, 0.30, 0.40],
        '2020-11-30': [1.25, sbv, 0.30, 0.40],
        '2020-12-03': [1.50, sbv, 0.50, 0.70],
        '2020-12-20': [1.25, 0.00, 0.20, 0.40],
        '2020-12-25': [1.50, 0.00, 0.20, 0.40],
        '2020-12-26': [1.50, 0.00, 0.20, 0.40],
        '2020-12-31': [1.50, 0.00, 0.20, 0.40],
        '2021-01-01': [1.50, 0.00, 0.20, 0.40],
        '2021-01-04': [1.25, 0.14, 0.30, 0.40],
        '2021-01-11': [1.25, 0.14, 0.30, 0.40],
        '2021-01-18': [1.25, 0.14, 0.30, 0.40],
        '2021-01-30': [1.25, 0.14, 0.30, 0.40],
        '2021-02-08': [1.25, 0.14, 0.30, 0.40],
        '2021-02-15': [1.25, 0.14, 0.30, 0.40],
        '2021-02-22': [1.25, 0.14, 0.30, 0.40],
        '2021-03-08': [1.25, sbv, 0.30, 0.50],
        '2021-03-15': [1.25, sbv, 0.30, 0.50],
        '2021-03-22': [1.25, sbv, 0.30, 0.50],
        '2021-03-29': [1.25, 0.00, 0.30, 0.50],
        '2021-04-05': [1.25, 0.00, 0.30, 0.50],
        '2021-04-12': [1.25, 0.00, 0.40, 0.50],
        '2021-04-19': [1.25, sbv, 0.40, 0.50],
        '2021-04-26': [1.25, sbv, 0.40, 0.50],
        '2021-05-03': [1.25, sbv, 0.40, 0.50],
        '2021-05-10': [1.25, sbv, 0.40, 0.50],
        '2021-05-17': [1.15, sbv, 0.40, 0.60],
        '2021-05-21': [1.15, sbv, 0.40, 0.60],
        '2021-05-28': [1.15, 0.00, 0.40, 0.60],
        '2021-06-07': [1.15, sbv, 0.40, 0.60],
        '2021-06-14': [1.15, sbv, 0.40, 0.60],
        '2021-06-19': [1.15, sbv, 0.40, 0.60],
        '2021-06-21': [1.25, sbv, 0.40, 0.70],
        '2021-06-28': [1.25, sbv, 0.40, 0.70],
        '2021-07-05': [1.25, sbv, 0.40, 0.70],
        '2021-07-12': [1.25, sbv, 0.40, 0.70],
        '2021-07-19': [1.25, 0.00, 0.50, 0.80],
        '2021-07-26': [1.25, 0.00, 0.50, 0.80],
        '2021-08-02': [1.25, 0.00, 0.50, 0.80],
        '2021-08-16': [1.25, 0.00, 0.50, 0.80],
        '2021-09-01': [1.25, 0.63, 0.70, 0.90],
        '2021-09-15': [1.25, 0.63, 0.70, 0.90],
        '2021-09-29': [1.25, 0.63, 0.70, 0.90],
        '2021-10-13': [1.25, 0.63, 0.70, 0.90],
        '2021-10-22': [1.25, 0.02, 0.50, 0.90],
        '2021-11-01': [1.25, 0.63, 0.70, 0.90],
        '2021-11-08': [1.25, 0.63, 0.70, 0.90],
        '2021-11-15': [1.25, 0.63, 0.70, 0.90],
        '2021-11-22': [1.25, 0.63, 0.70, 0.90],
        '2021-12-01': [1.25, 0.63, 0.70, 0.90],
        #'2021-06-21': [1.25, sbv, 0.70, 0.90],
        #'2021-06-28': [1.25, sbv, 0.70, 0.90],
        #'2021-07-05': [1.25, sbv, 0.70, 0.90],
        #'2021-07-12': [1.25, sbv, 0.70, 0.90],
        #'2021-07-19': [1.25, 0.00, 0.70, 0.90],
        #'2021-07-26': [1.25, 0.00, 0.70, 0.90],
        #'2021-08-02': [1.25, 0.00, 0.70, 0.90],
        #'2021-08-16': [1.25, 0.00, 0.70, 0.90],
    })

    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 2021.
        if scenario == 'Roadmap_All':

            beta_scens = sc.odict({
                '2021-06-21': [1.25, sbv, 0.70, 0.90],
                '2021-06-28': [1.25, sbv, 0.70, 0.90],
                '2021-07-05': [1.25, sbv, 0.70, 0.90],
                '2021-07-12': [1.25, sbv, 0.70, 0.90],
                '2021-07-19': [1.25, 0.00, 0.70, 0.90],
                '2021-07-26': [1.25, 0.00, 0.70, 0.90],
                '2021-08-02': [1.25, 0.00, 0.70, 0.90],
                '2021-08-16': [1.25, 0.00, 0.70, 0.90],
                '2021-09-01': [1.25, 0.63, 0.70, 0.90],
                '2021-09-15': [1.25, 0.63, 0.70, 0.90],
                '2021-09-29': [1.25, 0.63, 0.70, 0.90],
                '2021-10-13': [1.25, 0.63, 0.70, 0.90],
                '2021-10-22': [1.25, 0.02, 0.50, 0.90],
                '2021-11-01': [1.25, 0.63, 0.70, 0.90],
                '2021-11-08': [1.25, 0.63, 0.70, 0.90],
                '2021-11-23': [1.25, 0.63, 0.70, 0.90],
                '2021-11-30': [1.25, 0.63, 0.70, 0.90],
                '2021-12-07': [1.25, 0.63, 0.70, 0.90],
                '2021-12-20': [1.25, 0.02, 0.50, 0.80],
                '2022-01-05': [1.25, 0.63, 0.70, 0.90],
            })

        ## reopening schools on 8th March, society stage 1 29th March, society stage 2 12th April ONLY
        ## NO (stage 3) 17th May and NO stage 4 21st June 2021.
        ## Projecting until end of 2021.
        #elif scenario == 'Roadmap_Stage2':

        #beta_scens = sc.odict({'2021-04-12': [1.25, 0.02, 0.40, 0.70],
        #                   '2021-04-19': [1.25, sbv, 0.40, 0.70],
        #                   '2021-04-26': [1.25, sbv, 0.40, 0.70],
        #                   '2021-05-03': [1.25, sbv, 0.40, 0.70],
        #                   '2021-05-10': [1.25, sbv, 0.40, 0.70],
        #                   '2021-05-17': [1.25, sbv, 0.40, 0.70],
        #                   '2021-05-21': [1.25, sbv, 0.40, 0.70],
        #                   '2021-05-28': [1.25, 0.02, 0.40, 0.70],
        #                   '2021-06-07': [1.25, sbv, 0.40, 0.70],
        #                   '2021-06-21': [1.25, sbv, 0.40, 0.70],
        #                   '2021-06-28': [1.25, sbv, 0.40, 0.70],
        #                   '2021-07-05': [1.25, sbv, 0.40, 0.70],
        #                   '2021-07-12': [1.25, sbv, 0.40, 0.70],
        #                   '2021-07-19': [1.25, 0.00, 0.40, 0.70],
        #                   '2021-07-26': [1.25, 0.00, 0.40, 0.70],
        #                   '2021-08-02': [1.25, 0.00, 0.40, 0.70],
        #                   '2021-08-16': [1.25, 0.00, 0.40, 0.70],
        #                   '2021-09-01': [1.25, 0.63, 0.70, 0.90],
        #                   '2021-09-15': [1.25, 0.63, 0.70, 0.90],
        #                   '2021-09-29': [1.25, 0.63, 0.70, 0.90],
        #                   '2021-10-13': [1.25, 0.63, 0.70, 0.90],
        #                   '2021-10-27': [1.25, 0.02, 0.70, 0.90],
        #                   '2021-11-08': [1.25, 0.63, 0.70, 0.90],
        #                   '2021-11-23': [1.25, 0.63, 0.70, 0.90],
        #                   '2021-11-30': [1.25, 0.63, 0.70, 0.90],
        #                   '2021-12-07': [1.25, 0.63, 0.70, 0.90],
        #                   '2021-12-21': [1.25, 0.63, 0.70, 0.90],
        #                  })
        ## reopening schools on 8th March, society stage 1 29th March, society stage 2 12th April,
        ## and society some more (stage 3) 17th May but NO stage 4 21st June 2021.
        ## Projecting until end of 2021.
        elif scenario == 'Roadmap_Stage3':
            beta_scens = sc.odict({
                '2021-06-21': [1.25, sbv, 0.40, 0.60],
                '2021-06-28': [1.25, sbv, 0.40, 0.60],
                '2021-07-05': [1.25, sbv, 0.40, 0.60],
                '2021-07-12': [1.25, sbv, 0.40, 0.60],
                '2021-07-19': [1.25, 0.00, 0.50, 0.80],
                '2021-07-26': [1.25, 0.00, 0.50, 0.80],
                '2021-08-02': [1.25, 0.00, 0.50, 0.80],
                '2021-08-16': [1.25, 0.00, 0.50, 0.80],
                '2021-09-01': [1.25, 0.63, 0.70, 0.90],
                '2021-09-15': [1.25, 0.63, 0.70, 0.90],
                '2021-09-29': [1.25, 0.63, 0.70, 0.90],
                '2021-10-13': [1.25, 0.63, 0.70, 0.90],
                '2021-10-22': [1.25, 0.02, 0.50, 0.90],
                '2021-11-01': [1.25, 0.63, 0.70, 0.90],
                '2021-11-08': [1.25, 0.63, 0.70, 0.90],
                '2021-11-23': [1.25, 0.63, 0.70, 0.90],
                '2021-11-30': [1.25, 0.63, 0.70, 0.90],
                '2021-12-07': [1.25, 0.63, 0.70, 0.90],
                '2021-12-20': [1.25, 0.02, 0.50, 0.80],
                '2022-01-05': [1.25, 0.63, 0.70, 0.90],
            })
        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.117 strain
    b117 = cv.variant('b117',
                      days=np.arange(sim.day('2020-08-01'),
                                     sim.day('2020-08-10')),
                      n_imports=500)
    b117.p['rel_beta'] = 1.5
    b117.p['rel_crit_prob'] = 1.3
    b117.p['rel_death_prob'] = 1.6
    b117.p['rel_severe_prob'] = 0.3
    sim['variants'] += [b117]
    # Add B.1.1351 strain
    b1351 = cv.variant('b1351',
                       days=np.arange(sim.day('2020-01-10'),
                                      sim.day('2020-01-20')),
                       n_imports=500)
    b1351.p['rel_beta'] = 1.0
    b1351.p['rel_death_prob'] = 1.0
    b1351.p['rel_severe_prob'] = 1.0
    sim['variants'] += [b1351]
    # Add B.X.XXX strain starting middle of March
    custom_strain = cv.variant(label='delta',
                               variant=cvp.get_variant_pars()['p1'],
                               days=np.arange(sim.day('2021-03-17'),
                                              sim.day('2021-03-24')),
                               n_imports=2000)
    custom_strain.p['rel_beta'] = 2.2
    custom_strain.p['rel_crit_prob'] = 1.3
    custom_strain.p['rel_death_prob'] = 1.1
    custom_strain.p['rel_severe_prob'] = 1.0
    sim['variants'] += [custom_strain]
    # seems like we need to do this to deal with cross immunity?
    sim.initialize()
    sim['immunity']
    prior = {'wild': 0.8, 'b117': 0.8, 'b1351': 0.8, 'delta': 0.8}
    pre = {'wild': 0.8, 'b117': 0.8, 'b1351': 0.8, 'delta': 0.8}
    for k, v in sim['variant_map'].items():
        if v == 'delta':
            for j, j_lab in sim['variant_map'].items():
                sim['immunity'][k][j] = prior[j_lab]
                sim['immunity'][j][k] = pre[j_lab]
                #if j != k:
                #    sim['immunity'][k][j] = cross_immunities['b117'][j_lab]
                #    sim['immunity'][j][k] = cross_immunities[j_lab]['b117']
    # # Add a new change in beta to represent the takeover of the novel variant VOC B117 202012/01
    # # Assume that the new variant is 60% more transmisible (https://cmmid.github.io/topics/covid19/uk-novel-variant.html,
    # # Assume that between Nov 1 and Jan 30, the new variant grows from 0-100% of cases

    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_april = sim.day('2021-03-01')
    #start of vaccinating those 75years+
    tti_day_vac1 = sim.day('2021-01-03')
    #start of vaccinating 60+ old
    tti_day_vac2 = sim.day('2021-02-03')
    #start of vaccinating 55+ years old
    tti_day_vac3 = sim.day('2021-02-28')
    #start of vaccination 50+ years old
    tti_day_vac4 = sim.day('2021-03-10')
    #start vaccinating of 45+
    tti_day_vac5 = sim.day('2021-03-30')
    #start vaccinating of 40+
    tti_day_vac6 = sim.day('2021-04-20')
    #start vaccinating of 35+
    tti_day_vac7 = sim.day('2021-05-05')
    #start vaccinating of 30+
    tti_day_vac8 = sim.day('2021-05-30')
    #start vaccinating of 25+
    tti_day_vac9 = sim.day('2021-06-10')
    #start vaccinating of 18+
    tti_day_vac10 = sim.day('2021-06-30')
    #start vaccinating of 11-17
    tti_day_vac11 = sim.day('2021-07-10')

    s_prob_april = 0.009
    s_prob_may = 0.012
    s_prob_june = 0.02769
    s_prob_july = 0.02769
    s_prob_august = 0.03769
    tn = 0.09
    s_prob_sep = 0.08769
    s_prob_oct = 0.08769
    s_prob_nov = 0.08769
    s_prob_dec = 0.08769
    s_prob_jan = 0.08769

    #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-july
    iso_vals = [{k: 0.1 for k in 'hswc'}]
    #isolation august
    iso_vals1 = [{k: 0.7 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.5 for k in 'hswc'}]
    #isolation december
    iso_vals5 = [{k: 0.4 for k in 'hswc'}]
    #isolation January-April
    #iso_vals6 = [{k:0.3 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_jan,
                     asymp_prob=0.008,
                     symp_quar_prob=0.0,
                     start_day=tti_day_march,
                     end_day=tti_day_april - 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_april,
                     test_delay=t_delay),
        cv.contact_tracing(trace_probs={
            'h': 1,
            's': 0.8,
            'w': 0.8,
            'c': 0.05
        },
                           trace_time={
                               'h': 0,
                               's': 1,
                               'w': 1,
                               'c': 2
                           },
                           start_day='2020-06-01',
                           end_day='2023-06-30',
                           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_august,
                 '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({'rel_death_prob': {'days': tti_day_vac, 'vals': 0.9}})]
    #cv.vaccine(days=[0,14], rel_sus=0.4, rel_symp=0.2, cumulative=[0.7, 0.3])]

    # derived from AZ default params (3.0.2) with increased interval between doses)
    # dose_pars = cvp.get_vaccine_dose_pars()['az']
    # dose_pars.update({'nab_interval': 14, 'interval':7*9})
    # strain_pars = cvp.get_vaccine_strain_pars()['az']
    # hard code them
    dose_pars = cvp.get_vaccine_dose_pars()['az']
    dose_pars['interval'] = 7 * 12
    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 * 12
    variant_pars = cvp.get_vaccine_variant_pars()['pfizer']
    pfizer_vaccine = sc.mergedicts({'label': 'pfizer_uk'},
                                   sc.mergedicts(dose_pars, variant_pars))

    #  age targeted vaccination
    #def subtarget_75_100(sim):
    #    inds = cv.true(sim.people.age >= 75)
    #    return {'inds': inds, 'vals': 0.020*np.ones(len(inds))}
    #interventions += [utils_vac.vaccinate(vaccine=vaccine, prob=0.1, subtarget=subtarget_75_100,
    #                               days=np.arange(sim.day('2020-12-20'), sim.day('2023-01-01')))]

    #  age targeted vaccination
    def subtarget_75_100(sim):
        inds = cv.true(sim.people.age >= 75)
        if not hasattr(sim, 'subtarget_75_100'):
            sim.subtarget_75_100 = cv.binomial_filter(
                0.05, inds)  # 95% of 70+ years olds vaccinated
        inds = np.setdiff1d(inds, sim.subtarget_75_100)
        return {'inds': inds, 'vals': 0.02 * np.ones(len(inds))}

    interventions += [
        cv.vaccinate(vaccine=pfizer_vaccine,
                     subtarget=subtarget_75_100,
                     days=np.arange(sim.day('2020-12-20'),
                                    sim.day('2021-09-15')))
    ]

    def subtarget_60_75(sim):
        inds = cv.true((sim.people.age >= 60) & (sim.people.age < 75))
        if not hasattr(sim, 'subtarget_60_75'):
            sim.subtarget_60_75 = cv.binomial_filter(
                0.05, inds)  # 95% of 60+ years olds vaccinated
        inds = np.setdiff1d(inds, sim.subtarget_60_75)
        return {'inds': inds, 'vals': 0.02 * np.ones(len(inds))}

    interventions += [
        cv.vaccinate(vaccine=pfizer_vaccine,
                     subtarget=subtarget_60_75,
                     days=np.arange(sim.day('2021-01-28'),
                                    sim.day('2021-09-15')))
    ]

    def subtarget_50_60(sim):
        inds = cv.true((sim.people.age >= 50) & (sim.people.age < 60))
        if not hasattr(sim, 'subtarget_50_60'):
            sim.subtarget_50_60 = cv.binomial_filter(
                0.1, inds)  # 90% of 50-60 years olds vaccinated
        inds = np.setdiff1d(inds, sim.subtarget_50_60)
        return {'inds': inds, 'vals': 0.005 * np.ones(len(inds))}

    interventions += [
        cv.vaccinate(vaccine=az_vaccine,
                     subtarget=subtarget_50_60,
                     days=np.arange(sim.day('2021-02-10'),
                                    sim.day('2021-09-15')))
    ]

    #def subtarget_40_50(sim):
    #    inds = cv.true((sim.people.age >= 40) & (sim.people.age < 50))
    #    if not hasattr(sim, 'subtarget_40_50'):
    #        sim.subtarget_40_50 = cv.binomial_filter(0.07, inds) # 93% of 40-50 years olds vaccinated
    #    inds = np.setdiff1d(inds, sim.subtarget_40_50)
    #    return {'inds': inds, 'vals': 0.005*np.ones(len(inds))}
    #interventions += [cv.vaccinate(vaccine=az_vaccine, prob=0.1, subtarget=subtarget_40_50,
    #                               days=np.arange(sim.day('2021-04-10'), sim.day('2023-01-01')))]

    def subtarget_45_50(sim):
        inds = cv.true((sim.people.age >= 45) & (sim.people.age < 50))
        if not hasattr(sim, 'subtarget_45_50'):
            sim.subtarget_45_50 = cv.binomial_filter(
                0.1, inds)  # 90% of 45-50 years olds vaccinated
        inds = np.setdiff1d(inds, sim.subtarget_45_50)
        return {'inds': inds, 'vals': 0.002 * np.ones(len(inds))}

    interventions += [
        cv.vaccinate(vaccine=az_vaccine,
                     subtarget=subtarget_45_50,
                     days=np.arange(sim.day('2021-03-20'),
                                    sim.day('2021-09-15')))
    ]

    def subtarget_40_45(sim):
        inds = cv.true((sim.people.age >= 40) & (sim.people.age < 45))
        if not hasattr(sim, 'subtarget_40_45'):
            sim.subtarget_40_45 = cv.binomial_filter(
                0.1, inds)  # 90% of 40-45 years olds vaccinated
        inds = np.setdiff1d(inds, sim.subtarget_40_45)
        return {'inds': inds, 'vals': 0.002 * np.ones(len(inds))}

    interventions += [
        cv.vaccinate(vaccine=az_vaccine,
                     subtarget=subtarget_40_45,
                     days=np.arange(sim.day('2021-04-10'),
                                    sim.day('2021-09-15')))
    ]

    def subtarget_30_40(sim):
        inds = cv.true((sim.people.age >= 30) & (sim.people.age < 40))
        if not hasattr(sim, 'subtarget_30_40'):
            sim.subtarget_30_40 = cv.binomial_filter(
                0.1, inds)  # 90% of 30-40 years olds  vaccinated
        inds = np.setdiff1d(inds, sim.subtarget_30_40)
        return {'inds': inds, 'vals': 0.002 * np.ones(len(inds))}

    interventions += [
        cv.vaccinate(vaccine=pfizer_vaccine,
                     subtarget=subtarget_30_40,
                     days=np.arange(sim.day('2021-05-10'),
                                    sim.day('2021-09-15')))
    ]

    def subtarget_25_30(sim):
        inds = cv.true((sim.people.age >= 25) & (sim.people.age < 30))
        if not hasattr(sim, 'subtarget_25_30'):
            sim.subtarget_25_30 = cv.binomial_filter(
                0.1, inds)  # 90% of 25-30 years olds vaccinated
        inds = np.setdiff1d(inds, sim.subtarget_25_30)
        return {'inds': inds, 'vals': 0.002 * np.ones(len(inds))}

    interventions += [
        cv.vaccinate(vaccine=pfizer_vaccine,
                     subtarget=subtarget_25_30,
                     days=np.arange(sim.day('2021-06-10'),
                                    sim.day('2021-09-15')))
    ]

    def subtarget_18_25(sim):
        inds = cv.true((sim.people.age >= 18) & (sim.people.age < 25))
        if not hasattr(sim, 'subtarget_18_30'):
            sim.subtarget_18_25 = cv.binomial_filter(
                0.1, inds)  # 90% of 18-25 years vaccinated
        inds = np.setdiff1d(inds, sim.subtarget_18_25)
        return {'inds': inds, 'vals': 0.002 * np.ones(len(inds))}

    interventions += [
        cv.vaccinate(vaccine=pfizer_vaccine,
                     subtarget=subtarget_18_25,
                     days=np.arange(sim.day('2021-06-20'),
                                    sim.day('2021-09-15')))
    ]

    def subtarget_16_17(sim):
        inds = cv.true((sim.people.age >= 16) & (sim.people.age < 17))
        if not hasattr(sim, 'subtarget_16_17'):
            sim.subtarget_16_17 = cv.binomial_filter(
                0.9, inds)  # 10% of 16-18 years olds vaccinated
        inds = np.setdiff1d(inds, sim.subtarget_16_17)
        return {'inds': inds, 'vals': 0.002 * np.ones(len(inds))}

    interventions += [
        cv.vaccinate(vaccine=pfizer_vaccine,
                     subtarget=subtarget_16_17,
                     days=np.arange(sim.day('2021-06-20'),
                                    sim.day('2021-09-15')))
    ]

    analyzers = []

    # add daily age stats analyzer
    analyzers += [
        cv.daily_age_stats(edges=[0, 10, 20, 30, 40, 50, 60, 70, 80, 90])
    ]
    #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
Example #16
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
Example #17
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(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
        #                       '2021-12-07': [1.25, 0.63, 0.70, 0.90],
        #                       '2021-12-20': [1.25, 0.02, 0.50, 0.80],
        #                       '2022-01-05': [1.25, 0.63, 0.70, 0.90],
                              })
        #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.117 strain
    b117 = cv.variant('b117', days=np.arange(sim.day('2020-08-20'), sim.day('2020-08-30')), n_imports=500)
    b117.p['rel_beta']        = 1.6
    b117.p['rel_symp_prob']   = 1.1
    b117.p['rel_severe_prob'] = 0.6
    b117.p['rel_crit_prob']   = 2.7
    b117.p['rel_death_prob']  = 0.6
    sim['variants'] += [b117]
    # Add B.1.1351 strain
    b1351 = cv.variant('b1351', days=np.arange(sim.day('2021-01-10'), sim.day('2021-01-20')), n_imports=1500)
    b1351.p['rel_beta']        = 1.0
    b1351.p['rel_severe_prob'] = 1.0
    b1351.p['rel_crit_prob']   = 1.0
    b1351.p['rel_death_prob']  = 1.0
    sim['variants'] += [b1351]
    # Add B.X.XXX strain starting middle of March
    b16172 = cv.variant('b16172', days=np.arange(sim.day('2021-03-17'), sim.day('2021-03-20')), n_imports=1000)
Example #19
0
import numpy as np
import sciris as sc
assert sc.__version__ > '1.2.0'
import covasim as cv

if __name__ == '__main__':

    pars = sc.objdict(
        pop_infected=0,
        n_agents=1e5,
        pop_scale=10,
        start_day='2021-06-01',
        end_day='2021-10-01',
        use_waning=True,
        variants=cv.variant('delta',
                            days='2021-06-01',
                            n_imports=10,
                            rescale=False),
    )

    sims = []

    for scen in ['baseline', 'vx_extra_pfizer', 'vx_extra_az']:

        vxdict = {}

        def age_sequence(people):
            return np.argsort(people.age)

        if 'extra' in scen:
            total_doses = 2.0e6
        else:
Example #20
0
def test_varyingimmunity(do_plot=False, do_show=True, do_save=False):
    sc.heading('Test varying properties of immunity')

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

    # Define the scenarios
    b1351 = cv.variant('b1351', days=100, n_imports=20)

    scenarios = {
        'baseline': {
            'name': 'Default Immunity (decay at log(2)/90)',
            'pars': {
                'nab_decay':
                dict(form='nab_decay',
                     decay_rate1=np.log(2) / 90,
                     decay_time1=250,
                     decay_rate2=0.001),
            },
        },
        'faster_immunity': {
            'name': 'Faster Immunity (decay at log(2)/30)',
            'pars': {
                'nab_decay':
                dict(form='nab_decay',
                     decay_rate1=np.log(2) / 30,
                     decay_time1=250,
                     decay_rate2=0.001),
            },
        },
        'baseline_b1351': {
            'name': 'Default Immunity (decay at log(2)/90), B1351 on day 100',
            'pars': {
                'nab_decay':
                dict(form='nab_decay',
                     decay_rate1=np.log(2) / 90,
                     decay_time1=250,
                     decay_rate2=0.001),
                'variants': [b1351],
            },
        },
        'faster_immunity_b1351': {
            'name': 'Faster Immunity (decay at log(2)/30), B1351 on day 100',
            'pars': {
                'nab_decay':
                dict(form='nab_decay',
                     decay_rate1=np.log(2) / 30,
                     decay_time1=250,
                     decay_rate2=0.001),
                'variants': [b1351],
            },
        },
    }

    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'],
        'New re-infections': ['new_reinfections'],
        'Population Nabs': ['pop_nabs'],
        'Population Immunity': ['pop_protection'],
    })
    if do_plot:
        scens.plot(do_save=do_save,
                   do_show=do_show,
                   fig_path='results/test_basic_immunity.png',
                   to_plot=to_plot)

    return scens
def make_sim(seed, beta, calibration=True, future_symp_test=None, scenario=None, vx_scenario=None, end_day='2021-10-30', 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,
        rel_symp_prob = 0.9,
        rel_severe_prob = 0.7,
        rel_crit_prob = 4.7,
        rel_death_prob=1.2,
    )

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

   # 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.90
    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],
                           #schools start in Sep 2020
                           '2020-09-02': [1.15, sbv,  0.50, 0.70],
                           '2020-10-01': [1.15, sbv, 0.40, 0.60],
                           '2020-10-16': [1.15, sbv, 0.40, 0.60],
                           #schools holiday Oct 2020
                           '2020-10-26': [1.15, 0.00, 0.30, 0.50],
                           #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-03': [1.15, sbv, 0.30, 0.40],
                           #2nd lockdown ends and opening for Christmas
                           '2020-12-10': [1.50, 0.00, 0.40, 0.70],
                           '2020-12-17': [1.50, 0.00, 0.40, 0.70],
                           '2020-12-25': [1.50, 0.00, 0.40, 0.70],
                           '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.30, 0.30],
                           #3rd lockdown starts
                           '2021-01-04': [1.10, 0.14, 0.20, 0.30],
                           '2021-01-11': [1.05, 0.14, 0.20, 0.30],
                           '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.30, 0.40],
                           '2021-04-05': [1.05, 0.00, 0.30, 0.40],
                           #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-28': [1.05, 0.00, 0.30, 0.40],
                           '2021-06-07': [1.05, sbv, 0.30, 0.60],
                           '2021-06-14': [1.05, sbv, 0.30, 0.60],
                           #full relaxing of social distancing - step 4 - delayed to 19/07/2021 
                           #but we needed to increase in the model to fit data
                           #note sporting events open and at the end of June
                           #large surge in cases from middle of June
                           '2021-06-19': [1.05, 0.50, 0.40, 0.80],
                           '2021-06-21': [1.05, 0.50, 0.40, 0.80],
                           '2021-06-28': [1.05, 0.50, 0.40, 0.80],
                           '2021-07-05': [1.05, 0.50, 0.40, 0.80],
                           '2021-07-12': [1.05, 0.50, 0.40, 0.80],
                           #cases start to drop from midle of July
                           '2021-07-16': [1.05, 0.00, 0.30, 0.50],
                           #easing of socal distancing measures - delayed step 4
                           '2021-07-26': [1.05, 0.00, 0.30, 0.50],
                           '2021-08-02': [1.05, 0.00, 0.30, 0.50],
                           '2021-08-09': [1.05, 0.00, 0.30, 0.50],
                           '2021-08-16': [1.05, 0.00, 0.30, 0.50],
                           '2021-08-23': [1.05, 0.00, 0.30, 0.50],
                           #reopening schools in Sep 2021
                           '2021-09-01': [1.05, sbv_new, 0.60, 0.80],
                           '2021-09-15': [1.05, sbv_new, 0.60, 0.80],
                           '2021-09-29': [1.05, sbv_new, 0.60, 0.80],
                           '2021-10-13': [1.05, sbv_new, 0.60, 0.80],
                           '2021-10-22': [1.05, 0.00, 0.60, 0.80],
                           '2021-11-01': [1.05, sbv_new, 0.60, 0.80],
                           '2021-11-08': [1.05, sbv_new, 0.60, 0.80],
                           '2021-11-15': [1.05, sbv_new, 0.60, 0.80],
                           '2021-11-22': [1.05, sbv_new, 0.60, 0.80],
                           '2021-12-01': [1.05, sbv_new, 0.60, 0.80],
                           #'2021-06-21': [1.25, sbv, 0.70, 0.90],
                           #'2021-06-28': [1.25, sbv, 0.70, 0.90],
                           #'2021-07-05': [1.25, sbv, 0.70, 0.90],
                           #'2021-07-12': [1.25, sbv, 0.70, 0.90],
                           #'2021-07-19': [1.25, 0.00, 0.70, 0.90],
                           #'2021-07-26': [1.25, 0.00, 0.70, 0.90],
                           #'2021-08-02': [1.25, 0.00, 0.70, 0.90],
                           #'2021-08-16': [1.25, 0.00, 0.70, 0.90],
                           })

    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 2021.
        if scenario == 'Roadmap_All':

            beta_scens = sc.odict({'2021-06-21': [1.25, sbv, 0.70, 0.90],
                               '2021-06-28': [1.25, sbv, 0.70, 0.90],
                               '2021-07-05': [1.25, sbv, 0.70, 0.90],
                               '2021-07-12': [1.25, sbv, 0.70, 0.90],
                               '2021-07-19': [1.25, 0.00, 0.70, 0.90],
                               '2021-07-26': [1.25, 0.00, 0.70, 0.90],
                               '2021-08-02': [1.25, 0.00, 0.70, 0.90],
                               '2021-08-16': [1.25, 0.00, 0.70, 0.90],
                               '2021-09-01': [1.25, 0.63, 0.70, 0.90],
                               '2021-09-15': [1.25, 0.63, 0.70, 0.90],
                               '2021-09-29': [1.25, 0.63, 0.70, 0.90],
                               '2021-10-13': [1.25, 0.63, 0.70, 0.90],
                               '2021-10-22': [1.25, 0.02, 0.50, 0.90],
                               '2021-11-01': [1.25, 0.63, 0.70, 0.90],
                               '2021-11-08': [1.25, 0.63, 0.70, 0.90],
                               '2021-11-23': [1.25, 0.63, 0.70, 0.90],
                               '2021-11-30': [1.25, 0.63, 0.70, 0.90],
                               '2021-12-07': [1.25, 0.63, 0.70, 0.90],
                               '2021-12-20': [1.25, 0.02, 0.50, 0.80],
                               '2022-01-05': [1.25, 0.63, 0.70, 0.90],
                              })

        ## reopening schools on 8th March, society stage 1 29th March, society stage 2 12th April ONLY
        ## NO (stage 3) 17th May and NO stage 4 21st June 2021.
        ## Projecting until end of 2021.
        #elif scenario == 'Roadmap_Stage2':

            #beta_scens = sc.odict({'2021-04-12': [1.25, 0.02, 0.40, 0.70],
            #                   '2021-04-19': [1.25, sbv, 0.40, 0.70],
            #                   '2021-04-26': [1.25, sbv, 0.40, 0.70],
            #                   '2021-05-03': [1.25, sbv, 0.40, 0.70],
            #                   '2021-05-10': [1.25, sbv, 0.40, 0.70],
            #                   '2021-05-17': [1.25, sbv, 0.40, 0.70],
            #                   '2021-05-21': [1.25, sbv, 0.40, 0.70],
            #                   '2021-05-28': [1.25, 0.02, 0.40, 0.70],
            #                   '2021-06-07': [1.25, sbv, 0.40, 0.70],
            #                   '2021-06-21': [1.25, sbv, 0.40, 0.70],
            #                   '2021-06-28': [1.25, sbv, 0.40, 0.70],
            #                   '2021-07-05': [1.25, sbv, 0.40, 0.70],
            #                   '2021-07-12': [1.25, sbv, 0.40, 0.70],
            #                   '2021-07-19': [1.25, 0.00, 0.40, 0.70],
            #                   '2021-07-26': [1.25, 0.00, 0.40, 0.70],
            #                   '2021-08-02': [1.25, 0.00, 0.40, 0.70],
            #                   '2021-08-16': [1.25, 0.00, 0.40, 0.70],
            #                   '2021-09-01': [1.25, 0.63, 0.70, 0.90],
            #                   '2021-09-15': [1.25, 0.63, 0.70, 0.90],
            #                   '2021-09-29': [1.25, 0.63, 0.70, 0.90],
            #                   '2021-10-13': [1.25, 0.63, 0.70, 0.90],
            #                   '2021-10-27': [1.25, 0.02, 0.70, 0.90],
            #                   '2021-11-08': [1.25, 0.63, 0.70, 0.90],
            #                   '2021-11-23': [1.25, 0.63, 0.70, 0.90],
            #                   '2021-11-30': [1.25, 0.63, 0.70, 0.90],
            #                   '2021-12-07': [1.25, 0.63, 0.70, 0.90],
            #                   '2021-12-21': [1.25, 0.63, 0.70, 0.90],
            #                  })
        ## reopening schools on 8th March, society stage 1 29th March, society stage 2 12th April,
        ## and society some more (stage 3) 17th May but NO stage 4 21st June 2021.
        ## Projecting until end of 2021.
        elif scenario == 'Roadmap_Stage3':
            beta_scens = sc.odict({'2021-06-21': [1.25, sbv, 0.40, 0.60],
                               '2021-06-28': [1.25, sbv, 0.40, 0.60],
                               '2021-07-05': [1.25, sbv, 0.40, 0.60],
                               '2021-07-12': [1.25, sbv, 0.40, 0.60],
                               '2021-07-19': [1.25, 0.00, 0.50, 0.80],
                               '2021-07-26': [1.25, 0.00, 0.50, 0.80],
                               '2021-08-02': [1.25, 0.00, 0.50, 0.80],
                               '2021-08-16': [1.25, 0.00, 0.50, 0.80],
                               '2021-09-01': [1.25, 0.63, 0.70, 0.90],
                               '2021-09-15': [1.25, 0.63, 0.70, 0.90],
                               '2021-09-29': [1.25, 0.63, 0.70, 0.90],
                               '2021-10-13': [1.25, 0.63, 0.70, 0.90],
                               '2021-10-22': [1.25, 0.02, 0.50, 0.90],
                               '2021-11-01': [1.25, 0.63, 0.70, 0.90],
                               '2021-11-08': [1.25, 0.63, 0.70, 0.90],
                               '2021-11-23': [1.25, 0.63, 0.70, 0.90],
                               '2021-11-30': [1.25, 0.63, 0.70, 0.90],
                               '2021-12-07': [1.25, 0.63, 0.70, 0.90],
                               '2021-12-20': [1.25, 0.02, 0.50, 0.80],
                               '2022-01-05': [1.25, 0.63, 0.70, 0.90],
                              })
        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.117 strain
    b117 = cv.variant('b117', days=np.arange(sim.day('2020-08-20'), sim.day('2020-08-30')), n_imports=500)
    b117.p['rel_beta']        = 1.6
    b117.p['rel_symp_prob']   = 1.1
    b117.p['rel_severe_prob'] = 0.6
    b117.p['rel_crit_prob']   = 2.7
    b117.p['rel_death_prob']  = 0.6
    #b117.p['rel_severe_prob'] = 0.7
    #b117.p['rel_crit_prob']   = 1.0
    #b117.p['rel_death_prob']  = 1.0
    sim['variants'] += [b117]
    # Add B.1.1351 strain
    b1351 = cv.variant('b1351', days=np.arange(sim.day('2021-01-10'), sim.day('2021-01-20')), n_imports=1500)
    b1351.p['rel_beta']        = 1.0
    b1351.p['rel_severe_prob'] = 1.0
    b1351.p['rel_crit_prob']   = 1.0
    b1351.p['rel_death_prob']  = 1.0
    sim['variants'] += [b1351]
    # Add B.X.XXX strain starting middle of March
    b16172 = cv.variant('b16172', days=np.arange(sim.day('2021-03-17'), sim.day('2021-03-20')), n_imports=1000)
    b16172.p['rel_beta']         = 2.1
    b16172.p['rel_symp_prob']    = 0.4
    b16172.p['rel_severe_prob']  = 0.1
    b16172.p['rel_crit_prob']    = 0.2
    b16172.p['rel_death_prob']   = 0.4
    #b16172.p['rel_severe_prob'] = 0.7
    #b16172.p['rel_crit_prob']   = 1.0
    #b16172.p['rel_death_prob']  = 0.7
    sim['variants'] += [b16172]
    # seems like we need to do this to deal with cross immunity?
    #sim.initialize()
    #sim['immunity']
    #prior = {'wild': 0.8, 'b117': 0.5, 'b1351': 0.8, 'b16172': 0.8}
    #pre = {'wild': 0.8, 'b117': 0.5, 'b1351': 0.8, 'b16172': 0.8}
    #for k,v in sim['variant_map'].items():
    #    if v == 'b16172':
    #        for j, j_lab in sim['variant_map'].items():
    #            sim['immunity'][k][j] = prior[j_lab]
    #            sim['immunity'][j][k] = pre[j_lab]
                 #if j != k:
                 #    sim['immunity'][k][j] = cross_immunities['b117'][j_lab]
                 #    sim['immunity'][j][k] = cross_immunities[j_lab]['b117']
    # # Add a new change in beta to represent the takeover of the novel variant VOC B117 202012/01
    # # Assume that the new variant is 60% more transmisible (https://cmmid.github.io/topics/covid19/uk-novel-variant.html,
    # # Assume that between Nov 1 and Jan 30, the new variant grows from 0-100% of cases

    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_april= sim.day('2021-03-01')
    tti_day_july21= sim.day('2021-07-20')
    tti_day_august21= sim.day('2021-08-15')

    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
    # tn = 0.09
    s_prob_sep = 0.07769
    s_prob_oct = 0.07769
    s_prob_nov = 0.07769
    s_prob_dec = 0.07769
    s_prob_jan = 0.07769
    s_prob_march = 0.07769
    s_prob_july21 = 0.032769
    s_prob_august21 = 0.05769

    #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.5 for k in 'hswc'}]
     #isolation december
    iso_vals5 = [{k:0.4 for k in 'hswc'}]
    #isolation July 2021
    iso_vals6 = [{k:0.4 for k in 'hswc'}]
     #isolation from August 2021
    #iso_vals7 = [{k:0.4 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_april-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_april, 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.008, symp_quar_prob=0.0, start_day=tti_day_august21, test_delay=t_delay),
        cv.contact_tracing(trace_probs={'h': 1, 's': 0.8, 'w': 0.8, 'c': 0.05},
                           trace_time={'h': 0, 's': 1, 'w': 1, 'c': 2},
                           start_day='2020-06-01', end_day='2023-06-30',
                           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_july21, 'vals': iso_vals6}})]
        #cv.dynamic_pars({'iso_factor': {'days': tti_day_august21, 'vals': iso_vals7}})]
        #cv.dynamic_pars({'rel_death_prob': {'days': tti_day_vac, 'vals': 0.9}})]
        #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(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
Example #22
0
'''
Illustrate multiple variants
'''

import covasim as cv

# Define three new variants: B117, B1351, and a custom-defined variant
alpha = cv.variant('alpha', days=0, n_imports=10)
beta = cv.variant('beta', days=0, n_imports=10)
custom = cv.variant(label='3x more transmissible',
                    variant={'rel_beta': 3.0},
                    days=7,
                    n_imports=10)

# Create the simulation
sim = cv.Sim(variants=[alpha, beta, custom], pop_infected=10, n_days=32)

# Run and plot
sim.run()
sim.plot('variant')