Skip to content

Commit

Permalink
do only check existence of bau when running checkCfg
Browse files Browse the repository at this point in the history
  • Loading branch information
orichters committed Sep 3, 2024
1 parent 99f33c7 commit 3b5f014
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- plastic waste by default does not lag plastics production by ten years
anymore; can be re-activated using `cm_wastelag`
- moved to edgeTransport 2.0 version [[#1749](https://github.com/remindmodel/remind/pull/1749)]
- **scripts** in readCheckScenarioConfig(), do not automatically remove path_gdx_bau if allegedly 'not needed'
[[#1809](https://github.com/remindmodel/remind/pull/1809)]

### added
- **50_damages**, **51_internalizeDamages** add KotzWenz realization based on Kotz & Wenz (2024)
Expand Down
38 changes: 16 additions & 22 deletions scripts/start/readCheckScenarioConfig.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,31 +97,25 @@ readCheckScenarioConfig <- function(filename, remindPath = ".", testmode = FALSE
", no column path_gdx_refpolicycost for policy cost comparison found, using path_gdx_ref instead.")
message(msg)
}
if ("path_gdx_bau" %in% names(scenConf)) {
# fix if bau given despite not needed. needBau is defined in needBau.R
# initialize vector with FALSE everywhere and turn elements to TRUE if a scenario config row setting matches a needBau element
scenNeedsBau <- rep(FALSE, nrow(scenConf))
for (n in intersect(names(needBau), names(scenConf))) {
scenNeedsBau <- scenNeedsBau | scenConf[[n]] %in% needBau[[n]]
}
BAUbutNotNeeded <- ! is.na(scenConf$path_gdx_bau) & ! (scenNeedsBau)
if (sum(BAUbutNotNeeded) > 0 && ! grepl("scenario_config_coupled", filename)) {
message("In ", sum(BAUbutNotNeeded), " scenarios, 'path_gdx_bau' is not empty although no realization is selected that needs it.\n",
"Either adjust 'scripts/start/needBau.R' or set 'path_gdx_bau' to NA to avoid unnecessary dependencies to other runs for:\n",
paste(rownames(scenConf)[BAUbutNotNeeded], collapse = ", "))
}
# fail if bau not given but needed
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
scenConf[, names(path_gdx_list)[! names(path_gdx_list) %in% names(scenConf)]] <- NA

# check if path_gdx_bau is needed, based on needBau.R
# initialize vector with FALSE everywhere and turn elements to TRUE if a scenario config row setting matches a needBau element
scenNeedsBau <- rep(FALSE, nrow(scenConf))
for (n in intersect(names(needBau), names(scenConf))) {
scenNeedsBau <- scenNeedsBau | scenConf[[n]] %in% needBau[[n]]
}
# fail if bau not given but needed
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 = " "))
}

# collect errors
errorsfound <- length(colduplicates) + sum(toolong) + sum(regionname) + sum(nameisNA) + sum(illegalchars) + whitespaceErrors + copyConfigFromErrors + pathgdxerrors + missingRealizations

Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test_01-readCheckScenarioConfig.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ test_that("readCheckScenarioConfig fails on error-loaden config", {
expect_match(w, "Do not use 'NA' as scenario name", all = FALSE, fixed = TRUE)
expect_match(w, "For module carbonprice.*notNDC_but_has_path_gdx_bau", all = FALSE, fixed = FALSE)
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, "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

0 comments on commit 3b5f014

Please sign in to comment.