diff --git a/DESCRIPTION b/DESCRIPTION index b871ba3c2..f188f5472 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -17,7 +17,7 @@ Imports: data.table, devtools, dplyr, - edgeTransport (>= 1.5.4), + edgeTransport (>= 1.5.5), flexdashboard, GDPuc, gdx (>= 1.53.0), @@ -51,7 +51,7 @@ Imports: nleqslv, optparse, piamenv (>= 0.4.0), - piamInterfaces (>= 0.15.2), + piamInterfaces (>= 0.17.0), plotly, purrr, quitte (>= 0.3128.4), diff --git a/output.R b/output.R index 98d2313fb..1c0993e1e 100755 --- a/output.R +++ b/output.R @@ -131,7 +131,7 @@ if (isTRUE(comp)) comp <- "comparison" if (! exists("output")) { modules <- gsub("\\.R$", "", grep("\\.R$", list.files(paste0("./scripts/output/", if (isFALSE(comp)) "single" else comp)), value = TRUE)) - output <- chooseFromList(modules, type = "modules to be used for output generation", addAllPattern = FALSE) + output <- if (length(modules) == 1) modules else chooseFromList(modules, type = "modules to be used for output generation", addAllPattern = FALSE) } # Select output directories if not defined by readArgs diff --git a/scripts/output/export/xlsx_IIASA.R b/scripts/output/export/xlsx_IIASA.R index c7a612b83..c3b2244b0 100644 --- a/scripts/output/export/xlsx_IIASA.R +++ b/scripts/output/export/xlsx_IIASA.R @@ -43,7 +43,7 @@ projects <- list( ) # add pure mapping from piamInterfaces -mappings <- setdiff(names(piamInterfaces::templateNames()), c(names(projects), "AR6_NGFS")) +mappings <- setdiff(names(piamInterfaces::mappingNames()), c(names(projects), "AR6_NGFS")) projects <- c(projects, do.call(c, lapply(mappings, function(x) stats::setNames(list(list(mapping = x)), x)))) @@ -65,16 +65,16 @@ lucode2::readArgs("outputdirs", "filename_prefix", "outputFilename", "model", "mapping", "logFile", "removeFromScen", "addToScen", "iiasatemplate") if (is.null(mapping)) { - mapping <- gms::chooseFromList(names(piamInterfaces::templateNames()), type = "mapping template") + mapping <- gms::chooseFromList(names(piamInterfaces::mappingNames()), type = "mapping") } -if (length(mapping) == 0 || ! all(file.exists(mapping) | mapping %in% names(templateNames()))) { +if (length(mapping) == 0 || ! all(file.exists(mapping) | mapping %in% names(mappingNames()))) { stop("mapping='", paste(mapping, collapse = ", "), "' not found.") } if (exists("iiasatemplate") && ! is.null(iiasatemplate) && ! file.exists(iiasatemplate)) { stop("iiasatemplate=", iiasatemplate, " not found.") } -# variables to be deleted although part of the template +# variables to be deleted although part of the mapping temporarydelete <- NULL # example: c("GDP|MER", "GDP|PPP") ### define filenames diff --git a/scripts/output/single/checkProjectSummations.R b/scripts/output/single/checkProjectSummations.R index 04501d356..2cd39426a 100644 --- a/scripts/output/single/checkProjectSummations.R +++ b/scripts/output/single/checkProjectSummations.R @@ -26,24 +26,24 @@ vars <- c("", "|Energy", "|Energy Demand|Transportation", "|Energy and Industria gasvars <- expand.grid(gases, vars, stringsAsFactors = FALSE) bunkervars <- unique(sort(c("Gross Emissions|CO2", paste0("Emissions|", gasvars$Var1, gasvars$Var2)))) -for (template in c("AR6", "NAVIGATE")) { - message("\n### Check project summations for ", template) - templateVariables <- template %>% - getTemplateVariables(paste0("RT", if (any(grepl("^MAgPIE", levels(mifdata$model)))) "M")) %>% +for (mapping in c("AR6", "NAVIGATE")) { + message("\n### Check project summations for ", mapping) + mappingVariables <- mapping %>% + getMappingVariables(paste0("RT", if (any(grepl("^MAgPIE", levels(mifdata$model)))) "M")) %>% unique() %>% removePlus() computedVariables <- unique(paste0(removePlus(mifdata$variable), " (", gsub("^$", "unitless", mifdata$unit), ")")) - missingVariables <- sort(setdiff(templateVariables, computedVariables)) + missingVariables <- sort(setdiff(mappingVariables, computedVariables)) if (length(missingVariables) > 0) { message("# The following ", length(missingVariables), " variables are expected in the piamInterfaces package ", - "for template ", template, ", but cannot be found in the reporting:\n- ", + "for mapping ", mapping, ", but cannot be found in the reporting:\n- ", paste(missingVariables, collapse = ",\n- "), "\n") } d <- generateIIASASubmission(mifdata, outputDirectory = NULL, logFile = NULL, - mapping = template, checkSummation = FALSE) + mapping = mapping, checkSummation = FALSE) failvars <- d %>% - checkSummations(template = template, summationsFile = template, logFile = NULL, dataDumpFile = NULL, + checkSummations(template = mapping, summationsFile = mapping, logFile = NULL, dataDumpFile = NULL, absDiff = absDiff, relDiff = relDiff) %>% filter(abs(diff) >= absDiff, abs(reldiff) >= relDiff) %>% df_variation() %>% @@ -59,13 +59,13 @@ for (template in c("AR6", "NAVIGATE")) { filter(! .data$variable %in% bunkervars) %>% select(-"model", -"scenario") if (nrow(failregi) > 0) { - message("For those ", template, " variables, the sum of regional values does not match the World value in 2050:") + message("For those ", mapping, " variables, the sum of regional values does not match the World value in 2050:") failregi %>% piamInterfaces::niceround() %>% print(n = 1000) } else { message("Regional summation checks are fine.") } - if (nrow(failvars) > 0 || nrow(failregi) > 0 || length(missingVariables) > 0) stopmessage <- c(stopmessage, template) + if (nrow(failvars) > 0 || nrow(failregi) > 0 || length(missingVariables) > 0) stopmessage <- c(stopmessage, mapping) } if (length(stopmessage) > 0) {