From 4f6189b256d3d516a78b365c86983f18a53d0c2a Mon Sep 17 00:00:00 2001 From: Falk Benke Date: Mon, 9 Dec 2024 17:53:01 +0100 Subject: [PATCH 1/2] move reading in REMIND fuel costs to mrtransport --- .buildlibrary | 2 +- CITATION.cff | 4 ++-- DESCRIPTION | 4 ++-- R/calcEdgeTransportSA.R | 3 --- R/toolEdgeTransportSA.R | 8 +------- R/toolLoadInputs.R | 5 ++--- R/toolLoadREMINDfuelCosts.R | 6 +++++- R/toolLoadmrremindData.R | 10 +++++----- README.md | 8 ++++---- man/EdgeTransportSA.Rd | 3 --- man/toolEdgeTransportSA.Rd | 3 --- man/toolLoadInputs.Rd | 4 +--- 12 files changed, 23 insertions(+), 37 deletions(-) diff --git a/.buildlibrary b/.buildlibrary index 2d5af7f..c34ea5a 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '42518720' +ValidationKey: '42559986' AutocreateReadme: yes AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' diff --git a/CITATION.cff b/CITATION.cff index c701c50..5a8939b 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: 'edgeTransport: Prepare EDGE Transport Data for the REMIND model' -version: 2.12.0 -date-released: '2024-11-29' +version: 2.12.1 +date-released: '2024-12-09' abstract: EDGE-T is a fork of the GCAM transport module https://jgcri.github.io/gcam-doc/energy.html#transportation with a high level of detail in its representation of technological and modal options. It is a partial equilibrium model with a nested multinomial logit structure and diff --git a/DESCRIPTION b/DESCRIPTION index 33dfdf0..d973d3d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: edgeTransport Title: Prepare EDGE Transport Data for the REMIND model -Version: 2.12.0 +Version: 2.12.1 Authors@R: c( person("Johanna", "Hoppe", , "johanna.hoppe@pik-potsdam.de", role = c("aut", "cre"), comment = c(ORCID = "0009-0004-6753-5090")), @@ -19,7 +19,7 @@ Encoding: UTF-8 LazyData: true RoxygenNote: 7.3.2 VignetteBuilder: knitr -Date: 2024-11-29 +Date: 2024-12-09 Config/testthat/edition: 3 Imports: rmndt, diff --git a/R/calcEdgeTransportSA.R b/R/calcEdgeTransportSA.R index e714593..a693f29 100644 --- a/R/calcEdgeTransportSA.R +++ b/R/calcEdgeTransportSA.R @@ -8,7 +8,6 @@ #' @param transportPolScen EDGE-T transport policy scenario #' @param isICEban optional enabling of ICE ban #' @param demScen Demand scenario, used to apply reduction factors on total demands from the regression -#' @param gdxPath Path to a GDX file to load price signals from a REMIND run #' @param outputFolder Path to folder for storing output data #' @param isStored Optional saving of intermediate RDS files #' @param isTransportReported Optional transport reporting in MIF format @@ -24,7 +23,6 @@ calcEdgeTransportSA <- function(SSPscen, transportPolScen, isICEban = FALSE, demScen = "default", - gdxPath = NULL, outputFolder = NULL, isStored = FALSE, isTransportReported = TRUE, @@ -37,7 +35,6 @@ calcEdgeTransportSA <- function(SSPscen, transportPolScen, isICEban, demScen, - gdxPath, outputFolder, isStored, isTransportReported, diff --git a/R/toolEdgeTransportSA.R b/R/toolEdgeTransportSA.R index 034828f..a374636 100644 --- a/R/toolEdgeTransportSA.R +++ b/R/toolEdgeTransportSA.R @@ -8,7 +8,6 @@ #' @param transportPolScen EDGE-T transport policy scenario #' @param isICEban optional enabling of ICE ban #' @param demScen Demand scenario, used to apply reduction factors on total demands from the regression -#' @param gdxPath Path to a GDX file to load price signals from a REMIND run #' @param outputFolder Path to folder for storing output data #' @param isStored Optional saving of intermediate RDS files #' @param isTransportReported Optional transport reporting in MIF format @@ -25,7 +24,6 @@ toolEdgeTransportSA <- function(SSPscen, transportPolScen, isICEban = FALSE, demScen = "default", - gdxPath = NULL, outputFolder = NULL, isStored = TRUE, isTransportReported = TRUE, @@ -46,11 +44,8 @@ toolEdgeTransportSA <- function(SSPscen, ## Load input data ######################################################## if (is.null(outputFolder) & isStored) stop("Please provide an outputfolder to store your results") - if (is.null(gdxPath)) {gdxPath <- file.path(getConfig("sourcefolder"), - "REMINDinputForTransportStandalone", "v1.2", "fulldata.gdx")} - if (!file.exists(gdxPath)) stop("Please provide valid path to REMIND fulldata.gdx as input for fuel costs") - inputs <- toolLoadInputs(SSPscen, transportPolScen, demScen, gdxPath, hybridElecShare) + inputs <- toolLoadInputs(SSPscen, transportPolScen, demScen, hybridElecShare) helpers <- inputs$helpers genModelPar <- inputs$genModelPar @@ -229,7 +224,6 @@ toolEdgeTransportSA <- function(SSPscen, SSPscen = SSPscen, transportPolScen = transportPolScen, demScen = demScen, - gdxPath = gdxPath, hybridElecShare = hybridElecShare, histPrefs = histPrefs, fleetSizeAndComposition = fleetSizeAndComposition, diff --git a/R/toolLoadInputs.R b/R/toolLoadInputs.R index 584de75..f7f94af 100644 --- a/R/toolLoadInputs.R +++ b/R/toolLoadInputs.R @@ -3,13 +3,12 @@ #' @param SSPscen SSP or SDP scenario #' @param transportPolScen EDGE-T transport policy scenario #' @param demScen Demand scenario, used to apply reduction factors on total demands from the regression -#' @param gdxPath Path to a GDX file to load price signals from a REMIND run #' @param hybridElecShare Share of electricity in Hybrid electric vehicles #' @returns list with different input data sets #' @import data.table #' @export -toolLoadInputs <- function(SSPscen, transportPolScen, demScen, gdxPath, hybridElecShare) { +toolLoadInputs <- function(SSPscen, transportPolScen, demScen, hybridElecShare) { ### load inputs ------------------------------------------------------------ @@ -48,7 +47,7 @@ toolLoadInputs <- function(SSPscen, transportPolScen, demScen, gdxPath, hybridEl mrdriversData <- toolLoadmrdriversData(SSPscen, helpers) ## from REMIND - REMINDfuelCosts <- toolLoadREMINDfuelCosts(gdxPath, hybridElecShare, helpers) + REMINDfuelCosts <- toolLoadREMINDfuelCosts(gdxPath = NULL, hybridElecShare, helpers) # from mrremind (soon to be replaced by mrtransport data) mrremindData <- toolLoadmrremindData(helpers) diff --git a/R/toolLoadREMINDfuelCosts.R b/R/toolLoadREMINDfuelCosts.R index 206e2f8..db7fe80 100644 --- a/R/toolLoadREMINDfuelCosts.R +++ b/R/toolLoadREMINDfuelCosts.R @@ -22,7 +22,11 @@ toolLoadREMINDfuelCosts <- function(gdxPath, hybridElecShare, helpers){ decisionTree <- copy(helpers$decisionTree) # load prices from REMIND gdx - fuelCosts <- readGDX(gdxPath, "pm_FEPrice", format = "first_found", restore_zeros = FALSE)[,, "trans.ES", pmatch = TRUE] + if (is.null(gdxPath)) { + fuelCosts <- readSource("REMINDinputForTransportStandalone", convert = FALSE) + } else { + fuelCosts <- readGDX(gdxPath, "pm_FEPrice", format = "first_found", restore_zeros = FALSE)[, , "trans.ES", pmatch = TRUE] + } ## smooth prices from REMIND gdx (over years) and convert to data.table fuelCosts <- fuelCosts %>% lowpass() %>% magpie2dt() diff --git a/R/toolLoadmrremindData.R b/R/toolLoadmrremindData.R index 2f79dc1..96143fe 100644 --- a/R/toolLoadmrremindData.R +++ b/R/toolLoadmrremindData.R @@ -23,17 +23,17 @@ toolLoadmrremindData <- function(helpers) { yearOut = 2030 ## attribute first (to the countries that have them) the same incentives value until the phase out year subsidies[, value := ifelse(period >= 2020 & period <= yearOut, value[period == 2020], 0), - by = c("region", "technology")] + by = c("region", "technology")] # map on decision tree, apply only on 4 wheelers subsidies <- merge(unique(helpers$decisionTree[subsectorL3 == "trn_pass_road_LDV_4W", - c("region", "univocalName", "technology")]), subsidies, + c("region", "univocalName", "technology")]), subsidies, by = c("region", "technology"), all.x = TRUE, allow.cartesian = TRUE) monUnit <- gsub(".*?(\\d{4}).*", "US$\\1", mrdrivers::toolGetUnitDollar()) subsidies <- subsidies[!is.na(value)][, variable := "Capital costs subsidy"][, unit := paste0(monUnit, "/veh")] #Q: How to include phase out of the incentives? Is that needed at all? -return(list( - subsidies = subsidies -)) + return(list( + subsidies = subsidies + )) } diff --git a/README.md b/README.md index 6f04236..6489120 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Prepare EDGE Transport Data for the REMIND model -R package **edgeTransport**, version **2.12.0** +R package **edgeTransport**, version **2.12.1** -[![CRAN status](https://www.r-pkg.org/badges/version/edgeTransport)](https://cran.r-project.org/package=edgeTransport) [![R build status](https://github.com/pik-piam/edgeTransport/workflows/check/badge.svg)](https://github.com/pik-piam/edgeTransport/actions) [![codecov](https://codecov.io/gh/pik-piam/edgeTransport/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/edgeTransport) [![r-universe](https://pik-piam.r-universe.dev/badges/edgeTransport)](https://pik-piam.r-universe.dev/builds) +[![CRAN status](https://www.r-pkg.org/badges/version/edgeTransport)](https://cran.r-project.org/package=edgeTransport) [![R build status](https://github.com/pik-piam/edgeTransport/workflows/check/badge.svg)](https://github.com/pik-piam/edgeTransport/actions) [![codecov](https://codecov.io/gh/pik-piam/edgeTransport/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/edgeTransport) [![r-universe](https://pik-piam.r-universe.dev/badges/edgeTransport)](https://pik-piam.r-universe.dev/builds) ## Purpose and Functionality @@ -46,7 +46,7 @@ In case of questions / problems please contact Johanna Hoppe . +Hoppe J, Dirnaichner A, Rottoli M, Muessel J (2024). _edgeTransport: Prepare EDGE Transport Data for the REMIND model_. R package version 2.12.1, . A BibTeX entry for LaTeX users is @@ -55,7 +55,7 @@ A BibTeX entry for LaTeX users is title = {edgeTransport: Prepare EDGE Transport Data for the REMIND model}, author = {Johanna Hoppe and Alois Dirnaichner and Marianna Rottoli and Jarusch Muessel}, year = {2024}, - note = {R package version 2.12.0}, + note = {R package version 2.12.1}, url = {https://github.com/pik-piam/edgeTransport}, } ``` diff --git a/man/EdgeTransportSA.Rd b/man/EdgeTransportSA.Rd index bff774c..8a22447 100644 --- a/man/EdgeTransportSA.Rd +++ b/man/EdgeTransportSA.Rd @@ -9,7 +9,6 @@ calcEdgeTransportSA( transportPolScen, isICEban = FALSE, demScen = "default", - gdxPath = NULL, outputFolder = NULL, isStored = FALSE, isTransportReported = TRUE, @@ -27,8 +26,6 @@ calcEdgeTransportSA( \item{demScen}{Demand scenario, used to apply reduction factors on total demands from the regression} -\item{gdxPath}{Path to a GDX file to load price signals from a REMIND run} - \item{outputFolder}{Path to folder for storing output data} \item{isStored}{Optional saving of intermediate RDS files} diff --git a/man/toolEdgeTransportSA.Rd b/man/toolEdgeTransportSA.Rd index 4042ef9..2d3f640 100644 --- a/man/toolEdgeTransportSA.Rd +++ b/man/toolEdgeTransportSA.Rd @@ -9,7 +9,6 @@ toolEdgeTransportSA( transportPolScen, isICEban = FALSE, demScen = "default", - gdxPath = NULL, outputFolder = NULL, isStored = TRUE, isTransportReported = TRUE, @@ -27,8 +26,6 @@ toolEdgeTransportSA( \item{demScen}{Demand scenario, used to apply reduction factors on total demands from the regression} -\item{gdxPath}{Path to a GDX file to load price signals from a REMIND run} - \item{outputFolder}{Path to folder for storing output data} \item{isStored}{Optional saving of intermediate RDS files} diff --git a/man/toolLoadInputs.Rd b/man/toolLoadInputs.Rd index 8203d33..6ed3021 100644 --- a/man/toolLoadInputs.Rd +++ b/man/toolLoadInputs.Rd @@ -4,7 +4,7 @@ \alias{toolLoadInputs} \title{Load all inputs that are required to run the model} \usage{ -toolLoadInputs(SSPscen, transportPolScen, demScen, gdxPath, hybridElecShare) +toolLoadInputs(SSPscen, transportPolScen, demScen, hybridElecShare) } \arguments{ \item{SSPscen}{SSP or SDP scenario} @@ -13,8 +13,6 @@ toolLoadInputs(SSPscen, transportPolScen, demScen, gdxPath, hybridElecShare) \item{demScen}{Demand scenario, used to apply reduction factors on total demands from the regression} -\item{gdxPath}{Path to a GDX file to load price signals from a REMIND run} - \item{hybridElecShare}{Share of electricity in Hybrid electric vehicles} } \value{ From 28d996ec69abad7a5e84c235873adacff6c6c4ec Mon Sep 17 00:00:00 2001 From: Falk Benke Date: Fri, 13 Dec 2024 10:38:48 +0100 Subject: [PATCH 2/2] bring back option to set gdx path in EDGE Transport SA --- .buildlibrary | 2 +- CITATION.cff | 2 +- DESCRIPTION | 2 +- R/calcEdgeTransportSA.R | 3 +++ R/toolEdgeTransportSA.R | 5 ++++- R/toolLoadInputs.R | 5 +++-- man/EdgeTransportSA.Rd | 3 +++ man/toolEdgeTransportSA.Rd | 3 +++ man/toolLoadInputs.Rd | 4 +++- 9 files changed, 22 insertions(+), 7 deletions(-) diff --git a/.buildlibrary b/.buildlibrary index c34ea5a..5150191 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '42559986' +ValidationKey: '42568470' AutocreateReadme: yes AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' diff --git a/CITATION.cff b/CITATION.cff index 5a8939b..27b368e 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -3,7 +3,7 @@ message: If you use this software, please cite it using the metadata from this f type: software title: 'edgeTransport: Prepare EDGE Transport Data for the REMIND model' version: 2.12.1 -date-released: '2024-12-09' +date-released: '2024-12-13' abstract: EDGE-T is a fork of the GCAM transport module https://jgcri.github.io/gcam-doc/energy.html#transportation with a high level of detail in its representation of technological and modal options. It is a partial equilibrium model with a nested multinomial logit structure and diff --git a/DESCRIPTION b/DESCRIPTION index d973d3d..dec0eb8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,7 +19,7 @@ Encoding: UTF-8 LazyData: true RoxygenNote: 7.3.2 VignetteBuilder: knitr -Date: 2024-12-09 +Date: 2024-12-13 Config/testthat/edition: 3 Imports: rmndt, diff --git a/R/calcEdgeTransportSA.R b/R/calcEdgeTransportSA.R index a693f29..e714593 100644 --- a/R/calcEdgeTransportSA.R +++ b/R/calcEdgeTransportSA.R @@ -8,6 +8,7 @@ #' @param transportPolScen EDGE-T transport policy scenario #' @param isICEban optional enabling of ICE ban #' @param demScen Demand scenario, used to apply reduction factors on total demands from the regression +#' @param gdxPath Path to a GDX file to load price signals from a REMIND run #' @param outputFolder Path to folder for storing output data #' @param isStored Optional saving of intermediate RDS files #' @param isTransportReported Optional transport reporting in MIF format @@ -23,6 +24,7 @@ calcEdgeTransportSA <- function(SSPscen, transportPolScen, isICEban = FALSE, demScen = "default", + gdxPath = NULL, outputFolder = NULL, isStored = FALSE, isTransportReported = TRUE, @@ -35,6 +37,7 @@ calcEdgeTransportSA <- function(SSPscen, transportPolScen, isICEban, demScen, + gdxPath, outputFolder, isStored, isTransportReported, diff --git a/R/toolEdgeTransportSA.R b/R/toolEdgeTransportSA.R index a374636..246cad1 100644 --- a/R/toolEdgeTransportSA.R +++ b/R/toolEdgeTransportSA.R @@ -8,6 +8,7 @@ #' @param transportPolScen EDGE-T transport policy scenario #' @param isICEban optional enabling of ICE ban #' @param demScen Demand scenario, used to apply reduction factors on total demands from the regression +#' @param gdxPath Path to a GDX file to load price signals from a REMIND run #' @param outputFolder Path to folder for storing output data #' @param isStored Optional saving of intermediate RDS files #' @param isTransportReported Optional transport reporting in MIF format @@ -24,6 +25,7 @@ toolEdgeTransportSA <- function(SSPscen, transportPolScen, isICEban = FALSE, demScen = "default", + gdxPath = NULL, outputFolder = NULL, isStored = TRUE, isTransportReported = TRUE, @@ -45,7 +47,7 @@ toolEdgeTransportSA <- function(SSPscen, ######################################################## if (is.null(outputFolder) & isStored) stop("Please provide an outputfolder to store your results") - inputs <- toolLoadInputs(SSPscen, transportPolScen, demScen, hybridElecShare) + inputs <- toolLoadInputs(SSPscen, transportPolScen, demScen, gdxPath, hybridElecShare) helpers <- inputs$helpers genModelPar <- inputs$genModelPar @@ -224,6 +226,7 @@ toolEdgeTransportSA <- function(SSPscen, SSPscen = SSPscen, transportPolScen = transportPolScen, demScen = demScen, + gdxPath = gdxPath, hybridElecShare = hybridElecShare, histPrefs = histPrefs, fleetSizeAndComposition = fleetSizeAndComposition, diff --git a/R/toolLoadInputs.R b/R/toolLoadInputs.R index f7f94af..584de75 100644 --- a/R/toolLoadInputs.R +++ b/R/toolLoadInputs.R @@ -3,12 +3,13 @@ #' @param SSPscen SSP or SDP scenario #' @param transportPolScen EDGE-T transport policy scenario #' @param demScen Demand scenario, used to apply reduction factors on total demands from the regression +#' @param gdxPath Path to a GDX file to load price signals from a REMIND run #' @param hybridElecShare Share of electricity in Hybrid electric vehicles #' @returns list with different input data sets #' @import data.table #' @export -toolLoadInputs <- function(SSPscen, transportPolScen, demScen, hybridElecShare) { +toolLoadInputs <- function(SSPscen, transportPolScen, demScen, gdxPath, hybridElecShare) { ### load inputs ------------------------------------------------------------ @@ -47,7 +48,7 @@ toolLoadInputs <- function(SSPscen, transportPolScen, demScen, hybridElecShare) mrdriversData <- toolLoadmrdriversData(SSPscen, helpers) ## from REMIND - REMINDfuelCosts <- toolLoadREMINDfuelCosts(gdxPath = NULL, hybridElecShare, helpers) + REMINDfuelCosts <- toolLoadREMINDfuelCosts(gdxPath, hybridElecShare, helpers) # from mrremind (soon to be replaced by mrtransport data) mrremindData <- toolLoadmrremindData(helpers) diff --git a/man/EdgeTransportSA.Rd b/man/EdgeTransportSA.Rd index 8a22447..bff774c 100644 --- a/man/EdgeTransportSA.Rd +++ b/man/EdgeTransportSA.Rd @@ -9,6 +9,7 @@ calcEdgeTransportSA( transportPolScen, isICEban = FALSE, demScen = "default", + gdxPath = NULL, outputFolder = NULL, isStored = FALSE, isTransportReported = TRUE, @@ -26,6 +27,8 @@ calcEdgeTransportSA( \item{demScen}{Demand scenario, used to apply reduction factors on total demands from the regression} +\item{gdxPath}{Path to a GDX file to load price signals from a REMIND run} + \item{outputFolder}{Path to folder for storing output data} \item{isStored}{Optional saving of intermediate RDS files} diff --git a/man/toolEdgeTransportSA.Rd b/man/toolEdgeTransportSA.Rd index 2d3f640..4042ef9 100644 --- a/man/toolEdgeTransportSA.Rd +++ b/man/toolEdgeTransportSA.Rd @@ -9,6 +9,7 @@ toolEdgeTransportSA( transportPolScen, isICEban = FALSE, demScen = "default", + gdxPath = NULL, outputFolder = NULL, isStored = TRUE, isTransportReported = TRUE, @@ -26,6 +27,8 @@ toolEdgeTransportSA( \item{demScen}{Demand scenario, used to apply reduction factors on total demands from the regression} +\item{gdxPath}{Path to a GDX file to load price signals from a REMIND run} + \item{outputFolder}{Path to folder for storing output data} \item{isStored}{Optional saving of intermediate RDS files} diff --git a/man/toolLoadInputs.Rd b/man/toolLoadInputs.Rd index 6ed3021..8203d33 100644 --- a/man/toolLoadInputs.Rd +++ b/man/toolLoadInputs.Rd @@ -4,7 +4,7 @@ \alias{toolLoadInputs} \title{Load all inputs that are required to run the model} \usage{ -toolLoadInputs(SSPscen, transportPolScen, demScen, hybridElecShare) +toolLoadInputs(SSPscen, transportPolScen, demScen, gdxPath, hybridElecShare) } \arguments{ \item{SSPscen}{SSP or SDP scenario} @@ -13,6 +13,8 @@ toolLoadInputs(SSPscen, transportPolScen, demScen, hybridElecShare) \item{demScen}{Demand scenario, used to apply reduction factors on total demands from the regression} +\item{gdxPath}{Path to a GDX file to load price signals from a REMIND run} + \item{hybridElecShare}{Share of electricity in Hybrid electric vehicles} } \value{