Skip to content

Commit

Permalink
Merge pull request pik-piam#271 from johannah-pik/includeHistESdemand
Browse files Browse the repository at this point in the history
Include historical energy service demand for fleet calculation
  • Loading branch information
johannah-pik authored Sep 2, 2024
2 parents 0a259ad + b920f2f commit 9a9882e
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '4392300'
ValidationKey: '4592640'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0009-0004-6753-5090")),
Expand All @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions R/iterativeEDGETransport.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
40 changes: 27 additions & 13 deletions R/supportFunctionsIterative.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion R/toolCalculateFVdemand.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)){
Expand Down
4 changes: 2 additions & 2 deletions R/toolLoadREMINDesDemand.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -46,7 +46,7 @@ In case of questions / problems please contact Johanna Hoppe <johanna.hoppe@pik-

To cite package **edgeTransport** in publications use:

Hoppe J, Dirnaichner A, Rottoli M, Muessel J (2024). _edgeTransport: Prepare EDGE Transport Data for the REMIND model_. R package version 2.2.0, <https://github.com/pik-piam/edgeTransport>.
Hoppe J, Dirnaichner A, Rottoli M, Muessel J (2024). _edgeTransport: Prepare EDGE Transport Data for the REMIND model_. R package version 2.3.0, <https://github.com/pik-piam/edgeTransport>.

A BibTeX entry for LaTeX users is

Expand All @@ -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},
}
```

0 comments on commit 9a9882e

Please sign in to comment.