Skip to content

Commit

Permalink
automatically check export summations
Browse files Browse the repository at this point in the history
  • Loading branch information
orichters committed Feb 29, 2024
1 parent 0e2dddb commit 1ac5c96
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion config/default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ cfg$logoption <- 2

# Just list the name of the output scripts that should be used by output.R
# At the moment there are several R-scripts located in scripts/output/
cfg$output <- c("reporting","reportCEScalib","rds_report","fixOnRef") #"ar6Climate","emulator"
cfg$output <- c("reporting","reportCEScalib","rds_report","fixOnRef","checkExportSummations")
# "ar6Climate","validation","emulator","reportCEScalib","validationSummary","dashboard"

# Set the format for the results folder, type string :date: in order to use the current time stamp in the folder name (e.g. "results:date:") use :title: to use the current title in the folder name
cfg$results_folder <- "output/:title::date:"
Expand Down
37 changes: 37 additions & 0 deletions scripts/output/single/checkExportSummations.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
library(piamInterfaces)
library(quitte)
suppressPackageStartupMessages(library(tidyverse))

if(! exists("source_include")) {
# Define arguments that can be read from command line
outputdir <- "."
lucode2::readArgs("outputdir")
}

scen <- lucode2::getScenNames(outputdir)
mif <- file.path(outputdir, paste0("REMIND_generic_", scen, ".mif"))

stopmessage <- NULL

absDiff <- 0.00001
relDiff <- 0.01

for (template in c("AR6", "NAVIGATE")) {

d <- generateIIASASubmission(mif, outputDirectory = NULL, logFile = NULL, mapping = template, checkSummation = FALSE)
failing <- d %>%
checkSummations(template = template, summationsFile = template, logFile = NULL, dataDumpFile = NULL,
absDiff = absDiff, relDiff = relDiff) %>%
filter(abs(diff) >= absDiff, abs(reldiff) >= relDiff) %>%
df_variation() %>%
droplevels()

if (nrow(failing) > 0) {
stopmessage <- c(stopmessage,
paste0("\nThe following variables do not satisfy the ", template, " summation checks:"),
paste("\n-", unique(failing$variable), collapse = ""))
}
}
if (length(stopmessage) > 0) {
stop("Failing summation checks, see above.", stopmessage)
}

0 comments on commit 1ac5c96

Please sign in to comment.