Skip to content

Commit

Permalink
Merge pull request #211 from HopkinsIDD/SL_small_fixes
Browse files Browse the repository at this point in the history
Misc fixes during R18
  • Loading branch information
shauntruelove authored May 7, 2024
2 parents db69937 + dab0254 commit ca0a720
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
2 changes: 1 addition & 1 deletion batch/inference_job_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def autodetect_params(config, data_path, *, num_jobs=None, sims_per_job=None, nu
print(f"Setting number of blocks to {num_blocks} [via num_blocks (-k) argument]")
print(f"Setting sims per job to {sims_per_job} [via {iterations_per_slot} iterations_per_slot in config]")
else:
if config["data_path"]:
if "data_path" in config:
raise ValueError("The config has a data_path section. This is no longer supported.")
geodata_fname = pathlib.Path(data_path) / config["subpop_setup"]["geodata"]
with open(geodata_fname) as geodata_fp:
Expand Down
10 changes: 5 additions & 5 deletions flepimop/R_packages/flepiconfig/R/create_config_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ set_npi_params <- function(npi_name = "waning_npi",
param_name = "epsilon",
npi_category = "universal_npi",
affected_subpops = "all",
spatial_groups = NULL,
subpop_groups = NULL,
sim_start_date=as.Date("2020-01-01"),
sim_end_date=Sys.Date()+60,
modifier_method = "SinglePeriodModifier",
Expand All @@ -41,16 +41,16 @@ set_npi_params <- function(npi_name = "waning_npi",
p_mean = 0, p_sd = 0.05, p_a = -1, p_b = 1 ){

# check that universal npi was implemented correctly
if (npi_category == "universal_npi" & is.null(spatial_groups)){
spatial_groups <- "all"
if (npi_category == "universal_npi" & is.null(subpop_groups)){
subpop_groups <- "all"
}

sim_start_date <- as.Date(sim_start_date)
sim_end_date <- as.Date(sim_end_date)

local_var <- dplyr::tibble(USPS = "",
subpop = affected_subpops,
spatial_groups = spatial_groups,
subpop_groups = subpop_groups,
name = npi_name,
type = "transmission",
category = npi_category,
Expand All @@ -71,7 +71,7 @@ set_npi_params <- function(npi_name = "waning_npi",
pert_b = p_b) %>%
dplyr::mutate(pert_dist = ifelse(inference, as.character(pert_dist), NA_character_),
dplyr::across(pert_mean:pert_b, ~ifelse(inference, as.numeric(.x), NA_real_))) %>%
dplyr::select(USPS, subpop, spatial_groups, start_date, end_date, name, modifier_method, type, category, parameter, baseline_scenario,
dplyr::select(USPS, subpop, subpop_groups, start_date, end_date, name, modifier_method, type, category, parameter, baseline_scenario,
tidyselect::starts_with("value_"), tidyselect::starts_with("pert_"))

return(local_var)
Expand Down
48 changes: 28 additions & 20 deletions flepimop/R_packages/flepiconfig/R/yaml_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ collapse_intervention<- function(dat){
dplyr::group_by(dplyr::across(-period)) %>%
dplyr::summarize(period = paste0(period, collapse="\n "))

if (exists("mtr$spatial_groups") && (!all(is.na(mtr$spatial_groups)) & !all(is.null(mtr$spatial_groups)))) {
if (exists("mtr$subpop_groups") && (!all(is.na(mtr$subpop_groups)) & !all(is.null(mtr$subpop_groups)))) {

mtr <- mtr %>%
dplyr::group_by(dplyr::across(-subpop)) %>%
Expand Down Expand Up @@ -1335,9 +1335,17 @@ print_outcomes <- function (resume_modifier = NULL,
incidC_pert <- ""
pert_repeat <- prod(compartment_tract_length[-1], na.rm = TRUE)

variant_strata = compartment_tract_list$variant_strata
vaccine_strata = compartment_tract_list$vaccine_strata
age_strata = compartment_tract_list$age_strata
variant_strata = `$`(compartment_tract_list, 'variant')
vaccine_strata = `$`(compartment_tract_list, 'vacc')
age_strata = `$`(compartment_tract_list, 'age')
strata_names <- names(compartment_tract_list)
inf_strata_name <- strata_names[grepl('inf', strata_names)]
variant_strata_name <- strata_names[grepl('var', strata_names)]
vacc_strata_name <- strata_names[grepl('vacc', strata_names)]
age_strata_name <- strata_names[grepl('age_', strata_names)]
# variant_strata = compartment_tract_list$variant_strata
# vaccine_strata = compartment_tract_list$vaccine_strata
# age_strata = compartment_tract_list$age_strata

for (i in 1:pert_repeat) {
if (incidC_perturbation) {
Expand Down Expand Up @@ -1405,10 +1413,10 @@ print_outcomes <- function (resume_modifier = NULL,
incidH <- paste0(incidH,
" incidH_", outcomes_base_data$variant_strata[i],
":\n", " source:\n", " incidence:\n",
" infection_stage: \"I1\"\n",
" vaccination_strata: \"", paste0(outcomes_base_data$vacc[i], collapse = "\", \""), "\"\n",
" variant_strata: \"", paste0(outcomes_base_data$variant[i], collapse = "\", \""), "\"\n",
" age_strata: \"", paste0(outcomes_base_data$age_strata[i]), "\"\n",
" ", inf_strata_name, ": \"I1\"\n",
" ", vacc_strata_name, ": \"", paste0(outcomes_base_data$vacc[i], collapse = "\", \""), "\"\n",
" ", variant_strata_name, ": \"", paste0(outcomes_base_data$variant[i], collapse = "\", \""), "\"\n",
" ", age_strata_name, ": \"", paste0(outcomes_base_data$age_strata[i]), "\"\n",
" probability:\n",
if ("incidH" %in% intervention_params) paste0(" modifier_parameter: \"", incidItoHparam, "\"\n"),
print_value(value_dist = incidH_prob_dist,
Expand Down Expand Up @@ -1437,10 +1445,10 @@ print_outcomes <- function (resume_modifier = NULL,
incidD <- paste0(incidD,
" incidD_", outcomes_base_data$variant_strata[i],
":\n", " source:\n", " incidence:\n",
" infection_stage: \"I1\"\n",
" vaccination_strata: \"", paste0(outcomes_base_data$vacc[i], collapse = "\", \""), "\"\n",
" variant_strata: \"", paste0(outcomes_base_data$variant[i], collapse = "\", \""), "\"\n",
" age_strata: \"", paste0(outcomes_base_data$age_strata[i]), "\"\n",
" ", inf_strata_name, ": \"I1\"\n",
" ", vacc_strata_name, ": \"", paste0(outcomes_base_data$vacc[i], collapse = "\", \""), "\"\n",
" ", variant_strata_name, ": \"", paste0(outcomes_base_data$variant[i], collapse = "\", \""), "\"\n",
" ", age_strata_name, ": \"", paste0(outcomes_base_data$age_strata[i]), "\"\n",
" probability:\n",
if ("incidD" %in% intervention_params) paste0(" modifier_parameter: \"", incidItoDparam, "\"\n"),
print_value(value_dist = incidD_prob_dist,
Expand Down Expand Up @@ -1470,10 +1478,10 @@ print_outcomes <- function (resume_modifier = NULL,
" incidC_", outcomes_base_data$variant_strata[i], ":\n",
" source:\n",
" incidence:\n",
" infection_stage: \"I1\"\n",
" vaccination_strata: \"", paste0(outcomes_base_data$vacc[i], collapse = "\", \""), "\"\n",
" variant_strata: \"", paste0(outcomes_base_data$variant[i], collapse = "\", \""), "\"\n",
" age_strata: \"", paste0(outcomes_base_data$age_strata[i]), "\"\n",
" ", inf_strata_name, ": \"I1\"\n",
" ", vacc_strata_name, ": \"", paste0(outcomes_base_data$vacc[i], collapse = "\", \""), "\"\n",
" ", variant_strata_name, ": \"", paste0(outcomes_base_data$variant[i], collapse = "\", \""), "\"\n",
" ", age_strata_name, ": \"", paste0(outcomes_base_data$age_strata[i]), "\"\n",
" probability:\n",
if ("incidC" %in% intervention_params) paste0(" modifier_parameter: \"", incidItoCparam, "\"\n"),
print_value(value_dist = incidC_prob_dist,
Expand All @@ -1492,10 +1500,10 @@ print_outcomes <- function (resume_modifier = NULL,
" incidI_", outcomes_base_data$variant_strata[i], ":\n",
" source:\n",
" incidence:\n",
" infection_stage: \"I1\"\n",
" vaccination_strata: \"", paste0(outcomes_base_data$vacc[i], collapse = "\", \""), "\"\n",
" variant_strata: \"", paste0(outcomes_base_data$variant[i], collapse = "\", \""), "\"\n",
" age_strata: \"", paste0(outcomes_base_data$age_strata[i]), "\"\n",
" ", inf_strata_name, ": \"I1\"\n",
" ", vacc_strata_name, ": \"", paste0(outcomes_base_data$vacc[i], collapse = "\", \""), "\"\n",
" ", variant_strata_name, ": \"", paste0(outcomes_base_data$variant[i], collapse = "\", \""), "\"\n",
" ", age_strata_name, ": \"", paste0(outcomes_base_data$age_strata[i]), "\"\n",
" probability:\n",
if("incidI" %in% intervention_params) paste0(' modifier_parameter: "incidI_total"\n'),
print_value(value_dist = "fixed",
Expand Down

0 comments on commit ca0a720

Please sign in to comment.