WorldDev.2026.1073278 / code /02_run_main_ate_optional.R
cjerzak's picture
Upload 24 files
748dd7d verified
#!/usr/bin/env Rscript
file_arg <- grep("^--file=", commandArgs(FALSE), value = TRUE)
script_path <- sub("^--file=", "", file_arg[[1]])
source(file.path(dirname(normalizePath(script_path, mustWork = FALSE)), "common.R"))
root <- set_replication_root()
args <- commandArgs(trailingOnly = TRUE)
if (length(args) == 0) {
stop("Pass one or more outer-sequence row indices. Example: Rscript code/02_run_main_ate_optional.R 1")
}
resave_tfrecords <- parse_env_flag("IMAGEDECONFOUND_RESAVE_TFRECORDS", default = FALSE)
tfrecord_home <- resolve_external_path("IMAGEDECONFOUND_TFRECORD_HOME", "external_artifacts/tfrecords")
image_root <- resolve_external_path("IMAGEDECONFOUND_IMAGE_ROOT", "external_artifacts/images/dhs_tifs_5k_3yr")
ensure_dir(tfrecord_home)
if (!resave_tfrecords) {
tfrecord_n <- length(list.files(tfrecord_home, pattern = "\\.tfrecord$", full.names = TRUE))
if (tfrecord_n == 0) {
stop(
"No TFRecord files were found in ", tfrecord_home, ". ",
"Either place the required TFRecords there or rerun with IMAGEDECONFOUND_RESAVE_TFRECORDS=true ",
"after downloading the excluded image files locally."
)
}
} else if (!dir.exists(image_root)) {
stop(
"IMAGEDECONFOUND_RESAVE_TFRECORDS=true but the image directory does not exist: ",
image_root
)
}
run_replication_script(
"code/lib/call_CI_Conf_5k_3yr.R",
overrides = list(
SAVE_RESULTS_FOLDER_OVERRIDE = "per_run_csv/Epoch5EarlyStopNewTreatDefLabelS_Run2",
X_APPROACH_OPTIONS_OVERRIDE = c(
"noX", "onlyX", "onlyFE", "onlyXandFE",
"withX", "withFE", "withXandFE"
),
REQUIRE_EXPLICIT_OUTER_SEQ = TRUE,
TFRECORD_HOME_OVERRIDE = tfrecord_home,
IMAGE_ROOT_OVERRIDE = image_root,
RESAVE_TFRECORDS_OVERRIDE = resave_tfrecords
)
)