Skip to content
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
-

### added
-
- **scripts** Introduce new optional argument to compare scenario scripts ``validationConfig`` to enable plotting validation thresholds from piamValidation directly
into line plots of cs documents.
[[#2493](https://github.com/remindmodel/remind/pull/2493)]

### removed
- **scripts** Drop the `gdxrrw`/`gdx` R dependency from REMIND scripts; GDX writes now use `gamstransfer`-based `quitte::write.gdx`
Expand Down
1 change: 1 addition & 0 deletions scripts/cs2/profiles.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"_TITLE_": "Profiles for compareScenarios2",
"_NOTE_": "Entries on the top level with a name starting with _ are ignored.",
"_DESCRIPTION_": "The top level entries identify the profiles for compareScenarios2 (cs2) when called via 'Rscript output.R'. The sub-entries define the arguments passed to piamPlotComparison::compareScenarios(). See the R help page of this function for the meaning of the arguments. The values of the sub-entries are strings, i.e., they start and end with a double quote. These strings will be evaluated as R-code. Use single quotes inside these expressions when quotes are needed. The expressions may contain a variable named '.'. It refers to the value of the variable before applying the profile, e.g., setting outputFile to paste0(., '-suffix') will add a suffix to the file name. For more details, see 'scripts/cs2/run_compareScenarios2.R' and 'output/comparison/compareScenarios2.R'.",
"_VALIDATION_": "A profile may set validationConfig (name of or path to a piamValidation config, e.g. \"'default'\") to show validation thresholds as colored background bands in line plots. Alternatively, pass --validationConfig=<name> on the command line.",
"default": {
"projectLibrary": "'remind2'"
},
Expand Down
11 changes: 8 additions & 3 deletions scripts/cs2/run_compareScenarios2.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@
library(piamPlotComparison)

if (!exists("source_include")) {
lucode2::readArgs("outputdirs", "outFileName", "profileName", "aliases", "sections")
lucode2::readArgs("outputdirs", "outFileName", "profileName", "aliases", "sections", "validationConfig")
}
if (!exists("aliases")) { aliases <- NULL }
if (!exists("sections")) { sections <- "all" }
if (!exists("validationConfig")) { validationConfig <- NULL }

run_compareScenarios2 <- function(
outputdirs,
outFileName,
profileName,
aliases,
sections
sections,
validationConfig
) {

stopifnot(length(profileName) == 1 && is.character(profileName) && !is.na(profileName))
Expand Down Expand Up @@ -60,6 +62,9 @@ run_compareScenarios2 <- function(
sections = sections
)

# show piamValidation thresholds in line plots, can be overwritten by profiles
args$validationConfig <- validationConfig

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put that directly in the definition of the args aboce

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that would break backwards compatibility, I'd rather keep it here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding it to the definition of args directly above does not change the behavior

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it does, if the argument is NULL, it would still create args$validationConfig if created in the list, while args$validationConfig <- NULL will not create it. Older versions will not expect that arg and throw an error in the first case.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I learned another weird quirk of R today


# Load cs2 profile and change args.
message("Applying profile ", profileName)
profile <- profiles[[profileName]]
Expand Down Expand Up @@ -99,4 +104,4 @@ run_compareScenarios2 <- function(
message("Done!\n")
}

run_compareScenarios2(outputdirs, outFileName, profileName, aliases, sections)
run_compareScenarios2(outputdirs, outFileName, profileName, aliases, sections, validationConfig)
15 changes: 12 additions & 3 deletions scripts/output/comparison/compareScenarios2.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#' @param sections List of section numbers to be included in the PDF
#' separated by commas. Default: "all".
#' Examples: --sections=2 --sections=2,3
#' @param validationConfig Name of or path to a piamValidation config. If
#' given, validation thresholds are shown as colored background bands in
#' line plots. Example: --validationConfig=default



Expand Down Expand Up @@ -48,7 +51,8 @@ startComp <- function(
nameCore,
profileName,
aliases,
sections
sections,
validationConfig
) {
if (!exists("slurmConfig")) {
slurmConfig <- "--qos=standby"
Expand Down Expand Up @@ -77,6 +81,7 @@ startComp <- function(
" --outFileName=", shQuote(outFileName),
" --aliases=", shQuote(paste(aliases, collapse = ",")),
" --sections=", shQuote(paste(sections, collapse = ",")),
if (!is.null(validationConfig)) paste0(" --validationConfig=", shQuote(validationConfig)),
Comment thread
pweigmann marked this conversation as resolved.
"\"")
cat(clcom, "\n")
system(clcom)
Expand All @@ -97,11 +102,14 @@ startComp <- function(
# Load cs2 profiles.
profiles <- piamPlotComparison::getCs2Profiles()

lucode2::readArgs("profileNames", "sections")
lucode2::readArgs("profileNames", "sections", "validationConfig")

if (! exists("sections")) {
sections = "all"
}
if (! exists("validationConfig")) {
validationConfig <- NULL
}

# Let user choose cs2 profile(s).
profileNamesDefault <- determineDefaultProfiles(outputdirs[1])
Expand Down Expand Up @@ -137,5 +145,6 @@ for (profileName in profileNames) {
nameCore = nameCore,
profileName = profileName,
aliases = aliases,
sections = sections)
sections = sections,
validationConfig = validationConfig)
}
Loading