Skip to content

Commit

Permalink
Merge pull request #80 from InstituteforDiseaseModeling/ben_20231016
Browse files Browse the repository at this point in the history
Fix add_all_interventions RTSS error and being dependent on smc_df problem
  • Loading branch information
stitova-idm authored Oct 31, 2023
2 parents 586c673 + 4643302 commit 916e159
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 33 deletions.
71 changes: 71 additions & 0 deletions examples/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import emod_api.campaign as campaign
import numpy as np
import pandas as pd
from snt.hbhi.set_up_interventions import InterventionSuite
from emod_api.interventions.common import BroadcastEvent, DelayedIntervention
from emodpy_malaria.interventions.common import add_triggered_campaign_delay_event
from snt.hbhi.set_up_interventions import add_all_interventions
from emodpy_malaria.interventions.vaccine import add_scheduled_vaccine, add_triggered_vaccine
import manifest

def non_snt_camp():
import emod_api.campaign as campaign
campaign.schema_path = manifest.schema_file

delay_distribution = {"Delay_Period_Distribution": "CONSTANT_DISTRIBUTION",
"Delay_Period_Constant": 274}
event_name = "RTSS_1_eligible"
broadcast_event = BroadcastEvent(campaign, event_name)
delayed_event = DelayedIntervention(campaign, Configs=[broadcast_event],
Delay_Dict=delay_distribution)
add_triggered_campaign_delay_event(campaign, start_day=1,
trigger_condition_list=['Births'],
demographic_coverage=0.504,
individual_intervention=delayed_event)
add_triggered_vaccine(campaign,
start_day=1,
trigger_condition_list=["RTSS_1_eligible"],
intervention_name='RTSS',
broadcast_event='Received_Vaccine',
vaccine_type="AcquisitionBlocking",
vaccine_initial_effect=0.8,
vaccine_box_duration=0,
vaccine_decay_time_constant=592.4067,
efficacy_is_multiplicative=False)

return campaign


def snt_camp():
import emod_api.campaign as campaign
campaign.schema_path = manifest.schema_file

int_suite = InterventionSuite()
int_suite.rtss_auto_changeips = False

rtss_df = pd.DataFrame({
'DS_Name': ['Yomou'],
'coverage_levels': [0.504],
'round': [3],
'vaccine': ['simple'],
'initial_killing': [0.8],
'decay_time_constant': [592.4067],
'rtss_touchpoints': [274],
'decay_class': ['WaningEffectExponential'],
'RTSS_day': [1],
'deploy_type': ['EPI'],
'distribution_name': ['CONSTANT_DISTRIBUTION'],
'distribution_std': [1]
})
print(rtss_df)
add_all_interventions(campaign, int_suite, my_ds="Yomou",
rtss_df=rtss_df)

return campaign


camp1 = non_snt_camp()
camp2 = snt_camp()

camp1.save("camp1.json")
camp2.save("camp2.json")
36 changes: 18 additions & 18 deletions snt/hbhi/set_up_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ def set_input_files(config, my_ds, archetype_ds=None, demographic_suffix='',
else:
ds = my_ds

config.parameters['District_Sanitaire'] = 'my_ds'
config.parameters['Archetype'] = 'archetype_ds'
# config.parameters['District_Sanitaire'] = 'my_ds'
# config.parameters['Archetype'] = 'archetype_ds'

if demographic_suffix is not None:
config.parameters.Demographics_Filenames = [
Expand Down Expand Up @@ -196,7 +196,7 @@ def set_input_files(config, my_ds, archetype_ds=None, demographic_suffix='',
return {'DS_Name': my_ds}


def add_input_files(task, iopath, my_ds, archetype_ds=None, demographic_suffix='',
def add_input_files(task, inputpath, my_ds, archetype_ds=None, demographic_suffix='',
climate_suffix='', climate_prefix=True, use_archetype=True):
"""
Add assets corresponding to the filename parameters set in set_input_files.
Expand Down Expand Up @@ -232,58 +232,58 @@ def add_input_files(task, iopath, my_ds, archetype_ds=None, demographic_suffix='

if demographic_suffix is not None:
demog_path = os.path.join(ds, f'{ds}_demographics{demographic_suffix}.json')
task.common_assets.add_asset(os.path.join(iopath, 'simulation_inputs', demog_path),
task.common_assets.add_asset(os.path.join(inputpath, demog_path),
relative_path=str(Path(demog_path).parent), fail_on_duplicate=False)

if climate_suffix is not None:
if climate_prefix:
file_path = os.path.join(ds, f'{ds}_air_temperature_daily{climate_suffix}.bin')
task.common_assets.add_asset(os.path.join(iopath, 'simulation_inputs', file_path),
task.common_assets.add_asset(os.path.join(inputpath, file_path),
relative_path=str(Path(file_path).parent), fail_on_duplicate=False)
file_path = os.path.join(ds, f'{ds}_air_temperature_daily{climate_suffix}.bin.json')
task.common_assets.add_asset(os.path.join(iopath, 'simulation_inputs', file_path),
task.common_assets.add_asset(os.path.join(inputpath, file_path),
relative_path=str(Path(file_path).parent), fail_on_duplicate=False)

file_path = os.path.join(ds, f'{ds}_rainfall_daily{climate_suffix}.bin')
task.common_assets.add_asset(os.path.join(iopath, 'simulation_inputs', file_path),
task.common_assets.add_asset(os.path.join(inputpath, file_path),
relative_path=str(Path(file_path).parent), fail_on_duplicate=False)
file_path = os.path.join(ds, f'{ds}_rainfall_daily{climate_suffix}.bin.json')
task.common_assets.add_asset(os.path.join(iopath, 'simulation_inputs', file_path),
task.common_assets.add_asset(os.path.join(inputpath, file_path),
relative_path=str(Path(file_path).parent), fail_on_duplicate=False)

file_path = os.path.join(ds, f'{ds}_relative_humidity_daily{climate_suffix}.bin')
task.common_assets.add_asset(os.path.join(iopath, 'simulation_inputs', file_path),
task.common_assets.add_asset(os.path.join(inputpath, file_path),
relative_path=str(Path(file_path).parent), fail_on_duplicate=False)
file_path = os.path.join(ds, f'{ds}_relative_humidity_daily{climate_suffix}.bin.json')
task.common_assets.add_asset(os.path.join(iopath, 'simulation_inputs', file_path),
task.common_assets.add_asset(os.path.join(inputpath, file_path),
relative_path=str(Path(file_path).parent), fail_on_duplicate=False)
else:
file_path = os.path.join(ds, f'air_temperature_daily{climate_suffix}.bin')
task.common_assets.add_asset(os.path.join(iopath, 'simulation_inputs', file_path),
task.common_assets.add_asset(os.path.join(inputpath, file_path),
relative_path=str(Path(file_path).parent), fail_on_duplicate=False)
file_path = os.path.join(ds, f'air_temperature_daily{climate_suffix}.bin.json')
task.common_assets.add_asset(os.path.join(iopath, 'simulation_inputs', file_path),
task.common_assets.add_asset(os.path.join(inputpath, file_path),
relative_path=str(Path(file_path).parent), fail_on_duplicate=False)

file_path = os.path.join(ds, f'rainfall_daily{climate_suffix}.bin')
task.common_assets.add_asset(os.path.join(iopath, 'simulation_inputs', file_path),
task.common_assets.add_asset(os.path.join(inputpath, file_path),
relative_path=str(Path(file_path).parent), fail_on_duplicate=False)
file_path = os.path.join(ds, f'rainfall_daily{climate_suffix}.bin.json')
task.common_assets.add_asset(os.path.join(iopath, 'simulation_inputs', file_path),
task.common_assets.add_asset(os.path.join(inputpath, file_path),
relative_path=str(Path(file_path).parent), fail_on_duplicate=False)

file_path = os.path.join(ds, f'relative_humidity_daily{climate_suffix}.bin')
task.common_assets.add_asset(os.path.join(iopath, 'simulation_inputs', file_path),
task.common_assets.add_asset(os.path.join(inputpath, file_path),
relative_path=str(Path(file_path).parent), fail_on_duplicate=False)
file_path = os.path.join(ds, f'relative_humidity_daily{climate_suffix}.bin.json')
task.common_assets.add_asset(os.path.join(iopath, 'simulation_inputs', file_path),
task.common_assets.add_asset(os.path.join(inputpath, file_path),
relative_path=str(Path(file_path).parent), fail_on_duplicate=False)


def setup_ds(config, manifest, platform, my_ds, archetype_ds=None,
pull_from_serialization=False,
burnin_id='', ser_date=50 * 365,
burnin_fname='',
burnin_df=None,
rel_abund_df=None, lhdf=None, use_arch_burnin=True,
from_arch=None, demographic_suffix='',
climate_suffix='',
Expand Down Expand Up @@ -379,7 +379,7 @@ def setup_ds(config, manifest, platform, my_ds, archetype_ds=None,
if burnin_id:
ser_df = platform.create_sim_directory_df(burnin_id) # TODO: or we can pass ser_df in
else:
ser_df = pd.read_csv(burnin_fname)
ser_df = burnin_df

if use_arch_burnin:
ser_df = ser_df[ser_df[ds_name] == archetype_ds]
Expand Down
21 changes: 11 additions & 10 deletions snt/hbhi/set_up_interventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def add_hs_from_file(self, campaign, row, duration):
'rate': rates
})
add_treatment_seeking(campaign, start_day=start_day, targets=targets, drug=['Artemether', 'Lumefantrine'],
duration=duration)
duration=duration, broadcast_event_name='Received_Treatment')

# Severe
targets = []
Expand Down Expand Up @@ -531,7 +531,7 @@ def add_epi_rtss(self, campaign, rtss_df):
for tp_time_trigger, coverage, vtype, event_name, std, init_eff, decay_t in \
zip(rtss_touchpoints, coverage_levels, rtss_types, rtss_event_names, std_dev_list,
initial_effect_list, decay_time_constant_list):

tp_time_trigger = float(tp_time_trigger)
if delay_distribution_name == "LOG_NORMAL_DISTRIBUTION":
delay_distribution = {"Delay_Period_Distribution": "LOG_NORMAL_DISTRIBUTION",
"Delay_Period_Log_Normal_Mu": (
Expand Down Expand Up @@ -677,7 +677,7 @@ def add_ds_vaccpmc(self, campaign, pmc_df, my_ds):
num_iiv_groups = 1

pmc_touchpoints_dict = {}
for i, tp in enumerate(df['pmc_touchpoints']):
for i, tp in enumerate(df[self.pmc_touchpoint_col]):
pmc_touchpoints_dict[f'{i}'] = tp

add_vaccdrug_campaign(campaign, campaign_type='PMC', start_days=list(df[self.pmc_start_col]),
Expand Down Expand Up @@ -838,13 +838,14 @@ def add_all_interventions(campaign, int_suite, my_ds, hs_df=pd.DataFrame(),
if has_irs > 0:
event_list.append('Received_IRS')

if not smc_df[smc_df[int_suite.smc_ds_col] == my_ds].empty:
if addtl_smc_func:
addtl_smc = addtl_smc_func(campaign, smc_df, my_ds)
# has_smc = int_suite.add_ds_smc(cb, smc_df, my_ds) # 'Received_Campaign_Drugs'
has_smc = int_suite.add_ds_vaccsmc(campaign, smc_df, my_ds) # per default use vaccsmc
if has_smc > 0:
event_list = event_list + ['Received_SMC_VaccDrug'] # 'Received_Vehicle'
if not smc_df.empty:
if not smc_df[smc_df[int_suite.smc_ds_col] == my_ds].empty:
if addtl_smc_func:
addtl_smc = addtl_smc_func(campaign, smc_df, my_ds)
# has_smc = int_suite.add_ds_smc(cb, smc_df, my_ds) # 'Received_Campaign_Drugs'
has_smc = int_suite.add_ds_vaccsmc(campaign, smc_df, my_ds) # per default use vaccsmc
if has_smc > 0:
event_list = event_list + ['Received_SMC_VaccDrug'] # 'Received_Vehicle'

if not itn_df.empty:
has_itn = int_suite.add_ds_itns(campaign, itn_df, my_ds)
Expand Down
10 changes: 5 additions & 5 deletions snt/support_files/malaria_vaccdrug_campaigns.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def add_vacc_smc(campaign, start_days, coverages, target_group: dict = None,
vaccine_initial_effect=vacc_initial_effect,
vaccine_box_duration=vacc_box_duration,
vaccine_decay_time_constant=vacc_decay_duration / math.log(2),
efficacy_is_multiplicative=False,
efficacy_is_multiplicative=True,
broadcast_event=receiving_vaccine_event)

return {'smc_cov': sum(coverages) / len(coverages),
Expand Down Expand Up @@ -521,7 +521,7 @@ def add_vaccdrug_pmc(campaign, start_days: list, coverages: list,
vaccine_initial_effect=vaccine_initial_effect,
vaccine_box_duration=vaccine_box_duration,
vaccine_decay_time_constant=vaccine_decay_duration / math.log(2),
efficacy_is_multiplicative=False
efficacy_is_multiplicative=True
)
else:
add_triggered_vaccine(campaign,
Expand All @@ -535,7 +535,7 @@ def add_vaccdrug_pmc(campaign, start_days: list, coverages: list,
vaccine_initial_effect=vaccine_initial_effect,
vaccine_box_duration=vaccine_box_duration,
vaccine_decay_time_constant=vaccine_decay_duration / math.log(2),
efficacy_is_multiplicative=False
efficacy_is_multiplicative=True
)

return {'pmc_cov': sum(coverages) / len(coverages),
Expand Down Expand Up @@ -628,7 +628,7 @@ def add_vacc_pmc(campaign, start_days: list, coverages: list, target_group: dict
vaccine_initial_effect=vaccine_initial_effect,
vaccine_box_duration=vaccine_box_duration,
vaccine_decay_time_constant=vaccine_decay_duration / math.log(2),
efficacy_is_multiplicative=False
efficacy_is_multiplicative=True
)

else:
Expand All @@ -645,7 +645,7 @@ def add_vacc_pmc(campaign, start_days: list, coverages: list, target_group: dict
vaccine_initial_effect=vaccine_initial_effect,
vaccine_box_duration=vaccine_box_duration,
vaccine_decay_time_constant=vaccine_decay_duration / math.log(2),
efficacy_is_multiplicative=False
efficacy_is_multiplicative=True
)

return {'pmc_cov': sum(coverages) / len(coverages),
Expand Down

0 comments on commit 916e159

Please sign in to comment.