Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix path_gdx_bau checks, some more realizations need it #1419

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions scripts/start/readCheckScenarioConfig.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,34 @@ readCheckScenarioConfig <- function(filename, remindPath = ".", testmode = FALSE
}
if ("path_gdx_bau" %in% names(scenConf)) {
# fix if bau given despite not needed
NDC45 <- if ("carbonprice" %in% names(scenConf)) scenConf$carbonprice %in% "NDC" else FALSE
NDC46 <- if ("carbonpriceRegi" %in% names(scenConf)) scenConf$carbonpriceRegi %in% "NDC" else FALSE
noNDCbutBAU <- ! is.na(scenConf$path_gdx_bau) & ! (NDC45 | NDC46)
if (sum(noNDCbutBAU) > 0) {
msg <- paste0("In ", sum(noNDCbutBAU), " scenarios, neither 'carbonprice' nor 'carbonpriceRegi' is set to 'NDC', but 'path_gdx_bau' is not empty.\n",
needBau <- list(welfare = "ineqLognormal",
carbonprice = c("NDC", "diffPriceSameCost"),
carbonpriceRegi = "NDC",
emicapregi = "AbilityToPay")
scenNeedsBau <- rep(FALSE, nrow(scenConf))
for (n in names(needBau)) {
if (n %in% names(scenConf)) {
if (n == "welfare" && "cm_emiscen" %in% names(scenConf)) {
scenNeedsBAU <- scenNeedsBau | (scenConf[[n]] %in% needBau[[n]] & scenConf[["cm_emiscen"]] != 1)
} else {
scenNeedsBau <- scenNeedsBau | scenConf[[n]] %in% needBau[[n]]
}
}
}
BAUbutNotNeeded <- ! is.na(scenConf$path_gdx_bau) & ! (scenNeedsBau)
if (sum(BAUbutNotNeeded) > 0) {
msg <- paste0("In ", sum(BAUbutNotNeeded), " scenarios, 'path_gdx_bau' is not empty although no realization is selected that needs it.\n",
"To avoid unnecessary dependencies to other runs, setting 'path_gdx_bau' to NA.")
message(msg)
scenConf$path_gdx_bau[noNDCbutBAU] <- NA
scenConf$path_gdx_bau[BAUbutNotNeeded] <- NA
}
# fail if bau not given but needed
noBAUbutNDC <- is.na(scenConf$path_gdx_bau) & (NDC45 | NDC46)
if (sum(noBAUbutNDC) > 0) {
pathgdxerrors <- pathgdxerrors + sum(noBAUbutNDC)
warning("In ", sum(noBAUbutNDC), " scenarios, 'carbonprice' or 'carbonpriceRegi' is set to 'NDC' ",
"which requires a reference gdx in 'path_gdx_bau', but it is empty.")
noBAUbutNeeded <- is.na(scenConf$path_gdx_bau) & (scenNeedsBau)
if (sum(noBAUbutNeeded) > 0) {
pathgdxerrors <- pathgdxerrors + sum(noBAUbutNeeded)
warning("In ", sum(noBAUbutNeeded), " scenarios, a reference gdx in 'path_gdx_bau' is needed, but it is empty. ",
"These realizations need it: ",
paste0(names(needBau), ": ", sapply(needBau, paste, collapse = ", "), ".", collapse = " "))
}
}
# make sure every path gdx column exists
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test_01-readCheckScenarioConfig.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ test_that("readCheckScenarioConfig fails on error-loaden config", {
expect_match(w, "contain whitespaces", all = FALSE, fixed = TRUE)
expect_match(w, "scenario names indicated in copyConfigFrom column were not found", all = FALSE, fixed = TRUE)
expect_match(w, "specify in copyConfigFrom column a scenario name defined below in the file", all = FALSE, fixed = TRUE)
expect_match(w, "which requires a reference gdx", all = FALSE, fixed = TRUE)
expect_match(w, "a reference gdx in 'path_gdx_bau'", all = FALSE, fixed = TRUE)
expect_match(w, "Do not use 'NA' as scenario name", all = FALSE, fixed = TRUE)
expect_match(m, "no column path_gdx_refpolicycost for policy cost comparison found, using path_gdx_ref instead", all = FALSE, fixed = TRUE)
expect_match(m, "In 1 scenarios, neither 'carbonprice'", all = FALSE, fixed = TRUE)
expect_match(m, "is not empty although no realization is selected that needs it", all = FALSE, fixed = TRUE)
copiedFromPBS <- c("c_budgetCO2", "path_gdx", "path_gdx_ref")
expect_identical(unlist(scenConf["PBS", copiedFromPBS]),
unlist(scenConf["PBScopy", copiedFromPBS]))
Expand Down
Loading