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

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

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

    # basic test for vaccine
    b117 = cv.strain('b117', days=0)
    sim = cv.Sim(use_waning=True, strains=[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 #3
0
def test_strains(do_plot=False):
    sc.heading('Testing strains...')

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

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

    return sim
Example #4
0
def test_vaccines(do_plot=False):
    sc.heading('Testing vaccines...')

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

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

    return sim
Example #5
0
def test_import2strains_changebeta(do_plot=False, do_show=True, do_save=False):
    sc.heading(
        'Test introducing 2 new strains partway through a sim, with a change_beta intervention'
    )

    strain2 = {'rel_beta': 1.5, 'rel_severe_prob': 1.3}

    strain3 = {'rel_beta': 2, 'rel_symp_prob': 1.6}

    intervs = cv.change_beta(days=[5, 20, 40], changes=[0.8, 0.7, 0.6])
    strains = [
        cv.strain(strain=strain2, days=10, n_imports=20),
        cv.strain(strain=strain3, days=30, n_imports=20),
    ]
    sim = cv.Sim(use_waning=True,
                 interventions=intervs,
                 strains=strains,
                 label='With imported infections',
                 **base_pars)
    sim.run()

    return sim
Example #6
0
def test_import1strain(do_plot=False, do_show=True, do_save=False):
    sc.heading('Test introducing a new strain partway through a sim')

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

    return sim
Example #7
0
def test_importstrain_longerdur(do_plot=False, do_show=True, do_save=False):
    sc.heading(
        'Test introducing a new strain with longer duration partway through a sim'
    )

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

    strain_pars = {
        'rel_beta': 1.5,
    }

    strain = cv.strain(strain=strain_pars,
                       label='Custom strain',
                       days=10,
                       n_imports=30)
    sim = cv.Sim(use_waning=True,
                 pars=pars,
                 strains=strain,
                 label='With imported infections')
    sim.run()

    return sim
Example #8
0
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.1,
        #rel_severe_prob = 0.45,
        #rel_crit_prob = 1.0,
        #rel_death_prob=1.15,
    )

    sim = cv.Sim(pars=pars, datafile=data_path, location='uk')
    sim['prognoses']['sus_ORs'][0] = 1.0  # 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.50, 0.70],
        '2020-12-25': [1.50, 0.00, 0.20, 0.70],
        '2020-12-26': [1.50, 0.00, 0.20, 0.70],
        '2020-12-31': [1.50, 0.00, 0.20, 0.70],
        '2021-01-01': [1.50, 0.00, 0.20, 0.70],
        '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-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.02, 0.30, 0.50],
        '2021-04-05': [1.25, 0.02, 0.30, 0.50],
        '2021-04-12': [1.25, 0.02, 0.40, 0.60],
        '2021-04-19': [1.25, sbv, 0.40, 0.60],
        '2021-04-26': [1.25, sbv, 0.40, 0.60],
        '2021-05-03': [1.25, sbv, 0.40, 0.60],
        '2021-05-10': [1.25, sbv, 0.40, 0.60],
        '2021-05-17': [1.25, sbv, 0.50, 0.70],
        '2021-05-21': [1.25, sbv, 0.50, 0.70],
        '2021-05-28': [1.25, 0.02, 0.50, 0.70],
    })

    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-05-03': [1.25, sbv, 0.40, 0.60],
                '2021-05-10': [1.25, sbv, 0.40, 0.60],
                '2021-05-17': [1.25, sbv, 0.50, 0.70],
                '2021-05-21': [1.25, sbv, 0.50, 0.70],
                '2021-05-28': [1.25, 0.02, 0.50, 0.70],
                '2021-06-07': [1.25, sbv, 0.50, 0.70],
                '2021-06-14': [1.25, sbv, 0.50, 0.70],
                '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-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 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-04-12': [1.25, 0.02, 0.40, 0.60],
                '2021-04-19': [1.25, sbv, 0.40, 0.60],
                '2021-04-26': [1.25, sbv, 0.40, 0.60],
                '2021-05-03': [1.25, sbv, 0.40, 0.60],
                '2021-05-10': [1.25, sbv, 0.40, 0.60],
                '2021-05-17': [1.25, sbv, 0.50, 0.70],
                '2021-05-21': [1.25, sbv, 0.50, 0.70],
                '2021-05-28': [1.25, 0.02, 0.50, 0.70],
                '2021-06-07': [1.25, sbv, 0.50, 0.70],
                '2021-06-14': [1.25, sbv, 0.50, 0.70],
                '2021-06-21': [1.25, sbv, 0.50, 0.70],
                '2021-06-28': [1.25, sbv, 0.50, 0.70],
                '2021-07-05': [1.25, sbv, 0.50, 0.70],
                '2021-07-12': [1.25, sbv, 0.50, 0.70],
                '2021-07-19': [1.25, 0.00, 0.50, 0.70],
                '2021-07-26': [1.25, 0.00, 0.50, 0.70],
                '2021-08-02': [1.25, 0.00, 0.50, 0.70],
                '2021-08-16': [1.25, 0.00, 0.50, 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],
            })
        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.strain('b117',
                     days=np.arange(sim.day('2020-09-01'),
                                    sim.day('2020-09-10')),
                     n_imports=100)
    sim['strains'] += [b117]
    # Add B.1.1351 strain
    b1351 = cv.strain('b1351',
                      days=np.arange(sim.day('2020-11-20'),
                                     sim.day('2020-11-30')),
                      n_imports=600)
    sim['strains'] += [b1351]
    # Add B.X.XXX strain starting middle of April
    custom_strain = cv.strain(label='custom',
                              strain=cvp.get_strain_pars()['p1'],
                              days=np.arange(sim.day('2021-03-10'),
                                             sim.day('2021-03-10')),
                              n_imports=600)
    sim['strains'] += [custom_strain]
    # seems like we need to do this to deal with cross immunity?!
    sim.init_strains()
    sim.init_immunity()
    sim['immunity']
    prior = {'wild': 0.5, 'b117': 0.8, 'b1351': 0.8, 'custom': 0.8}
    pre = {'wild': 0.5, 'b117': 0.8, 'b1351': 0.8, 'custom': 0.8}
    cross_immunities = cvp.get_cross_immunity()
    for k, v in sim['strain_map'].items():
        if v == 'custom':
            for j, j_lab in sim['strain_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.7 for k in 'hswc'}]
    #isolation october
    iso_vals3 = [{k: 0.7 for k in 'hswc'}]
    #isolation november
    iso_vals4 = [{k: 0.7 for k in 'hswc'}]
    #isolation december
    iso_vals5 = [{k: 0.7 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.012,
                     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.012,
                     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.012,
                     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 in
    dose_pars = {
        'nab_eff': {
            'sus': {
                'slope': 1.6,
                'n_50': 0.05
            }
        },
        'nab_init': {
            'dist': 'normal',
            'par1': -0.85,
            'par2': 2
        },
        'nab_boost': 3,
        'doses': 2,
        'interval': 7 * 12,
        'nab_interval': 14
    }
    strain_pars = {
        'wild': 1.0,
        'b117': 1 / 2.3,
        'b1351': 1 / 9,
        'p1': 1 / 2.9,
        'custom': 1 / 2.3
    }
    vaccine = sc.mergedicts({'label': 'az_uk'},
                            sc.mergedicts(dose_pars, strain_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')))
    ]

    def subtarget_60_75(sim):
        inds = cv.true((sim.people.age >= 60) & (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_60_75,
                            days=np.arange(sim.day('2021-01-28'),
                                           sim.day('2023-01-01')))
    ]

    def subtarget_50_60(sim):
        inds = cv.true((sim.people.age >= 50) & (sim.people.age < 60))
        return {'inds': inds, 'vals': 0.010 * np.ones(len(inds))}

    interventions += [
        utils_vac.vaccinate(vaccine=vaccine,
                            prob=0.1,
                            subtarget=subtarget_50_60,
                            days=np.arange(sim.day('2021-02-10'),
                                           sim.day('2023-01-01')))
    ]

    def subtarget_40_50(sim):
        inds = cv.true((sim.people.age >= 40) & (sim.people.age < 50))
        return {'inds': inds, 'vals': 0.005 * np.ones(len(inds))}

    interventions += [
        utils_vac.vaccinate(vaccine=vaccine,
                            prob=0.1,
                            subtarget=subtarget_40_50,
                            days=np.arange(sim.day('2021-04-10'),
                                           sim.day('2023-01-01')))
    ]

    def subtarget_30_40(sim):
        inds = cv.true((sim.people.age >= 30) & (sim.people.age < 40))
        return {'inds': inds, 'vals': 0.003 * np.ones(len(inds))}

    interventions += [
        utils_vac.vaccinate(vaccine=vaccine,
                            prob=0.1,
                            subtarget=subtarget_30_40,
                            days=np.arange(sim.day('2021-05-10'),
                                           sim.day('2023-01-01')))
    ]

    def subtarget_18_30(sim):
        inds = cv.true((sim.people.age >= 18) & (sim.people.age < 30))
        return {'inds': inds, 'vals': 0.003 * np.ones(len(inds))}

    interventions += [
        utils_vac.vaccinate(vaccine=vaccine,
                            prob=0.01,
                            subtarget=subtarget_18_30,
                            days=np.arange(sim.day('2021-06-10'),
                                           sim.day('2023-01-01')))
    ]

    analyzers = []
    #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 #9
0
import covasim as cv
import numpy as np
import covasim.parameters as cvp
pars = {'use_waning': True, 'pop_infected': 100}
sim = cv.Sim(pars=pars)
#custom_strain = cv.strain(label='custom', strain=cvp.get_strain_pars()['b117'],
#                          days=np.arange(20, 21), n_imports=40)
#sim['strains'] += [custom_strain]

b117 = cv.strain('b117', days=np.arange(sim.day('2020-03-01'), sim.day('2020-03-10')), n_imports=100)
#im['strains'] += [b117]
    # Add B.1.1351 strain
b1351 = cv.strain('b1351', days=np.arange(sim.day('2020-04-05'), sim.day('2020-04-20')), n_imports=200)
#sim['strains'] += [b1351]
custom_strain = cv.strain(label='custom', strain = cvp.get_strain_pars()['b1351'],
                              days=np.arange(sim.day('2020-03-15'), sim.day('2020-03-30')), n_imports=40)
sim['strains'] += [b117, b1351, custom_strain]

sim.init_strains()
sim.init_immunity()
sim['immunity']
pre = {'wild': 0.0, 'b117': 0.0, 'b1351': 0.0, 'custom':1.0}
prior = {'wild': 0.0, 'b117': 0.0, 'b1351': 0.0, 'custom': 1.0}
cross_immunities = cvp.get_cross_immunity()
for k, v in sim['strain_map'].items():
    if v == 'custom':
        for j, j_lab in sim['strain_map'].items():
            sim['immunity'][k][j] = prior[j_lab]
            sim['immunity'][j][k] = pre[j_lab]
sim.run()
sim.plot('strains', do_save=True, do_show=False, fig_path=f'uk_strain.png')
Example #10
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.strain('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),
                'strains': [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),
                'strains': [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
Example #11
0
def test_vaccine_2strains_scen(do_plot=False, do_show=True, do_save=False):
    sc.heading(
        'Run a basic sim with b117 strain 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.strain('b1351', days=10, n_imports=20)
    p1 = cv.strain('p1', days=100, n_imports=100)

    # Define the scenarios

    scenarios = {
        'baseline': {
            'name': 'B1351 on day 10, No Vaccine',
            'pars': {
                'strains': [b1351]
            }
        },
        'b1351': {
            'name': 'B1351 on day 10, J&J starting on day 60',
            'pars': {
                'interventions': [jnj],
                'strains': [b1351],
            }
        },
        'p1': {
            'name': 'B1351 on day 10, J&J starting on day 60, p1 on day 100',
            'pars': {
                'interventions': [jnj],
                'strains': [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