def test_age_hist(): sc.heading('Testing age histogram') day_list = ["2020-03-20", "2020-04-20"] age_analyzer = cv.age_histogram(days=day_list) sim = cv.Sim(pars, analyzers=age_analyzer) sim.run() # Checks to see that compute windows returns correct number of results sim.make_age_histogram() # Show post-hoc example agehist = sim.get_analyzer() agehist.compute_windows() agehist.get() # Not used, but check get agehist.get(day_list[1]) assert len(age_analyzer.window_hists) == len( day_list), "Number of histograms should equal number of days" # Check plot() if do_plot: plots = agehist.plot(windows=True) assert len(plots) == len( day_list), "Number of plots generated should equal number of days" # Check daily age histogram daily_age = cv.daily_age_stats() sim = cv.Sim(pars, analyzers=daily_age) sim.run() return agehist
def test_age_hist(): sc.heading('Testing age histogram') day_list = ["2020-03-20", "2020-04-20"] age_analyzer = cv.age_histogram(days=day_list) sim = cv.Sim(pars, analyzers=age_analyzer) sim.run() # Checks to see that compute windows returns correct number of results agehist = sim['analyzers'][0] agehist.compute_windows() assert len(age_analyzer.window_hists) == len(day_list), "Number of histograms should equal number of days" # checks compute_windows and plot() plots = agehist.plot(windows=True) assert len(plots) == len(day_list), "Number of plots generated should equal number of days" return agehist
def create_sim(pars=None, use_safegraph=True, label=None, show_intervs=False): ''' Create a single simulation for further use ''' p = sc.objdict( sc.mergedicts(define_pars(which='best', use_safegraph=use_safegraph), pars)) if 'rand_seed' not in p: seed = 1 print(f'Note, could not find random seed in {pars}! Setting to {seed}') p['rand_seed'] = seed # Ensure this exists # Basic parameters and sim creation pars = { 'pop_size': 225e3, 'pop_scale': 10, 'pop_type': 'synthpops', 'pop_infected': 300, 'beta': p.beta, 'start_day': '2020-01-27', 'end_day': '2020-06-08', 'rescale': True, 'rescale_factor': 1.1, 'verbose': p.get('verbose', 0.01), 'rand_seed': int(p.rand_seed), 'analyzers': cv.age_histogram(datafile=age_data_file), 'beta_layer': dict(h=3.0, s=0.6, w=0.6, c=0.3, l=1.5), } # Create and initialize the sim if pars['verbose']: print(f'Creating sim! safegraph={use_safegraph}, seed={p.rand_seed}') sim = cv.Sim(pars, label=label, popfile=get_popfile(pars), load_pop=True, datafile=epi_data_file ) # Create this here so can be used for test numbers etc. # Define testing interventions -- 97% sensitivity from https://www.ncbi.nlm.nih.gov/pmc/articles/PMC7177629/ test_kwargs = dict(daily_tests=sim.data['new_tests'], test_delay=2, sensitivity=0.97, subtarget=test_num_subtarg) tn = cv.test_num(symp_test=p.tn, start_day='2020-01-27', end_day=None, **test_kwargs, label='tn') interventions = [tn] # Define beta interventions sim.intervention_info = sc.objdict() hwc_days = ['2020-02-24', '2020-03-23', '2020-05-31'] # Change date here, 04-27 or 05-04 hwc_days = sim.day(hwc_days) b_wc_ch = [1.0, p.bc_wc1, p.get('bc_wc2', p.bc_wc1) ] # To allow either one or two beta change parameters b_h_ch = [1.0, 1.1, 1.1] # Optional household all_b_days = np.arange(hwc_days[0], hwc_days[-1] + 1) # Full time series all_ch_wc = np.interp(all_b_days, hwc_days, b_wc_ch) # Linearly interpolate all_ch_h = np.interp(all_b_days, hwc_days, b_h_ch) # Linearly interpolate interventions += [ cv.change_beta(days=all_b_days, changes=all_ch_h, layers='h', label='beta_h') ] lkeys = ['w', 'c', 's'] if use_safegraph else [ 'w', 'c' ] # Skip schools if not using SafeGraph for lkey in lkeys: # Assume schools also use masks, etc. so have same non-movement beta change cb = cv.change_beta(days=all_b_days, changes=all_ch_wc, layers=lkey, label=f'beta_{lkey}') interventions += [cb] sim.intervention_info.bc = sc.objdict({ 'days': all_b_days, 'changes': all_ch_wc }) # Store for plotting later # LTCF beta change b_l_days = ['2020-02-24', '2020-03-23'] b_l_days = np.arange(sim.day(b_l_days[0]), sim.day(b_l_days[1])) b_l_ch = np.linspace(1.0, p.bc_lf, len(b_l_days)) interventions += [ cv.change_beta(days=b_l_days, changes=b_l_ch, layers='l', label='beta_l') ] sim.people.contacts['c'] = remove_ltcf_community( sim) # Remove community contacts from LTCF # SafeGraph intervention & tidy up if use_safegraph: interventions += make_safegraph(sim) else: interventions += [ cv.clip_edges(days='2020-03-12', changes=0.1, layers='s', label='clip_s') ] sim['interventions'] = interventions # Don't show interventions in plots, there are too many for interv in sim['interventions']: interv.do_plot = False # These are copied from parameters.py -- modified to capture change in work status at age 65 sim['prognoses']['age_cutoffs'] = np.array( [0, 10, 20, 30, 40, 50, 65, 70, 80, 90]) # Age cutoffs (upper limits) return sim
def create_sim(pars=None, label=None, use_safegraph=True, show_intervs=False, people=None): ''' Create a single simulation for further use ''' p = sc.objdict( sc.mergedicts( define_pars(which='best', kind='both', use_safegraph=use_safegraph), pars)) if 'rand_seed' not in p: seed = 1 print(f'Note, could not find random seed in {pars}! Setting to {seed}') p['rand_seed'] = seed # Ensure this exists if 'end_day' not in p: end_day = '2020-07-19' p['end_day'] = end_day # Basic parameters and sim creation pars = { 'pop_size': 225e3, 'pop_scale': 10, 'pop_type': 'synthpops', 'pop_infected': 400, 'beta': p.beta, 'start_day': '2020-01-27', 'end_day': '2020-07-19', 'rescale': True, 'rescale_factor': 1.1, 'verbose': 0, 'rand_seed': p.rand_seed, 'analyzers': cv.age_histogram(datafile=age_data_file), 'beta_layer': dict(h=p.bl_h, s=p.bl_s, w=p.bl_w, c=p.bl_c, l=p.bl_l), } pars.update({'n_days': cv.daydiff(pars['start_day'], pars['end_day'])}) # If supplied, use an existing people object if people: popfile = people else: # Generate the population filename n_popfiles = 5 popfile = popfile_stem + str(pars['rand_seed'] % n_popfiles) + '.ppl' # Check that the population file exists if not os.path.exists(popfile): errormsg = f'WARNING: could not find population file {popfile}! Please regenerate first' raise FileNotFoundError(errormsg) # Create and initialize the sim sim = cv.Sim(pars, label=label, popfile=popfile, load_pop=True, datafile=epi_data_file ) # Create this here so can be used for test numbers etc. # Define testing interventions test_kwargs = dict(daily_tests=sim.data['new_tests'], quar_test=1.0, test_delay=2) tn1 = cv.test_num(symp_test=p.tn1, start_day='2020-01-27', end_day='2020-03-23', **test_kwargs, label='tn1') tn2 = cv.test_num(symp_test=p.tn2, start_day='2020-03-24', end_day='2020-04-14', **test_kwargs, label='tn2') tn3 = cv.test_num(symp_test=p.tn3, start_day='2020-04-15', end_day=None, **test_kwargs, label='tn3') interventions = [tn1, tn2, tn3] # Define beta interventions (for calibration) b_ch = sc.objdict() b_days = ['2020-03-04', '2020-03-12', '2020-04-25'] b_ch.s = [1.00, 0.00, 0.00] b_ch.w = [p.bc_wc1, p.bc_wc2, p.bc_wc3] b_ch.c = [p.bc_wc1, p.bc_wc2, p.bc_wc3] for lkey, ch in b_ch.items(): interventions += [ cv.change_beta(days=b_days, changes=b_ch[lkey], layers=lkey, label=f'beta_{lkey}') ] # LTCF intervention b_days_l = np.arange(sim.day(b_days[0]), sim.day(b_days[2]) + 1) b_ch_l = np.linspace(1.0, p.bc_lf, len(b_days_l)) interventions += [ cv.change_beta(days=b_days_l, changes=b_ch_l, layers='l', label=f'beta_l') ] # SafeGraph intervention & tidy up interventions += make_safegraph(sim) sim['interventions'] = interventions # Don't show interventions in plots, there are too many if show_intervs == False: for interv in sim['interventions']: interv.do_plot = False # These are copied from parameters.py -- needed to get younger and 60-65 groups right sim['prognoses']['age_cutoffs'] = np.array( [0, 15, 20, 30, 40, 50, 65, 70, 80, 90]) # Age cutoffs (upper limits) return sim
def create_sim(pars=None, label=None, use_safegraph=True, show_intervs=False, people=None, school_reopening_pars=None, teacher_test_scen=None): ''' Create a single simulation for further use ''' p = sc.objdict( sc.mergedicts( define_pars(which='best', kind='both', use_safegraph=use_safegraph), pars)) if 'rand_seed' not in p: seed = 1 print(f'Note, could not find random seed in {pars}! Setting to {seed}') p['rand_seed'] = seed # Ensure this exists if 'end_day' not in p: end_day = '2020-05-30' p['end_day'] = end_day # Basic parameters and sim creation pars = { 'pop_size': 225e3, 'pop_scale': 10, 'pop_type': 'synthpops', 'pop_infected': 400, 'beta': p.beta, 'start_day': '2020-01-27', 'end_day': p['end_day'], 'rescale': True, 'rescale_factor': 1.1, 'verbose': 0.1, 'rand_seed': p.rand_seed, # 'analyzers' : cv.age_histogram(datafile=age_data_file), 'beta_layer': dict(h=p.bl_h, s=p.bl_s, w=p.bl_w, c=p.bl_c, l=p.bl_l), } pars.update({'n_days': cv.daydiff(pars['start_day'], pars['end_day'])}) # If supplied, use an existing people object if people: popfile = people else: # Generate the population filename n_popfiles = 5 popfile = popfile_stem + str(pars['rand_seed'] % n_popfiles) + '.ppl' popfile_change = popfile_stem_change + str( pars['rand_seed'] % n_popfiles) + '.ppl' # Check that the population file exists if not os.path.exists(popfile): errormsg = f'WARNING: could not find population file {popfile}! Please regenerate first' raise FileNotFoundError(errormsg) # Create and initialize the sim sim = cv.Sim(pars, label=label, popfile=popfile, load_pop=True, datafile=epi_data_file ) # Create this here so can be used for test numbers etc. # Define testing interventions test_kwargs = dict(daily_tests=sim.data['new_tests'], quar_test=1.0, test_delay=2) tn1 = cv.test_num(symp_test=p.tn1, start_day='2020-01-27', end_day='2020-03-23', **test_kwargs, label='tn1') tn2 = cv.test_num(symp_test=p.tn2, start_day='2020-03-24', end_day='2020-04-14', **test_kwargs, label='tn2') tn3 = cv.test_num(symp_test=p.tn3, start_day='2020-04-15', end_day=None, **test_kwargs, label='tn3') interventions = [tn1, tn2, tn3] ttq_scen = school_reopening_pars['ttq_scen'] if ttq_scen == 'lower': tp = sc.objdict( symp_prob=0.08, asymp_prob=0.001, symp_quar_prob=0.8, asymp_quar_prob=0.1, test_delay=2.0, ) ct = sc.objdict( trace_probs=0.01, trace_time=3.0, ) elif ttq_scen == 'medium': tp = sc.objdict( symp_prob=0.12, asymp_prob=0.0015, symp_quar_prob=0.8, asymp_quar_prob=0.1, test_delay=2.0, ) ct = sc.objdict( trace_probs=0.25, trace_time=3.0, ) elif ttq_scen == 'upper': tp = sc.objdict( symp_prob=0.24, asymp_prob=0.003, symp_quar_prob=0.8, asymp_quar_prob=0.1, test_delay=2.0, ) ct = sc.objdict( trace_probs=0.5, trace_time=3.0, ) if ttq_scen is not None: interventions += [ cv.test_prob(start_day='2020-06-10', **tp), cv.contact_tracing(start_day='2020-06-10', **ct) ] # Define beta interventions (for school reopening) b_ch = sc.objdict() b_days = [ '2020-03-04', '2020-03-12', '2020-03-23', '2020-04-25', '2020-08-30' ] b_ch.w = [1.00, p.bc_wc1, p.bc_wc2, p.bc_wc3, p.bc_wc3] b_ch.c = [1.00, p.bc_wc1, p.bc_wc2, p.bc_wc3, p.bc_wc3] NPI_schools = school_reopening_pars['NPI_schools'] if NPI_schools is None: b_ch.s = [1.00, 1.00, 1.00, 1.00, 1.00] else: b_ch.s = [1.00, 1.00, 1.00, 1.00, NPI_schools] # LTCF intervention b_days_l = np.arange(sim.day(b_days[0]), sim.day(b_days[2]) + 1) b_ch_l = np.linspace(1.0, p.bc_lf, len(b_days_l)) interventions += [ cv.change_beta(days=b_days_l, changes=b_ch_l, layers='l', label=f'beta_l') ] for lkey, ch in b_ch.items(): interventions += [ cv.change_beta(days=b_days, changes=b_ch[lkey], layers=lkey, label=f'beta_{lkey}') ] # Define school closure interventions network_change = school_reopening_pars['network_change'] if network_change: popfile_new = popfile_change else: popfile_new = None school_start_day = school_reopening_pars['school_start_day'] intervention_start_day = school_reopening_pars['intervention_start_day'] num_pos = None test_prob = teacher_test_scen['test_prob'] trace_prob = teacher_test_scen['trace_prob'] mobility_file = school_reopening_pars['mobility_file'] interventions += [ cv.close_schools(day_schools_closed='2020-03-12', start_day=school_start_day, pop_file=popfile_new, label='close_schools') ] test_freq = teacher_test_scen['test_freq'] interventions += [ cv.reopen_schools(start_day=intervention_start_day, num_pos=num_pos, test=test_prob, trace=trace_prob, ili_prev=0.002, test_freq=test_freq) ] # SafeGraph intervention interventions += make_safegraph(sim, mobility_file) sim['interventions'] = interventions analyzers = [cv.age_histogram(datafile=age_data_file)] sim['analyzers'] += analyzers # Don't show interventions in plots, there are too many if show_intervs == False: for interv in sim['interventions']: interv.do_plot = False # These are copied from parameters.py -- needed to get younger and 60-65 groups right sim['prognoses']['age_cutoffs'] = np.array( [0, 15, 20, 30, 40, 50, 65, 70, 80, 90]) # Age cutoffs (upper limits) return sim
''' Demonstrate simple analyzer usage ''' import covasim as cv # Age histograms sim = cv.Sim(interventions=cv.test_prob(0.5), analyzers=cv.age_histogram()) sim.run() agehist = sim.get_analyzer( ) # Only one analyzer so we can retrieve it like this agehist.plot() # Transmission trees tt = sim.make_transtree() fig1 = tt.plot() fig2 = tt.plot_histograms() # A custom analyzer def check_88(sim): people_who_are_88 = sim.people.age.round( ) == 88 # Find everyone who's aged 88 (to the nearest year) people_exposed = sim.people.exposed # Find everyone who's infected with COVID people_who_are_88_with_covid = cv.true( people_who_are_88 * people_exposed) # Multiplication is the same as logical "and" n = len(people_who_are_88_with_covid) # Count how many people there are if n: print( f'Oh no! {n} people aged 88 have covid on timestep {sim.t} {"🤯"*n}'
# # vaccinating 50-65 years old # interventions += [utils.two_dose_daily_delayed(300e3, start_day=tti_day_vac2, dose_delay=21, delay=12*7, # take_prob=1.0, rel_symp=0.05, # rel_trans=0.5, cumulative=[0.7, 1.0], dose_priority=[1, 0.1], # priority_days=[tti_day_vac2, tti_day_vac3], age_priority=[50,40])] #vaccinating 18-50 years old #interventions += [utils.two_dose_daily_delayed(300e3, start_day=tti_day_vac3, dose_delay=21, delay=7*7, # take_prob=1.0, rel_symp=0.05, # rel_trans=0.5, cumulative=[0.7, 1.0], dose_priority=[1, 0.1], # priority_days=[tti_day_vac3, tti_day_vac4], age_priority=[50,18])] analyzers = [] analyzers += [utils.record_dose_flows(vacc_class=utils.two_dose_daily_delayed)] 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
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} 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, rel_severe_prob=0.4, rel_crit_prob=2.3, analyzers=[ cv.age_histogram(datafile='uk_deaths_by_age.xlsx', edges=np.concatenate([ np.linspace(0, 90, 19), np.array([100]) ])) ] #rel_death_prob=1.5, ) 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.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] }) 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 == 'FNL': beta_s_feb22, beta_s_mar01, beta_s_mar08, beta_s_mar15, beta_s_mar22, beta_s_mar29, beta_s_apr01 = 0.14, 0.14, 0.14, 0.14, 0.14, 0.14, 0.02 ##primaries and yars 11 and 13 back on 22/02 all other years 01/03 ##9/14 years back -30% transmission reduction = 45% reduction remaining from 22/02 ##transmision increases to 63% remaining from 01/03 ##Easter holiday 01/04-08/04 elif scenario == 'staggeredPNL': beta_s_feb22, beta_s_mar01, beta_s_mar08, beta_s_mar15, beta_s_mar22, beta_s_mar29, beta_s_apr01 = 0.14, 0.14, 0.40, sbv, sbv, sbv, 0.02, ##primaries and secondaries back fully 22/02; 14/14 years but assume 90% attendence and ##30% reduction in transmission due to hygiene, masks etc to remaining transmision to 0.63 ##Easter holiday 01/04-08/04 elif scenario == 'fullPNL': beta_s_feb22, beta_s_mar01, beta_s_mar08, beta_s_mar15, beta_s_mar22, beta_s_mar29, beta_s_apr01 = 0.14, 0.14, sbv, sbv, sbv, sbv, 0.02 elif scenario == 'primaryPNL': beta_s_feb22, beta_s_mar01, beta_s_mar08, beta_s_mar15, beta_s_mar22, beta_s_mar29, beta_s_apr01 = 0.14, 0.14, 0.31, 0.31, 0.40, 0.40, 0.02 elif scenario == 'rotasecondaryPNL': beta_s_feb22, beta_s_mar01, beta_s_mar08, beta_s_mar15, beta_s_mar22, beta_s_mar29, beta_s_apr01 = 0.14, 0.14, 0.31, 0.31, sbv, sbv, 0.02 beta_scens = sc.odict({ '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, beta_s_feb22, 0.30, 0.40], '2021-03-01': [1.25, beta_s_mar01, 0.30, 0.40], '2021-03-08': [1.25, beta_s_mar08, 0.30, 0.50], '2021-03-15': [1.25, beta_s_mar15, 0.30, 0.50], '2021-03-22': [1.25, beta_s_mar22, 0.30, 0.50], '2021-03-29': [1.25, beta_s_mar29, 0.30, 0.50], '2021-04-01': [1.25, beta_s_apr01, 0.30, 0.50], '2021-04-12': [1.25, 0.02, 0.30, 0.50], '2021-04-19': [1.25, sbv, 0.50, 0.70], '2021-04-26': [1.25, sbv, 0.50, 0.70], '2021-05-03': [1.25, sbv, 0.50, 0.70] }) 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-01-30'), 31) voc_prop = 0.62 / ( 1 + np.exp(-0.069 * (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_vac = sim.day('2020-12-20') 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_sept = 0.08769 s_prob_oct = 0.08769 s_prob_nov = 0.08769 s_prob_may = 0.02769 s_prob_june = 0.02769 s_prob_july = 0.02769 s_prob_august = 0.03769 s_prob_sep = 0.08769 s_prob_oct = 0.08769 s_prob_nov = 0.08769 s_prob_dec = 0.08769 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.5 for k in 'hswc'}] #isolation october iso_vals3 = [{k: 0.5 for k in 'hswc'}] #isolation november iso_vals4 = [{k: 0.5 for k in 'hswc'}] #isolation december iso_vals5 = [{k: 0.5 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.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, 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 }}), 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(200e3, start_day=tti_day_vac, dose_delay=14, delay=7 * 7, take_prob=1.0, rel_symp=0.05, rel_trans=0.9, cumulative=[0.7, 1.0], dose_priority=[1, 0.1]) ] analyzers = sim['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
''' Confirm that with default settings, all analyzers can be exported as JSONs. ''' import sciris as sc import covasim as cv datafile = sc.thisdir(__file__, aspath=True).parent / 'example_data.csv' # Create and runt he sim sim = cv.Sim(analyzers=[ cv.snapshot(days='2020-04-04'), cv.age_histogram(), cv.daily_age_stats(), cv.daily_stats() ], datafile=datafile) sim.run() # Compute extra analyzers tt = sim.make_transtree() fit = sim.compute_fit() # Construct list of all analyzers analyzers = sim['analyzers'] + [tt, fit] # Make jsons jsons = {} for an in analyzers: print(f'Working on analyzer {an.label}...') jsons[an.label] = an.to_json()
''' Test the age-histogram analyzer. ''' import covasim as cv intervs = [ cv.change_beta(days=40, changes=0.5), cv.test_prob(start_day=20, symp_prob=0.1, asymp_prob=0.01) ] # Common interventions pars = dict( pop_size=20000, # Population size pop_infected= 100, # Number of initial infections -- use more for increased robustness pop_type= 'hybrid', # Population to use -- "hybrid" is random with household, school,and work structure verbose=0, # Don't print details of the run interventions=intervs # Include the most common interventions ) sim = cv.Sim(pars, analyzers=cv.age_histogram(datafile='example_age_data.csv')) sim.run() agehist = sim['analyzers'][0] hists = agehist.get() agehist.plot() sim = cv.Sim(pars, analyzers=cv.age_histogram(days=['2020-04-01', 'end'])) sim.run() agehist = sim['analyzers'][0] agehist.plot(windows=True)
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 create_sim(pars=None, use_safegraph=True, label=None, show_intervs=False, people=None, adjust_ORs=False, num_pos=None, test_prob=None, trace_prob=None, NPI_schools=None, test_freq=None, network_change=False, schedule=None, school_start_day=None, intervention_start_day=None, ttq_scen=None ): ''' Create a single simulation for further use ''' p = sc.objdict(sc.mergedicts(define_pars(which='best', kind='both', use_safegraph=use_safegraph), pars)) if 'rand_seed' not in p: seed = 1 print(f'Note, could not find random seed in {pars}! Setting to {seed}') p['rand_seed'] = seed # Ensure this exists # Basic parameters and sim creation pars = {'pop_size': 225e3, 'pop_scale': 10, 'pop_type': 'synthpops', 'pop_infected': p.pop_infected, 'beta': p.beta, 'start_day': '2020-02-01', 'end_day': p['end_day'], 'rescale': True, 'rescale_factor': 1.1, 'verbose': 0.1, 'rand_seed': p.rand_seed, 'analyzers': [cv.age_histogram(datafile=age_data_file, states=['exposed', 'dead', 'tested', 'diagnosed', 'severe'])], 'beta_layer': dict(h=p.bl_h, s=p.bl_s, w=p.bl_w, c=p.bl_c, l=p.bl_l), } # If supplied, use an existing people object if people: popfile = people else: # Generate the population filename n_popfiles = 5 popfile = popfile_stem + str(pars['rand_seed'] % n_popfiles) + '.ppl' popfile_change = popfile_stem_change + str(pars['rand_seed'] % n_popfiles) + '.ppl' # Check that the population file exists if not os.path.exists(popfile): errormsg = f'WARNING: could not find population file {popfile}! Please regenerate first' raise FileNotFoundError(errormsg) # Create and initialize the sim print(f'Creating sim! safegraph={use_safegraph}, seed={p.rand_seed}') sim = cv.Sim(pars, label=label, popfile=popfile, load_pop=True, datafile=epi_data_file) # Create this here so can be used for test numbers etc. interventions = [] # Testing bins df = pd.read_csv(age_series_file) age_bins = [0, 20, 40, 60, 80, np.inf] test_num_subtargs = [ftest_num_subtarg1, ftest_num_subtarg2, ftest_num_subtarg3, ftest_num_subtarg4, ftest_num_subtarg5] for ia in range(len(age_bins) - 1): label = '{}-{}'.format(age_bins[ia], age_bins[ia + 1] - 1) df_ = df[(df['age'] >= age_bins[ia]) & (df['age'] < age_bins[ia + 1])] # sum for the dates df_ = df_.groupby('date').sum() df_['age'] = age_bins[ia] df_['datetime'] = [sc.readdate(d) for d in df_.index.values] df_ = df_.set_index('datetime') # make sure we have all the days we care about new_index = pd.date_range(df_.index[0], df_.index[-1], freq='1d') df_ = df_.reindex(new_index, fill_value=0.0, method='nearest') test_kwargs = dict(daily_tests=df_['new_tests'], quar_test=1.0, test_delay=2, subtarget=test_num_subtargs[ia]) interventions += [cv.test_num(symp_test=p.tn1, start_day='2020-01-27', end_day='2020-03-23', **test_kwargs, label='tn1 ' + label)] interventions += [cv.test_num(symp_test=p.tn2, start_day='2020-03-24', end_day='2020-04-14', **test_kwargs, label='tn2 ' + label)] interventions += [cv.test_num(symp_test=p.tn3, start_day='2020-04-15', end_day='2020-05-07', **test_kwargs, label='tn3 ' + label)] interventions += [cv.test_num(symp_test=p.tn4, start_day='2020-05-08', end_day='2020-06-04', **test_kwargs, label='tn4 ' + label)] interventions += [cv.test_num(symp_test=p.tn5, start_day='2020-06-17', end_day='2020-06-18', **test_kwargs, label='tn5 ' + label)] interventions += [cv.test_num(symp_test=p.tn6, start_day='2020-06-19', end_day=None, **test_kwargs, label='tn6 ' + label)] # Seed in LTCF interventions += [seed_ltcf(days=[15], seeds=[p.lseeds])] # Define beta interventions b_days = ['2020-03-02', '2020-03-12', '2020-03-23', '2020-04-15', '2020-05-08', '2020-06-05', '2020-06-19' ] # Home and school beta changes interventions += [ cv.change_beta(days=b_days[1], changes=p.bc_s, layers='s', label="beta_s") ] # Work and community beta changes b_days_wc = np.arange(sim.day(b_days[0]), sim.day(b_days[1]) + 1).tolist() + b_days[2:] b_ch_wc = np.linspace(1.0, p.bc_wc1, len(b_days_wc) - 5).tolist() + [p.bc_wc2, p.bc_wc3, p.bc_wc4, p.bc_wc5, p.bc_wc6] for lkey in ['w', 'c']: interventions += [cv.change_beta(days=b_days_wc, changes=b_ch_wc, layers=lkey, label=f'beta_{lkey}')] # LTCF beta change b_days_l = np.arange(sim.day(b_days[0]), sim.day(b_days[2]) + 1) b_ch_l = np.linspace(1.0, p.bc_lf, len(b_days_l)) interventions += [cv.change_beta(days=b_days_l, changes=b_ch_l, layers='l', label='beta_l')] # sim.people.contacts['c'] = remove_ltcf_community(sim) # Remove community contacts from LTCF # Age-based beta changes b_age_days = ["2020-05-08", "2020-06-05", "2020-06-19"] b_age_changes = [[p.bc_age_u10_a, # 0 p.bc_age_10_20_a, # 10 p.bc_age_20_30_a, # 20 p.bc_age_30_40_a, # 30 1.0, # 40 1.0, # 50 p.bc_age_65u_a, # 65 p.bc_age_65u_a, # 70 p.bc_age_65u_a, # 80 p.bc_age_65u_a, # 90 ], [p.bc_age_u10_b, # 0 p.bc_age_10_20_b, # 10 p.bc_age_20_30_b, # 20 p.bc_age_30_40_b, # 30 1.0, # 40 1.0, # 50 p.bc_age_65u_b, # 65 p.bc_age_65u_b, # 70 p.bc_age_65u_b, # 80 p.bc_age_65u_b, # 90 ], [p.bc_age_u10_c, # 0 p.bc_age_10_20_c, # 10 p.bc_age_20_30_c, # 20 p.bc_age_30_40_c, # 30 1.0, # 40 1.0, # 50 p.bc_age_65u_c, # 65 p.bc_age_65u_c, # 70 p.bc_age_65u_c, # 80 p.bc_age_65u_c, # 90 ] ] interventions += [beta_change_age.change_beta_age(b_age_days, b_age_changes)] # SafeGraph intervention & tidy up if use_safegraph: interventions += make_safegraph(sim) if ttq_scen == 'lower': tp = sc.objdict( symp_prob=0.08, asymp_prob=0.001, symp_quar_prob=0.8, asymp_quar_prob=0.1, test_delay=2.0, ) ct = sc.objdict( trace_probs=0.01, trace_time=3.0, ) elif ttq_scen == 'medium': tp = sc.objdict( symp_prob=0.12, asymp_prob=0.0015, symp_quar_prob=0.8, asymp_quar_prob=0.1, test_delay=2.0, ) ct = sc.objdict( trace_probs=0.25, trace_time=3.0, ) elif ttq_scen == 'upper': tp = sc.objdict( symp_prob=0.24, asymp_prob=0.003, symp_quar_prob=0.8, asymp_quar_prob=0.1, test_delay=2.0, ) ct = sc.objdict( trace_probs=0.5, trace_time=3.0, ) if ttq_scen is not None: interventions += [cv.test_prob(start_day='2020-07-10', **tp), cv.contact_tracing(start_day='2020-07-10', **ct)] if network_change: popfile_new = popfile_change else: popfile_new = None if NPI_schools is not None: interventions += [cv.change_beta(days=sim.day('2020-09-01'), changes=NPI_schools, layers='s')] interventions += [cv.close_schools(day_schools_closed='2020-03-12', start_day=school_start_day, pop_file=popfile_new)] interventions += [cv.reopen_schools(start_day=intervention_start_day, num_pos=num_pos, test=test_prob, trace=trace_prob, ili_prev=0.002, test_freq=test_freq, schedule=schedule)] sim['interventions'] = interventions # Don't show interventions in plots, there are too many for interv in sim['interventions']: interv.do_plot = False # Prognoses (particularly to severe/hospitalizations) need attention prognoses = sc.dcp(cv.get_prognoses()) prognoses['severe_probs'] *= prognoses[ 'symp_probs'] # Conditional probability of symptoms becoming severe, given symptomatic prognoses['crit_probs'] *= prognoses[ 'severe_probs'] # Conditional probability of symptoms becoming critical, given severe prognoses['death_probs'] *= prognoses['crit_probs'] # Conditional probability of dying, given critical symptoms prognoses.update({'age_cutoff': np.array([0, 10, 20, 30, 40, 50, 65, 70, 80, 90])}) prognoses.update({'severe_probs': np.array([1, 1, 1, p.rsp1, p.rsp1, p.rsp1, p.rsp1, p.rsp1, p.rsp2, p.rsp2]) * prognoses['severe_probs']}) prognoses['death_probs'] /= prognoses['crit_probs'] # Conditional probability of dying, given critical symptoms prognoses['crit_probs'] /= prognoses[ 'severe_probs'] # Conditional probability of symptoms becoming critical, given severe prognoses['severe_probs'] /= prognoses[ 'symp_probs'] # Conditional probability of symptoms becoming severe, given symptomatic sim.pars.update({'prognoses': prognoses}) return sim