Skip to content

Commit

Permalink
Merge pull request #280 from johannah-pik/unitShift2
Browse files Browse the repository at this point in the history
Shift to US$2017 for monetary units
  • Loading branch information
johannah-pik authored Sep 20, 2024
2 parents 088b004 + c90e73a commit 10e786f
Show file tree
Hide file tree
Showing 18 changed files with 355 additions and 355 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '5235546'
ValidationKey: '5396220'
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.6.2
date-released: '2024-09-17'
version: 2.7.0
date-released: '2024-09-20'
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.6.2
Version: 2.7.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-09-17
Date: 2024-09-20
Config/testthat/edition: 3
Imports:
rmndt,
Expand Down
8 changes: 4 additions & 4 deletions R/iterativeEDGETransport.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,20 @@ iterativeEdgeTransport <- function() {

## Load REMIND fuel cost
REMINDfuelCost <- toolLoadREMINDfuelCosts(gdx, hybridElecShare, helpers)
# Convert fuel costs from US$2005/MJ to US$2005/vehkm
# Convert fuel costs from US$2017/MJ to US$2017/vehkm
# Merge with energy intensity
energyIntensity <- copy(RDSinputs$scenSpecEnIntensity)
energyIntensity[, c("variable", "unit") := NULL]
setnames(energyIntensity, "value", "energyIntensity")
REMINDfuelCost <- merge(REMINDfuelCost, energyIntensity, by = c("region", "univocalName", "technology", "period"))
REMINDfuelCost[, value := value * energyIntensity][, unit := "US$2005/vehkm"][, energyIntensity := NULL]
# Convert fuel costs from US$2005/vehkm to US$2005/(p|t)km
REMINDfuelCost[, value := value * energyIntensity][, unit := "US$2017/vehkm"][, energyIntensity := NULL]
# Convert fuel costs from US$2017/vehkm to US$2017/(p|t)km
loadFactor <- copy(RDSinputs$scenSpecLoadFactor)
loadFactor[, c("variable", "unit") := NULL]
setnames(loadFactor, "value", "loadFactor")
REMINDfuelCost <- merge(REMINDfuelCost, loadFactor, by = c("region", "univocalName", "technology", "period"))
REMINDfuelCost[, value := value / loadFactor][, loadFactor := NULL]
REMINDfuelCost[, unit := ifelse(univocalName %in% c(helpers$filter$trn_pass, "International Aviation"), "US$2005/pkm", "US$2005/tkm")]
REMINDfuelCost[, unit := ifelse(univocalName %in% c(helpers$filter$trn_pass, "International Aviation"), "US$2017/pkm", "US$2017/tkm")]

pathFuelCosts <- list.files(file.path(".", edgeTransportFolder), "REMINDfuelCostIterations.RDS", recursive = TRUE, full.names = TRUE)
if (length(pathFuelCosts) > 0) {
Expand Down
2 changes: 1 addition & 1 deletion R/toolCalculateFS3share.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

toolCalculateFS3share <- function(endoCostData, timesteps, timeValue, preferences, lambdas, helpers){

#time costs in [$2005/pkm] for traveling with mode X in region Y
#time costs in [US$2017/pkm] for traveling with mode X in region Y
timeValueCosts <- merge(timeValue, unique(helpers$decisionTree[, -c("technology")]), by = c("region", "univocalName"), all.x = TRUE)
timeValueCosts[, type := "Travel time"][, c("unit", "univocalName", "variable") := NULL]
if (length(timesteps) > 1) {
Expand Down
14 changes: 7 additions & 7 deletions R/toolCalculateInitialIncoCost.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @param annualMileage annual mileage data
#' @param helpers list with helpers
#' @import data.table
#' @returns data.table including initial inconvenience costs from 1990-2020 for LDV 4W US$2005/(p|t)km
#' @returns data.table including initial inconvenience costs from 1990-2020 for LDV 4W US$2017/(p|t)km

toolCalculateInitialIncoCost <- function(combinedCost, incoCostStartVal, annuity, loadFactor, annualMileage, helpers) {

Expand Down Expand Up @@ -65,13 +65,13 @@ toolCalculateInitialIncoCost <- function(combinedCost, incoCostStartVal, annuity
incoCostStartValReg <- merge(decTree, incoCostStartValReg, by = c("region", "univocalName", "technology"),
all.x = TRUE, allow.cartesian = TRUE)

incoCostStartValReg[, unit := "US$2005/veh/yr"]
incoCostStartValReg[, unit := "US$2017/veh/yr"]
setnames(incoCostStartValReg, "incoCostType", "variable")

# convert to US$2005/pkm
# Annualize and discount to convert to US$2005/veh/yr
# convert to US$2017/pkm
# Annualize and discount to convert to US$2017/veh/yr
annualizedincoCostStartVal <- merge(incoCostStartValReg, annuity, by = "univocalName", allow.cartesian = TRUE)
annualizedincoCostStartVal[, value := value * annuity][, unit := "US$2005/veh/yr"][, annuity := NULL]
annualizedincoCostStartVal[, value := value * annuity][, unit := "US$2017/veh/yr"][, annuity := NULL]

loadFactor <- copy(loadFactor)
loadFactor[, c("variable", "unit") := NULL]
Expand All @@ -85,9 +85,9 @@ toolCalculateInitialIncoCost <- function(combinedCost, incoCostStartVal, annuity
annualizedincoCostStartVal <- merge(annualizedincoCostStartVal, annualMileage,
c("region", "univocalName", "technology", "period"), all.x = TRUE)
annualizedincoCostStartVal[, value := value / (annualMileage * loadFactor)][, c("loadFactor", "annualMileage") := NULL]
#unit US$2005/pkm for passenger and unit US$2005/tkm for freight
#unit US$2017/pkm for passenger and unit US$2017/tkm for freight
annualizedincoCostStartVal[, unit := ifelse(univocalName %in% c(helpers$filter$trn_pass, "International Aviation"),
"US$2005/pkm", "US$2005/tkm")]
"US$2017/pkm", "US$2017/tkm")]

if (anyNA(annualizedincoCostStartVal) == TRUE) {
stop("Inconvenience cost start values contain NAs")
Expand Down
24 changes: 12 additions & 12 deletions R/toolCombineCAPEXandOPEX.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Function that converts CAPEX and OPEX into US$2005/(p|t)km and provides them combined in a structured format
#' Function that converts CAPEX and OPEX into US$2017/(p|t)km and provides them combined in a structured format
#'
#' @param CAPEXtrackedFleet CAPEX data for vehicle types that feature fleet tracking: Cars, trucks, busses
#' @param nonFuelOPEXtrackedFleet non-fuel OPEX data for vehicle types that feature fleet tracking: Cars, trucks, busses
Expand All @@ -12,7 +12,7 @@
#' @param annuity calculated annuity for different vehicle types
#' @param helpers list with helpers
#' @import data.table
#' @returns data.table including total costs of ownership in US$2005/(p|t)km
#' @returns data.table including total costs of ownership in US$2017/(p|t)km


toolCombineCAPEXandOPEX <- function(CAPEXtrackedFleet,
Expand All @@ -33,42 +33,42 @@ toolCombineCAPEXandOPEX <- function(CAPEXtrackedFleet,
value), by = c("region", "period", "value")]

# Tracked fleet (LDV 4W, Trucks, Busses)
# Annualize and discount CAPEX to convert to US$2005/veh/yr
# Annualize and discount CAPEX to convert to US$2017/veh/yr
# Include subsidies on LDV 4 Wheelers
upfrontCAPEXtrackedFleet <- rbind(CAPEXtrackedFleet, subsidies) # in US$2005/veh
upfrontCAPEXtrackedFleet <- rbind(CAPEXtrackedFleet, subsidies) # in US$2017/veh
cols <- names(upfrontCAPEXtrackedFleet)
cols <- cols[!cols %in% c("value", "variable")]
upfrontCAPEXtrackedFleet[, .(value = sum(value)), by = cols][, variable := "Upfront capital costs sales"]
annualizedCapexTrackedFleet <- merge(upfrontCAPEXtrackedFleet, annuity, by = "univocalName", allow.cartesian = TRUE)
annualizedCapexTrackedFleet[, value := value * annuity][, unit := "US$2005/veh/yr"][, annuity := NULL]
annualizedCapexTrackedFleet[, value := value * annuity][, unit := "US$2017/veh/yr"][, annuity := NULL]
# Combine with non Fuel OPEX
CAPEXandNonFuelOPEXtrackedFleet <- rbind(annualizedCapexTrackedFleet, nonFuelOPEXtrackedFleet)
# Merge with annual mileage to convert to US$2005/vehkm
# Merge with annual mileage to convert to US$2017/vehkm
annualMileage <- copy(annualMileage)
annualMileage[, c("variable", "unit") := NULL]
setnames(annualMileage, "value", "annualMileage")
CAPEXandNonFuelOPEXtrackedFleet <- merge(CAPEXandNonFuelOPEXtrackedFleet, annualMileage, by = c("region", "univocalName", "technology", "period"))
CAPEXandNonFuelOPEXtrackedFleet[, value := value / annualMileage][, unit := "US$2005/vehkm"][, annualMileage := NULL]
CAPEXandNonFuelOPEXtrackedFleet[, value := value / annualMileage][, unit := "US$2017/vehkm"][, annualMileage := NULL]

# Combine with other modes of transport provided in US$2005/vehkm
# Combine with other modes of transport provided in US$2017/vehkm
CAPEXandNonFuelOPEX <- rbind(CAPEXandNonFuelOPEXtrackedFleet, CAPEXother, nonFuelOPEXother)

# Convert fuel costs from US$2005/MJ to US$2005/vehkm
# Convert fuel costs from US$2017/MJ to US$2017/vehkm
# Merge with energy intensity
energyIntensity <- copy(energyIntensity)
energyIntensity[, c("variable", "unit") := NULL]
setnames(energyIntensity, "value", "energyIntensity")
fuelCosts <- merge(fuelCosts, energyIntensity, by = c("region", "univocalName", "technology", "period"))
fuelCosts[, value := value * energyIntensity][, unit := "US$2005/vehkm"][, energyIntensity := NULL]
fuelCosts[, value := value * energyIntensity][, unit := "US$2017/vehkm"][, energyIntensity := NULL]
combinedCAPEXandOPEX <- rbind(CAPEXandNonFuelOPEX, fuelCosts)

# Convert all cost components from US$2005/vehkm to US$2005/(p|t)km
# Convert all cost components from US$2017/vehkm to US$2017/(p|t)km
loadFactor <- copy(loadFactor)
loadFactor[, c("variable", "unit") := NULL]
setnames(loadFactor, "value", "loadFactor")
combinedCAPEXandOPEX <- merge(combinedCAPEXandOPEX, loadFactor, by = c("region", "univocalName", "technology", "period"))
combinedCAPEXandOPEX[, value := value / loadFactor][, loadFactor := NULL]
combinedCAPEXandOPEX[, unit := ifelse(univocalName %in% c(helpers$filter$trn_pass, "International Aviation"), "US$2005/pkm", "US$2005/tkm")]
combinedCAPEXandOPEX[, unit := ifelse(univocalName %in% c(helpers$filter$trn_pass, "International Aviation"), "US$2017/pkm", "US$2017/tkm")]

# add zeros for active modes (time value costs are treated seperately)
# use dummy that does not feature fleet tracking
Expand Down
8 changes: 4 additions & 4 deletions R/toolLoadREMINDfuelCosts.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Load fuel prices from a REMIND fulldata.gdx in [US$2005/MJ] and map them on to
#' Load fuel prices from a REMIND fulldata.gdx in [US$2017/MJ] and map them on to
#' the edgeTransport decision tree. The output is provided in the same spatial resolution
#' as the transferred gdx file and the temporal resolution is set according to the param yrs.
#'
Expand Down Expand Up @@ -26,10 +26,10 @@ toolLoadREMINDfuelCosts <- function(gdxPath, hybridElecShare, helpers){
fuelCosts <- fuelCosts %>% lowpass() %>% magpie2dt()
setnames(fuelCosts, c("all_regi", "ttot"), c("region", "period"))
fuelCosts <- fuelCosts[, c("region", "period", "all_enty", "value")]
# convert from TerraUS2005$ per TWyear to US2005$ per EJ
# convert from TerraUS$2017 per TWyear to US$2017 per EJ
tdptwyr2dpgj <- 31.71 # TerraDollar per TWyear to Dollar per GJ
GJtoMJ <- 1e-3 # dollar per GJ to dollar per MJ
fuelCosts[, value := value * tdptwyr2dpgj * GJtoMJ] # US$2005/MJ
fuelCosts[, value := value * tdptwyr2dpgj * GJtoMJ] # US$2017/MJ
# map on EDGE-T structure
fuelCosts <- merge(fuelCosts, mapEdgeToREMIND, by = "all_enty", all.y = TRUE, allow.cartesian = TRUE)[, all_enty := NULL]
# calculate price for hybrids
Expand All @@ -49,7 +49,7 @@ toolLoadREMINDfuelCosts <- function(gdxPath, hybridElecShare, helpers){
print("Values are filtered out and are interpolated from other timesteps.")
}

fuelCosts[, variable := "Fuel costs"][, unit := "US$2005/MJ"]
fuelCosts[, variable := "Fuel costs"][, unit := "US$2017/MJ"]

# get right temporal resolution
fuelCosts <- toolApplyMixedTimeRes(fuelCosts, helpers)
Expand Down
4 changes: 2 additions & 2 deletions R/toolLoadmrremindData.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ toolLoadmrremindData <- function(helpers) {
#average between legal and private entities
subsidies <- subsidies[, .(value = mean(value)), by = c("region", "period", "technology")]
# exchange rate 2020: 1 euro = 1.12 dollar
# conversion from EUR2020 to US$2005 : inflation/exchange rate = 1.3504/1.12 = 1.205714286
# conversion from EUR2020 to US$2017 : inflation/exchange rate = 1.3504/1.12 = 1.205714286
subsidies[, value := value / 1.205714286] # in 2005 USD
subsidies[, value := - value] # count subsidies negative
completeSub <- unique(subsidies[, c("region", "technology")])[, temporal := "all"]
Expand All @@ -32,7 +32,7 @@ toolLoadmrremindData <- function(helpers) {
subsidies <- merge(unique(helpers$decisionTree[subsectorL3 == "trn_pass_road_LDV_4W",
c("region", "univocalName", "technology")]), subsidies,
by = c("region", "technology"), all.x = TRUE, allow.cartesian = TRUE)
subsidies <- subsidies[!is.na(value)][, variable := "Capital costs subsidy"][, unit := "US$2005/veh"]
subsidies <- subsidies[!is.na(value)][, variable := "Capital costs subsidy"][, unit := "US$2017/veh"]
#Q: How to include phase out of the incentives? Is that needed at all?

return(list(
Expand Down
10 changes: 5 additions & 5 deletions R/toolLoadmrtransportData.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ toolLoadmrtransportData <- function(SSPscen) {
regionmapping = "regionmapping_21_EU11.csv", subtype = "loadFactor", SSPscen = SSPscen)
loadFactorRaw <- magpie2dt(loadFactorMagpieobj)[, variable := paste0(variable, " (raw)")]

# CAPEX for the tracked fleet (cars, trucks, busses) [US$2005/veh]
# CAPEX for the tracked fleet (cars, trucks, busses) [US$2017/veh]
CAPEXtrackedFleetMagpieobj <- calcOutput(type = "EdgeTransportSAinputs", aggregate = TRUE, warnNA = FALSE,
regionmapping = "regionmapping_21_EU11.csv", subtype = "CAPEXtrackedFleet", SSPscen = SSPscen)
CAPEXtrackedFleet <- magpie2dt(CAPEXtrackedFleetMagpieobj)

# non-fuel OPEX for the tracked fleet (cars, trucks, busses) [US$2005/veh/yr]
# non-fuel OPEX for the tracked fleet (cars, trucks, busses) [US$2017/veh/yr]
nonFuelOPEXtrackedFleetMagpieobj <- calcOutput(type = "EdgeTransportSAinputs", aggregate = TRUE, warnNA = FALSE,
regionmapping = "regionmapping_21_EU11.csv", subtype = "nonFuelOPEXtrackedFleet", SSPscen = SSPscen)
nonFuelOPEXtrackedFleet <- magpie2dt(nonFuelOPEXtrackedFleetMagpieobj)

# CAPEX other [US$2005/vehkm]
# CAPEX other [US$2017/vehkm]
CAPEXotherMagpieobj <- calcOutput(type = "EdgeTransportSAinputs", aggregate = TRUE, warnNA = FALSE,
regionmapping = "regionmapping_21_EU11.csv", subtype = "CAPEXother", SSPscen = SSPscen)
CAPEXother <- magpie2dt(CAPEXotherMagpieobj)

# non-fuel OPEX other [US$2005/vehkm]
# non-fuel OPEX other [US$2017/vehkm]
nonFuelOPEXotherMagpieobj <- calcOutput(type = "EdgeTransportSAinputs", aggregate = TRUE, warnNA = FALSE,
regionmapping = "regionmapping_21_EU11.csv", subtype = "nonFuelOPEXother", SSPscen = SSPscen)
nonFuelOPEXother <- magpie2dt(nonFuelOPEXotherMagpieobj)
Expand All @@ -45,7 +45,7 @@ toolLoadmrtransportData <- function(SSPscen) {
regionmapping = "regionmapping_21_EU11.csv", subtype = "annualMileage", SSPscen = SSPscen)
annualMileage <- magpie2dt(annualMileageMagpieobj)

# Time value costs [US$2005/pkm]
# Time value costs [US$2017/pkm]
timeValueCostsMagpieobj <- calcOutput(type = "EdgeTransportSAinputs", aggregate = TRUE, warnNA = FALSE,
regionmapping = "regionmapping_21_EU11.csv", subtype = "timeValueCosts", SSPscen = SSPscen)
timeValueCosts <- magpie2dt(timeValueCostsMagpieobj)
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.6.2**
R package **edgeTransport**, version **2.7.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.6.2, <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.7.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.6.2},
note = {R package version 2.7.0},
url = {https://github.com/pik-piam/edgeTransport},
}
```
32 changes: 16 additions & 16 deletions inst/extdata/genParDemRegression.csv
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
* Description: Income elasticities used in the demand regression for time steps before the scenario differentiation is applied ;;;
variable;sector;GDPpcPPP;value
Income elasticity;trn_pass;10000;0.8
Income elasticity;trn_pass;20000;0.75
Income elasticity;trn_pass;30000;0.5
Income elasticity;trn_pass;40000;0.1
Income elasticity;trn_aviation_intl;10000;1.1
Income elasticity;trn_aviation_intl;20000;1.3
Income elasticity;trn_aviation_intl;30000;0.8
Income elasticity;trn_aviation_intl;40000;0.3
Income elasticity;trn_freight;10000;1.5
Income elasticity;trn_freight;20000;0.9
Income elasticity;trn_freight;30000;0.4
Income elasticity;trn_freight;40000;0.16
Income elasticity;trn_shipping_intl;10000;0.5
Income elasticity;trn_shipping_intl;20000;0.3
Income elasticity;trn_shipping_intl;30000;0.2
Income elasticity;trn_shipping_intl;40000;0.1
Income elasticity;trn_pass;12314;0.8
Income elasticity;trn_pass;24628;0.75
Income elasticity;trn_pass;36941;0.5
Income elasticity;trn_pass;49255;0.1
Income elasticity;trn_aviation_intl;12314;1.1
Income elasticity;trn_aviation_intl;24628;1.3
Income elasticity;trn_aviation_intl;36941;0.8
Income elasticity;trn_aviation_intl;49255;0.3
Income elasticity;trn_freight;12314;1.5
Income elasticity;trn_freight;24628;0.9
Income elasticity;trn_freight;36941;0.4
Income elasticity;trn_freight;49255;0.16
Income elasticity;trn_shipping_intl;12314;0.5
Income elasticity;trn_shipping_intl;24628;0.3
Income elasticity;trn_shipping_intl;36941;0.2
Income elasticity;trn_shipping_intl;49255;0.1
Loading

0 comments on commit 10e786f

Please sign in to comment.