diff --git a/datasetup/build_US_setup.R b/datasetup/build_US_setup.R index 2943a3b2a..0b281258f 100644 --- a/datasetup/build_US_setup.R +++ b/datasetup/build_US_setup.R @@ -119,6 +119,7 @@ census_data <- census_data %>% terr_census_data <- arrow::read_parquet(file.path(opt$p,"datasetup", "usdata","united-states-commutes","census_tracts_island_areas_2010.gz.parquet")) census_data <- terr_census_data %>% + dplyr::rename(subpop = geoid) %>% dplyr::filter(length(filterUSPS) == 0 | ((USPS %in% filterUSPS) & !(USPS %in% census_data)))%>% rbind(census_data) @@ -219,3 +220,4 @@ if(state_level & !file.exists(paste0(config$data_path, "/", config$subpop_setup$ ## @endcond + diff --git a/flepimop/R_packages/config.writer/NAMESPACE b/flepimop/R_packages/config.writer/NAMESPACE index 4ce6d3a33..db027d3f4 100644 --- a/flepimop/R_packages/config.writer/NAMESPACE +++ b/flepimop/R_packages/config.writer/NAMESPACE @@ -25,7 +25,7 @@ export(print_interventions) export(print_outcomes) export(print_seeding) export(print_seir) -export(print_spatial_setup) +export(print_subpop_setup) export(print_value) export(print_value1) export(process_npi_ca) diff --git a/flepimop/gempyor_pkg/docs/Rinterface.Rmd b/flepimop/gempyor_pkg/docs/Rinterface.Rmd index af1d61d44..03806aa37 100644 --- a/flepimop/gempyor_pkg/docs/Rinterface.Rmd +++ b/flepimop/gempyor_pkg/docs/Rinterface.Rmd @@ -55,7 +55,7 @@ gempyor_simulator <- gempyor$GempyorSimulator( npi_scenario="inference", # NPIs scenario to use outcome_scenario="med", # Outcome scenario to use stoch_traj_flag=FALSE, - spatial_path_prefix = '../tests/npi/' # prefix where to find the folder indicated in spatial_setup + spatial_path_prefix = '../tests/npi/' # prefix where to find the folder indicated in subpop_setup ) ``` Here we specified that the data folder specified in the config lies in the `test/npi/` folder, not in the current directory. The only mandatory arguments is the `config_path`. The default values of the other arguments are diff --git a/flepimop/gempyor_pkg/docs/Rinterface.html b/flepimop/gempyor_pkg/docs/Rinterface.html index 26cd8f05c..16c2883a9 100644 --- a/flepimop/gempyor_pkg/docs/Rinterface.html +++ b/flepimop/gempyor_pkg/docs/Rinterface.html @@ -255,7 +255,7 @@
Here we specify that the data folder specified in the config lies in the test/npi/
folder, not in the current directory. The only mandatory arguments is the config_path
. The default values of the other arguments are
run_id="test_run_id", # an ommited argument will be left at its default value
diff --git a/flepimop/gempyor_pkg/docs/integration_benchmark.ipynb b/flepimop/gempyor_pkg/docs/integration_benchmark.ipynb
index 22cb46d6c..83da8764c 100644
--- a/flepimop/gempyor_pkg/docs/integration_benchmark.ipynb
+++ b/flepimop/gempyor_pkg/docs/integration_benchmark.ipynb
@@ -121,7 +121,7 @@
"source": [
"config.set_file(config_path)\n",
"\n",
- "spatial_config = config[\"spatial_setup\"]\n",
+ "spatial_config = config[\"subpop_setup\"]\n",
"spatial_base_path = pathlib.Path(\"../../COVID19_USA/\" + config[\"data_path\"].get())\n",
"npi_scenario = npi_scenario\n",
"outcome_scenario = outcome_scenario\n",
@@ -200,7 +200,7 @@
"\n",
"s = setup.Setup(\n",
" setup_name=config[\"name\"].get() + \"_\" + str(npi_scenario),\n",
- " spatial_setup=subpopulation_structure.SubpopulationStructure(\n",
+ " subpop_setup=subpopulation_structure.SubpopulationStructure(\n",
" setup_name=config[\"setup_name\"].get(),\n",
" geodata_file=spatial_base_path / spatial_config[\"geodata\"].get(),\n",
" mobility_file=spatial_base_path / spatial_config[\"mobility\"].get(),\n",
diff --git a/flepimop/gempyor_pkg/docs/integration_doc.ipynb b/flepimop/gempyor_pkg/docs/integration_doc.ipynb
index c9cec9c83..b2a816b10 100644
--- a/flepimop/gempyor_pkg/docs/integration_doc.ipynb
+++ b/flepimop/gempyor_pkg/docs/integration_doc.ipynb
@@ -63,7 +63,7 @@
" npi_scenario=\"inference\", # NPIs scenario to use\n",
" outcome_scenario=\"med\", # Outcome scenario to use\n",
" stoch_traj_flag=False,\n",
- " spatial_path_prefix=\"../tests/npi/\", # prefix where to find the folder indicated in spatial_setup$\n",
+ " spatial_path_prefix=\"../tests/npi/\", # prefix where to find the folder indicated in subpop_setup$\n",
")\n",
"config.clear()\n",
"config.read(user=False)\n",
diff --git a/flepimop/gempyor_pkg/docs/interface.ipynb b/flepimop/gempyor_pkg/docs/interface.ipynb
index 0e0e1d2c7..a22910e85 100644
--- a/flepimop/gempyor_pkg/docs/interface.ipynb
+++ b/flepimop/gempyor_pkg/docs/interface.ipynb
@@ -54,7 +54,7 @@
" npi_scenario=\"inference\", # NPIs scenario to use\n",
" outcome_scenario=\"med\", # Outcome scenario to use\n",
" stoch_traj_flag=False,\n",
- " spatial_path_prefix=\"../tests/npi/\", # prefix where to find the folder indicated in spatial_setup$\n",
+ " spatial_path_prefix=\"../tests/npi/\", # prefix where to find the folder indicated in subpop_setup$\n",
")"
]
},
diff --git a/flepimop/gempyor_pkg/tests/seir/interface.ipynb b/flepimop/gempyor_pkg/tests/seir/interface.ipynb
index cde1ad0bd..5e1b141b3 100644
--- a/flepimop/gempyor_pkg/tests/seir/interface.ipynb
+++ b/flepimop/gempyor_pkg/tests/seir/interface.ipynb
@@ -54,7 +54,7 @@
" npi_scenario=\"inference\", # NPIs scenario to use\n",
" outcome_scenario=\"med\", # Outcome scenario to use\n",
" stoch_traj_flag=False,\n",
- " spatial_path_prefix=\"../tests/npi/\", # prefix where to find the folder indicated in spatial_setup$\n",
+ " spatial_path_prefix=\"../tests/npi/\", # prefix where to find the folder indicated in subpop_setup$\n",
")"
]
},
diff --git a/flepimop/main_scripts/create_seeding.R b/flepimop/main_scripts/create_seeding.R
index 47fb7758c..ce6e321f5 100644
--- a/flepimop/main_scripts/create_seeding.R
+++ b/flepimop/main_scripts/create_seeding.R
@@ -295,7 +295,7 @@ all_times <- lubridate::ymd(config$start_date) +
seq_len(lubridate::ymd(config$end_date) - lubridate::ymd(config$start_date))
geodata <- flepicommon::load_geodata_file(
- file.path(config$data_path, config$spatial_setup$geodata),
+ file.path(config$data_path, config$subpop_setup$geodata),
5,
"0",
TRUE
diff --git a/postprocessing/model_output_notebook.Rmd b/postprocessing/model_output_notebook.Rmd
index 4ed788dcb..9122c0624 100644
--- a/postprocessing/model_output_notebook.Rmd
+++ b/postprocessing/model_output_notebook.Rmd
@@ -55,7 +55,7 @@ import_model_outputs <-
"incidD",
# lim_hosp = c("date",
# sapply(1:length(names(config$inference$statistics)), function(i) purrr::flatten(config$inference$statistics[i])$sim_var),
- config$spatial_setup$nodenames)) {
+ config$subpop_setup$nodenames)) {
# "subpop")){
dir_ <- paste0(
scn_dir,
@@ -118,7 +118,7 @@ print(res_dir)
# Pull in subpop data
geodata <-
setDT(read.csv(file.path(
- config$data_path, config$spatial_setup$geodata
+ config$data_path, config$subpop_setup$geodata
)))
# geodata <- setDT(read.csv(file.path(config$data_path, config$subpop_setup$geodata)))
@@ -197,7 +197,7 @@ print(
```{r snpi, cache = TRUE, fig.dim = c(8,20), results='hide',fig.keep='all'}
# read in model outputs
snpi_outputs_global <- setDT(import_model_outputs(res_dir, "snpi", 'global', 'final'))
-node_names <- unique(snpi_outputs_global %>% .[ , get(config$spatial_setup$nodenames)])
+node_names <- unique(snpi_outputs_global %>% .[ , get(config$subpop_setup$nodenames)])
# node_names <- unique(sort(snpi_outputs_global %>% .[ , "subpop"]))
node_names <- c(node_names[str_detect(node_names,",")], node_names[!str_detect(node_names,",")]) # sort so that multiple subpops are in front
@@ -287,10 +287,10 @@ outcome_vars_ <- outcome_vars[!str_detect(outcome_vars, "_")]
# read in model outputs
hosp_outputs_global <- setDT(import_model_outputs(res_dir, "hosp", 'global', 'final',
- lim_hosp = c("date", config$spatial_setup$nodenames, outcome_vars_)))
+ lim_hosp = c("date", config$subpop_setup$nodenames, outcome_vars_)))
# lim_hosp = c("date", "subpop", outcome_vars_)))
# num_nodes <- length(unique(hosp_outputs_global %>% .[,"subpop"]))
-num_nodes <- length(unique(hosp_outputs_global %>% .[,get(config$spatial_setup$nodenames)]))
+num_nodes <- length(unique(hosp_outputs_global %>% .[,get(config$subpop_setup$nodenames)]))
sim_sample <- sample(unique(hosp_outputs_global$slot),1)
@@ -319,7 +319,7 @@ for(i in 1:length(outcome_vars_)){
aes(lubridate::as_date(date), value), color = 'firebrick', alpha = 0.1)
} +
# facet_wrap(~subpop, scales = 'free') +
- facet_wrap(~get(config$spatial_setup$nodenames), scales = 'free') +
+ facet_wrap(~get(config$subpop_setup$nodenames), scales = 'free') +
labs(x = 'date', y = outcome_vars_[i], title = "Incidence") +
theme_classic() + theme_small
)
@@ -341,7 +341,7 @@ for(i in 1:length(outcome_vars_)){
aes(lubridate::as_date(date), csum), color = 'firebrick', alpha = 0.1)
} +
# facet_wrap(~subpop, scales = 'free') +
- facet_wrap(~get(config$spatial_setup$nodenames), scales = 'free') +
+ facet_wrap(~get(config$subpop_setup$nodenames), scales = 'free') +
labs(x = 'date', y = paste0("cumulative ", outcome_vars_[i]), title = "Cumulative") +
theme_classic() + theme_small
)
@@ -373,7 +373,7 @@ if(length(unique(hosp_outputs_global$slot)) > 1){
hosp_outputs_global %>%
.[, date := lubridate::as_date(date)] %>%
# .[, as.list(quantile(get(outcome_vars_[i]), c(.05, .25, .5, .75, .95), na.rm = TRUE, names = FALSE)), by = c("date", "subpop")] %>%
- .[, as.list(quantile(get(outcome_vars_[i]), c(.05, .25, .5, .75, .95), na.rm = TRUE, names = FALSE)), by = c("date", config$spatial_setup$nodenames)] %>%
+ .[, as.list(quantile(get(outcome_vars_[i]), c(.05, .25, .5, .75, .95), na.rm = TRUE, names = FALSE)), by = c("date", config$subpop_setup$nodenames)] %>%
setnames(., paste0("V", 1:5), paste0("q", c(.05,.25,.5,.75,.95))) %>%
ggplot() +
geom_ribbon(aes(x = date, ymin = q0.05, ymax = q0.95), alpha = 0.1) +
@@ -386,7 +386,7 @@ if(length(unique(hosp_outputs_global$slot)) > 1){
aes(lubridate::as_date(date), value), color = 'firebrick', alpha = 0.1)
} +
# facet_wrap(~subpop, scales = 'free') +
- facet_wrap(~get(config$spatial_setup$nodenames), scales = 'free') +
+ facet_wrap(~get(config$subpop_setup$nodenames), scales = 'free') +
labs(x = 'date', y = outcome_vars_[i], title = "Incidence") +
theme_classic()+ theme_small
)
@@ -411,7 +411,7 @@ if(length(unique(hosp_outputs_global$slot)) > 1){
aes(lubridate::as_date(date), csum), color = 'firebrick', alpha = 0.1)
} +
# facet_wrap(~subpop, scales = 'free') +
- facet_wrap(~get(config$spatial_setup$nodenames), scales = 'free') +
+ facet_wrap(~get(config$subpop_setup$nodenames), scales = 'free') +
labs(x = 'date', y = paste0("cumulative ", outcome_vars_[i]), title = "Cumulative") +
theme_classic() + theme_small
)
@@ -431,7 +431,7 @@ if(length(unique(hosp_outputs_global$slot)) > 1){
```{r hnpi, cache = TRUE, fig.dim = c(8,20), results='hide',fig.keep='all'}
# read in model outputs
hnpi_outputs_global <- setDT(import_model_outputs(res_dir, "hnpi", 'global', 'final'))
-node_names <- unique(hnpi_outputs_global %>% .[ , get(config$spatial_setup$nodenames)])
+node_names <- unique(hnpi_outputs_global %>% .[ , get(config$subpop_setup$nodenames)])
# node_names <- unique(sort(hnpi_outputs_global %>% .[ , "subpop"]))
node_names <- c(node_names[str_detect(node_names,",")], node_names[!str_detect(node_names,",")]) # sort so that multiple subpops are in front
@@ -540,7 +540,7 @@ if(inference){
geom_point(data = df_gt,
aes(lubridate::as_date(date), data_var), color = 'firebrick', alpha = 0.1) +
# facet_wrap(~subpop, scales = 'free') +
- facet_wrap(~get(config$spatial_setup$nodenames), scales = 'free') +
+ facet_wrap(~get(config$subpop_setup$nodenames), scales = 'free') +
labs(x = 'date', y = statistics$name, title = "Incidence") +
theme_classic() + theme_small
)
@@ -561,7 +561,7 @@ if(inference){
.[, csum := cumsum(data_var) , by = .(geoid)],
aes(lubridate::as_date(date), csum), color = 'firebrick', alpha = 0.1) +
# facet_wrap(~subpop, scales = 'free') +
- facet_wrap(~get(config$spatial_setup$nodenames), scales = 'free') +
+ facet_wrap(~get(config$subpop_setup$nodenames), scales = 'free') +
labs(x = 'date', y = paste0("cumulative ", statistics$name), title = "Cumulative") +
theme_classic() + theme_small
)
@@ -599,7 +599,7 @@ if(length(unique(hosp_outputs_global$slot)) > 1 & inference){
geom_point(data = df_gt,
aes(lubridate::as_date(date), data_var), color = 'firebrick', alpha = 0.1) +
# facet_wrap(~subpop, scales = 'free') +
- facet_wrap(~get(config$spatial_setup$nodenames), scales = 'free') +
+ facet_wrap(~get(config$subpop_setup$nodenames), scales = 'free') +
labs(x = 'date', y = statistics$name) +
theme_classic() + theme_small
)
@@ -623,7 +623,7 @@ if(length(unique(hosp_outputs_global$slot)) > 1 & inference){
.[, csum := cumsum(data_var) , by = .(geoid)],
aes(lubridate::as_date(date), csum), color = 'firebrick', alpha = 0.1) +
# facet_wrap(~subpop, scales = 'free') +
- facet_wrap(~get(config$spatial_setup$nodenames), scales = 'free') +
+ facet_wrap(~get(config$subpop_setup$nodenames), scales = 'free') +
labs(x = 'date', y = paste0("cumulative ", statistics$name)) +
theme_classic() + theme_small
)
@@ -651,16 +651,16 @@ if(inference){
if(exists("llik")){
llik_rank <- llik %>%
.[, .SD[order(ll)], geoid]
- high_low_llik <- rbindlist(list(data.table(llik_rank, key = eval(config$spatial_setup$nodenames)) %>%
- .[, head(.SD,5), by = eval(config$spatial_setup$nodenames)] %>%
+ high_low_llik <- rbindlist(list(data.table(llik_rank, key = eval(config$subpop_setup$nodenames)) %>%
+ .[, head(.SD,5), by = eval(config$subpop_setup$nodenames)] %>%
.[, llik_bin := "top"],
- data.table(llik_rank, key = eval(config$spatial_setup$nodenames)) %>%
- .[, tail(.SD,5), by = eval(config$spatial_setup$nodenames)]%>%
+ data.table(llik_rank, key = eval(config$subpop_setup$nodenames)) %>%
+ .[, tail(.SD,5), by = eval(config$subpop_setup$nodenames)]%>%
.[, llik_bin := "bottom"])
)
high_low_hosp_llik <- hosp_outputs_global %>%
- .[high_low_llik, on = c("slot", eval(config$spatial_setup$nodenames))]
+ .[high_low_llik, on = c("slot", eval(config$subpop_setup$nodenames))]
hosp_llik_plots <- lapply(unique(high_low_hosp_llik %>% .[, geoid]),
function(e){