def cache_populations(seed=0, popfile=None): ''' Pre-generate the synthpops population ''' pars = sc.objdict( pop_size=pop_size, pop_type='synthpops', rand_seed=seed, ) if popfile is None: popfile = f'{popfile_stem}{pars.rand_seed}.ppl' T = sc.tic() print(f'Making "{popfile}"...') sim = cv.Sim(pars) cv.make_people(sim, popfile=popfile, save_pop=True, with_facilities=True, generate=True, layer_mapping={'LTCF': 'l'}) sc.toc(T) print('Done') return
def plot_people(self, *args, **kwargs): ''' Placeholder example of plotting the people in a population ''' import covasim as cv # Optional import pars = dict( pop_size = self.n, pop_type = 'synthpops', beta_layer = {k: 1 for k in 'hscwl'}, ) sim = cv.Sim(pars, popfile=self.popdict) ppl = cv.make_people(sim) # Create the corresponding population fig = ppl.plot(*args, **kwargs) return fig
def cache_populations(seed=0, popfile=None): ''' Pre-generate the hybrid population ''' pars = sc.objdict( pop_size=225e3, pop_type='hybrid', rand_seed=seed, ) if popfile is None: popfile = f'inputs/kc_hybrid_seed{pars.rand_seed}.ppl' T = sc.tic() print(f'Making "{popfile}"...') sim = cv.Sim(pars) cv.make_people(sim, popfile=popfile, save_pop=True, school_type=True, school_type_ages=[[6, 11], [11, 14], [14, 18], [18, 22]]) sc.toc(T) print('Done') return
location = 'seattle_metro' undirected = True n_days = 1 rand_seed = None with_facilities = False pars = { 'pop_size': pop_size, 'pop_type': pop_type, 'rand_seed': rand_seed, 'n_days': n_days, } sim = cv.Sim(pars) popdict = cv.make_people(sim, generate=True, with_facilities=with_facilities, layer_mapping={'LTCF': 'l'}) sim = cv.Sim(pars, popfile=popdict, load_pop=True) # Select which keys to plot! # keys_to_plot = ['h', 'l'] # keys_to_plot = ['s', 'w'] keys_to_plot = ['h', 'l', 's', 'w'] # keys_to_plot = ['h', 's', 'w'] keys = ['l', 'w', 's', 'h'] # keys = ['w', 's', 'h'] if with_facilities is False: if 'l' in keys_to_plot: keys_to_plot.remove('l')
prognoses['symp_probs'] = np.array( [0.905, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]) # Equally susceptible prognoses['severe_probs'] = np.array( [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]) # Zero'd out prognoses['crit_probs'] = np.array( [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]) # Zero'd out prognoses['death_probs'] = np.array( [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]) # Zero'd out pars['prognoses'] = prognoses pars['start_day'] = '2020-01-01' pars['n_days'] = 60 pars['quar_period'] = 140 sim = cv.Sim(pars=pars) # Setup sim sim.initialize() people = cv.make_people(sim) # Make the actual people for the simulation inds_o5 = sc.findinds(people.age >= 10) people.rel_sus[inds_o5] = 0 inds_u5 = sc.findinds(people.age < 10) imm_frac = 0.8 inds_u5imm = inds_u5[sc.findinds( np.random.uniform(low=0.0, high=1.0, size=len(inds_u5)) < imm_frac)] people.rel_sus[inds_u5imm] = 0 sim.people = people # sim['interventions'] = [cv.test_prob(symp_prob=1.00, asymp_prob=0.00)] # Test 100% of symptomatics and 0% of asymptomatics sim['interventions'] = [ cv.test_prob(symp_prob=1.00, asymp_prob=0.00), cv.contact_tracing() ] sim.run() sim.plot()
def make_population(seed=0, popfile=None): ''' Pre-generate the synthpops population ''' pars = sc.objdict( pop_size=10e3, pop_type='synthpops', rand_seed=seed, ) use_two_group_reduction = True average_LTCF_degree = 20 ltcf_staff_age_min = 20 ltcf_staff_age_max = 60 with_school_types = True average_class_size = 20 inter_grade_mixing = 0.1 average_student_teacher_ratio = 20 average_teacher_teacher_degree = 3 teacher_age_min = 25 teacher_age_max = 75 with_non_teaching_staff = True # if with_non_teaching_staff is False, but generate is True, then average_all_staff_ratio should be average_student_teacher_ratio or 0 average_student_all_staff_ratio = 11 average_additional_staff_degree = 20 staff_age_min = 20 staff_age_max = 75 school_mixing_type = { 'pk': 'clustered', 'es': 'clustered', 'ms': 'clustered', 'hs': 'random', 'uv': 'random' } if popfile is None: popfile = f'inputs/kc_synthpops_clustered_withstaff_10e3.ppl' T = sc.tic() print(f'Making "{popfile}"...') sim = cv.Sim(pars) cv.make_people( sim, popfile=popfile, save_pop=True, generate=True, with_facilities=True, use_two_group_reduction=use_two_group_reduction, average_LTCF_degree=average_LTCF_degree, ltcf_staff_age_min=ltcf_staff_age_min, ltcf_staff_age_max=ltcf_staff_age_max, with_school_types=with_school_types, school_mixing_type=school_mixing_type, average_class_size=average_class_size, inter_grade_mixing=inter_grade_mixing, average_student_teacher_ratio=average_student_teacher_ratio, average_teacher_teacher_degree=average_teacher_teacher_degree, teacher_age_min=teacher_age_min, teacher_age_max=teacher_age_max, with_non_teaching_staff=with_non_teaching_staff, average_student_all_staff_ratio=average_student_all_staff_ratio, average_additional_staff_degree=average_additional_staff_degree, staff_age_min=staff_age_min, staff_age_max=staff_age_max) sc.toc(T) print('Done') return
reportdir = pathlib.Path(os.path.dirname(__file__), "covasim_report") os.makedirs(reportdir, exist_ok=True) n = 2e4 + 1 # Total population size for seed in range(1, 500, 100): for ltcf in [True, False]: label = "ltcf_" if ltcf else "" print("seed:", seed) # Random seed # Everything here gets passed to sp.make_population() pop_pars = dict( generate=True, with_facilities=ltcf, ) if ltcf: pop_pars["layer_mapping"] = {'LTCF': 'l'} sim = cv.Sim(pop_size=n, rand_seed=seed, pop_type='synthpops', beta_layer={k: 1 for k in 'hscwl'}) else: sim = cv.Sim(pop_size=n, rand_seed=seed, pop_type='synthpops') # Make the Covasim oject ppl = cv.make_people(sim, **pop_pars) # Create the corresponding population fig = ppl.plot() fig.savefig(os.path.join( reportdir, f"{label}covasim_graph_{n}_seed{seed}_new.png"), format="png")
def cache_populations(seed=0, popfile=None): ''' Pre-generate the synthpops population ''' pars = sc.objdict( # pop_size = 2.25e6, pop_size=225e3, pop_type='synthpops', rand_seed=seed, ) use_two_group_reduction = True average_LTCF_degree = 20 ltcf_staff_age_min = 20 ltcf_staff_age_max = 60 with_school_types = True average_class_size = 20 inter_grade_mixing = 0.1 average_student_teacher_ratio = 20 average_teacher_teacher_degree = 3 teacher_age_min = 25 teacher_age_max = 75 with_non_teaching_staff = True # if with_non_teaching_staff is False, but generate is True, then average_all_staff_ratio should be average_student_teacher_ratio or 0 average_student_all_staff_ratio = 11 average_additional_staff_degree = 20 staff_age_min = 20 staff_age_max = 75 # For reference re: school_types # school_mixing_type = 'random' means that students in the school have edges randomly chosen from other students, teachers, and non teaching staff across the school. Students, teachers, and non teaching staff are treated the same in terms of edge generation. # school_mixing_type = 'age_clustered' means that students in the school have edges mostly within their own age/grade, with teachers, and non teaching staff. Strict classrooms are not generated. Teachers have some additional edges with other teachers. # school_mixing_type = 'age_and_class_clustered' means that students are cohorted into classes of students of the same age/grade with at least 1 teacher, and then some have contact with non teaching staff. Teachers have some additional edges with other teachers. cohorting = False if cohorting: strategy = 'clustered' # students in pre-k, elementary, and middle school are cohorted into strict classrooms school_mixing_type = { 'pk': 'age_and_class_clustered', 'es': 'age_and_class_clustered', 'ms': 'age_and_class_clustered', 'hs': 'random', 'uv': 'random' } else: strategy = 'normal' school_mixing_type = { 'pk': 'age_clustered', 'es': 'age_clustered', 'ms': 'age_clustered', 'hs': 'random', 'uv': 'random' } if popfile is None: popfile = f'inputs/kc_synthpops_{strategy}_withstaff_seed{pars.rand_seed}.ppl' # popfile = f'inputs/kc_synthpops_{strategy}_withstaff_1m_seed{pars.rand_seed}.ppl' T = sc.tic() print(f'Making "{popfile}"...') sim = cv.Sim(pars) cv.make_people( sim, popfile=popfile, save_pop=True, generate=True, with_facilities=True, use_two_group_reduction=use_two_group_reduction, average_LTCF_degree=average_LTCF_degree, ltcf_staff_age_min=ltcf_staff_age_min, ltcf_staff_age_max=ltcf_staff_age_max, with_school_types=with_school_types, school_mixing_type=school_mixing_type, average_class_size=average_class_size, inter_grade_mixing=inter_grade_mixing, average_student_teacher_ratio=average_student_teacher_ratio, average_teacher_teacher_degree=average_teacher_teacher_degree, teacher_age_min=teacher_age_min, teacher_age_max=teacher_age_max, with_non_teaching_staff=with_non_teaching_staff, average_student_all_staff_ratio=average_student_all_staff_ratio, average_additional_staff_degree=average_additional_staff_degree, staff_age_min=staff_age_min, staff_age_max=staff_age_max) sc.toc(T) print('Done') return
sc.toc(label='default') plist = people.to_people() sc.toc(label='to people') ppl2 = cv.People() ppl2.from_people(plist) sc.toc(label='from people') ppl3 = people + ppl2 sim = cv.Sim(pop_type='random', pop_size=20000) cv.make_people(sim) ppl4 = sim.people sc.toc(label='as sim') df = ppl4.to_df() arr = ppl4.to_arr() sc.toc(label='to df/arr') sc.toc() sim.people.initialize() df = sim.people.contacts