From 2e73294d6407729fc0d68aadafdcdbb13775182b Mon Sep 17 00:00:00 2001 From: johannah-pik <89136160+johannah-pik@users.noreply.github.com> Date: Thu, 29 Aug 2024 10:41:27 +0200 Subject: [PATCH 1/3] Include historical ES demand for fleet calculation --- R/iterativeEDGETransport.R | 6 ++++-- R/supportFunctionsIterative.R | 40 +++++++++++++++++++++++------------ R/toolCalculateFVdemand.R | 2 +- R/toolLoadREMINDesDemand.R | 4 ++-- 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/R/iterativeEDGETransport.R b/R/iterativeEDGETransport.R index e54765e..1a27015 100644 --- a/R/iterativeEDGETransport.R +++ b/R/iterativeEDGETransport.R @@ -60,12 +60,12 @@ iterativeEdgeTransport <- function() { "scenSpecEnIntensity", "initialIncoCosts", "annualMileage", - "timeValueCosts") + "timeValueCosts", + "f29_trpdemand") inputs <- toolLoadIterativeInputs(edgeTransportFolder, inputFolder, inputFiles, numberOfRegions, SSPscen, transportPolScen, demScen) - helpers <- inputs$helpers genModelPar <- inputs$genModelPar scenModelPar <- inputs$scenModelPar @@ -74,6 +74,8 @@ iterativeEdgeTransport <- function() { # Data from previous REMIND iteration ## Load REMIND energy service demand REMINDsectorESdemand <- toolLoadREMINDesDemand(gdx, helpers) + REMINDsectorESdemand <- rbind(REMINDsectorESdemand, RDSinputs$f29_trpdemand[!period %in% unique(REMINDsectorESdemand$period)]) + ## Load REMIND fuel cost REMINDfuelCost <- toolLoadREMINDfuelCosts(gdx, hybridElecShare, helpers) # Convert fuel costs from US$2005/MJ to US$2005/vehkm diff --git a/R/supportFunctionsIterative.R b/R/supportFunctionsIterative.R index 77ee0a4..f49f36b 100644 --- a/R/supportFunctionsIterative.R +++ b/R/supportFunctionsIterative.R @@ -17,6 +17,7 @@ "level", "variable", "unit", "value") else if (filename == "initialIncoCosts") colNames <- c("period", "region", "SSPscen", "demScen", "transportPolScen", "univocalName","technology","variable","unit","type","value") else if (filename == "timeValueCosts") colNames <- c("period", "region", "SSPscen", "demScen", "transportPolScen", "univocalName", "variable", "unit", "value") + else if (filename == "f29_trpdemand") colNames <- c("period", "region", "SSPscen", "demScen", "transportPolScen", "all_in", "value") else colNames <- c("period", "region", "SSPscen", "demScen", "transportPolScen", "univocalName", "technology", "variable", "unit", "value") tmp <- fread( @@ -52,19 +53,6 @@ toolLoadRDSinputs <- function(edgeTransportFolder, inputFiles) { #' @export toolLoadIterativeInputs <- function(edgeTransportFolder, inputFolder, inputFiles, numberOfRegions, SSPscenario, transportPolScenario, demScenario) { - # Input from REMIND input data - # In the first iteration input data needs to be loaded - if (!dir.exists(file.path(edgeTransportFolder))) { - print("Loading csv data from input folder and creating RDS files...")} - RDSfiles <- list() - for (filename in inputFiles) { - if (length(list.files(file.path(".", edgeTransportFolder), paste0(filename, ".RDS"), recursive = TRUE, full.names = TRUE)) < 1) { - RDSfiles <- append(RDSfiles, csv2RDS(filename, inputFolder, SSPscenario, demScenario, transportPolScenario)) - } - } - if (length(RDSfiles) > 0) storeData(file.path(".", edgeTransportFolder), varsList = RDSfiles) - - if (!length(RDSfiles) == length(inputFiles)) RDSfiles <- toolLoadRDSinputs(edgeTransportFolder, inputFiles) # Model input parameters from the package ## Exponents discrete choice model @@ -109,6 +97,32 @@ toolLoadIterativeInputs <- function(edgeTransportFolder, inputFolder, inputFiles filterEntries[["trackedFleet"]] <- c(filterEntries[["trn_pass_road_LDV_4W"]], filterEntries[["trn_freight_road"]], getFilterEntriesUnivocalName("Bus", decisionTree)[["Bus"]]) + # Input from REMIND input data + # In the first iteration input data needs to be loaded + if (!dir.exists(file.path(edgeTransportFolder))) { + print("Loading csv data from input folder and creating RDS files...")} + RDSfiles <- list() + for (filename in inputFiles) { + if (length(list.files(file.path(".", edgeTransportFolder), paste0(filename, ".RDS"), recursive = TRUE, full.names = TRUE)) < 1) { + RDSfiles <- append(RDSfiles, csv2RDS(filename, inputFolder, SSPscenario, demScenario, transportPolScenario)) + } + } + if (!is.null(RDSfiles$f29_trpdemand)) { + mapEdgeSectorToREMIND <- merge(mapEdgeToREMIND, unique(decisionTree[, c("sector", "univocalName")]), by = "univocalName", allow.cartesian = TRUE, all.x = TRUE) + mapEdgeSectorToREMIND <- mapEdgeSectorToREMIND[!is.na(all_in)] + mapEdgeSectorToREMIND <- unique(mapEdgeSectorToREMIND[, c("all_in", "sector")]) + RDSfiles$f29_trpdemand <- merge(RDSfiles$f29_trpdemand[period >= 1990], mapEdgeSectorToREMIND, by = "all_in")[, all_in := NULL] + ## convert unit + trillionToBillion <- 1e3 + RDSfiles$f29_trpdemand[, value := value + * trillionToBillion] + RDSfiles$f29_trpdemand[, unit := ifelse(sector %in% c("trn_pass", "trn_aviation_intl"), "billion pkm/yr", "billion tkm/yr")][, variable := "ES"] + setcolorder(RDSfiles$f29_trpdemand, c("region", "period", "sector", "value", "unit")) + } + if (length(RDSfiles) > 0) storeData(file.path(".", edgeTransportFolder), varsList = RDSfiles) + + if (!length(RDSfiles) == length(inputFiles)) RDSfiles <- toolLoadRDSinputs(edgeTransportFolder, inputFiles) + # Time resolution dtTimeRes <- unique(RDSfiles$scenSpecEnIntensity[, c("univocalName", "period")]) highRes <- unique(dtTimeRes$period) diff --git a/R/toolCalculateFVdemand.R b/R/toolCalculateFVdemand.R index 3aef178..59a8b67 100644 --- a/R/toolCalculateFVdemand.R +++ b/R/toolCalculateFVdemand.R @@ -19,7 +19,7 @@ toolCalculateFVdemand <- function(sectorESdemand, salesAndModeShares, helpers, h FVSshares <- FVSshares[, c("region", "sector", "subsectorL1", "subsectorL2", "subsectorL3", "vehicleType", "technology", "period", "FVSshare")] # Apply shares on demand -------------------------------------------- - fuelVehicleESdemand <- merge(sectorESdemand, FVSshares, by = intersect(names(sectorESdemand), names(FVSshares)), all = TRUE) + fuelVehicleESdemand <- merge(sectorESdemand, FVSshares, by = intersect(names(sectorESdemand), names(FVSshares)), all.y = TRUE) fuelVehicleESdemand[, value := value * FVSshare][, FVSshare := NULL] if (!is.null(histESdemand)){ diff --git a/R/toolLoadREMINDesDemand.R b/R/toolLoadREMINDesDemand.R index aa27bb8..3f3b40c 100644 --- a/R/toolLoadREMINDesDemand.R +++ b/R/toolLoadREMINDesDemand.R @@ -14,11 +14,11 @@ toolLoadREMINDesDemand <- function(gdxPath, helpers) { value <- unit <- variable <- NULL mapEdgeToREMIND <- merge(helpers$mapEdgeToREMIND, unique(helpers$decisionTree[, c("sector", "univocalName")]), by = "univocalName", allow.cartesian = TRUE, all.x = TRUE) + mapEdgeToREMIND <- mapEdgeToREMIND[!is.na(all_in)] mapEdgeToREMIND <- unique(mapEdgeToREMIND[, c("all_in", "sector")]) - ESdemand <- readGDX(gdxPath, c("vm_cesIO"), field = "l") + ESdemand <- readGDX(gdxPath, c("vm_cesIO"), field = "l", restore_zeros = FALSE) ESdemand <- ESdemand[, , c("entrp_pass_sm", "entrp_pass_lo", "entrp_frgt_sm", "entrp_frgt_lo")] - ESdemand <- magpie2dt(ESdemand, regioncol = "region", yearcol = "period", datacols = "all_in") From 5eef75f57a4eb7a3fcc27a43981baa6387fd8906 Mon Sep 17 00:00:00 2001 From: johannah-pik <89136160+johannah-pik@users.noreply.github.com> Date: Fri, 30 Aug 2024 16:49:37 +0200 Subject: [PATCH 2/3] buildLib --- .buildlibrary | 2 +- CITATION.cff | 4 ++-- DESCRIPTION | 4 ++-- README.md | 6 +++--- man/iterativeEdgeTransport.Rd | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.buildlibrary b/.buildlibrary index ee181df..6d656b9 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '4208817' +ValidationKey: '4392300' AutocreateReadme: yes AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' diff --git a/CITATION.cff b/CITATION.cff index 40de071..61fe7cc 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.1.1 -date-released: '2024-08-12' +version: 2.2.0 +date-released: '2024-08-30' 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 55c523e..8d67a54 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: edgeTransport Title: Prepare EDGE Transport Data for the REMIND model -Version: 2.1.1 +Version: 2.2.0 Authors@R: c( person("Johanna", "Hoppe", , "johanna.hoppe@pik-potsdam.de", role = c("aut", "cre"), comment = c(ORCID = "0009-0004-6753-5090")), @@ -18,7 +18,7 @@ Encoding: UTF-8 LazyData: true RoxygenNote: 7.3.2 VignetteBuilder: knitr -Date: 2024-08-12 +Date: 2024-08-30 Config/testthat/edition: 3 Imports: rmndt, diff --git a/README.md b/README.md index 6e28c62..4a8e852 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Prepare EDGE Transport Data for the REMIND model -R package **edgeTransport**, version **2.1.1** +R package **edgeTransport**, version **2.2.0** [![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) @@ -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.2.0, . 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.1.1}, + note = {R package version 2.2.0}, url = {https://github.com/pik-piam/edgeTransport}, } ``` diff --git a/man/iterativeEdgeTransport.Rd b/man/iterativeEdgeTransport.Rd index c8e6b3b..2d40d8c 100644 --- a/man/iterativeEdgeTransport.Rd +++ b/man/iterativeEdgeTransport.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/iterativeEdgeTransport.R +% Please edit documentation in R/iterativeEDGETransport.R \name{iterativeEdgeTransport} \alias{iterativeEdgeTransport} \title{EDGE-Transport iterative} From b920f2f27a788817144f5a01d5833e03998b58e4 Mon Sep 17 00:00:00 2001 From: johannah-pik <89136160+johannah-pik@users.noreply.github.com> Date: Mon, 2 Sep 2024 09:16:45 +0200 Subject: [PATCH 3/3] buildLib --- .buildlibrary | 2 +- CITATION.cff | 4 ++-- DESCRIPTION | 4 ++-- README.md | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.buildlibrary b/.buildlibrary index 6d656b9..fbb2165 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '4392300' +ValidationKey: '4592640' AutocreateReadme: yes AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' diff --git a/CITATION.cff b/CITATION.cff index 61fe7cc..546b774 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.2.0 -date-released: '2024-08-30' +version: 2.3.0 +date-released: '2024-09-02' 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 8d67a54..f0e38d5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: edgeTransport Title: Prepare EDGE Transport Data for the REMIND model -Version: 2.2.0 +Version: 2.3.0 Authors@R: c( person("Johanna", "Hoppe", , "johanna.hoppe@pik-potsdam.de", role = c("aut", "cre"), comment = c(ORCID = "0009-0004-6753-5090")), @@ -18,7 +18,7 @@ Encoding: UTF-8 LazyData: true RoxygenNote: 7.3.2 VignetteBuilder: knitr -Date: 2024-08-30 +Date: 2024-09-02 Config/testthat/edition: 3 Imports: rmndt, diff --git a/README.md b/README.md index 4a8e852..c9ac18d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Prepare EDGE Transport Data for the REMIND model -R package **edgeTransport**, version **2.2.0** +R package **edgeTransport**, version **2.3.0** [![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) @@ -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.3.0, . 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.2.0}, + note = {R package version 2.3.0}, url = {https://github.com/pik-piam/edgeTransport}, } ```