# \donttest{
# set country code
country_codeiso <- "GMB"
set.seed(123)
# Set parameters for simulation
total_population <- 266
urban_proportion <- 0.602
total_coords <- 266
lon_range <- c(-16.802, -13.849)
lat_range <- c(13.149, 13.801)
mean_web_x <- -1764351
mean_web_y <- 1510868
# Simulate processed survey dataset for Gambia
df_gambia <- NULL
df_gambia$age_param_data <- dplyr::tibble(
country = "Gambia",
country_code_iso3 = "GMB",
country_code_dhs = "GM",
year_of_survey = 2024,
id_coords = rep(1:total_coords, length.out = total_population),
lon = runif(total_population, lon_range[1], lon_range[2]),
lat = runif(total_population, lat_range[1], lat_range[2]),
web_x = rnorm(total_population, mean_web_x, 50000),
web_y = rnorm(total_population, mean_web_y, 50000),
log_scale = rnorm(total_population, 2.82, 0.2),
log_shape = rnorm(total_population, 0.331, 0.1),
urban = rep(c(1, 0), c(
round(total_population * urban_proportion),
total_population - round(total_population * urban_proportion)
)),
b1 = rnorm(total_population, 0.0142, 0.002),
c = rnorm(total_population, -0.00997, 0.001),
b2 = rnorm(total_population, 0.00997, 0.002),
nsampled = sample(180:220, total_population, replace = TRUE)
)
# Create temp directory with normalized path
tf <- file.path(tempdir(), "test_env")
dir.create(tf, recursive = TRUE, showWarnings = FALSE)
tf <- normalizePath(tf, winslash = "/", mustWork = FALSE)
AgePopDenom::init(
r_script_name = "full_pipeline.R",
cpp_script_name = "model.cpp",
path = tf,
open_r_script = FALSE
)
# save as processed dhs data
saveRDS(
df_gambia,
file = file.path(
tf, "01_data", "1a_survey_data", "processed",
"dhs_pr_records_combined.rds"
) |>
normalizePath(winslash = "/", mustWork = FALSE)
)
# Download shapefiles
download_shapefile(
country_codes = country_codeiso,
dest_file = file.path(
tf, "01_data", "1c_shapefiles",
"district_shape.gpkg"
) |>
normalizePath(winslash = "/", mustWork = FALSE)
)
# Download population rasters from worldpop
download_pop_rasters(
country_codes = country_codeiso,
dest_dir = file.path(tf, "01_data", "1b_rasters", "pop_raster") |>
normalizePath(winslash = "/", mustWork = FALSE)
)
# Extract urban extent raster
extract_afurextent(
dest_dir = file.path(tf, "01_data", "1b_rasters", "urban_extent") |>
normalizePath(winslash = "/", mustWork = FALSE)
)
# Modelling --------------------------------------------------------------
run_full_workflow(
country_code = country_codeiso,
survey_data_path = file.path(
tf, "01_data", "1a_survey_data", "processed"
) |>
normalizePath(winslash = "/", mustWork = FALSE),
survey_data_suffix = "dhs_pr_records_combined.rds",
shape_path = file.path(
tf, "01_data", "1c_shapefiles"
) |>
normalizePath(winslash = "/", mustWork = FALSE),
shape_suffix = "district_shape.gpkg",
pop_raster_path = file.path(
tf, "01_data", "1b_rasters", "pop_raster"
) |>
normalizePath(winslash = "/", mustWork = FALSE),
pop_raster_suffix = "_ppp_2020_constrained.tif",
ur_raster_path = file.path(
tf, "01_data", "1b_rasters", "urban_extent"
) |>
normalizePath(winslash = "/", mustWork = FALSE),
ur_raster_suffix = "afurextent.asc",
pred_save_file = FALSE,
raster_width = 2500,
raster_height = 2000,
raster_resolution = 300,
save_raster = TRUE,
pyramid_line_color = "#67000d",
pyramid_fill_high = "#fee0d2",
pyramid_fill_low = "#a50f15",
pyramid_caption = paste0(
"Note: Total population includes ",
"ages 99+, pyramid shows ages 0-99"
),
generate_pop_raster = TRUE,
output_paths = list(
model = file.path(tf, "03_outputs", "3a_model_outputs"),
plot = file.path(tf, "03_outputs", "3b_visualizations"),
raster = file.path(tf, "03_outputs", "3c_raster_outputs"),
table = file.path(tf, "03_outputs", "3c_table_outputs"),
compiled = file.path(tf, "03_outputs", "3d_compiled_results"),
excel = file.path(
tf, "03_outputs", "3d_compiled_results",
"age_pop_denom_compiled.xlsx"
),
log = file.path(
tf, "03_outputs", "3a_model_outputs", "modelling_log.rds"
)
) |> lapply(\(x) normalizePath(x, winslash = "/", mustWork = FALSE)),
model_params = list(
cell_size = 5000,
n_sim = 10,
ignore_cache = FALSE,
age_range = c(0, 1),
age_interval = 1,
return_prop = TRUE,
scale_outcome = "log_scale",
shape_outcome = "log_shape",
covariates = "urban",
cpp_script = file.path(tf, "02_scripts", "model") |>
normalizePath(winslash = "/", mustWork = FALSE),
control_params = list(trace = 2),
manual_params = NULL,
verbose = TRUE
),
return_results = FALSE,
n_cores = 1
)
# }
Run the code above in your browser using DataLab