# dtk analyze compatibility site = sites[0] analyzers = site.analyzers # Restrict to only those params that are initially active params = [p for p in params if p['Dynamic']] plotters = [LikelihoodPlotter(), OptimToolPlotter()] # Setting up our model configuration from templates dir_path = os.path.dirname(os.path.realpath(__file__)) template_files_dir = os.path.join(dir_path, 'Templates') static_files_dir = os.path.join(dir_path, 'Static') demog = DemographicsTemplate.from_file( os.path.join(static_files_dir, 'Rakai_Demographics_With_Properties.json')) demog_pfa = DemographicsTemplate.from_file( os.path.join(template_files_dir, 'PFA_Overlay.json')) demog_acc = DemographicsTemplate.from_file( os.path.join(template_files_dir, 'Accessibility_and_Risk_IP_Overlay.json')) demog_asrt = DemographicsTemplate.from_file( os.path.join(template_files_dir, 'Risk_Assortivity_Overlay.json')) cfg = ConfigTemplate.from_file(os.path.join(template_files_dir, 'config.json')) cpn = make_campaign_template(template_files_dir) # For quick test simulations, this is set to a very low value static_params = {'Base_Population_Scale_Factor': 0.05} cfg.set_params(static_params) cpn.set_params(static_params) # Prepare templates
config.set_param("Enable_Demographics_Builtin", 0, allow_new_parameters=True) # Load the campaigns cpnFT = CampaignTemplate.from_file( os.path.join(plugin_files_dir, 'campaign_western_Kenya.json')) cpnSQ = CampaignTemplate.from_file( os.path.join(plugin_files_dir, 'campaign_western_Kenya.json')) campaigns = {"cpnFT": cpnFT, "cpnSQ": cpnSQ} ###### If your scenarios require choosing among multiple campaign files, load additional files and assign variable names to them: ###### # cpn2 = CampaignTemplate.from_file(os.path.join(plugin_files_dir, 'Campaigns', 'campaign_file_name_2.json')) # cpn3 = CampaignTemplate.from_file(os.path.join(plugin_files_dir, 'Campaigns', 'campaign_file_name_2.json')) # campaigns = {"cpn1":cpn1, "cpn2":cpn2, "cpn3":cpn3} # Load the demographics demog = DemographicsTemplate.from_file( os.path.join(static_files_dir, 'Demographics.json')) demog_pfa = DemographicsTemplate.from_file( os.path.join(plugin_files_dir, 'PFA_Overlay.json')) demog_acc = DemographicsTemplate.from_file( os.path.join(plugin_files_dir, 'Accessibility_and_Risk_IP_Overlay.json')) demog_asrt = DemographicsTemplate.from_file( os.path.join(plugin_files_dir, 'Risk_Assortivity_Overlay.json')) ########################################## ## name and configure the scenarios ## ########################################## # Load the scenarios scenario_header = [ 'Start_Year__KP_PrEP_HIGH_Start_Year', 'Event_Coordinator_Config__KP_PrEP_HIGH_Event.Target_Gender',
# and the system will automatically complete their json path(s). # Any given tag can be repeated in several locations in a file, and even across several files. # # Active templates will be written to the working directly. # # Note, you could easily use a different tag for each file / file type # (config vs campaign vs demographics), but we have not demonstrated that here. cfg = ConfigTemplate.from_file( template_filepath=os.path.join(plugin_files_dir, 'config.json')) # Here is how you set the tag, "__KP", for campaign, demographics, and potentially also config files cpn = CampaignTemplate.from_file(template_filepath=os.path.join( plugin_files_dir, 'campaign.json'), tag='__KP') cpn_outbreak = CampaignTemplate.from_file(template_filepath=os.path.join( plugin_files_dir, 'campaign_outbreak_only.json')) demog_pfa = DemographicsTemplate.from_file( template_filepath=os.path.join(plugin_files_dir, 'pfa_overlay.json')) # Templates Querying # ================== # You can query and obtain values from templates. # Because some parameters can exist in multiple locations, i.e. tagged parameters, get_param return a tuple of (paths, values). # The example below is listing every places where the Start_Year__KP_Seesing_Year appears in the cpn template demo_key = 'Start_Year__KP_Seeding_Year' # the has_param allows to check if a template includes a KP parameter if cpn.has_param(param=demo_key): print("Demo getting values of {}:".format(demo_key)) # get_param returns all the paths and values for the particular KP parameter paths, values = cpn.get_param(param=demo_key) # Print the couple path:value for (path, value) in zip(paths, values): print("\t{}: {}".format(path, value))
cpn7 = CampaignTemplate.from_file( os.path.join(plugin_files_dir, 'Campaigns', 'ART100pct_nodelay.json')) campaigns = { "cpn1": cpn1, "cpn2": cpn2, "cpn3": cpn3, "cpn4": cpn4, "cpn5": cpn5, "cpn6": cpn6, "cpn7": cpn7 } # Load the demographics demog = DemographicsTemplate.from_file( os.path.join(plugin_files_dir, 'Demographics', 'Swaziland_Demographics_With_Properties.json')) demog_pfa = DemographicsTemplate.from_file( os.path.join(plugin_files_dir, 'Demographics', 'PFA_Overlay.json')) demog_acc = DemographicsTemplate.from_file( os.path.join(plugin_files_dir, 'Demographics', 'Accessibility_and_Risk_IP_Overlay.json')) demog_asrt = DemographicsTemplate.from_file( os.path.join(plugin_files_dir, 'Demographics', 'Risk_Assortivity_Overlay.json')) # Load the scenarios scenario_header = ['Scenario', 'Campaign_Template'] scenarios = [['Baseline', "cpn1"]]