Skip to content

Commit

Permalink
fix Notes in EDGE-T functions
Browse files Browse the repository at this point in the history
  • Loading branch information
fbenke-pik committed Sep 30, 2024
1 parent 489b448 commit 6ed6309
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 139 deletions.
3 changes: 1 addition & 2 deletions .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '38546504'
ValidationKey: '38572284'
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
- 'Warning: namespace ''.*'' is not available and has been replaced'
Expand All @@ -10,7 +10,6 @@ AcceptedNotes:
- unable to verify current time
- Imports includes .* non-default packages.
- installed size is
- 'Undefined global functions or variables:'
AutocreateReadme: yes
allowLinterWarnings: yes
enforceVersionUpdate: yes
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: 'mrremind: MadRat REMIND Input Data Package'
version: 0.192.8
date-released: '2024-09-27'
version: 0.192.9
date-released: '2024-09-30'
abstract: The mrremind packages contains data preprocessing for the REMIND model.
authors:
- family-names: Baumstark
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: mrremind
Title: MadRat REMIND Input Data Package
Version: 0.192.8
Date: 2024-09-27
Version: 0.192.9
Date: 2024-09-30
Authors@R: c(
person("Lavinia", "Baumstark", , "[email protected]", role = c("aut", "cre")),
person("Renato", "Rodrigues", role = "aut"),
Expand Down
189 changes: 96 additions & 93 deletions R/calcEDGETransport.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,103 +5,106 @@
#' @param subtype REMIND/iterative EDGE-T input data subtypes
#' @return REMIND/iterative EDGE-T input data for all scenario combinations
#' @examples
#' \dontrun{ a <- calcOutput(type = "EDGETransport", subtype = "CAPEXandNonFuelOPEX", aggregate = F)
#' \dontrun{
#' a <- calcOutput(type = "EDGETransport", subtype = "CAPEXandNonFuelOPEX", aggregate = F)
#' }

calcEDGETransport <- function(subtype) {

x <- readSource("EDGETransport", subtype)

weightSum <- value <- NULL

switch(subtype,
"f35_esCapCost" = {
weight <- readSource("EDGETransport", subtype = "weightESdemand")
#Rule out numerical errors after disaggregating very small numbers
weight[weight < 1e-5] <- 0
#check whether weightsum is zero for some cases
#if so, the values should just be aggregated equally in order to prevent zeros in the results
weight <- rmndt::magpie2dt(weight)
regMap <- toolGetMapping(getConfig("regionmapping"), type = "regional", where = "mappingfolder")
setnames(regMap, "CountryCode", "all_regi")
weight <- merge(weight, regMap[, c("all_regi", "RegionCode")], by = "all_regi")
weight[, weightSum := sum(value), by = c("RegionCode", "GDP_scenario", "DEM_scenario", "EDGE_scenario", "all_teEs", "tall")]
weight[weightSum == 0, value := 1]
weight[, c("RegionCode", "weightSum") := NULL]
weight <- as.magpie(weight)
unit = "2017US$/(p|t)km"
description = "Capital cost (purchase) per energy service demand on CES level."
},
"f35_fe2es" = {
weight = readSource("EDGETransport", "f35_demByTech")
weight[weight < 1e-5] <- 0
#check whether weightsum is zero for some cases
#if so, the values should just be aggregated equally in order to prevent zeros in the results
weight <- rmndt::magpie2dt(weight)
regMap <- toolGetMapping(getConfig("regionmapping"), type = "regional", where = "mappingfolder")
setnames(regMap, "CountryCode", "all_regi")
weight <- merge(weight, regMap[, c("all_regi", "RegionCode")], by = "all_regi")
weight[, weightSum := sum(value), by = c("RegionCode", "GDP_scenario", "DEM_scenario", "EDGE_scenario", "all_enty", "all_in", "all_teEs", "tall")]
weight[weightSum == 0, value := 1]
weight[, c("RegionCode", "weightSum", "all_enty", "all_in") := NULL]
weight <- as.magpie(weight)
unit = "trn (p|t)km/Twa"
description = "Energy efficiency on CES level."
},
"f35_demByTech" = {
weight = NULL
unit = "TWa"
description = "Final energy demand on CES level."
},
"f29_trpdemand" = {
weight = NULL
unit = "trillion pkm/trillion tkm"
description = "Energy service demand on CES level."
},
"CAPEXandNonFuelOPEX" = {
gdp <- calcOutput("GDP", aggregate = FALSE)[,,"gdp_SSP2"]
weight = gdp |> time_interpolate(getYears(x))
unit = "2017US$/(p|t)km"
description = "Capital cost (purchase) and non-fuel operational costs on technology level."
},
"scenSpecPrefTrends" = {
gdp <- calcOutput("GDP", aggregate = FALSE)[,,"gdp_SSP2"]
weight = gdp |> time_interpolate(getYears(x))
unit = "-"
description = "Scenario specific preference trends on technology level."
},
"scenSpecLoadFactor" = {
gdp <- calcOutput("GDP", aggregate = FALSE)[,,"gdp_SSP2"]
weight = gdp |> time_interpolate(getYears(x))
unit = "-"
description = "Scenario specific load factor on technology level."
},
"scenSpecEnIntensity" = {
gdp <- calcOutput("GDP", aggregate = FALSE)[,,"gdp_SSP2"]
weight = gdp |> time_interpolate(getYears(x))
unit = "MJ/vehkm"
description = "Scenario specific energy intensity on technology level."
},
"initialIncoCosts" = {
gdp <- calcOutput("GDP", aggregate = FALSE)[,,"gdp_SSP2"]
weight = gdp |> time_interpolate(getYears(x))
unit = "2017US$/(p|t)km"
description = "Initial inconvenience cost values."
},
"annualMileage" = {
gdp <- calcOutput("GDP", aggregate = FALSE)[,,"gdp_SSP2"]
weight = gdp |> time_interpolate(getYears(x))
unit = "vehkm/yr"
description = "Annual vehicle km traveled."
},
"timeValueCosts" = {
gdp <- calcOutput("GDP", aggregate = FALSE)[,,"gdp_SSP2"]
weight = gdp |> time_interpolate(getYears(x))
unit = "2017US$/(p|t)km"
description = "Value of time cost equivalent."
}
)
"f35_esCapCost" = {
weight <- readSource("EDGETransport", subtype = "weightESdemand")
# Rule out numerical errors after disaggregating very small numbers
weight[weight < 1e-5] <- 0
# check whether weightsum is zero for some cases
# if so, the values should just be aggregated equally in order to prevent zeros in the results
weight <- rmndt::magpie2dt(weight)
regMap <- toolGetMapping(getConfig("regionmapping"), type = "regional", where = "mappingfolder")
setnames(regMap, "CountryCode", "all_regi")
weight <- merge(weight, regMap[, c("all_regi", "RegionCode")], by = "all_regi")
weight[, weightSum := sum(value), by = c("RegionCode", "GDP_scenario", "DEM_scenario", "EDGE_scenario", "all_teEs", "tall")]
weight[weightSum == 0, value := 1]
weight[, c("RegionCode", "weightSum") := NULL]
weight <- as.magpie(weight)
unit <- "2017US$/(p|t)km"
description <- "Capital cost (purchase) per energy service demand on CES level."
},
"f35_fe2es" = {
weight <- readSource("EDGETransport", "f35_demByTech")
weight[weight < 1e-5] <- 0
# check whether weightsum is zero for some cases
# if so, the values should just be aggregated equally in order to prevent zeros in the results
weight <- rmndt::magpie2dt(weight)
regMap <- toolGetMapping(getConfig("regionmapping"), type = "regional", where = "mappingfolder")
setnames(regMap, "CountryCode", "all_regi")
weight <- merge(weight, regMap[, c("all_regi", "RegionCode")], by = "all_regi")
weight[, weightSum := sum(value), by = c("RegionCode", "GDP_scenario", "DEM_scenario", "EDGE_scenario", "all_enty", "all_in", "all_teEs", "tall")]
weight[weightSum == 0, value := 1]
weight[, c("RegionCode", "weightSum", "all_enty", "all_in") := NULL]
weight <- as.magpie(weight)
unit <- "trn (p|t)km/Twa"
description <- "Energy efficiency on CES level."
},
"f35_demByTech" = {
weight <- NULL
unit <- "TWa"
description <- "Final energy demand on CES level."
},
"f29_trpdemand" = {
weight <- NULL
unit <- "trillion pkm/trillion tkm"
description <- "Energy service demand on CES level."
},
"CAPEXandNonFuelOPEX" = {
gdp <- calcOutput("GDP", aggregate = FALSE)[, , "gdp_SSP2"]
weight <- gdp |> time_interpolate(getYears(x))
unit <- "2017US$/(p|t)km"
description <- "Capital cost (purchase) and non-fuel operational costs on technology level."
},
"scenSpecPrefTrends" = {
gdp <- calcOutput("GDP", aggregate = FALSE)[, , "gdp_SSP2"]
weight <- gdp |> time_interpolate(getYears(x))
unit <- "-"
description <- "Scenario specific preference trends on technology level."
},
"scenSpecLoadFactor" = {
gdp <- calcOutput("GDP", aggregate = FALSE)[, , "gdp_SSP2"]
weight <- gdp |> time_interpolate(getYears(x))
unit <- "-"
description <- "Scenario specific load factor on technology level."
},
"scenSpecEnIntensity" = {
gdp <- calcOutput("GDP", aggregate = FALSE)[, , "gdp_SSP2"]
weight <- gdp |> time_interpolate(getYears(x))
unit <- "MJ/vehkm"
description <- "Scenario specific energy intensity on technology level."
},
"initialIncoCosts" = {
gdp <- calcOutput("GDP", aggregate = FALSE)[, , "gdp_SSP2"]
weight <- gdp |> time_interpolate(getYears(x))
unit <- "2017US$/(p|t)km"
description <- "Initial inconvenience cost values."
},
"annualMileage" = {
gdp <- calcOutput("GDP", aggregate = FALSE)[, , "gdp_SSP2"]
weight <- gdp |> time_interpolate(getYears(x))
unit <- "vehkm/yr"
description <- "Annual vehicle km traveled."
},
"timeValueCosts" = {
gdp <- calcOutput("GDP", aggregate = FALSE)[, , "gdp_SSP2"]
weight <- gdp |> time_interpolate(getYears(x))
unit <- "2017US$/(p|t)km"
description <- "Value of time cost equivalent."
}
)

return(list(x = x,
weight = weight,
unit = unit,
description = description))
return(list(
x = x,
weight = weight,
unit = unit,
description = description
))
}
3 changes: 1 addition & 2 deletions R/calcFeDemandTransport.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#'
#' @author Alois Dirnaicher, Johanna Hoppe
calcFeDemandTransport <- function() {

# Read in stationary data and map to REMIND variables ----

# REMIND transport items
Expand Down Expand Up @@ -74,7 +73,7 @@ calcFeDemandTransport <- function() {
select("scenario", "region", "year" = "period", "item", "value") %>%
filter(.data$scenario == "gdp_SSP2") %>%
mutate("scenario" = "gdp_SDP") %>%
as.data.table()
data.table::as.data.table()

## get population
pop <- data.table::as.data.table(calcOutput("Population"))[
Expand Down
18 changes: 10 additions & 8 deletions R/convertEDGETransport.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,28 @@
#' @importFrom madrat toolAggregate
#' @author Johanna Hoppe

convertEDGETransport = function(x, subtype) {
convertEDGETransport <- function(x, subtype) {

RegionCode <- CountryCode <- . <- NULL

mappingfile <- setDT(toolGetMapping("regionmapping_21_EU11.csv", type = "regional",
where = "mappingfolder"))[, .(iso = CountryCode, region = RegionCode)]
if (subtype %in% c("f35_demByTech", "f29_trpdemand", "weightESdemand")) {
gdp <- calcOutput("GDP", aggregate = FALSE) |> time_interpolate(getYears(x), extrapolation_type = "constant")
gdp <- gdp[,,"gdp_SSP2"]
gdp <- gdp[, , "gdp_SSP2"]
result <- toolAggregate(x = x, weight = gdp, rel = mappingfile, from = "region", to = "iso")
} else if (!subtype == "shares_LDV_transport") {
result <- toolAggregate(x = x, rel = mappingfile, weight = NULL, from = "region", to = "iso")
} else if (subtype %in% c("shares_LDV_transport")) {
## only the first EDGE-T scenario for SSP2 is used as a proxy for the LDV shares
x <- x[,, "gdp_SSP2.Mix1.gdp_SSP2.share_LDV_totliq.shares_LDV_transport"]
x <- x[, , "gdp_SSP2.Mix1.gdp_SSP2.share_LDV_totliq.shares_LDV_transport"]

for (year in getYears(x, as.integer = T)){
x[,year,] <- as.vector(x[,c(2010),]) + ((0.55 - as.vector(x[,c(2010),]))/(2100-2010))*(year-2010)
for (year in getYears(x, as.integer = TRUE)) {
x[, year, ] <- as.vector(x[, c(2010), ]) + ((0.55 - as.vector(x[, c(2010), ])) / (2100 - 2010)) * (year - 2010)
}
#extending values
x <- time_interpolate(x, integrate_interpolated_years=T, interpolated_year = seq(from = 1990, to = 2100), extrapolation_type = "linear")
x <- time_interpolate(x, integrate_interpolated_years=T, interpolated_year = c(seq(from = 1970, to = 1989),seq(from = 2101, to = 2150)), extrapolation_type = "constant")
# extending values
x <- time_interpolate(x, integrate_interpolated_years = TRUE, interpolated_year = seq(from = 1990, to = 2100), extrapolation_type = "linear")
x <- time_interpolate(x, integrate_interpolated_years = TRUE, interpolated_year = c(seq(from = 1970, to = 1989), seq(from = 2101, to = 2150)), extrapolation_type = "constant")
result <- x
}
return(result)
Expand Down
50 changes: 26 additions & 24 deletions R/readEDGETransport.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
#' @param subtype REMIND/iterative EDGE-T input data subtypes
#'
#' @examples
#' \dontrun{ a <- readSource(type = "EDGETransport")
#' \dontrun{
#' a <- readSource(type = "EDGETransport")
#' }
#' @importFrom tidyr expand_grid
#' @importFrom dplyr bind_rows
#' @importFrom data.table data.table rbindlist := setnames setkeyv

readEDGETransport <- function(subtype) {

EDGE_scenario <- DEM_scenario <- NULL
#############################################################
## Define all scenario combinations for which
## input data should be generated
Expand All @@ -33,32 +35,32 @@ readEDGETransport <- function(subtype) {
# Specific project scenarios
tribble(
~SSPscen, ~transportPolScen, ~isICEban, ~demScen,
'SSP1', 'Mix1', FALSE, 'default',
'SSP1', 'Mix2', FALSE, 'default',
'SSP1', 'Mix3', TRUE, 'default',
'SSP1', 'Mix4', TRUE, 'default',
'SSP2', 'Mix1', FALSE, 'SSP2_demRedStrong',
'SSP2', 'Mix2', FALSE, 'SSP2_demRedStrong',
'SSP2', 'Mix3', TRUE, 'SSP2_demRedStrong',
'SSP2', 'Mix4', TRUE, 'SSP2_demRedStrong',
'SSP2', 'Mix4', TRUE, 'SSP2_demDiffer',
'SSP2', 'Mix1', FALSE, 'SSP2_demDiffer',
'SDP_EI', 'Mix4', TRUE, 'default',
'SDP_MC', 'Mix4', TRUE, 'default',
'SDP_RC', 'Mix3', TRUE, 'default',
'SSP2', 'HydrHype4', TRUE, 'default',
'SSP2', 'NAV_act', FALSE, 'SSP2_demRedStrong',
'SSP2', 'NAV_tec', FALSE, 'default',
'SSP2', 'NAV_ele', TRUE, 'default',
'SSP2', 'NAV_all', TRUE, 'SSP2_demRedStrong',
'SSP2', 'NAV_lce', FALSE, 'SSP2_demRedStrong',
'SSP2', 'CAMP_lscWeak', TRUE, 'SSP2_demRedWeak',
'SSP2', 'CAMP_lscStrong', TRUE, 'SSP2_demRedStrong'
"SSP1", "Mix1", FALSE, "default",
"SSP1", "Mix2", FALSE, "default",
"SSP1", "Mix3", TRUE, "default",
"SSP1", "Mix4", TRUE, "default",
"SSP2", "Mix1", FALSE, "SSP2_demRedStrong",
"SSP2", "Mix2", FALSE, "SSP2_demRedStrong",
"SSP2", "Mix3", TRUE, "SSP2_demRedStrong",
"SSP2", "Mix4", TRUE, "SSP2_demRedStrong",
"SSP2", "Mix4", TRUE, "SSP2_demDiffer",
"SSP2", "Mix1", FALSE, "SSP2_demDiffer",
"SDP_EI", "Mix4", TRUE, "default",
"SDP_MC", "Mix4", TRUE, "default",
"SDP_RC", "Mix3", TRUE, "default",
"SSP2", "HydrHype4", TRUE, "default",
"SSP2", "NAV_act", FALSE, "SSP2_demRedStrong",
"SSP2", "NAV_tec", FALSE, "default",
"SSP2", "NAV_ele", TRUE, "default",
"SSP2", "NAV_all", TRUE, "SSP2_demRedStrong",
"SSP2", "NAV_lce", FALSE, "SSP2_demRedStrong",
"SSP2", "CAMP_lscWeak", TRUE, "SSP2_demRedWeak",
"SSP2", "CAMP_lscStrong", TRUE, "SSP2_demRedStrong"
)
)

# generate list from data frame rows
allScens <- split(allScens, seq(nrow(allScens)))
allScens <- split(allScens, seq_len(nrow(allScens)))

#############################################################
## Run EDGE-Transport SA with all scenario combinations
Expand All @@ -82,7 +84,7 @@ readEDGETransport <- function(subtype) {
# Bind rows of equally named subtypes
EdgeTransportSAdata <- lapply(types, function(type, outerList) {
listOfDataTables <- lapply(outerList, function(innerList) innerList[[type]])
result <- rbindlist(listOfDataTables)
rbindlist(listOfDataTables)
}, EdgeTransportSAdata)

EdgeTransportSAdata <- setNames(EdgeTransportSAdata, types)
Expand Down
2 changes: 1 addition & 1 deletion R/readGlobalEnergyMonitor.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ readGlobalEnergyMonitor <- function() {
c2 = "Country/area 2 (hydropower only)",
v1 = "Country/area 1 Capacity (MW) (hydropower only)",
v2 = "Country/area 2 Capacity (MW) (hydropower only)") %>%
filter(status %in% c("announced", "pre-construction", "construction", "operating")) %>%
filter(.data$status %in% c("announced", "pre-construction", "construction", "operating")) %>%
# ASSUMPTION: rows with empty start year are ignored
# only look at pipeline until 2030
filter(!is.na(.data$start), .data$start < 2031) %>%
Expand Down
Loading

0 comments on commit 6ed6309

Please sign in to comment.