diff --git a/CHANGELOG.md b/CHANGELOG.md index 346ba00b74..a8b18c3202 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - **37_industry** add process-based steel model as alternative to CES-tree branch - **47_regipol** add support for delaying quantity targets and improving regional emission tax convergence - **core** change of preference parameters and associated computation of interest rates/mark ups +- **scripts** add script to automatically check project summations from piamInterfaces + [[#1587](https://github.com/remindmodel/remind/pull/1587)] ### fixed - fixed weights of energy carriers in `pm_IndstCO2Captured` diff --git a/config/default.cfg b/config/default.cfg index 0250948ad2..50fcef9d26 100644 --- a/config/default.cfg +++ b/config/default.cfg @@ -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","checkProjectSummations") +# "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:" diff --git a/scripts/output/single/checkProjectSummations.R b/scripts/output/single/checkProjectSummations.R new file mode 100644 index 0000000000..86f0ed797c --- /dev/null +++ b/scripts/output/single/checkProjectSummations.R @@ -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) +}