def get_old_and_new_dist_shape(): old_new_dist = pd.read_csv(get_data_dir('raw', 'district_relation.csv')) old_new_dist_map = old_new_dist[[ 'DIST2012', 'NEW_DIST_ID_2' ]].set_index('DIST2012').to_dict()['NEW_DIST_ID_2'] pop_dense = pd.read_csv( get_data_dir('raw', 'district_pop_dens_friction.csv')) old_new_dist = old_new_dist.merge(pop_dense, on='DIST2012') # p = gpd.read_file('../data/geo2_zw2012.shp') shape = p = gpd.read_file( get_data_dir('raw', 'shapefiles', 'new_districts', 'ZWE_adm2.shp')) shape['total_population'] = shape['ID_2'].map( old_new_dist.groupby('NEW_DIST_ID_2')['total_pop'].sum()) return old_new_dist, shape
def set_intra_district_decreased_mobility_rates(self, intra_district_decreased_mobility_rates_file): self.LOCKDOWN_DECREASED_MOBILITY_RATE = pd.read_csv( get_data_dir('preprocessed', 'mobility', intra_district_decreased_mobility_rates_file), index_col=0 )['pctdif_distance'] self.LOCKDOWN_DECREASED_MOBILITY_RATE = { self.DISTRICT_NAME_TO_ID[i]: j for i, j in self.LOCKDOWN_DECREASED_MOBILITY_RATE.items() }
def set_new_district_seed(self, seed_infected): # NOTE: This should be updated when the admin level is changed. # model.params.DISTRICT_NAME_TO_ID['d_1'] -> 0 Bulawayo # model.params.DISTRICT_NAME_TO_ID['d_2'] -> 11 Harare # model.params.DISTRICT_NAME_TO_ID['d_18'] -> 9 Goromonzi with open(get_data_dir('preprocessed', 'line_list', 'latest_line_list.pickle'), 'rb') as fl: infected_count = pickle.load(fl) self.DISTRICT_ID_INFECTED_COUNT = {self.DISTRICT_NAME_TO_ID.get(i): j for i, j in infected_count.items()} self.DISTRICT_ID_INFECTED_PROB = pd.Series(self.DISTRICT_ID_INFECTED_COUNT) self.DISTRICT_ID_INFECTED_PROB = (self.DISTRICT_ID_INFECTED_PROB / self.DISTRICT_ID_INFECTED_PROB.sum()).to_dict() self.SEED_INFECT_DISTRICT_IDS = np.array([i for i in self.DISTRICT_ID_INFECTED_COUNT]) self.SEED_INFECT_AGE_MIN = 20 self.SEED_INFECT_AGE_MAX = 60 self.SEED_INFECT_NUM = seed_infected # 3 -> 66 for a 5% sample self.SIMULATION_START_DATE = datetime(2020, 9, 1, 8) self.data_file_name = get_data_dir('preprocessed', 'census', f'zimbabwe_expanded_census_consolidated_{self.data_sample_size}pct.pickle')
def scenario_handwashing_risk(self): self.SCENARIO = 'HANDWASHING_RISK' self.risk_data = pd.read_csv( get_data_dir('preprocessed', 'risk', 'hw_and_severe_disease_risk.csv')) self.DISTRICT_HW_RISK = self.risk_data[['ID_2', 'mean_hw_risk_pop_weighted']].copy() self.MEAN_HW_RISK = self.DISTRICT_HW_RISK['mean_hw_risk_pop_weighted'].mean() self.MIN_HW_RISK = self.DISTRICT_HW_RISK['mean_hw_risk_pop_weighted'].min() self.DISTRICT_HW_RISK['ID_2'] = self.DISTRICT_HW_RISK['ID_2'].map(lambda x: f'd_{x}') self.DISTRICT_HW_RISK['effective_hw_risk'] = self.DISTRICT_HW_RISK['mean_hw_risk_pop_weighted'].map(self.get_effective_R0) self.DISTRICT_HW_RISK = self.DISTRICT_HW_RISK.set_index('ID_2').to_dict()['effective_hw_risk'] self.DISTRICT_SEVERE_DISEASE_RISK = self.risk_data[['ID_2', 'severe_covid_risk']].copy() self.DISTRICT_SEVERE_DISEASE_RISK['severe_covid_risk'] = ( self.DISTRICT_SEVERE_DISEASE_RISK['severe_covid_risk'] / self.MEAN_HOSPITALIZATION_RATE ) self.DISTRICT_SEVERE_DISEASE_RISK = self.DISTRICT_SEVERE_DISEASE_RISK.set_index('ID_2').to_dict()['severe_covid_risk']
def run_scenario(scenarioClass, scenario_name, sim_fname, R0, sample_size, seed_num, start_date=None, timestep=timedelta(hours=4), scaled_mobility=False): import pickle import sys from covid19_abm.params import ParamsConfig from covid19_abm.dir_manager import get_data_dir # scenario_name = sys.argv[0] # sim_fname = sys.argv[1].zfill(2) # R0 = 1.9 # sample_size = 10 # seed_num = 90 # 6 -> 66 for 10% data sample sim_fname = sim_fname.zfill(2) if scaled_mobility: sim_fname = f'scaled_{scenario_name}_{sim_fname}_R{R0}_samp{sample_size}_seed{seed_num}' stay_duration_file = 'weekday_mobility_duration_count_df-new-district-scaled.pickle' transition_probability_file = 'daily_region_transition_probability-new-district-scaled.csv' else: sim_fname = f'{scenario_name}_{sim_fname}_R{R0}_samp{sample_size}_seed{seed_num}' stay_duration_file = 'weekday_mobility_duration_count_df-new-district.pickle' transition_probability_file = 'daily_region_transition_probability-new-district-pre-lockdown.csv' now = datetime.now().isoformat() model_log_file = get_data_dir('logs', f'model_log_file_{sim_fname}.{now}.log') individual_log_file = get_data_dir( 'logs', f'individual_log_file_{sim_fname}.{now}.log') params = ParamsConfig( district='new', data_sample_size=sample_size, R0=R0, normal_interaction_matrix_file=get_data_dir( 'raw', 'final_close_interaction_matrix_normal.xlsx'), lockdown_interaction_matrix_file=get_data_dir( 'raw', 'final_close_interaction_matrix_lockdown.xlsx'), stay_duration_file=get_data_dir('preprocessed', 'mobility', stay_duration_file), transition_probability_file=get_data_dir('preprocessed', 'mobility', transition_probability_file), timestep=timestep) params.set_new_district_seed(seed_infected=seed_num) model = scenarioClass(params, model_log_file=model_log_file, individual_log_file=individual_log_file) if start_date is not None: params.SIMULATION_START_DATE = start_date model.scheduler.real_time = params.SIMULATION_START_DATE model.load_agents(params.data_file_name, size=None, infect_num=params.SEED_INFECT_NUM) # end_date = model.scheduler.real_time + timedelta(days=30 * 24, hours=4) end_date = datetime(2021, 6, 1) while model.scheduler.real_time <= end_date: model.step() if ((model.epidemic_state >= model.STATE_INFECTED) & (model.epidemic_state < model.STATE_RECOVERED)).sum() == 0: break model_dump_file = get_data_dir( 'logs', f'model_dump_file_{sim_fname}.{now}.pickle') with open(model_dump_file, 'wb') as fl: pickle.dump(model, fl)
def scenario_test_interaction_matrix_sensitivity(self): self.SCENARIO = 'INTERACTION_MATRIX_SENSITIVITY' self.set_interaction_parameters( get_data_dir('raw', 'sensitivity_interaction_matrix.xlsx'))