From f251eaf445f71d90c737a8f9ff5998c258e1e097 Mon Sep 17 00:00:00 2001 From: orichters Date: Fri, 13 Sep 2024 15:52:43 +0200 Subject: [PATCH 1/5] adjust xlsx_IIASA for scenarioMip --- scripts/output/export/xlsx_IIASA.R | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/scripts/output/export/xlsx_IIASA.R b/scripts/output/export/xlsx_IIASA.R index 743ca297d..fcffea91e 100644 --- a/scripts/output/export/xlsx_IIASA.R +++ b/scripts/output/export/xlsx_IIASA.R @@ -21,11 +21,13 @@ model <- paste("REMIND", paste0(strsplit(gms::readDefaultConfig(".")$model_versi removeFromScen <- "" # you can use regex such as: "_diff|_expoLinear" +renameScen <- NULL # c(newname1 = "oldname1", …), without the `C_` and `-rem-[0-9]` stuff addToScen <- NULL # is added at the beginning # filenames relative to REMIND main directory (or use absolute path) mapping <- NULL # file obtained from piamInterfaces, or AR6/SHAPE/NAVIGATE or NULL to get asked iiasatemplate <- NULL # provided for each project, can be yaml or xlsx with a column 'Variable' +checkSummation <- TRUE # if TRUE, tries to use the one from mapping. Or specify here # note: you can also pass all these options to output.R, so 'Rscript output.R logFile=mylogfile.txt' works. lucode2::readArgs("project") @@ -41,6 +43,11 @@ projects <- list( mapping = c("AR6", "AR6_NGFS"), iiasatemplate = "https://files.ece.iiasa.ac.at/ngfs-phase-5/ngfs-phase-5-template.xlsx", removeFromScen = "C_|_bIT|_bit|_bIt|_KLW"), + ScenarioMIP = list(model = "REMIND-MAgPIE 3.4-4.8", + mapping = "ScenarioMIP", + iiasatemplate = "https://files.ece.iiasa.ac.at/ssp-submission/ssp-submission-template.xlsx", + renameScen = c(laurin = "SMIPv03-M-SSP2-NPi-def"), + checkSummation = "NAVIGATE"), SHAPE = list(mapping = c("NAVIGATE", "SHAPE")), TESTTHAT = list(mapping = "AR6") ) @@ -58,14 +65,15 @@ if (! exists("project")) { } projectdata <- projects[[project]] message("# Overwrite settings with project settings for '", project, "'.") -varnames <- c("mapping", "iiasatemplate", "addToScen", "removeFromScen", "model", "outputFilename", "logFile") +varnames <- c("mapping", "iiasatemplate", "addToScen", "removeFromScen", "renameScen", + "model", "outputFilename", "logFile", "checkSummation") for (p in intersect(varnames, names(projectdata))) { assign(p, projectdata[[p]]) } # overwrite settings with those specified as command-line arguments -lucode2::readArgs("outputdirs", "filename_prefix", "outputFilename", "model", - "mapping", "logFile", "removeFromScen", "addToScen", "iiasatemplate") +lucode2::readArgs("outputdirs", "filename_prefix", "outputFilename", "model", "mapping", + "summationFile", "logFile", "removeFromScen", "addToScen", "iiasatemplate") if (is.null(mapping)) { mapping <- gms::chooseFromList(names(piamInterfaces::mappingNames()), type = "mapping") @@ -130,6 +138,12 @@ withCallingHandlers({ # piping messages to logFile mifdata <- rbind(mifdata, thismifdata) } + levels(mifdata$scenario) <- gsub("^C_|-rem-[0-9]+", "", levels(mifdata$scenario)) + for (i in names(renameScen)) { + message("Rename scenario: ", i, " -> ", renameScen[[i]]) + levels(mifdata$scenario)[i == levels(mifdata$scenario)] == renameScen[[i]] + } + message("# ", length(temporarydelete), " variables are in the list to be temporarily deleted, ", length(unique(mifdata$variable[mifdata$variable %in% temporarydelete])), " were deleted.") write(paste0(" - ", paste(unique(mifdata$variable[mifdata$variable %in% temporarydelete]), collapse = "\n - "), "\n\n"), @@ -141,7 +155,7 @@ withCallingHandlers({ # piping messages to logFile generateIIASASubmission(mifdata, mapping = mapping, model = model, removeFromScen = removeFromScen, addToScen = addToScen, - outputDirectory = outputFolder, + outputDirectory = outputFolder, checkSummation = checkSummation, logFile = logFile, outputFilename = basename(OUTPUT_xlsx), iiasatemplate = iiasatemplate, generatePlots = TRUE) From 49c22cf0b36e3ff197657a48c245e4dbaa536f63 Mon Sep 17 00:00:00 2001 From: orichters Date: Wed, 11 Sep 2024 16:14:13 +0200 Subject: [PATCH 2/5] accept urls in xlsx_IIASA From 3e417ae9d85ce9631ff81c0151485e93b15ef6db Mon Sep 17 00:00:00 2001 From: orichters Date: Fri, 13 Sep 2024 16:06:13 +0200 Subject: [PATCH 3/5] some adjustments to scenario renaming --- scripts/output/export/xlsx_IIASA.R | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/output/export/xlsx_IIASA.R b/scripts/output/export/xlsx_IIASA.R index fcffea91e..81d86a1d7 100644 --- a/scripts/output/export/xlsx_IIASA.R +++ b/scripts/output/export/xlsx_IIASA.R @@ -21,7 +21,7 @@ model <- paste("REMIND", paste0(strsplit(gms::readDefaultConfig(".")$model_versi removeFromScen <- "" # you can use regex such as: "_diff|_expoLinear" -renameScen <- NULL # c(newname1 = "oldname1", …), without the `C_` and `-rem-[0-9]` stuff +renameScen <- NULL # c(oldname1 = "newname1", …), without the `C_` and `-rem-[0-9]` stuff addToScen <- NULL # is added at the beginning # filenames relative to REMIND main directory (or use absolute path) @@ -46,7 +46,7 @@ projects <- list( ScenarioMIP = list(model = "REMIND-MAgPIE 3.4-4.8", mapping = "ScenarioMIP", iiasatemplate = "https://files.ece.iiasa.ac.at/ssp-submission/ssp-submission-template.xlsx", - renameScen = c(laurin = "SMIPv03-M-SSP2-NPi-def"), + renameScen = c("SMIPv03-M-SSP2-NPi-def" = "laurin", "SMIPv03-LOS-SSP2-EcBudg400-def" = "newname"), checkSummation = "NAVIGATE"), SHAPE = list(mapping = c("NAVIGATE", "SHAPE")), TESTTHAT = list(mapping = "AR6") @@ -138,11 +138,13 @@ withCallingHandlers({ # piping messages to logFile mifdata <- rbind(mifdata, thismifdata) } - levels(mifdata$scenario) <- gsub("^C_|-rem-[0-9]+", "", levels(mifdata$scenario)) + mifdata$scenario <- gsub("^C_", "", mifdata$scenario) + message("Old names: ", sort(unique(mifdata$scenario))) for (i in names(renameScen)) { message("Rename scenario: ", i, " -> ", renameScen[[i]]) - levels(mifdata$scenario)[i == levels(mifdata$scenario)] == renameScen[[i]] + mifdata$scenario[i == mifdata$scenario] <- renameScen[[i]] } + message("New names: ", sort(unique(mifdata$scenario))) message("# ", length(temporarydelete), " variables are in the list to be temporarily deleted, ", length(unique(mifdata$variable[mifdata$variable %in% temporarydelete])), " were deleted.") From 4c3643390d975e137a1eb4784a88f41e89753595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurin=20K=C3=B6hler-Schindler?= Date: Fri, 13 Sep 2024 16:47:12 +0200 Subject: [PATCH 4/5] Added ScenarioMIP to list of projects for export. --- scripts/output/export/xlsx_IIASA.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/output/export/xlsx_IIASA.R b/scripts/output/export/xlsx_IIASA.R index 81d86a1d7..a0a1ab1ed 100644 --- a/scripts/output/export/xlsx_IIASA.R +++ b/scripts/output/export/xlsx_IIASA.R @@ -46,7 +46,7 @@ projects <- list( ScenarioMIP = list(model = "REMIND-MAgPIE 3.4-4.8", mapping = "ScenarioMIP", iiasatemplate = "https://files.ece.iiasa.ac.at/ssp-submission/ssp-submission-template.xlsx", - renameScen = c("SMIPv03-M-SSP2-NPi-def" = "laurin", "SMIPv03-LOS-SSP2-EcBudg400-def" = "newname"), + renameScen = c("SMIPv03-M-SSP2-NPi-def" = "SSP2 - Medium Emissions", "SMIPv03-LOS-SSP2-EcBudg400-def" = "SSP2 - Low Overshoot", "SMIPv03-ML-SSP2-PkPrice200-fromL" = "SSP2 - Medium-Low Emissions","SMIPv03-L-SSP2-PkPrice265-inc6-def" = "SSP2 - Low Emissions", "SMIPv03-VL-SSP2_SDP_MC-PkPrice300-def" = "SSP2 - Very Low Emissions"), checkSummation = "NAVIGATE"), SHAPE = list(mapping = c("NAVIGATE", "SHAPE")), TESTTHAT = list(mapping = "AR6") From 7059c3d0534519ede36362d9d613483f22b77bc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurin=20K=C3=B6hler-Schindler?= <163062134+laurinks@users.noreply.github.com> Date: Tue, 17 Sep 2024 15:51:21 +0200 Subject: [PATCH 5/5] Update scripts/output/export/xlsx_IIASA.R Co-authored-by: orichters <90761609+orichters@users.noreply.github.com> --- scripts/output/export/xlsx_IIASA.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/output/export/xlsx_IIASA.R b/scripts/output/export/xlsx_IIASA.R index a0a1ab1ed..772c4d17f 100644 --- a/scripts/output/export/xlsx_IIASA.R +++ b/scripts/output/export/xlsx_IIASA.R @@ -139,12 +139,12 @@ withCallingHandlers({ # piping messages to logFile } mifdata$scenario <- gsub("^C_", "", mifdata$scenario) - message("Old names: ", sort(unique(mifdata$scenario))) + message("Old names: ", paste(sort(unique(mifdata$scenario)), collapse = ", ")) for (i in names(renameScen)) { message("Rename scenario: ", i, " -> ", renameScen[[i]]) mifdata$scenario[i == mifdata$scenario] <- renameScen[[i]] } - message("New names: ", sort(unique(mifdata$scenario))) + message("New names: ", paste(sort(unique(mifdata$scenario)), collapse = ", ")) message("# ", length(temporarydelete), " variables are in the list to be temporarily deleted, ", length(unique(mifdata$variable[mifdata$variable %in% temporarydelete])), " were deleted.")