def map_sample_to_model_input(cb, sample): # arab_constant = sample["arab_constant_scale"] arab_constant = 6.3 arab_rainfall = sample["arab_rainfall_scale"] # funest_spline = sample["funest_spline_scale"] log_spline_rainfall_ratio = sample["log_spline_rainfall_ratio"] funest_spline = arab_rainfall + log_spline_rainfall_ratio # funest_veg = sample["funest_veg_scale"] funest_veg = 6.3 arab_constant_rescale = 1.0 #pow(10, arab_constant) / pow(10, burnin_params['arab_constant_scale']) arab_rainfall_rescale = pow(10, arab_rainfall) / pow( 10, burnin_params['arab_rainfall_scale']) funest_spline_rescale = pow(10, funest_spline) / pow( 10, burnin_params['funest_spline_scale']) funest_veg_rescale = 1.0 #pow(10, funest_veg) / pow(10, burnin_params['funest_veg_scale']) scale_larval_habitats(cb, pd.DataFrame({ 'CONSTANT.arabiensis': [arab_constant_rescale], 'TEMPORARY_RAINFALL.arabiensis': [arab_rainfall_rescale], 'LINEAR_SPLINE.funestus': [funest_spline_rescale], 'WATER_VEGETATION.funestus': [funest_veg_rescale] }), start_day=0) return sample
def simulation_setup(cb, species_details, site_vector_props, max_larval_capacity=4e8): site_dir = os.path.join('sites', 'all') # directories cb.update_params({ "Demographics_Filenames": [ os.path.join(site_dir, "demographics.json"), os.path.join(site_dir, "demographics_net_overlay.json") ], "Air_Temperature_Filename": os.path.join(site_dir, "air_temperature_daily.bin"), "Land_Temperature_Filename": os.path.join(site_dir, "air_temperature_daily.bin"), "Rainfall_Filename": os.path.join(site_dir, "rainfall_daily.bin"), "Relative_Humidity_Filename": os.path.join(site_dir, "relative_humidity_daily.bin") }) # Find vector proportions for each vector set_params_by_species(cb.params, [name for name in species_details.keys()]) larval_habs_per_site = {"NodeID": site_vector_props["node_id"]} for species_name, species_modifications in species_details.items(): set_species_param(cb, species_name, "Adult_Life_Expectancy", 20) set_species_param(cb, species_name, 'Vector_Sugar_Feeding_Frequency', 'VECTOR_SUGAR_FEEDING_EVERY_DAY') for param, val in species_modifications.items(): if param == "habitat_split": new_vals = { hab: hab_prop * max_larval_capacity for hab, hab_prop in val.items() } set_species_param(cb, species_name, "Larval_Habitat_Types", new_vals) larval_habs_per_site.update({ ".".join([species_name, hab]): site_vector_props[species_name] for hab in val.keys() }) else: set_species_param(cb, species_name, param, val) scale_larval_habitats(cb, pd.DataFrame(larval_habs_per_site))
def scale_larval_habs_for_bairro(cb, bairro_num, bairro_df, arab_mult, funest_mult, start_day=0): # Get grid cells for this bairro bairro_grid_cells = bairro_df[bairro_df['bairro'] == bairro_num]['grid_cell'] n_cells = len(bairro_grid_cells) # Make a dataframe for these node ids, with the appropriate multipliers scale_larval_habitats( cb, pd.DataFrame({ 'LINEAR_SPLINE.arabiensis': [arab_mult] * n_cells, 'LINEAR_SPLINE.funestus': [funest_mult] * n_cells, 'Start_Day': [start_day] * n_cells, 'NodeID': [int(x) for x in bairro_grid_cells] }))
def map_sample_to_model_input(cb, sample): sim_time_dict = serialization_setup(cb, calib_stage) add_interventions_and_reports(cb, sim_time_dict) dd = best_run_so_far() # ===================================================================================== # Global habitats if calib_stage == 1 or calib_stage == 2: a_sc = sample['arabiensis_scale'] f_sc = sample['funestus_scale'] if calib_stage == 1: # LOAD FROM SPLINE: arab_times, arab_spline = MozambiqueExperiment.catch_3_yr_spline( catch, "gambiae") funest_times, funest_spline = MozambiqueExperiment.catch_3_yr_spline( catch, "funestus") hab = { 'arabiensis': { "LINEAR_SPLINE": { "Capacity_Distribution_Number_Of_Years": 3, "Capacity_Distribution_Over_Time": { # "Capacity_Distribution_Per_Year": { "Times": arab_times, "Values": arab_spline }, "Max_Larval_Capacity": pow(10, a_sc) } }, 'funestus': { "LINEAR_SPLINE": { "Capacity_Distribution_Number_Of_Years": 3, "Capacity_Distribution_Over_Time": { # "Capacity_Distribution_Per_Year": { "Times": funest_times, "Values": funest_spline }, "Max_Larval_Capacity": pow(10, f_sc) # "Max_Larval_Capacity": pow(10,a_sc)/arab_funest_ratio } } } set_larval_habitat(cb, hab) elif calib_stage >= 2: arab_rescale = pow(10, a_sc) / pow(10, dd['a_sc_burnin']) funest_rescale = pow(10, f_sc) / pow(10, dd['f_sc_burnin']) if calib_stage == 2: scale_larval_habitats(cb, pd.DataFrame({ 'LINEAR_SPLINE.arabiensis': [arab_rescale], 'LINEAR_SPLINE.funestus': [funest_rescale] }), start_day=0) elif calib_stage == 3: for bairro_num in bairro_df["bairro"].unique(): scale_larval_habs_for_bairro( cb, bairro_num, bairro_df, arab_rescale * sample['b{}_vector_mult'.format(int(bairro_num))], funest_rescale * sample['b{}_vector_mult'.format(int(bairro_num))], start_day=0) # FOR TESTING ONLY: if mode == 'fast': cb.set_param('x_Temporary_Larval_Habitat', 0) cb.set_param('x_Regional_Migration', 0) return sample
cd = catch_specific_params(cb, catch) arab_constant_rescale = pow(10, arab_constant) / pow( 10, burnin_params['arab_constant_scale']) arab_rainfall_rescale = pow(10, arab_rainfall) / pow( 10, burnin_params['arab_rainfall_scale']) funest_spline_rescale = pow(10, funest_spline) / pow( 10, burnin_params['funest_spline_scale']) funest_veg_rescale = pow(10, funest_veg) / pow( 10, burnin_params['funest_veg_scale']) scale_larval_habitats(cb, pd.DataFrame({ 'CONSTANT.arabiensis': [arab_constant_rescale], 'TEMPORARY_RAINFALL.arabiensis': [arab_rainfall_rescale], 'LINEAR_SPLINE.funestus': [funest_spline_rescale], 'WATER_VEGETATION.funestus': [funest_veg_rescale] }), start_day=0) # Add interventions # zm.add_all_interventions(cb, catch) zm.add_reports_for_likelihood_analyzers(cb, catch, filter_duration_days=sim_duration_days) # Draw from serialized file (from rank0 burnin): if catch == "bbondo": cb.update_params({ "Serialized_Population_Path":
def map_sample_to_model_input(cb, sample): sim_time_dict = serialization_setup(cb, calib_stage) add_interventions_and_reports(cb, sim_time_dict) # ===================================================================================== # Global habitats if calib_stage == 1: a_sc = sample['arabiensis_scale'] f_sc = sample['funestus_scale'] if sim_time_dict["burnin"]: # LOAD FROM SPLINE: arab_times, arab_spline = MozambiqueExperiment.catch_3_yr_spline( catch, "gambiae") funest_times, funest_spline = MozambiqueExperiment.catch_3_yr_spline( catch, "funestus") hab = { 'arabiensis': { "LINEAR_SPLINE": { "Capacity_Distribution_Number_Of_Years": 3, "Capacity_Distribution_Over_Time": { # "Capacity_Distribution_Per_Year": { "Times": arab_times, "Values": arab_spline }, "Max_Larval_Capacity": pow(10, a_sc) } }, 'funestus': { "LINEAR_SPLINE": { "Capacity_Distribution_Number_Of_Years": 3, "Capacity_Distribution_Over_Time": { # "Capacity_Distribution_Per_Year": { "Times": funest_times, "Values": funest_spline }, "Max_Larval_Capacity": pow(10, f_sc) # "Max_Larval_Capacity": pow(10,a_sc)/arab_funest_ratio } } } set_larval_habitat(cb, hab) if not sim_time_dict["burnin"]: # Get best-fit parameters from LL_all of Stage 1: # Need to find best BURNIN to rescale to, not best run. Since the sims before 2009 are purely from burnins: LL_all = pd.read_csv(LL_all_path) LL_all_burnins = LL_all[LL_all["iteration"] == 0] p1_list = list(LL_all_burnins['arabiensis_scale']) p2_list = list(LL_all_burnins['funestus_scale']) a_sc_burnin = p1_list[-1] f_sc_burnin = p2_list[-1] if calib_stage == 2: # Draw params from best RUN (may not be a burnin) p1_list = list(LL_all['arabiensis_scale']) p2_list = list(LL_all['funestus_scale']) a_sc = p1_list[-1] f_sc = p2_list[-1] arab_rescale = pow(10, a_sc) / pow(10, a_sc_burnin) funest_rescale = pow(10, f_sc) / pow(10, f_sc_burnin) if calib_stage == 1: scale_larval_habitats(cb, pd.DataFrame({ 'LINEAR_SPLINE.arabiensis': [arab_rescale], 'LINEAR_SPLINE.funestus': [funest_rescale] }), start_day=0) elif calib_stage == 2: for bairro_num in bairro_df["bairro"].unique(): scale_larval_habs_for_bairro( cb, bairro_num, bairro_df, arab_rescale * sample['b{}_vector_mult'.format(int(bairro_num))], funest_rescale * sample['b{}_vector_mult'.format(int(bairro_num))], start_day=0) # FOR TESTING ONLY: if mode == 'fast': cb.set_param('x_Temporary_Larval_Habitat', 0) cb.set_param('x_Regional_Migration', 0) return sample