def create_sim(x): beta = x[0] pop_infected = x[1] s_prob_sep = x[2] s_prob_oct = x[3] s_prob_nov = x[4] iso_vals1 = x[5] iso_vals2 = x[6] iso_vals3 = x[7] iso_vals4 = x[8] start_day = '2020-01-21' end_day = '2020-12-07' data_path = 'UK_Covid_cases_december6.xlsx' # Set the parameters total_pop = 67.86e6 # UK population size pop_size = 100e3 # Actual simulated population pop_scale = int(total_pop / pop_size) pop_type = 'hybrid' asymp_factor = 2 contacts = {'h': 3.0, 's': 20, 'w': 20, 'c': 20} pars = sc.objdict( 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, verbose=0.1, ) # Create the baseline simulation sim = cv.Sim(pars=pars, datafile=data_path, location='uk') sim['prognoses']['sus_ORs'][0] = 1 # ages 0-10 sim['prognoses']['sus_ORs'][1] = 1 # ages 10-20 sim['rel_severe_prob'] = 1.0 sim['rel_crit_prob'] = 1.0 # Scale factor for proportion of severe cases that become critical sim['rel_death_prob'] = 1.0 # Scale factor for proportion of critical cases that result in death 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') #some schools reopen 1st June and start of enhanced TTI 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') ti_day = sim.day('2020-12-07') beta_days = [ '2020-02-14', '2020-03-16', '2020-03-23', '2020-04-30', '2020-05-15', '2020-06-01', '2020-06-15', '2020-07-22', '2020-08-01', '2020-09-02', '2020-10-01', '2020-10-16', '2020-10-26', '2020-11-01', '2020-11-05', '2020-11-14', '2020-11-21', '2020-11-30', '2020-12-03' ] h_beta_changes = [ 1.00, 1.00, 1.29, 1.29, 1.29, 1.00, 1.00, 1.29, 1.29, 1.29, 1.29, 1.29, 1.29, 1.29, 1.50, 1.50, 1.50, 1.29, 1.29 ] s_beta_changes = [ 1.00, 0.90, 0.02, 0.02, 0.02, 0.23, 0.38, 0.00, 0.00, 0.63, 0.63, 0.63, 0.00, 0.63, 0.63, 0.63, 0.63, 0.63, 0.63 ] #w_beta_changes =[14feb16march23marh30apr 5may 1june15june22july 1aug 2sep 1octoct16oct 26oct 1nov 5nov 14nov 21nov 30nov dec03 w_beta_changes = [ 0.90, 0.80, 0.20, 0.20, 0.20, 0.30, 0.30, 0.40, 0.40, 0.50, 0.50, 0.50, 0.50, 0.50, 0.40, 0.40, 0.40, 0.40, 0.60 ] c_beta_changes = [ 0.90, 0.80, 0.20, 0.20, 0.20, 0.30, 0.30, 0.40, 0.40, 0.60, 0.60, 0.60, 0.60, 0.60, 0.40, 0.40, 0.40, 0.40, 0.70 ] # Define the beta changes h_beta = cv.change_beta(days=beta_days, changes=h_beta_changes, layers='h') s_beta = cv.change_beta(days=beta_days, changes=s_beta_changes, layers='s') w_beta = cv.change_beta(days=beta_days, changes=w_beta_changes, layers='w') c_beta = cv.change_beta(days=beta_days, changes=c_beta_changes, layers='c') #next line to save the intervention interventions = [h_beta, w_beta, s_beta, c_beta] s_prob_march = 0.012 s_prob_april = 0.017 s_prob_may = 0.02769 s_prob_june = 0.02769 s_prob_july = 0.02769 s_prob_august = 0.02769 s_prob_sept = 0.05769 s_prob_oct = 0.05769 s_prob_nov = 0.05769 t_delay = 1.0 #isolation until august iso_vals = [{k: 0.1 for k in 'hswc'}] #isolation in august iso_vals1 = [{k: 0.3 for k in 'hswc'}] #isolation in september iso_vals2 = [{k: 0.4 for k in 'hswc'}] #isolation in october iso_vals3 = [{k: 0.7 for k in 'hswc'}] #isolation in november iso_vals4 = [{k: 0.7 for k in 'hswc'}] #tracing level at 42.35% in June; 47.22% in July, 44.4% in August and 49.6% in Septembre (until 16th Sep) t_eff_june = 0.42 t_eff_july = 0.47 t_eff_august = 0.44 t_eff_sep = 0.50 t_eff_oct = 0.50 t_eff_nov = 0.60 t_probs_june = {k: t_eff_june for k in 'hwsc'} t_probs_july = {k: t_eff_july for k in 'hwsc'} t_probs_august = {k: t_eff_august for k in 'hwsc'} t_probs_sep = {k: t_eff_sep for k in 'hwsc'} t_probs_oct = {k: t_eff_oct for k in 'hwsc'} t_probs_nov = {k: t_eff_nov for k in 'hwsc'} trace_d_1 = {'h': 0, 's': 1, 'w': 1, 'c': 2} #testing and isolation intervention interventions += [ cv.test_prob(symp_prob=0.009, asymp_prob=0.0, symp_quar_prob=0.0, asymp_quar_prob=0.0, start_day=tc_day, end_day=te_day - 1, test_delay=t_delay, test_sensitivity=0.97), cv.test_prob(symp_prob=s_prob_april, asymp_prob=0.0, symp_quar_prob=0.0, asymp_quar_prob=0.0, start_day=te_day, end_day=tt_day - 1, test_delay=t_delay, test_sensitivity=0.97), cv.test_prob(symp_prob=s_prob_may, asymp_prob=0.0075, symp_quar_prob=0.0, asymp_quar_prob=0.0, start_day=tt_day, end_day=tti_day - 1, test_delay=t_delay, test_sensitivity=0.97), cv.test_prob(symp_prob=s_prob_june, asymp_prob=0.0075, symp_quar_prob=0.0, asymp_quar_prob=0.0, start_day=tti_day, end_day=tti_day_july - 1, test_delay=t_delay, test_sensitivity=0.97), cv.test_prob(symp_prob=s_prob_july, asymp_prob=0.0075, symp_quar_prob=0.0, asymp_quar_prob=0.0, start_day=tti_day_july, end_day=tti_day_august - 1, test_delay=t_delay, test_sensitivity=0.97), cv.test_prob(symp_prob=s_prob_august, asymp_prob=0.0075, symp_quar_prob=0.0, asymp_quar_prob=0.0, start_day=tti_day_august, end_day=tti_day_sep - 1, test_delay=t_delay, test_sensitivity=0.97), cv.test_prob(symp_prob=s_prob_sept, asymp_prob=0.0175, symp_quar_prob=0.0, asymp_quar_prob=0.0, start_day=tti_day_sep, end_day=tti_day_oct - 1, test_delay=t_delay, test_sensitivity=0.97), cv.test_prob(symp_prob=s_prob_oct, asymp_prob=0.0175, symp_quar_prob=0.0, asymp_quar_prob=0.0, start_day=tti_day_oct, end_day=tti_day_nov - 1, test_delay=t_delay, test_sensitivity=0.97), cv.test_prob(symp_prob=s_prob_nov, asymp_prob=0.0275, symp_quar_prob=0.0, asymp_quar_prob=0.0, start_day=tti_day_nov, test_delay=t_delay, test_sensitivity=0.97), cv.dynamic_pars({'iso_factor': { 'days': te_day, 'vals': iso_vals }}), cv.contact_tracing(trace_probs=t_probs_june, trace_time=trace_d_1, start_day=tti_day, end_day=tti_day_july - 1), cv.contact_tracing(trace_probs=t_probs_july, trace_time=trace_d_1, start_day=tti_day_july, end_day=tti_day_august - 1), cv.contact_tracing(trace_probs=t_probs_august, trace_time=trace_d_1, start_day=tti_day_august, end_day=tti_day_sep - 1), cv.contact_tracing(trace_probs=t_probs_sep, trace_time=trace_d_1, start_day=tti_day_sep, end_day=tti_day_oct - 1), cv.contact_tracing(trace_probs=t_probs_oct, trace_time=trace_d_1, start_day=tti_day_oct, end_day=tti_day_nov - 1), cv.contact_tracing(trace_probs=t_probs_nov, trace_time=trace_d_1, start_day=tti_day_nov), cv.dynamic_pars({'iso_factor': { 'days': tti_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({'rel_death_prob': {'days': tti_day_august, 'vals': 2.0}}), #cv.dynamic_pars({'rel_death_prob': {'days': [tti_day_july, tti_day_sep], 'vals': [0.5, 0.5]}}), ] sim.update_pars(interventions=interventions) for intervention in sim['interventions']: intervention.do_plot = False return sim
test_delay=t_delay), cv.test_prob(symp_prob=s_prob_july, asymp_prob=0.00075, symp_quar_prob=0.0, asymp_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.00075, symp_quar_prob=0.0, asymp_quar_prob=0.0, start_day=tti_day_august, test_delay=t_delay), cv.dynamic_pars({'iso_factor': { 'days': te_day, 'vals': iso_vals }}), cv.contact_tracing(trace_probs=t_probs_june, trace_time=trace_d_1, start_day=tti_day, end_day=tti_day_july - 1), cv.contact_tracing(trace_probs=t_probs_july, trace_time=trace_d_1, start_day=tti_day_july), ] elif tti_scen == 'optimal_masks15': # Tracing and enhanced testing strategy of symptimatics from 1st June with tracing at 40% #testing in June s_prob_march = 0.012
def make_ints(make_future_ints=True, mask_uptake=None, venue_trace_prob=None, future_test_prob=None, mask_eff=0.3): # Make historical interventions initresponse = '2020-03-15' lockdown = '2020-03-23' reopen1 = '2020-05-01' # Two adults allowed to visit a house reopen2 = '2020-05-15' # Up to 5 adults can visit a house; food service and non-essential retail start to resume reopen3 = '2020-06-01' # Pubs and regional travel open, plus more social activities reopen4 = '2020-07-01' # large events, cinemas, museums, open; fewer restrictions on cafes/pubs/etc, school_dates = ['2020-05-11', '2020-05-18', '2020-05-25'] comm_beta_aug = 0.7 ints = [cv.clip_edges(days=[initresponse,lockdown]+school_dates, changes=[0.75, 0.05, 0.8, 0.9, 1.0], layers=['S'], do_plot=False), cv.clip_edges(days=[lockdown, reopen2, reopen3, reopen4], changes=[0.5, 0.65, 0.75, 0.85], layers=['W'], do_plot=False), cv.clip_edges(days=[lockdown, reopen2, reopen4], changes=[0, 0.5, 1.0], layers=['pSport'], do_plot=False), cv.clip_edges(days=[lockdown, '2020-06-22'], changes=[0, 1.0], layers=['cSport'], do_plot=False), cv.change_beta(days=[lockdown, reopen2, reopen4], changes=[1.2, 1.1, 1.], layers=['H'], do_plot=True), cv.change_beta(days=[lockdown, reopen2], changes=[0, comm_beta_aug], layers=['church'], do_plot=False), cv.change_beta(days=[lockdown, reopen1, reopen2, reopen3, reopen4], changes=[0.0, 0.3, 0.4, 0.5, comm_beta_aug], layers=['social'], do_plot=False), # Dynamic layers ['C', 'entertainment', 'cafe_restaurant', 'pub_bar', 'transport', 'public_parks', 'large_events'] cv.change_beta(days=[lockdown], changes=[comm_beta_aug], layers=['C'], do_plot=True), cv.change_beta(days=[lockdown, reopen4], changes=[0, comm_beta_aug], layers=['entertainment'], do_plot=False), cv.change_beta(days=[lockdown, reopen2], changes=[0, comm_beta_aug], layers=['cafe_restaurant'], do_plot=False), cv.change_beta(days=[lockdown, reopen3, reopen4], changes=[0, 0.5, comm_beta_aug], layers=['pub_bar'], do_plot=False), cv.change_beta(days=[lockdown, reopen2, reopen4], changes=[0.2, 0.3, comm_beta_aug], layers=['transport'], do_plot=False), cv.change_beta(days=[lockdown, reopen2, reopen4], changes=[0.4, 0.5, comm_beta_aug], layers=['public_parks'], do_plot=False), cv.change_beta(days=[lockdown, reopen4], changes=[0.0, comm_beta_aug], layers=['large_events'], do_plot=False), ] # Approximate a mask intervention by changing beta in all layers where people would wear masks - assuming not in schools, sport, social gatherings, or home mask_uptake_aug = 0.15 mask_uptake_sep = 0.3 mask_beta_change_aug = (1-mask_uptake_aug)*comm_beta_aug + mask_uptake_aug*mask_eff*comm_beta_aug mask_beta_change_sep = (1-mask_uptake_sep)*comm_beta_aug + mask_uptake_sep*mask_eff*comm_beta_aug ints += [cv.change_beta(days=['2020-08-01', '2020-08-31'] * 8, changes=[mask_beta_change_aug, 0.7] * 8, layers=['church', 'C', 'entertainment', 'cafe_restaurant', 'pub_bar', 'transport', 'public_parks', 'large_events']), cv.change_beta(days=['2020-09-01', today] * 8, changes=[mask_beta_change_sep, 0.7] * 8, layers=['church', 'C', 'entertainment', 'cafe_restaurant', 'pub_bar', 'transport', 'public_parks', 'large_events']) ] if make_future_ints: ints += [cv.change_beta(days=[today] * 8, changes=[(1 - mask_uptake) * comm_beta_aug + mask_uptake * mask_eff * comm_beta_aug] * 8, layers=['church', 'C', 'entertainment', 'cafe_restaurant', 'pub_bar', 'transport', 'public_parks', 'large_events'])] # Testing symp_prob_prelockdown = 0.04 # Limited testing pre lockdown symp_prob_lockdown = 0.07 # 0.065 #Increased testing during lockdown symp_prob_postlockdown = 0.19 # 0.165 # Testing since lockdown asymp_quar_prob_postlockdown = (1-(1-symp_prob_postlockdown)**10) future_asymp_test_prob = (1-(1-future_test_prob)**10)/2 ints += [cv.test_prob(start_day=0, end_day=lockdown, symp_prob=symp_prob_prelockdown, asymp_quar_prob=0.01, do_plot=False), cv.test_prob(start_day=lockdown, end_day=reopen2, symp_prob=symp_prob_lockdown, asymp_quar_prob=0.01,do_plot=False), cv.test_prob(start_day=reopen2, end_day=today, symp_prob=symp_prob_postlockdown, asymp_quar_prob=asymp_quar_prob_postlockdown,do_plot=True)] if make_future_ints: ints += [cv.test_prob(start_day=tomorrow, symp_prob=future_test_prob, asymp_quar_prob=future_asymp_test_prob, do_plot=True)] # Tracing trace_probs = {'H': 1, 'S': 0.95, # Home and school 'W': 0.8, 'pSport': 0.8, 'cSport': 0.8, 'social': 0.8, # Work and social 'C': 0.05, 'public_parks': 0.05, # Non-venue-based 'church': 0.5, 'entertainment': 0.5, 'cafe_restaurant': 0.5, 'pub_bar': 0.5, 'large_events': 0.5, # Venue-based 'transport': 0.1, # Transport } trace_time = {'H': 0, 'S': 0.5, # Home and school 'W': 1, 'pSport': 1, 'cSport': 1, 'social': 1, # Work and social: [0.29, 0.59, 0.74, 0.78, 0.80, 0.80, 0.80, 0.80] 'C': 2, 'public_parks': 2, # Non-venue-based: [0.0068, 0.0203, 0.0338, 0.0429, 0.0474, 0.0492, 0.0498, 0.0499] 'church': 1, 'entertainment': 1, 'cafe_restaurant': 1, 'pub_bar': 1, 'large_events': 1, # Venue-based: [0.068, 0.203, 0.338, 0.429, 0.474, 0.492, 0.498, 0.499] 'transport': 1, # Transport: [0.014, 0.041, 0.068, 0.086, 0.095, 0.098, 0.100, 0.100] } trace_time_f = {'H': 0, 'S': 0.5, # Home and school 'W': 1, 'pSport': 1, 'cSport': 1, 'social': 1, # Work and social: [0.29, 0.59, 0.74, 0.78, 0.80, 0.80, 0.80, 0.80] 'C': 2, 'public_parks': 2, # Non-venue-based: [0.0068, 0.0203, 0.0338, 0.0429, 0.0474, 0.0492, 0.0498, 0.0499] 'church': 1, 'entertainment': 1, 'cafe_restaurant': 1, 'pub_bar': 1, 'large_events': 1, # Venue-based: [0.068, 0.203, 0.338, 0.429, 0.474, 0.492, 0.498, 0.499] 'transport': 2, # Transport: [0.014, 0.041, 0.068, 0.086, 0.095, 0.098, 0.100, 0.100] } ints += [cv.contact_tracing(trace_probs=trace_probs, trace_time=trace_time, distribute_times=True, start_day=0, end_day=today, do_plot=False)] if make_future_ints: ints += [cv.contact_tracing(trace_probs={'H': 1, 'S': 0.95, 'W': 0.8, 'pSport': 0.8, 'cSport': 0.8, 'social': 0.8, 'C': 0.05, 'public_parks': 0.05, 'church': venue_trace_prob, 'entertainment': venue_trace_prob, 'cafe_restaurant': venue_trace_prob, 'pub_bar': venue_trace_prob, 'large_events': venue_trace_prob, 'transport': 0.1}, trace_time=trace_time_f, distribute_times=True, start_day=tomorrow, do_plot=False)] # Close borders, then open them again to account for Victorian imports and leaky quarantine ints += [cv.dynamic_pars({'n_imports': {'days': [14, 112, 116], 'vals': [0, 8, 0]}}, do_plot=False)] return ints
def create_sim(seed): beta = 0.014 #0.011 pop_infected = 10 # initial cases of infection start_day = '2020-02-01' #end_day = '2020-11-30' #end_day = '2021-03-31' end_day = '2021-06-30' data_file = df # Set the parameters total_pop = 5.8e6 # Denmark population size pop_size = 100e3 # Actual simulated population pop_scale = int(total_pop / pop_size) pop_type = 'hybrid' asymp_factor = 2 pars = sc.objdict( 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, rescale=True, verbose=0.1, rand_seed=seed, ) # Create the baseline simulation sim = cv.Sim(pars=pars, datafile=data_file, location='denmark', analyzers=cv.age_histogram( edges=[0, 16, 65, 130], states=['exposed', 'symptomatic', 'dead'])) #edges = [0,16,65,130], relative_death = cv.dynamic_pars(rel_death_prob=dict(days=[ sim.day('2020-02-01'), sim.day('2020-06-09'), sim.day('2020-09-17') ], vals=[1.3, 0.8, 0.4])) interventions = [relative_death] ### Change beta ### beta_days = [ '2020-03-15', '2020-04-15', '2020-05-10', '2020-06-22', '2020-07-20', '2020-08-22', '2020-09-01', '2020-09-22', '2020-10-01', '2020-10-15', '2020-11-01', '2020-11-20', '2020-11-30', '2020-12-14', '2021-01-01', '2021-03-01', '2021-04-06' ] h_beta_changes = [ 1.10, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.10, 1.10, 1.10, 1.20, 1.30, 1.20, 1.10, 1.00, 1.00 ] s_beta_changes = [ 0.80, 0.50, 0.50, 0.40, 0.60, 0.60, 1.00, 0.80, 0.80, 1.00, 0.80, 1.00, 1.20, 1.00, 0.80, 0.70, 0.60 ] w_beta_changes = [ 0.80, 0.50, 0.50, 0.40, 0.60, 0.60, 1.00, 0.80, 0.80, 1.00, 0.80, 1.00, 1.20, 1.00, 0.80, 0.70, 0.50 ] c_beta_changes = [ 0.90, 0.60, 0.50, 0.70, 0.90, 0.80, 1.00, 0.70, 0.70, 1.00, 0.80, 1.10, 1.30, 1.10, 1.00, 0.80, 0.70 ] # Define the beta changes h_beta = cv.change_beta(days=beta_days, changes=h_beta_changes, layers='h') s_beta = cv.change_beta(days=beta_days, changes=s_beta_changes, layers='s') w_beta = cv.change_beta(days=beta_days, changes=w_beta_changes, layers='w') c_beta = cv.change_beta(days=beta_days, changes=c_beta_changes, layers='c') ### edge clipping ### clip_days = [ '2020-03-15', '2020-04-15', '2020-05-10', '2020-06-08', '2020-06-22', '2020-08-17', '2020-09-01', '2020-09-15', '2020-10-05', '2020-11-05', '2020-11-20', '2020-12-09', '2020-12-19', '2020-12-25', '2021-01-04', '2021-02-01', '2021-03-01', '2021-04-06' ] s_clip_changes = [ 0.01, 0.20, 0.40, 0.70, 0.05, 0.10, 0.90, 0.80, 0.70, 0.70, 0.70, 0.40, 0.05, 0.05, 0.05, 0.30, 0.50, 0.80 ] w_clip_changes = [ 0.10, 0.30, 0.50, 0.70, 0.60, 0.80, 1.00, 0.80, 0.70, 0.70, 0.70, 0.60, 0.40, 0.10, 0.50, 0.60, 0.60, 0.80 ] c_clip_changes = [ 0.20, 0.40, 0.60, 0.85, 1.00, 1.00, 1.00, 0.80, 0.80, 0.90, 0.90, 0.70, 0.80, 0.50, 0.60, 0.70, 0.80, 0.90 ] # Define the edge clipping s_clip = cv.clip_edges(days=clip_days, changes=s_clip_changes, layers='s') w_clip = cv.clip_edges(days=clip_days, changes=w_clip_changes, layers='w') c_clip = cv.clip_edges(days=clip_days, changes=c_clip_changes, layers='c') interventions += [h_beta, w_beta, s_beta, c_beta, w_clip, s_clip, c_clip] # Add a new change in beta to represent the takeover of the new variant B.1.1.7 nv_days = np.linspace(sim.day('2020-12-14'), sim.day('2021-03-28'), 15 * 7) nv_prop = 0.952 / (1 + np.exp(-0.099 * (nv_days - sim.day('2020-12-14') - 59))) nv_change = nv_prop * 1.5 + (1 - nv_prop) * 1.0 #r = 1.5 nv_beta = cv.change_beta(days=nv_days, changes=nv_change) c = np.r_[0.8 * np.ones(sim.day('2021-02-13') - sim.day('2020-12-14')), 0.4 * np.ones(sim.day('2021-03-29') - sim.day('2021-02-13'))] relative_severe = cv.dynamic_pars(rel_severe_prob=dict( days=nv_days, vals=nv_prop * 1.2 + (1 - nv_prop) * 1)) relative_critical = cv.dynamic_pars(rel_crit_prob=dict( days=nv_days, vals=nv_prop * 1.2 + (1 - nv_prop) * 1)) relative_death_nv = cv.dynamic_pars(rel_death_prob=dict( days=nv_days, vals=nv_prop * c * 1.2 + (1 - nv_prop) * c)) interventions += [ nv_beta, relative_severe, relative_critical, relative_death_nv ] # import infections from 2020-02-20 to 2020-03-01 imports1 = cv.dynamic_pars(n_imports=dict(days=[25, 35], vals=[2, 0])) imports2 = cv.dynamic_pars(n_imports=dict(days=[171, 190], vals=[2, 0])) interventions += [imports1, imports2] iso_vals = [{ 'h': 0.5, 's': 0.05, 'w': 0.05, 'c': 0.1 }] #dict(h=0.5, s=0.05, w=0.05, c=0.1) interventions += [ cv.dynamic_pars( {'iso_factor': { 'days': sim.day('2020-03-15'), 'vals': iso_vals }}) ] iso_vals2 = [{'h': 0.7, 's': 0.1, 'w': 0.1, 'c': 0.3}] interventions += [ cv.dynamic_pars( {'iso_factor': { 'days': sim.day('2021-05-01'), 'vals': iso_vals2 }}) ] # From May 12, starting tracing and isolation strategy tracing_prob = dict(h=1.0, s=0.5, w=0.5, c=0.2) trace_time = {'h': 0, 's': 1, 'w': 1, 'c': 2} interventions += [ cv.contact_tracing(trace_probs=tracing_prob, trace_time=trace_time, start_day='2020-05-12') ] interventions += [ cv.test_num(daily_tests=sim.data['new_tests'], start_day=0, end_day=sim.day('2021-03-31'), test_delay=1, symp_test=50, sensitivity=0.97, subtarget=prior_test) ] vaccine1 = vaccine_plan(daily1, start_day='2021-01-06', end_day='2021-01-24', delay=22, rel_symp=0.5, rel_sus=0.2, subtarget=vaccinate_by_age) vaccine2 = vaccine_plan(daily2, start_day='2021-01-25', end_day='2021-02-15', delay=27, rel_symp=0.5, rel_sus=0.2, subtarget=vaccinate_by_age) vaccine3 = vaccine_plan(daily3, start_day='2021-02-16', end_day='2021-03-07', delay=24, rel_symp=0.5, rel_sus=0.2, subtarget=vaccinate_by_age) vaccine4 = vaccine_plan(daily4, start_day='2021-03-08', end_day='2021-04-10', delay=37, rel_symp=0.5, rel_sus=0.2, subtarget=vaccinate_by_age) vaccine5 = vaccine_plan(vn, start_day='2021-04-11', end_day='2021-06-30', delay=37, rel_symp=0.5, rel_sus=0.2, subtarget=vaccinate_by_age) interventions += [ cv.test_num(daily_tests=t, start_day=sim.day('2021-04-01'), end_day=sim.day('2021-06-30'), test_delay=1, symp_test=50, sensitivity=0.97, subtarget=prior_test) ] interventions += [vaccine1, vaccine2, vaccine3, vaccine4, vaccine5] sim.update_pars(interventions=interventions) for intervention in sim['interventions']: intervention.do_plot = False sim.initialize() return sim
def make_sim(seed, beta, calibration=True, scenario=None, delta_beta=1.6, future_symp_test=None, end_day=None, verbose=0): # Set the parameters total_pop = 67.86e6 # UK population size pop_size = 100e3 # Actual simulated population pop_scale = int(total_pop / pop_size) pop_type = 'hybrid' pop_infected = 1500 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-04-10' pars = sc.objdict( 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_severe_prob=0.4, rel_crit_prob=2.3, 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.90], '2020-12-26': [1.50, 0.00, 0.20, 0.90], '2020-12-31': [1.50, 0.00, 0.20, 0.90], '2021-01-01': [1.50, 0.00, 0.20, 0.90], '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] }) if not calibration: ##no schools until 1st 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) if scenario == 'fullSchools': beta_scens = sc.odict({ '2021-03-08': [1.25, sbv, 0.30, 0.40], '2021-03-15': [1.25, sbv, 0.30, 0.40], '2021-03-22': [1.25, sbv, 0.30, 0.40], '2021-03-29': [1.25, 0.02, 0.30, 0.50], '2021-04-01': [1.25, 0.02, 0.30, 0.50], '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-14': [1.25, sbv, 0.40, 0.70], '2021-05-28': [1.25, sbv, 0.40, 0.70], '2021-06-10': [1.25, sbv, 0.40, 0.70], '2021-06-21': [1.25, sbv, 0.40, 0.80], '2021-06-28': [1.25, sbv, 0.50, 0.80], '2021-07-05': [1.25, sbv, 0.50, 0.80], '2021-07-12': [1.25, sbv, 0.50, 0.80], '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], }) 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 a new change in beta to represent the takeover of the novel variant VOC 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 voc_days = np.linspace(sim.day('2020-08-01'), sim.day('2021-02-10'), 31) voc_prop = 0.52 / ( 1 + np.exp(-0.075 * (voc_days - sim.day('2020-09-30'))) ) # Use a logistic growth function to approximate fig 2A of https://cmmid.github.io/topics/covid19/uk-novel-variant.html voc_change = voc_prop * 1.60 + (1 - voc_prop) * 1. voc_beta = cv.change_beta(days=voc_days, changes=voc_change) interventions = [h_beta, w_beta, s_beta, c_beta, voc_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_vac1 = sim.day('2020-12-20') tti_day_vac2 = sim.day('2021-03-08') tti_day_change = sim.day('2021-03-08') 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 #0.114=70%; 0.149=80%; 0.205=90% if future_symp_test is None: future_symp_test = s_prob_dec 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'}] #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=future_symp_test, asymp_prob=0.0063, symp_quar_prob=0.0, start_day=tti_day_jan, end_day=tti_day_change - 1, test_delay=t_delay), cv.test_prob(symp_prob=0.114, asymp_prob=0.0063, symp_quar_prob=0.0, start_day=tti_day_change, test_delay=t_delay), 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='2020-06-01', end_day='2021-02-28', 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])] # vaccination interventions interventions += [ utils.two_dose_daily_delayed(300e3, start_day='2020-12-20', dose_delay=21, delay=7 * 7, take_prob=1.0, rel_symp=0.05, age_priority=50, rel_trans=0.5, cumulative=[0.7, 1.0], dose_priority=[1, 0.2]) ] #interventions += [utils.two_dose_daily_delayed(300e3, start_day='2021-03-09', dose_delay=21, delay=10*7, # take_prob=1.0, rel_symp=0.05, age_priority=50, # rel_trans=0.5, cumulative=[0.7, 1.0], dose_priority=[1, 0.2])] analyzers = [] analyzers += [ utils.record_dose_flows(vacc_class=utils.two_dose_daily_delayed) ] # 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
def test_all_interventions(do_plot=False): ''' Test all interventions supported by Covasim ''' sc.heading('Testing default interventions') # Default parameters, using the random layer pars = sc.objdict( pop_size=1e3, pop_infected=10, n_days=90, verbose=verbose, ) hpars = sc.mergedicts( pars, {'pop_type': 'hybrid'}) # Some, but not all, tests require layers rsim = cv.Sim(pars) hsim = cv.Sim(hpars) def make_sim(which='r', interventions=None): ''' Helper function to avoid having to recreate the sim each time ''' if which == 'r': sim = sc.dcp(rsim) elif which == 'h': sim = sc.dcp(hsim) sim['interventions'] = interventions sim.initialize() return sim #%% Define the interventions # 1. Dynamic pars i1a = cv.test_prob(start_day=5, symp_prob=0.3) i1b = cv.dynamic_pars({ 'beta': { 'days': [40, 50], 'vals': [0.005, 0.015] }, 'rel_death_prob': { 'days': 30, 'vals': 2.0 } }) # Starting day 30, make diagnosed people stop transmitting # 2. Sequence i2 = cv.sequence(days=[15, 30, 45], interventions=[ cv.test_num(daily_tests=[20] * pars.n_days), cv.test_prob(symp_prob=0.0), cv.test_prob(symp_prob=0.2), ]) # 3. Change beta i3a = cv.change_beta([30, 50], [0.0, 1.0], layers='h') i3b = cv.change_beta([30, 40, 60], [0.0, 1.0, 0.5]) # 4. Clip edges -- should match the change_beta scenarios -- note that intervention i07 was removed i4a = cv.clip_edges([30, 50], [0.0, 1.0], layers='h') i4b = cv.clip_edges([30, 40, 60], [0.0, 1.0, 0.5]) # 5. Test number i5 = cv.test_num(daily_tests=[100, 100, 100, 0, 0, 0] * (pars.n_days // 6)) # 6. Test probability i6 = cv.test_prob(symp_prob=0.1) # 7. Contact tracing i7a = cv.test_prob(start_day=20, symp_prob=0.01, asymp_prob=0.0, symp_quar_prob=1.0, asymp_quar_prob=1.0, test_delay=0) i7b = cv.contact_tracing(start_day=20, trace_probs=dict(h=0.9, s=0.7, w=0.7, c=0.3), trace_time=dict(h=0, s=1, w=1, c=3)) # 8. Combination, with dynamically set days def check_inf(interv, sim, thresh=10, close_day=18): days = close_day if sim.people.infectious.sum() > thresh else np.nan return days i8a = cv.clip_edges(days=check_inf, changes=0.0, layers='s') # Close schools i8b = cv.clip_edges(days=[20, 32, 45], changes=[0.7, 0.3, 0.9], layers=['w', 'c']) # Reduce work and community i8c = cv.test_prob(start_day=38, symp_prob=0.01, asymp_prob=0.0, symp_quar_prob=1.0, asymp_quar_prob=1.0, test_delay=2) # Start testing for TTQ i8d = cv.contact_tracing(start_day=40, trace_probs=dict(h=0.9, s=0.7, w=0.7, c=0.3), trace_time=dict(h=0, s=1, w=1, c=3)) # Start tracing for TTQ # 9. Vaccine i9a = cv.simple_vaccine(days=20, prob=1.0, rel_sus=1.0, rel_symp=0.0) i9b = cv.simple_vaccine(days=50, prob=1.0, rel_sus=0.0, rel_symp=0.0) #%% Create the simulations sims = sc.objdict() sims.dynamic = make_sim('r', [i1a, i1b]) sims.sequence = make_sim('r', i2) sims.change_beta1 = make_sim('h', i3a) sims.clip_edges1 = make_sim('h', i4a) # Roughly equivalent to change_beta1 sims.change_beta2 = make_sim('r', i3b) sims.clip_edges2 = make_sim('r', i4b) # Roughly equivalent to change_beta2 sims.test_num = make_sim('r', i5) sims.test_prob = make_sim('r', i6) sims.tracing = make_sim('h', [i7a, i7b]) sims.combo = make_sim('h', [i8a, i8b, i8c, i8d]) sims.vaccine = make_sim('r', [i9a, i9b]) # Run the simualations for key, sim in sims.items(): sim.label = key sim.run() # Test intervention retrieval methods sim = sims.combo ce1, ce2 = sim.get_interventions(cv.clip_edges) ce, tp = sim.get_interventions([0, 2]) inds = sim.get_interventions(cv.clip_edges, as_inds=True) # Returns [0,1] assert inds == [0, 1] sim.get_interventions('summary') # Prints a summary #%% Plotting if do_plot: for sim in sims.values(): print(f'Running {sim.label}...') sim.plot() fig = pl.gcf() try: fig.axes[0].set_title(f'Simulation: {sim.label}') except: pass return
def test_interventions(do_plot=False, do_show=True, do_save=False, fig_path=None): sc.heading('Test of testing interventions') sc.heading('Setting up...') sc.tic() n_runs = 3 verbose = 1 base_pars = { 'pop_size': 1000, 'use_layers': True, } base_sim = cv.Sim(base_pars) # create sim object n_people = base_sim['pop_size'] npts = base_sim.npts # Define overall testing assumptions # As the most optimistic case, we assume countries could get to South Korea's testing levels. S Korea has tested # an average of 10000 people/day over March, or 270,000 in total. This is ~200 people per million every day (0.02%). max_optimistic_testing = 0.0002 optimistic_daily_tests = [ max_optimistic_testing * n_people ] * npts # Very best-case scenario for asymptomatic testing # Define the scenarios scenarios = { 'baseline': { 'name': 'Status quo, no testing', 'pars': { 'interventions': None, } }, 'test_skorea': { 'name': 'Assuming South Korea testing levels of 0.02% daily (untargeted); isolate positives', 'pars': { 'interventions': cv.test_num(daily_tests=optimistic_daily_tests) } }, 'tracing': { 'name': 'Assuming South Korea testing levels of 0.02% daily (with contact tracing); isolate positives', 'pars': { 'interventions': [ cv.test_num(daily_tests=optimistic_daily_tests), cv.dynamic_pars({'cont_factor': { 'days': 20, 'vals': 0.1 }}) ] # This means that people who've been in contact with known positives isolate with 90% effectiveness } }, 'floating': { 'name': 'Test with constant probability based on symptoms', 'pars': { 'interventions': cv.test_prob(symptomatic_prob=max_optimistic_testing, asymptomatic_prob=0.0) } }, 'historical': { 'name': 'Test a known number of positive cases', 'pars': { 'interventions': cv.test_historical(n_tests=[100] * npts, n_positive=[1] * npts) } }, 'sequence': { 'name': 'Historical switching to probability', 'pars': { 'interventions': cv.sequence(days=[10, 51], interventions=[ cv.test_historical(n_tests=[100] * npts, n_positive=[1] * npts), cv.test_prob(symptomatic_prob=0.2, asymptomatic_prob=0.002), ]) } }, } metapars = {'n_runs': n_runs} scens = cv.Scenarios(sim=base_sim, metapars=metapars, scenarios=scenarios) scens.run(verbose=verbose, debug=debug) if do_plot: scens.plot(do_save=do_save, do_show=do_show, fig_path=fig_path) return scens
def create_sim(x): beta = x[0] pop_infected = x[1] start_day = '2020-01-21' end_day = '2020-05-31' data_path = 'UK_Covid_cases_may21.xlsx' # Set the parameters total_pop = 67.86e6 # UK population size pop_size = 100e3 # Actual simulated population pop_scale = int(total_pop / pop_size) pop_type = 'hybrid' asymp_factor = 2 contacts = {'h': 3.0, 's': 20, 'w': 20, 'c': 20} pars = sc.objdict( 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, verbose=0.1, ) # Create the baseline simulation sim = cv.Sim(pars=pars, datafile=data_path, location='uk') sim['prognoses']['sus_ORs'][0] = 1.0 # ages 0-10 sim['prognoses']['sus_ORs'][1] = 1.0 # ages 10-20 beta_days = [ '2020-02-14', '2020-03-16', '2020-03-23', '2020-04-30', '2020-05-15', '2020-06-08' ] #June opening with society opening h_beta_changes = [1.00, 1.00, 1.29, 1.29, 1.29, 1.00] s_beta_changes = [1.00, 0.90, 0.02, 0.02, 0.02, 0.80] w_beta_changes = [0.90, 0.80, 0.20, 0.20, 0.20, 0.70] c_beta_changes = [0.90, 0.80, 0.20, 0.20, 0.20, 0.80] # Define the beta changes h_beta = cv.change_beta(days=beta_days, changes=h_beta_changes, layers='h') s_beta = cv.change_beta(days=beta_days, changes=s_beta_changes, layers='s') w_beta = cv.change_beta(days=beta_days, changes=w_beta_changes, layers='w') c_beta = cv.change_beta(days=beta_days, changes=c_beta_changes, layers='c') #next line to save the intervention interventions = [h_beta, w_beta, s_beta, c_beta] 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 # Tracing and enhanced testing strategy of symptimatics from 1st June #testing in June remains the same as before June under this scenario s_prob_march = 0.009 s_prob_april = 0.012 s_prob_may = 0.012 #no change in daily symptmatic probability in this scenario s_prob_june = 0.012 t_delay = 1.0 iso_vals = [{k: 0.1 for k in 'hswc'}] #tracing not on under this scenario t_eff_june = 0.0 t_probs_june = {k: t_eff_june for k in 'hwsc'} trace_d_1 = {'h': 0, 's': 1, 'w': 1, 'c': 2} #testing and isolation intervention interventions += [ cv.test_prob(symp_prob=s_prob_march, asymp_prob=0.0, symp_quar_prob=0.0, asymp_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, asymp_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.00075, symp_quar_prob=0.0, asymp_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.00075, symp_quar_prob=0.0, asymp_quar_prob=0.0, start_day=tti_day, test_delay=t_delay), cv.dynamic_pars({'iso_factor': { 'days': te_day, 'vals': iso_vals }}), cv.contact_tracing(trace_probs=t_probs_june, trace_time=trace_d_1, start_day=tti_day), ] sim.update_pars(interventions=interventions) for intervention in sim['interventions']: intervention.do_plot = False return sim
def make_sim(seed, beta, calibration=True, scenario=None, future_symp_test=None, future_t_eff=None, end_day=None, verbose=0): # Set the parameters total_pop = 67.86e6 # UK population size pop_size = 100e3 # Actual simulated population pop_scale = int(total_pop / pop_size) pop_type = 'hybrid' pop_infected = 1500 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 = '2020-12-31' pars = sc.objdict( 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_severe_prob = 0.4, #rel_crit_prob = 2.3, #rel_death_prob=1.5, ) sim = cv.Sim(pars=pars, datafile=data_path, location='uk') sim['prognoses']['sus_ORs'][0] = 1.0 # ages 0-10 sim['prognoses']['sus_ORs'][1] = 1.0 # ages 10-20 # ADD BETA INTERVENTIONS 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-04-30': [ 1.29, 0.02, 0.20, 0.20, ], '2020-05-15': [ 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-08-22': [ 1.29, 0.00, 0.30, 0.50, ] }) if not calibration: if scenario == 'masks15': sbv1, sbv2, wbv1, wbv2, cbv1, cbv2 = 0.765, 0.90, 0.595, 0.425, 0.765, 0.595 elif scenario == 'masks30': sbv1, sbv2, wbv1, wbv2, cbv1, cbv2 = 0.63, 0.90, 0.49, 0.35, 0.63, 0.49 elif scenario == 'masks15_notschools': sbv1, sbv2, wbv1, wbv2, cbv1, cbv2 = 0.90, 0.90, 0.595, 0.425, 0.765, 0.595 elif scenario == 'masks30_notschools': sbv1, sbv2, wbv1, wbv2, cbv1, cbv2 = 0.90, 0.90, 0.49, 0.35, 0.63, 0.49 beta_scens = sc.odict({ '2020-09-02': [1.25, sbv1, wbv1, cbv1], '2020-10-28': [1.25, 0.00, wbv2, cbv2], '2020-11-01': [1.25, sbv1, wbv1, cbv1], '2020-12-23': [1.25, 0.00, wbv2, cbv2], '2020-12-25': [1.50, 0.00, 0.20, 0.70], '2021-01-03': [1.25, sbv1, wbv1, cbv1], '2021-02-17': [1.25, 0.00, wbv2, cbv2], '2021-02-21': [1.25, sbv1, wbv1, cbv1], '2021-04-06': [1.25, 0.00, wbv2, cbv2], '2021-04-19': [1.25, sbv2, wbv1, cbv1] }) 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 a new change in beta to represent the takeover of the novel variant VOC 202012/01 # Assume that the new variant is 60% more transmisible (https://cmmid.github.io/topics/covid19/uk-novel-variant.html, # Assume that between August and Jan 30, the new variant grows from 0-100% of cases #voc_days = np.linspace(sim.day('2020-08-01'), sim.day('2021-01-30'), 31) #voc_prop = 0.6/(1+np.exp(-0.075*(voc_days-sim.day('2020-09-30')))) # Use a logistic growth function to approximate fig 2A of https://cmmid.github.io/topics/covid19/uk-novel-variant.html #voc_change = voc_prop*1.63 + (1-voc_prop)*1. #voc_beta = cv.change_beta(days=voc_days, # changes=voc_change) #interventions = [h_beta, w_beta, s_beta, c_beta, voc_beta] 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_vac = sim.day('2020-12-20') s_prob_april = 0.009 s_prob_may = 0.017 s_prob_june = 0.02769 s_prob_july = 0.02769 s_prob_august = 0.02769 s_prob_sep = 0.02769 if future_symp_test is None: future_symp_test = s_prob_sep t_delay = 1.0 #isolation may-july iso_vals = [{k: 0.7 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'}] #testing and isolation intervention interventions += [ cv.test_prob(symp_prob=0.0075, 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.00075, 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.00075, 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.00075, 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.00075, 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=future_symp_test, asymp_prob=0.00075, symp_quar_prob=0.0, start_day=tti_day_sep, test_delay=t_delay), 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='2020-06-01', quar_period=10), 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 }}) ] # Finally, update the parameters sim.update_pars(interventions=interventions) for intervention in sim['interventions']: intervention.do_plot = False sim.initialize() return sim
def test_all_interventions(): ''' Test all interventions supported by Covasim ''' pars = sc.objdict( pop_size=1e3, pop_infected=10, pop_type='hybrid', n_days=90, ) #%% Define the interventions # 1. Dynamic pars i1a = cv.test_prob(start_day=5, symp_prob=0.3) i1b = cv.dynamic_pars({ 'beta': { 'days': [40, 50], 'vals': [0.005, 0.015] }, 'rel_death_prob': { 'days': 30, 'vals': 2.0 } }) # Starting day 30, make diagnosed people stop transmitting # 2. Sequence i2 = cv.sequence(days=[15, 30, 45], interventions=[ cv.test_num(daily_tests=[20] * pars.n_days), cv.test_prob(symp_prob=0.0), cv.test_prob(symp_prob=0.2), ]) # 3. Change beta i3a = cv.change_beta([30, 50], [0.0, 1.0], layers='h') i3b = cv.change_beta([30, 40, 60], [0.0, 1.0, 0.5]) # 4. Clip edges -- should match the change_beta scenarios -- note that intervention i07 was removed i4a = cv.clip_edges([30, 50], [0.0, 1.0], layers='h') i4b = cv.clip_edges([30, 40, 60], [0.0, 1.0, 0.5]) # 5. Test number i5 = cv.test_num(daily_tests=[100, 100, 100, 0, 0, 0] * (pars.n_days // 6)) # 6. Test probability i6 = cv.test_prob(symp_prob=0.1) # 7. Contact tracing i7a = cv.test_prob(start_day=20, symp_prob=0.01, asymp_prob=0.0, symp_quar_prob=1.0, asymp_quar_prob=1.0, test_delay=0) i7b = cv.contact_tracing(start_day=20, trace_probs=dict(h=0.9, s=0.7, w=0.7, c=0.3), trace_time=dict(h=0, s=1, w=1, c=3)) # 8. Combination i8a = cv.clip_edges(days=18, changes=0.0, layers='s') # Close schools i8b = cv.clip_edges(days=[20, 32, 45], changes=[0.7, 0.3, 0.9], layers=['w', 'c']) # Reduce work and community i8c = cv.test_prob(start_day=38, symp_prob=0.01, asymp_prob=0.0, symp_quar_prob=1.0, asymp_quar_prob=1.0, test_delay=2) # Start testing for TTQ i8d = cv.contact_tracing(start_day=40, trace_probs=dict(h=0.9, s=0.7, w=0.7, c=0.3), trace_time=dict(h=0, s=1, w=1, c=3)) # Start tracing for TTQ #%% Create and run the simulations sims = sc.objdict() sims.dynamic = cv.Sim(pars=pars, interventions=[i1a, i1b]) sims.sequence = cv.Sim(pars=pars, interventions=i2) sims.change_beta1 = cv.Sim(pars=pars, interventions=i3a) sims.clip_edges1 = cv.Sim( pars=pars, interventions=i4a) # Roughly equivalent to change_beta1 sims.change_beta2 = cv.Sim(pars=pars, interventions=i3b) sims.clip_edges2 = cv.Sim( pars=pars, interventions=i4b) # Roughly euivalent to change_beta2 sims.test_num = cv.Sim(pars=pars, interventions=i5) sims.test_prob = cv.Sim(pars=pars, interventions=i6) sims.tracing = cv.Sim(pars=pars, interventions=[i7a, i7b]) sims.combo = cv.Sim(pars=pars, interventions=[i8a, i8b, i8c, i8d]) for key, sim in sims.items(): sim.label = key sim.run(verbose=verbose) #%% Plotting if do_plot: for sim in sims.values(): print(f'Running {sim.label}...') sim.plot() fig = pl.gcf() fig.axes[0].set_title(f'Simulation: {sim.label}') return
def create_base_sim(): # Create a sim calibrated to the UK epidemic to date, including interventions in effect until May 31 start_day = '2020-02-01' end_day = '2020-07-31' # We're running the analysis steps, which means running til July 2021 # Set the parameters total_pop = 67.86e6 # UK population size pop_size = 100e3 # Actual simulated population pop_scale = int(total_pop / pop_size) pop_type = 'hybrid' pop_infected = 2000 beta = 0.0070 asymp_factor = 2.0 contacts = {'h': 3.0, 's': 20, 'w': 20, 'c': 20} pars = sc.objdict( 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, ) # Create the baseline simulation sim = cv.Sim(pars=pars, datafile=data_path, location='uk') # Create the distancing interventions that were in effect from the beginning of the epidemic until May 31 beta_days = [ '2020-02-14', '2020-03-16', '2020-03-23', '2020-04-30', '2020-05-15' ] h_beta_changes = [ 1.00, 1.00, 1.29, 1.29, 1.29 ] # Assume increase household transmission after schools closed s_beta_changes = [ 1.00, 0.90, 0.02, 0.02, 0.02, ] # Schools closed March 23 w_beta_changes = [ 0.90, 0.80, 0.20, 0.20, 0.20, ] # Workplace closures c_beta_changes = [0.90, 0.80, 0.20, 0.20, 0.20] # Reduce effective community contacts h_beta = cv.change_beta(days=beta_days, changes=h_beta_changes, layers='h') s_beta = cv.change_beta(days=beta_days, changes=s_beta_changes, layers='s') w_beta = cv.change_beta(days=beta_days, changes=w_beta_changes, layers='w') c_beta = cv.change_beta(days=beta_days, changes=c_beta_changes, layers='c') interventions = [h_beta, w_beta, s_beta, c_beta] # Create the testing interventions that were in place from the beginning of the epidemic until May 31 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 s_prob_march = 0.009 s_prob_april = 0.012 s_prob_may = 0.0139 t_delay = 1.0 iso_vals = [{k: 0.1 for k in 'hswc'}] interventions += [ cv.test_prob(symp_prob=s_prob_march, asymp_prob=0.0, symp_quar_prob=0.0, asymp_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, asymp_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.00075, symp_quar_prob=0.0, asymp_quar_prob=0.0, start_day=tt_day, end_day=tti_day - 1, test_delay=t_delay), cv.dynamic_pars({'iso_factor': { 'days': te_day, 'vals': iso_vals }}), ] sim.update_pars(interventions=interventions) for intervention in sim['interventions']: intervention.do_plot = False return sim
''' Demonstrate dynamic parameters ''' import covasim as cv # Define the dynamic parameters imports = cv.dynamic_pars(n_imports=dict(days=[15, 30], vals=[100, 0])) # Create, run, and plot the simulations sim1 = cv.Sim(label='Baseline') sim2 = cv.Sim(interventions=imports, label='With imported infections') msim = cv.MultiSim([sim1, sim2]) msim.run() msim.plot()
asymp_prob=0.0175, symp_quar_prob=0.0, asymp_quar_prob=0.0, start_day=tti_day_oct, end_day=tti_day_nov - 1, test_delay=t_delay, sensitivity=0.97), cv.test_prob(symp_prob=s_prob_nov, asymp_prob=0.0275, symp_quar_prob=0.0, asymp_quar_prob=0.0, start_day=tti_day_nov, test_delay=t_delay, sensitivity=0.97), cv.dynamic_pars({'iso_factor': { 'days': te_day, 'vals': iso_vals }}), cv.contact_tracing(trace_probs=t_probs_june, trace_time=trace_d_1, start_day=tti_day, end_day=tti_day_july - 1), cv.contact_tracing(trace_probs=t_probs_july, trace_time=trace_d_1, start_day=tti_day_july, end_day=tti_day_august - 1), cv.contact_tracing(trace_probs=t_probs_august, trace_time=trace_d_1, start_day=tti_day_august, end_day=tti_day_sep - 1), cv.contact_tracing(trace_probs=t_probs_sep, trace_time=trace_d_1,
def test_all_interventions(): ''' Test all interventions supported by Covasim ''' pars = sc.objdict( pop_size=1e3, pop_infected=10, pop_type='hybrid', n_days=90, ) #%% Define the interventions # 1. Dynamic pars i00 = cv.test_prob(start_day=5, symp_prob=0.3) i01 = cv.dynamic_pars({ 'beta': { 'days': [40, 50], 'vals': [0.005, 0.015] }, 'diag_factor': { 'days': 30, 'vals': 0.0 } }) # Starting day 30, make diagnosed people stop transmitting # 2. Sequence i02 = cv.sequence(days=[15, 30, 45], interventions=[ cv.test_num(daily_tests=[20] * pars.n_days), cv.test_prob(symp_prob=0.0), cv.test_prob(symp_prob=0.2), ]) # 3. Change beta i03 = cv.change_beta([30, 50], [0.0, 1], layers='h') i04 = cv.change_beta([30, 40, 60], [0.0, 1.0, 0.5]) # 4. Clip edges -- should match the change_beta scenarios i05 = cv.clip_edges(start_day=30, end_day=50, change={'h': 0.0}) i06 = cv.clip_edges(start_day=30, end_day=40, change=0.0) i07 = cv.clip_edges(start_day=60, end_day=None, change=0.5) # 5. Test number i08 = cv.test_num(daily_tests=[100, 100, 100, 0, 0, 0] * (pars.n_days // 6)) # 6. Test probability i09 = cv.test_prob(symp_prob=0.1) # 7. Contact tracing i10 = cv.test_prob(start_day=20, symp_prob=0.01, asymp_prob=0.0, symp_quar_prob=1.0, asymp_quar_prob=1.0, test_delay=0) i11 = cv.contact_tracing(start_day=20, trace_probs=dict(h=0.9, s=0.7, w=0.7, c=0.3), trace_time=dict(h=0, s=1, w=1, c=3)) # 8. Combination i12 = cv.clip_edges(start_day=18, change={'s': 0.0}) # Close schools i13 = cv.clip_edges(start_day=20, end_day=32, change={ 'w': 0.7, 'c': 0.7 }) # Reduce work and community i14 = cv.clip_edges(start_day=32, end_day=45, change={ 'w': 0.3, 'c': 0.3 }) # Reduce work and community more i15 = cv.clip_edges(start_day=45, end_day=None, change={ 'w': 0.9, 'c': 0.9 }) # Reopen work and community more i16 = cv.test_prob(start_day=38, symp_prob=0.01, asymp_prob=0.0, symp_quar_prob=1.0, asymp_quar_prob=1.0, test_delay=2) # Start testing for TTQ i17 = cv.contact_tracing(start_day=40, trace_probs=dict(h=0.9, s=0.7, w=0.7, c=0.3), trace_time=dict(h=0, s=1, w=1, c=3)) # Start tracing for TTQ #%% Create and run the simulations sims = sc.objdict() sims.dynamic = cv.Sim(pars=pars, interventions=[i00, i01]) sims.sequence = cv.Sim(pars=pars, interventions=i02) sims.change_beta1 = cv.Sim(pars=pars, interventions=i03) sims.clip_edges1 = cv.Sim( pars=pars, interventions=i05) # Roughly equivalent to change_beta1 sims.change_beta2 = cv.Sim(pars=pars, interventions=i04) sims.clip_edges2 = cv.Sim( pars=pars, interventions=[i06, i07]) # Roughly euivalent to change_beta2 sims.test_num = cv.Sim(pars=pars, interventions=i08) sims.test_prob = cv.Sim(pars=pars, interventions=i09) sims.tracing = cv.Sim(pars=pars, interventions=[i10, i11]) sims.combo = cv.Sim(pars=pars, interventions=[i12, i13, i14, i15, i16, i17]) for key, sim in sims.items(): sim.label = key sim.run(verbose=verbose) #%% Plotting if do_plot: for sim in sims.values(): print(f'Running {sim.label}...') sim.plot() fig = pl.gcf() fig.axes[0].set_title(f'Simulation: {sim.label}') return
def create_sim(beta,n0,rd1,rd2,rd3,seed): beta = beta pop_infected = n0 # initial cases of infection start_day = '2020-02-01' end_day = '2020-11-30' data_file = df # Set the parameters total_pop = 5.8e6 # Denmark population size pop_size = 100e3 # Actual simulated population pop_scale = int(total_pop/pop_size) pop_type = 'hybrid' asymp_factor = 2 pars = sc.objdict( 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, rescale = True, verbose = 0.1, rand_seed = seed, ) # Create the baseline simulation sim = cv.Sim(pars=pars, datafile=data_file, location='denmark') relative_death = cv.dynamic_pars(rel_death_prob=dict(days=[1,130,230], vals=[rd1,rd2,rd3])) interventions = [relative_death] ### beta changes ### beta_days = ['2020-03-15','2020-04-15','2020-05-10','2020-06-22','2020-07-20','2020-08-22','2020-09-01','2020-09-22','2020-10-01','2020-10-15','2020-11-01', '2020-11-20'] h_beta_changes = [1.10, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.10, 1.10, 1.10, 1.20] s_beta_changes = [0.80, 0.50, 0.50, 0.40, 0.60, 0.60, 1.00, 0.80, 0.80, 1.00, 0.80, 0.90] w_beta_changes = [0.80, 0.50, 0.50, 0.40, 0.60, 0.60, 1.00, 0.80, 0.80, 1.00, 0.80, 0.90] c_beta_changes = [0.90, 0.60, 0.50, 0.70, 0.90, 0.80, 1.00, 0.70, 0.70, 1.00, 0.80, 1.10] # Define the beta changes h_beta = cv.change_beta(days=beta_days, changes=h_beta_changes, layers='h') s_beta = cv.change_beta(days=beta_days, changes=s_beta_changes, layers='s') w_beta = cv.change_beta(days=beta_days, changes=w_beta_changes, layers='w') c_beta = cv.change_beta(days=beta_days, changes=c_beta_changes, layers='c') ### edge clipping ### clip_days = ['2020-03-15','2020-04-15','2020-05-10','2020-06-08','2020-06-22','2020-08-17','2020-09-01','2020-09-15','2020-10-05', '2020-11-05','2020-11-20','2020-12-07','2020-12-19','2020-12-25'] s_clip_changes = [0.01, 0.20, 0.40, 0.70, 0.05, 0.10, 0.90, 0.80, 0.70, 0.70, 0.70, 0.60, 0.15, 0.05] w_clip_changes = [0.10, 0.30, 0.50, 0.70, 0.60, 0.80, 1.00, 0.80, 0.70, 0.70, 0.70, 0.70, 0.70, 0.10] c_clip_changes = [0.20, 0.40, 0.60, 0.85, 1.00, 1.00, 1.00, 0.80, 0.80, 0.90, 0.90, 0.90, 1.00, 0.30] # Define the edge clipping s_clip = cv.clip_edges(days=clip_days, changes=s_clip_changes, layers='s') w_clip = cv.clip_edges(days=clip_days, changes=w_clip_changes, layers='w') c_clip = cv.clip_edges(days=clip_days, changes=c_clip_changes, layers='c') interventions += [h_beta, w_beta, s_beta, c_beta, w_clip, s_clip, c_clip] # import infections from 2020-02-20 to 2020-03-01 imports1 = cv.dynamic_pars(n_imports=dict(days=[25, 35], vals=[2,0])) imports2 = cv.dynamic_pars(n_imports=dict(days=[171, 190], vals=[2,0])) interventions += [imports1,imports2] iso_vals = [{'h': 0.5, 's': 0.05, 'w': 0.05, 'c': 0.1}] #dict(h=0.5, s=0.05, w=0.05, c=0.1) interventions += [cv.dynamic_pars({'iso_factor': {'days': sim.day('2020-03-15'), 'vals': iso_vals }})] # From May 12, starting tracing and isolation strategy tracing_prob = dict(h=1.0, s=0.5, w=0.5, c=0.2) trace_time = {'h':0, 's':1, 'w':1, 'c':2} interventions += [cv.contact_tracing(trace_probs=tracing_prob, trace_time=trace_time, start_day='2020-05-12')] interventions += [cv.test_num(daily_tests=sim.data['new_tests'], start_day=0, end_day=sim.day(end_day), test_delay=1, symp_test=50, sensitivity=0.97,subtarget= prior_test)] sim.update_pars(interventions=interventions) for intervention in sim['interventions']: intervention.do_plot = False sim.initialize() 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) # 30% of 70+ years olds will not agree to get 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, prob=0.1, subtarget=subtarget_75_100, days=np.arange(sim.day('2020-12-20'), sim.day('2021-10-30'))) ] 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) # 5% of 70+ years olds will not agree to get 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, prob=0.1, subtarget=subtarget_60_75, days=np.arange(sim.day('2021-01-28'), sim.day('2021-10-30'))) ] 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.25, inds ) # 20% of 50-60 years olds will not agree to get 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, prob=0.1, subtarget=subtarget_50_60, days=np.arange(sim.day('2021-02-10'), sim.day('2021-10-30'))) ] #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) # 30% of 40-50 years olds will not agree to get 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.25, inds ) # 30% of 40-50 years olds will not agree to get 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, prob=0.1, subtarget=subtarget_45_50, days=np.arange(sim.day('2021-03-20'), sim.day('2021-10-30'))) ] 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.25, inds ) # 30% of 40-50 years olds will not agree to get 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, prob=0.1, subtarget=subtarget_40_45, days=np.arange(sim.day('2021-04-10'), sim.day('2021-10-30'))) ] 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.4, inds ) # 30% of 30-40+ years olds will not agree to get 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, prob=0.1, subtarget=subtarget_30_40, days=np.arange(sim.day('2021-05-10'), sim.day('2021-10-30'))) ] 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.4, inds) # 30% of 18+ years olds will not agree to get 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, prob=0.1, subtarget=subtarget_25_30, days=np.arange(sim.day('2021-06-10'), sim.day('2021-10-30'))) ] 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.4, inds) # 30% of 18+ years olds will not agree to get 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, prob=0.1, subtarget=subtarget_18_25, days=np.arange(sim.day('2021-06-20'), sim.day('2021-10-30'))) ] def subtarget_12_17(sim): inds = cv.true((sim.people.age >= 12) & (sim.people.age < 17)) if not hasattr(sim, 'subtarget_12_17'): sim.subtarget_18_25 = cv.binomial_filter( 0.3, inds) # 30% of 18+ years olds will not agree to get vaccinated inds = np.setdiff1d(inds, sim.subtarget_12_17) return {'inds': inds, 'vals': 0.002 * np.ones(len(inds))} interventions += [ cv.vaccinate(vaccine=pfizer_vaccine, prob=0.1, subtarget=subtarget_18_25, days=np.arange(sim.day('2021-07-20'), sim.day('2021-10-30'))) ] 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
'interventions': None, } }, 'distance': { 'name': 'Social distancing', 'pars': { 'interventions': cv.change_beta(days=interv_day, changes=interv_eff) } }, 'distance2': { # With noise = 0.0, this should be identical to the above 'name': 'Social distancing, version 2', 'pars': { 'interventions': cv.dynamic_pars({ 'beta': dict(days=interv_day, vals=interv_eff * default_beta) }) } }, } if __name__ == "__main__": # Required for parallel processing on Windows sc.tic() # If we're rerunning... if do_run: scens = cv.Scenarios(basepars=basepars, metapars=metapars, scenarios=scenarios) scens.run(verbose=verbose)
def make_sim(seed, beta, calibration=True, scenario=None, future_symp_test=None, future_t_eff=None, end_day=None, verbose=0): # Set the parameters total_pop = 67.86e6 # UK population size pop_size = 100e3 # Actual simulated population pop_scale = int(total_pop / pop_size) pop_type = 'hybrid' pop_infected = 1500 beta = beta asymp_factor = 2 contacts = {'h': 3.0, 's': 20, 'w': 20, 'c': 20} if end_day is None: end_day = '2021-03-31' pars = sc.objdict( 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] = 1.0 # ages 20-30 sim['prognoses']['sus_ORs'][1] = 1.0 # ages 20-30 # ADD BETA INTERVENTIONS 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-04-30': [ 1.29, 0.02, 0.20, 0.20, ], '2020-05-15': [ 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.425, 0.49, ], }) if not calibration: if scenario == 'masks15': sbv1, sbv2, wbv1, wbv2, cbv1, cbv2 = 0.765, 1.00, 0.595, 0.425, 0.765, 0.595 elif scenario == 'masks30': sbv1, sbv2, wbv1, wbv2, cbv1, cbv2 = 0.63, 0.70, 0.49, 0.35, 0.63, 0.49 elif scenario == 'masks15_notschools': sbv1, sbv2, wbv1, wbv2, cbv1, cbv2 = 0.90, 0.90, 0.595, 0.425, 0.765, 0.595 elif scenario == 'masks30_notschools': sbv1, sbv2, wbv1, wbv2, cbv1, cbv2 = 0.90, 0.70, 0.49, 0.35, 0.63, 0.49 beta_scens = sc.odict({ '2020-09-02': [1.00, sbv1, wbv1, cbv1], '2020-10-28': [1.00, 0.00, wbv2, cbv2], '2020-11-01': [1.00, sbv1, wbv1, cbv1], '2020-12-23': [1.00, 0.00, wbv2, cbv2], '2021-01-03': [1.00, sbv1, wbv1, cbv1], '2021-02-17': [1.00, 0.00, wbv2, cbv2], '2021-02-21': [1.00, sbv1, wbv1, cbv1], '2021-04-06': [1.00, 0.00, wbv2, cbv2], '2021-04-17': [1.00, sbv2, wbv1, cbv1] }) 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') 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' ) #intervention of tracing and enhanced testing (tti) at different levels starts on 1st August s_prob_april = 0.008 s_prob_may = 0.03 s_prob_june = 0.02 s_prob_july = 0.02 s_prob_august = 0.02 if future_symp_test is None: future_symp_test = s_prob_august t_delay = 1.0 iso_vals = [{k: 0.1 for k in 'hswc'}] #tracing level at 42.35% in June; 47.22% in July t_eff_june = 0.42 t_eff_july = 0.47 if future_t_eff is None: future_t_eff = t_eff_july t_probs_june = {k: t_eff_june for k in 'hwsc'} t_probs_july = {k: t_eff_july for k in 'hwsc'} future_t_probs = {k: future_t_eff for k in 'hwsc'} trace_d_1 = {'h': 0, 's': 1, 'w': 1, 'c': 2} #testing and isolation intervention interventions += [ cv.test_prob(symp_prob=0.0075, 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.00075, 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.00075, 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.00075, 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.00075, 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=future_symp_test, asymp_prob=0.00075, symp_quar_prob=0.0, start_day=tti_day_sep, test_delay=t_delay), cv.dynamic_pars({'iso_factor': { 'days': te_day, 'vals': iso_vals }}), cv.contact_tracing(trace_probs=t_probs_june, trace_time=trace_d_1, start_day=tti_day, end_day=tti_day_july - 1), cv.contact_tracing(trace_probs=t_probs_july, trace_time=trace_d_1, start_day=tti_day_july, end_day=tti_day_sep - 1), cv.contact_tracing(trace_probs=future_t_probs, trace_time=trace_d_1, start_day=tti_day_sep), ] # Finally, update the parameters sim.update_pars(interventions=interventions) for intervention in sim['interventions']: intervention.do_plot = False sim.initialize() return sim