diff --git a/.buildlibrary b/.buildlibrary index 8b8051c4..79a973de 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -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' @@ -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 diff --git a/CITATION.cff b/CITATION.cff index 9beaec83..8a7b6240 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: '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 diff --git a/DESCRIPTION b/DESCRIPTION index e96b26f0..7ef934df 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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", , "lavinia@pik-potsdam.de", role = c("aut", "cre")), person("Renato", "Rodrigues", role = "aut"), diff --git a/R/calcEDGETransport.R b/R/calcEDGETransport.R index 636c1654..1a8b45d9 100644 --- a/R/calcEDGETransport.R +++ b/R/calcEDGETransport.R @@ -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 + )) } diff --git a/R/calcFeDemandTransport.R b/R/calcFeDemandTransport.R index 6f6bdcd1..2ae27013 100644 --- a/R/calcFeDemandTransport.R +++ b/R/calcFeDemandTransport.R @@ -2,7 +2,6 @@ #' #' @author Alois Dirnaicher, Johanna Hoppe calcFeDemandTransport <- function() { - # Read in stationary data and map to REMIND variables ---- # REMIND transport items @@ -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"))[ diff --git a/R/convertEDGETransport.R b/R/convertEDGETransport.R index 9a16041b..4aac2792 100644 --- a/R/convertEDGETransport.R +++ b/R/convertEDGETransport.R @@ -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) diff --git a/R/readEDGETransport.R b/R/readEDGETransport.R index 6b4ffa77..90be8000 100644 --- a/R/readEDGETransport.R +++ b/R/readEDGETransport.R @@ -9,7 +9,8 @@ #' @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 @@ -17,6 +18,7 @@ readEDGETransport <- function(subtype) { + EDGE_scenario <- DEM_scenario <- NULL ############################################################# ## Define all scenario combinations for which ## input data should be generated @@ -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 @@ -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) diff --git a/R/readGlobalEnergyMonitor.R b/R/readGlobalEnergyMonitor.R index 779ed686..8f005536 100644 --- a/R/readGlobalEnergyMonitor.R +++ b/R/readGlobalEnergyMonitor.R @@ -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) %>% diff --git a/README.md b/README.md index 1ea5368d..8b74075b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # MadRat REMIND Input Data Package -R package **mrremind**, version **0.192.8** +R package **mrremind**, version **0.192.9** [![CRAN status](https://www.r-pkg.org/badges/version/mrremind)](https://cran.r-project.org/package=mrremind) [![R build status](https://github.com/pik-piam/mrremind/workflows/check/badge.svg)](https://github.com/pik-piam/mrremind/actions) [![codecov](https://codecov.io/gh/pik-piam/mrremind/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/mrremind) [![r-universe](https://pik-piam.r-universe.dev/badges/mrremind)](https://pik-piam.r-universe.dev/builds) @@ -39,7 +39,7 @@ In case of questions / problems please contact Lavinia Baumstark . +Baumstark L, Rodrigues R, Levesque A, Oeser J, Bertram C, Mouratiadou I, Malik A, Schreyer F, Soergel B, Rottoli M, Mishra A, Dirnaichner A, Pehl M, Giannousakis A, Klein D, Strefler J, Feldhaus L, Brecha R, Rauner S, Dietrich J, Bi S, Benke F, Weigmann P, Richters O, Hasse R, Fuchs S, Mandaroux R, Koch J (2024). _mrremind: MadRat REMIND Input Data Package_. R package version 0.192.9, . A BibTeX entry for LaTeX users is @@ -48,7 +48,7 @@ A BibTeX entry for LaTeX users is title = {mrremind: MadRat REMIND Input Data Package}, author = {Lavinia Baumstark and Renato Rodrigues and Antoine Levesque and Julian Oeser and Christoph Bertram and Ioanna Mouratiadou and Aman Malik and Felix Schreyer and Bjoern Soergel and Marianna Rottoli and Abhijeet Mishra and Alois Dirnaichner and Michaja Pehl and Anastasis Giannousakis and David Klein and Jessica Strefler and Lukas Feldhaus and Regina Brecha and Sebastian Rauner and Jan Philipp Dietrich and Stephen Bi and Falk Benke and Pascal Weigmann and Oliver Richters and Robin Hasse and Sophie Fuchs and Rahel Mandaroux and Johannes Koch}, year = {2024}, - note = {R package version 0.192.8}, + note = {R package version 0.192.9}, url = {https://github.com/pik-piam/mrremind}, } ``` diff --git a/man/calcEDGETransport.Rd b/man/calcEDGETransport.Rd index 295070a4..4ee8027e 100644 --- a/man/calcEDGETransport.Rd +++ b/man/calcEDGETransport.Rd @@ -16,7 +16,8 @@ REMIND/iterative EDGE-T input data for all scenario combinations Prepare EDGETransport inputs } \examples{ -\dontrun{ a <- calcOutput(type = "EDGETransport", subtype = "CAPEXandNonFuelOPEX", aggregate = F) +\dontrun{ +a <- calcOutput(type = "EDGETransport", subtype = "CAPEXandNonFuelOPEX", aggregate = F) } } \seealso{ diff --git a/man/readEDGETransport.Rd b/man/readEDGETransport.Rd index 21d8cff7..70770f71 100644 --- a/man/readEDGETransport.Rd +++ b/man/readEDGETransport.Rd @@ -17,7 +17,8 @@ Run EDGE-Transport Standalone in all used scenario combinations to supply input to REMIND and the iterative EDGE-T script } \examples{ -\dontrun{ a <- readSource(type = "EDGETransport") +\dontrun{ +a <- readSource(type = "EDGETransport") } } \seealso{