From e04aadefac57383b6721aecb6fa85a15b0024fa0 Mon Sep 17 00:00:00 2001 From: orichters Date: Tue, 6 Jun 2023 14:42:49 +0200 Subject: [PATCH] change gdx ref naming, fix aggregation in reportPrices --- .buildlibrary | 2 +- CITATION.cff | 4 +-- DESCRIPTION | 4 +-- R/colorScenConf.R | 2 +- R/convGDX2MIF.R | 26 +++++++++-------- R/reportPrices.R | 28 ++++++++----------- README.md | 6 ++-- man/convGDX2MIF.Rd | 8 +++--- tests/testthat/test-convGDX2mif.R | 2 +- tests/testthat/test-piamInterfaces-Ariadne.R | 2 +- tests/testthat/test-piamInterfaces-NAVIGATE.R | 2 +- tests/testthat/test-piamInterfaces-NGFS.R | 2 +- tests/testthat/test-piamInterfaces-SHAPE.R | 2 +- 13 files changed, 45 insertions(+), 45 deletions(-) diff --git a/.buildlibrary b/.buildlibrary index 66436b14..23522669 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '216772896' +ValidationKey: '216995680' AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' - 'Warning: namespace ''.*'' is not available and has been replaced' diff --git a/CITATION.cff b/CITATION.cff index f51c7f71..50f90fb3 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -2,8 +2,8 @@ cff-version: 1.2.0 message: If you use this software, please cite it using the metadata from this file. type: software title: 'remind2: The REMIND R package (2nd generation)' -version: 1.111.2 -date-released: '2023-06-03' +version: 1.112.0 +date-released: '2023-06-06' abstract: Contains the REMIND-specific routines for data and model output manipulation. authors: - family-names: Rodrigues diff --git a/DESCRIPTION b/DESCRIPTION index e8e14124..6386bd0b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: remind2 Title: The REMIND R package (2nd generation) -Version: 1.111.2 -Date: 2023-06-03 +Version: 1.112.0 +Date: 2023-06-06 Authors@R: c( person("Renato", "Rodrigues", , "renato.rodrigues@pik-potsdam.de", role = c("aut", "cre")), person("Lavinia", "Baumstark", role = "aut"), diff --git a/R/colorScenConf.R b/R/colorScenConf.R index ac7b410e..340cc055 100644 --- a/R/colorScenConf.R +++ b/R/colorScenConf.R @@ -38,7 +38,7 @@ colorScenConf <- function(fileList = "", remindPath = ".", expanddata = FALSE) { try(cfg$gms[["regionmapping"]] <- cfg$regionmapping) try(cfg$gms[["inputRevision"]] <- cfg$inputRevision) - if (fileList == "") { + if (fileList == "" || length(fileList) == 0) { cat("Specify folder with .csv files. The script also searches in subdirectories.\n") cat(paste0("Press enter to use current: ", getwd(), ".\n")) folder <- getLine() diff --git a/R/convGDX2MIF.R b/R/convGDX2MIF.R index 1374ea8c..ce93b64d 100644 --- a/R/convGDX2MIF.R +++ b/R/convGDX2MIF.R @@ -5,18 +5,18 @@ #' #' #' @param gdx a GDX as created by readGDX, or the file name of a gdx -#' @param gdx_ref reference-gdx for policy costs, a GDX as created by readGDX, or the file name of a gdx +#' @param gdx_ref reference-gdx for < cm_startyear, used for fixing the prices to this scenario #' @param file name of the mif file which will be written, if no name is #' provided a magpie object containing all the reporting information is #' returned #' @param scenario scenario name that is used in the *.mif reporting #' @param t temporal resolution of the reporting, default: #' t=c(seq(2005,2060,5),seq(2070,2110,10),2130,2150) -#' @param gdx_refprices reference-gdx for < cm_startyear, used for fixing the prices to this scenario +#' @param gdx_refpolicycost reference-gdx for policy costs, a GDX as created by readGDX, or the file name of a gdx #' @author Lavinia Baumstark #' @examples #' -#' \dontrun{convGDX2MIF(gdx,gdx_ref,file="REMIND_generic_default.csv",scenario="default")} +#' \dontrun{convGDX2MIF(gdx,gdx_refpolicycost,file="REMIND_generic_default.csv",scenario="default")} #' #' @export #' @importFrom gdx readGDX @@ -24,7 +24,11 @@ convGDX2MIF <- function(gdx, gdx_ref = NULL, file = NULL, scenario = "default", t = c(seq(2005, 2060, 5), seq(2070, 2110, 10), 2130, 2150), - gdx_refprices = NULL) { + gdx_refpolicycost = NULL) { + + if (is.null(gdx_refpolicycost)) { + gdx_refpolicycost <- gdx_ref + } # Define region subsets regionSubsetList <- toolRegionSubsets(gdx) @@ -70,7 +74,7 @@ convGDX2MIF <- function(gdx, gdx_ref = NULL, file = NULL, scenario = "default", message("running reportTechnology...") output <- mbind(output,reportTechnology(gdx,output,regionSubsetList,t)[,t,]) # needs output from reportSE message("running reportPrices...") - output <- mbind(output,reportPrices(gdx,output,regionSubsetList,t,gdx_ref = gdx_refprices)[,t,]) # needs output from reportSE, reportFE, reportEmi, reportExtraction, reportMacroEconomy + output <- mbind(output,reportPrices(gdx,output,regionSubsetList,t,gdx_ref = gdx_ref)[,t,]) # needs output from reportSE, reportFE, reportEmi, reportExtraction, reportMacroEconomy message("running reportCosts...") output <- mbind(output,reportCosts(gdx,output,regionSubsetList,t)[,t,]) # needs output from reportEnergyInvestment, reportPrices, reportEnergyInvestments message("running reportTax...") @@ -82,14 +86,14 @@ convGDX2MIF <- function(gdx, gdx_ref = NULL, file = NULL, scenario = "default", output <- mbind(output,reportCrossVariables(gdx,output,regionSubsetList,t)[,t,]) # Report policy costs, if possible and sensible - if(!is.null(gdx_ref)) { - if (file.exists(gdx_ref)) { + if(!is.null(gdx_refpolicycost)) { + if (file.exists(gdx_refpolicycost)) { gdp_scen <- try(readGDX(gdx,"cm_GDPscen",react ="error"),silent=T) - gdp_scen_ref <- try(readGDX(gdx_ref,"cm_GDPscen",react = "error"),silent=T) + gdp_scen_ref <- try(readGDX(gdx_refpolicycost,"cm_GDPscen",react = "error"),silent=T) if(!inherits(gdp_scen,"try-error") && !inherits(gdp_scen_ref,"try-error")){ if(gdp_scen[1]==gdp_scen_ref[1]){ - message("running reportPolicyCosts, comparing to ", basename(dirname(gdx_ref)), "/", basename(gdx_ref), "...") - output <- mbind(output,reportPolicyCosts(gdx,gdx_ref,regionSubsetList,t)[,t,]) + message("running reportPolicyCosts, comparing to ", basename(dirname(gdx_refpolicycost)), "/", basename(gdx_refpolicycost), "...") + output <- mbind(output,reportPolicyCosts(gdx,gdx_refpolicycost,regionSubsetList,t)[,t,]) } else { warning(paste0("The GDP scenario differs from that of the reference run. Did not execute 'reportPolicyCosts'! If a policy costs reporting is desired, please use the 'policyCosts' output.R script.")) } @@ -97,7 +101,7 @@ convGDX2MIF <- function(gdx, gdx_ref = NULL, file = NULL, scenario = "default", warning(paste0("A comparison of the GDP scenarios between this run and its reference run wasn't possible (old remind version). Therefore to avoid reporting unsensible policy costs, 'reportPolicyCosts' was not executed. If a policy costs reporting is required, please use the 'policyCosts' output.R script.")) } } else { - warning(paste0("File ",gdx_ref," not found. Did not execute 'reportPolicyCosts'! If a policy costs reporting is desired, please use the 'policyCosts' output.R script.")) + warning(paste0("File ",gdx_refpolicycost," not found. Did not execute 'reportPolicyCosts'! If a policy costs reporting is desired, please use the 'policyCosts' output.R script.")) } } diff --git a/R/reportPrices.R b/R/reportPrices.R index 1856a8e0..04553bb0 100644 --- a/R/reportPrices.R +++ b/R/reportPrices.R @@ -699,8 +699,9 @@ reportPrices <- function(gdx, output=NULL, regionSubsetList=NULL, out.reporting <- lowpass(out.reporting) # reset values for years smaller than cm_startyear to avoid inconsistencies in cm_startyear - 5 if (! is.null(gdx_ref)) { + message("reportPrices loads price for < cm_startyear from gdx_ref.") priceRef <- try(reportPrices(gdx_ref, output = NULL, regionSubsetList = regionSubsetList, t = t)) - fixedyears <- getYears(out)[getYears(out, as.integer = TRUE) < as.integer(cm_startyear)] + fixedyears <- getYears(out)[getYears(out, as.integer = TRUE) < cm_startyear] if (! inherits(priceRef, "try-error") && length(fixedyears) > 0) { out.reporting[, fixedyears, ] <- priceRef[getRegions(out), fixedyears, getNames(out)] } @@ -919,6 +920,16 @@ reportPrices <- function(gdx, output=NULL, regionSubsetList=NULL, "Price|Final Energy|Industry|Solids (US$2005/GJ)" = "FE|Industry|Solids (EJ/yr)" ) + # transport-specific mappings depending on realization + if (module2realisation["transport",2] == "complex") { + int2ext <- c(int2ext, + "Price|Final Energy|Transport|Liquids|HDV (US$2005/GJ)" = "FE|Transport|non-LDV|Liquids (EJ/yr)", + "Price|Final Energy|Transport|Liquids|LDV (US$2005/GJ)" = "FE|Transport|LDV|Liquids (EJ/yr)") + } else if (module2realisation["transport",2] == "edge_esm") { + int2ext <- c(int2ext, + "Price|Final Energy|Transport|Liquids|HDV (US$2005/GJ)" = "FE|Transport|Diesel Liquids (EJ/yr)", + "Price|Final Energy|Transport|Liquids|LDV (US$2005/GJ)" = "FE|Transport|Pass|Liquids (EJ/yr)") + } ## add weights definition for region aggregation for FE prices that were added automatically if(length(pm_FEPrice_by_FE) > 0) { @@ -936,21 +947,6 @@ reportPrices <- function(gdx, output=NULL, regionSubsetList=NULL, int2ext <- c(int2ext, vars) } - # transport-specific mappings depending on realization - - if (module2realisation["transport",2] == "complex") { - int2ext <- c(int2ext, - "Price|Final Energy|Transport|Liquids|HDV (US$2005/GJ)" = "FE|Transport|non-LDV|Liquids (EJ/yr)", - "Price|Final Energy|Transport|Liquids|LDV (US$2005/GJ)" = "FE|Transport|LDV|Liquids (EJ/yr)") - } else if (module2realisation["transport",2] == "edge_esm") { - int2ext <- c(int2ext, - "Price|Final Energy|Transport|Liquids|HDV (US$2005/GJ)" = "FE|Transport|Diesel Liquids (EJ/yr)", - "Price|Final Energy|Transport|Liquids|LDV (US$2005/GJ)" = "FE|Transport|Pass|Liquids (EJ/yr)", - "Price|Final Energy|Transport|Gases (US$2005/GJ)" = "FE|Transport|Gases (EJ/yr)") - } - - - ## moving averages and rawdata avgs <- getNames(out.lowpass) rawdata <- getNames(out.rawdata) diff --git a/README.md b/README.md index c56adc27..ee7ba33e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # The REMIND R package (2nd generation) -R package **remind2**, version **1.111.2** +R package **remind2**, version **1.112.0** [![CRAN status](https://www.r-pkg.org/badges/version/remind2)](https://cran.r-project.org/package=remind2) [![R build status](https://github.com/pik-piam/remind2/workflows/check/badge.svg)](https://github.com/pik-piam/remind2/actions) [![codecov](https://codecov.io/gh/pik-piam/remind2/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/remind2) [![r-universe](https://pik-piam.r-universe.dev/badges/remind2)](https://pik-piam.r-universe.dev/builds) @@ -49,7 +49,7 @@ In case of questions / problems please contact Renato Rodrigues . +Rodrigues R, Baumstark L, Benke F, Dietrich J, Dirnaichner A, Führlich P, Giannousakis A, Hasse R, Hilaire J, Klein D, Koch J, Kowalczyk K, Levesque A, Malik A, Merfort A, Merfort L, Morena-Leiva S, Pehl M, Pietzcker R, Rauner S, Richters O, Rottoli M, Schötz C, Schreyer F, Siala K, Sörgel B, Spahr M, Strefler J, Verpoort P (2023). _remind2: The REMIND R package (2nd generation)_. R package version 1.112.0, . A BibTeX entry for LaTeX users is @@ -58,7 +58,7 @@ A BibTeX entry for LaTeX users is title = {remind2: The REMIND R package (2nd generation)}, author = {Renato Rodrigues and Lavinia Baumstark and Falk Benke and Jan Philipp Dietrich and Alois Dirnaichner and Pascal Führlich and Anastasis Giannousakis and Robin Hasse and Jérome Hilaire and David Klein and Johannes Koch and Katarzyna Kowalczyk and Antoine Levesque and Aman Malik and Anne Merfort and Leon Merfort and Simón Morena-Leiva and Michaja Pehl and Robert Pietzcker and Sebastian Rauner and Oliver Richters and Marianna Rottoli and Christof Schötz and Felix Schreyer and Kais Siala and Björn Sörgel and Mike Spahr and Jessica Strefler and Philipp Verpoort}, year = {2023}, - note = {R package version 1.111.2}, + note = {R package version 1.112.0}, url = {https://github.com/pik-piam/remind2}, } ``` diff --git a/man/convGDX2MIF.Rd b/man/convGDX2MIF.Rd index 5af4b59b..948f11e6 100644 --- a/man/convGDX2MIF.Rd +++ b/man/convGDX2MIF.Rd @@ -10,13 +10,13 @@ convGDX2MIF( file = NULL, scenario = "default", t = c(seq(2005, 2060, 5), seq(2070, 2110, 10), 2130, 2150), - gdx_refprices = NULL + gdx_refpolicycost = NULL ) } \arguments{ \item{gdx}{a GDX as created by readGDX, or the file name of a gdx} -\item{gdx_ref}{reference-gdx for policy costs, a GDX as created by readGDX, or the file name of a gdx} +\item{gdx_ref}{reference-gdx for < cm_startyear, used for fixing the prices to this scenario} \item{file}{name of the mif file which will be written, if no name is provided a magpie object containing all the reporting information is @@ -27,7 +27,7 @@ returned} \item{t}{temporal resolution of the reporting, default: t=c(seq(2005,2060,5),seq(2070,2110,10),2130,2150)} -\item{gdx_refprices}{reference-gdx for < cm_startyear, used for fixing the prices to this scenario} +\item{gdx_refpolicycost}{reference-gdx for policy costs, a GDX as created by readGDX, or the file name of a gdx} } \description{ Read in all information from GDX file and create @@ -35,7 +35,7 @@ the *.mif reporting } \examples{ -\dontrun{convGDX2MIF(gdx,gdx_ref,file="REMIND_generic_default.csv",scenario="default")} +\dontrun{convGDX2MIF(gdx,gdx_refpolicycost,file="REMIND_generic_default.csv",scenario="default")} } \author{ diff --git a/tests/testthat/test-convGDX2mif.R b/tests/testthat/test-convGDX2mif.R index e9bcaf11..017e8e3a 100644 --- a/tests/testthat/test-convGDX2mif.R +++ b/tests/testthat/test-convGDX2mif.R @@ -116,7 +116,7 @@ test_that("Test if REMIND reporting is produced as it should and check data inte for (gdxPath in gdxPaths) { numberOfMifs <- numberOfMifs + 1 message("Running convGDX2MIF(", gdxPath, ")...") - mifContent <- convGDX2MIF(gdxPath, gdx_ref = gdxPath) + mifContent <- convGDX2MIF(gdxPath, gdx_refpolicycost = gdxPath) message("Checking integrity of created MIF...") checkIntegrity(mifContent, gdxPath) magclass::write.report( diff --git a/tests/testthat/test-piamInterfaces-Ariadne.R b/tests/testthat/test-piamInterfaces-Ariadne.R index 9dd541b8..acd3f3e9 100644 --- a/tests/testthat/test-piamInterfaces-Ariadne.R +++ b/tests/testthat/test-piamInterfaces-Ariadne.R @@ -10,7 +10,7 @@ test_that("Test if REMIND reporting produces mandatory variables for Ariadne rep mode = "wb", quiet = TRUE ) - mif <- convGDX2MIF(gdxPath, gdx_ref = gdxPath) + mif <- convGDX2MIF(gdxPath, gdx_refpolicycost = gdxPath) computedVariables <- getItems(mif, dim = 3.3) diff --git a/tests/testthat/test-piamInterfaces-NAVIGATE.R b/tests/testthat/test-piamInterfaces-NAVIGATE.R index aef86b0c..1e4adebb 100644 --- a/tests/testthat/test-piamInterfaces-NAVIGATE.R +++ b/tests/testthat/test-piamInterfaces-NAVIGATE.R @@ -10,7 +10,7 @@ test_that("Test if REMIND reporting produces mandatory variables for NAVIGATE re mode = "wb", quiet = TRUE ) - mif <- convGDX2MIF(gdxPath, gdx_ref = gdxPath) + mif <- convGDX2MIF(gdxPath, gdx_refpolicycost = gdxPath) computedVariables <- getItems(mif, dim = 3.3) diff --git a/tests/testthat/test-piamInterfaces-NGFS.R b/tests/testthat/test-piamInterfaces-NGFS.R index d999c41f..972f3a02 100644 --- a/tests/testthat/test-piamInterfaces-NGFS.R +++ b/tests/testthat/test-piamInterfaces-NGFS.R @@ -9,7 +9,7 @@ test_that("Test if REMIND reporting produces mandatory variables for NGFS report mode = "wb", quiet = TRUE ) - mif <- convGDX2MIF(gdxPath, gdx_ref = gdxPath) + mif <- convGDX2MIF(gdxPath, gdx_refpolicycost = gdxPath) computedVariables <- getItems(mif, dim = 3.3) diff --git a/tests/testthat/test-piamInterfaces-SHAPE.R b/tests/testthat/test-piamInterfaces-SHAPE.R index 4b3e877b..4c78e2f4 100644 --- a/tests/testthat/test-piamInterfaces-SHAPE.R +++ b/tests/testthat/test-piamInterfaces-SHAPE.R @@ -10,7 +10,7 @@ test_that("Test if REMIND reporting produces mandatory variables for SHAPE repor mode = "wb", quiet = TRUE ) - mif <- convGDX2MIF(gdxPath, gdx_ref = gdxPath) + mif <- convGDX2MIF(gdxPath, gdx_refpolicycost = gdxPath) computedVariables <- getItems(mif, dim = 3.3)