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 Mar 5, 2024
1 parent 6674f51 commit f499175
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
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","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:"
Expand Down
37 changes: 37 additions & 0 deletions scripts/output/single/checkProjectSummations.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 f499175

Please sign in to comment.