Skip to content

Commit

Permalink
update spatial_setup to subpop_setup
Browse files Browse the repository at this point in the history
  • Loading branch information
shauntruelove committed Oct 6, 2023
1 parent 4d977cf commit 5ffb9ff
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 29 deletions.
2 changes: 2 additions & 0 deletions datasetup/build_US_setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -219,3 +220,4 @@ if(state_level & !file.exists(paste0(config$data_path, "/", config$subpop_setup$


## @endcond

2 changes: 1 addition & 1 deletion flepimop/R_packages/config.writer/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion flepimop/gempyor_pkg/docs/Rinterface.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion flepimop/gempyor_pkg/docs/Rinterface.html
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ <h3>Building a simulator</h3>
npi_scenario=&quot;inference&quot;, # NPIs scenario to use
outcome_scenario=&quot;med&quot;, # Outcome scenario to use
stoch_traj_flag=FALSE,
spatial_path_prefix = &#39;../tests/npi/&#39; # prefix where to find the folder indicated in spatial_setup
spatial_path_prefix = &#39;../tests/npi/&#39; # prefix where to find the folder indicated in subpop_setup
)</code></pre>
<p>Here we specify that the data folder specified in the config lies in the <code>test/npi/</code> folder, not in the current directory. The only mandatory arguments is the <code>config_path</code>. The default values of the other arguments are</p>
<pre><code> run_id=&quot;test_run_id&quot;, # an ommited argument will be left at its default value
Expand Down
4 changes: 2 additions & 2 deletions flepimop/gempyor_pkg/docs/integration_benchmark.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion flepimop/gempyor_pkg/docs/integration_doc.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion flepimop/gempyor_pkg/docs/interface.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
")"
]
},
Expand Down
2 changes: 1 addition & 1 deletion flepimop/gempyor_pkg/tests/seir/interface.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
")"
]
},
Expand Down
2 changes: 1 addition & 1 deletion flepimop/main_scripts/create_seeding.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 20 additions & 20 deletions postprocessing/model_output_notebook.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
)
Expand All @@ -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
)
Expand Down Expand Up @@ -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) +
Expand All @@ -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
)
Expand All @@ -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
)
Expand All @@ -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
Expand Down Expand Up @@ -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
)
Expand All @@ -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
)
Expand Down Expand Up @@ -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
)
Expand All @@ -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
)
Expand Down Expand Up @@ -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){
Expand Down

0 comments on commit 5ffb9ff

Please sign in to comment.