diff --git a/.buildlibrary b/.buildlibrary index 1435535b..3c93a198 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '362724990' +ValidationKey: '36475351' AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' - 'Warning: namespace ''.*'' is not available and has been replaced' @@ -10,6 +10,7 @@ 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 14abe13b..38e309f4 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.182.10 -date-released: '2024-07-15' +version: 0.183.1 +date-released: '2024-07-17' abstract: The mrremind packages contains data preprocessing for the REMIND model. authors: - family-names: Baumstark diff --git a/DESCRIPTION b/DESCRIPTION index f1c2c6ea..d59c0267 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: mrremind Title: MadRat REMIND Input Data Package -Version: 0.182.10 -Date: 2024-07-15 +Version: 0.183.1 +Date: 2024-07-17 Authors@R: c( person("Lavinia", "Baumstark", , "lavinia@pik-potsdam.de", role = c("aut", "cre")), person("Renato", "Rodrigues", role = "aut"), @@ -38,7 +38,7 @@ Description: The mrremind packages contains data preprocessing for the License: LGPL-3 | file LICENSE URL: https://github.com/pik-piam/mrremind Depends: - edgeTransport (>= 0.17.0), + edgeTransport (>= 1.5.5), madrat (>= 3.7.1), magclass (>= 6.16.1), mrcommons (>= 1.38.0), @@ -64,7 +64,6 @@ Imports: readxl, reshape2, rlang, - rmndt, tibble, tidyr, tidyselect, diff --git a/NAMESPACE b/NAMESPACE index c5838a31..74c49214 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -84,12 +84,9 @@ importFrom(assertr,not_na) importFrom(assertr,verify) importFrom(assertr,within_bounds) importFrom(data.table,":=") -importFrom(data.table,as.data.table) importFrom(data.table,data.table) -importFrom(data.table,fread) importFrom(data.table,rbindlist) importFrom(data.table,setDT) -importFrom(data.table,setcolorder) importFrom(data.table,setkeyv) importFrom(data.table,setnames) importFrom(dplyr,across) @@ -151,6 +148,8 @@ importFrom(ggplot2,scale_linetype_manual) importFrom(ggplot2,scale_shape_manual) importFrom(ggplot2,theme) importFrom(ggplot2,theme_minimal) +importFrom(madrat,madratAttach) +importFrom(madrat,toolAggregate) importFrom(magclass,matchDim) importFrom(magrittr,"%>%") importFrom(quitte,add_countrycode_) diff --git a/R/calcEDGETrData.R b/R/calcEDGETrData.R deleted file mode 100644 index 695e722f..00000000 --- a/R/calcEDGETrData.R +++ /dev/null @@ -1,79 +0,0 @@ -#' @title Runs EDGE-T model -#' -#' @return list of EDGEtransport iterative inputs -#' @author Marianna Rottoli -#' @seealso \code{\link{readEDGETransport}}, \code{\link[madrat]{calcOutput}} -#' -#' @examples -#' \dontrun{ a <- calcOutput(type="EDGETrData", aggregate = F) -#' } -#' -#' @importFrom dplyr bind_rows -#' @importFrom tibble tribble -#' @importFrom tidyr expand_grid - -calcEDGETrData <- function() { - - if (!'edgeTransport' %in% unique(getCalculations('calc')$package)) { - stop(paste('calcEDGETrData() requires package edgeTransport to be loaded', - '(manually)')) - } - - allscens <- bind_rows( - ## for all "default" SSP variants we ship the whole zoo of EDGE-T scenarios - expand_grid( - SSP_scen = c("SSP1", "SSP2", "SSP5", "SSP2EU", "SDP"), - tech_scen = c("Mix1", "Mix2", "Mix3", "Mix4"), - DEM_scenario = c("default", "SSP2EU_demRedWeak", "SSP2EU_demRedStrong")), - - ## SHAPE scenarios are coupled to specific technologies - tribble( - ~SSP_scen, ~tech_scen, ~DEM_scenario, - 'SDP_EI', 'Mix4', 'default', - 'SDP_MC', 'Mix4', 'default', - 'SDP_RC', 'Mix3', 'default', - 'SSP2EU', 'HydrHype4', 'default', - 'SSP2EU', 'ECEMF_HighEl_HighEff', 'default', - 'SSP2EU', 'ECEMF_HighEl_LifestCha', 'SSP2EU_demRedStrong', - 'SSP2EU', 'ECEMF_HighEl_ModEff', 'default', - 'SSP2EU', 'ECEMF_HighH2_HighEff', 'default', - 'SSP2EU', 'ECEMF_HighH2_LifestCha', 'SSP2EU_demRedStrong', - 'SSP2EU', 'ECEMF_HighH2_ModEff', 'default', - 'SSP2EU', 'NAV_act', 'SSP2EU_demRedStrong', - 'SSP2EU', 'NAV_tec', 'default', - 'SSP2EU', 'NAV_ele', 'default', - 'SSP2EU', 'NAV_all', 'SSP2EU_demRedStrong', - 'SSP2EU', 'NAV_lce', 'SSP2EU_demRedStrong', - 'SSP2EU', 'PhOP', 'default', - 'SSP2EU', 'CAMP_lscWeak', 'SSP2EU_demRedWeak', - 'SSP2EU', 'CAMP_lscStrong', 'SSP2EU_demRedStrong' - ) - ) - - # generate list from data frame rows - allscens <- lapply(1:nrow(allscens), function(x) { - setNames(unlist(allscens[x, ]), NULL) - }) - - ## run EDGE-T - EDGETdata = lapply(allscens, - function(x) { - calcOutput(type = 'generateEDGEdata', - aggregate = FALSE, - supplementary = FALSE, - input_folder = paste0(getConfig("sourcefolder"), - "/EDGE-T_standalone/"), - output_folder = NULL, - SSP_scen = x[1], - tech_scen = x[2], - demScen = x[3], - storeRDS = FALSE) - }) - - return(list(x = EDGETdata, - class = 'list', - unit = NA, - description = 'EDGEtransport iterative inputs')) - - -} diff --git a/R/calcEDGETransport.R b/R/calcEDGETransport.R index 6bd3dbb6..53036338 100644 --- a/R/calcEDGETransport.R +++ b/R/calcEDGETransport.R @@ -1,132 +1,106 @@ #' @title Prepare EDGETransport inputs #' -#' @return magpie object of EDGEtransport iterative inputs -#' @author Alois Dirnaichner, Marianna Rottoli +#' @author Johanna Hoppe #' @seealso \code{\link{readSource}} -#' @param subtype refer to the code for a list of allowed subtypes. -#' +#' @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="logit_exponent", aggregate=F) +#' \dontrun{ a <- calcOutput(type = "EDGETransport", subtype = "CAPEXandNonFuelOPEX", aggregate = F) #' } -#' -#'@importFrom data.table as.data.table -calcEDGETransport <- function(subtype = "logit_exponent") { - value <- i.value <- NULL - if (subtype %in% c("logit_exponent", "ptab4W")) { - conv = FALSE - } else { - conv = TRUE - } +calcEDGETransport <- function(subtype) { - weightInt <- calcOutput("GDP", aggregate = F) - get_weight <- function(data, weightInt) { - year_inter = getYears(data) - ## define weight for intensive entries (for weighted average) - weightInt <- time_interpolate( - weightInt, - year_inter, - extrapolation_type="constant")[,, getNames(data, dim=1)] - ## create an empty object that has the same dimensions as data - weight <- new.magpie(cells_and_regions = getRegions(data), years = getYears(data), names = getNames(data), fill = 0) - ## use the GPD for each SSP in data to fill up the empty weight (it needs as many repetitions as SSP* is called in data) - regions <- getRegions(weightInt) - years <- getYears(weightInt) - for (gdpscen in getNames(weightInt)) { - mselect(weight, region=regions, year=years, data=gdpscen) <- weightInt[regions, years, gdpscen] - } - getSets(weight, fulldim=F)[3] <- getSets(data, fulldim=F)[3] - return(weight) - } - - if(subtype == "pm_trp_demand"){ - fe_dem <- as.data.table(as.quitte(readSource("EDGETransport", "fe_demand_tech")))[ - , c("model", "scenario", "variable", "unit") := NULL - ] - fe2es <- as.data.table(as.quitte(readSource("EDGETransport", "fe2es")))[ - , c("model", "scenario", "variable", "unit") := NULL - ] - es_dem <- fe_dem[fe2es, on=c("period", "region", "GDP_scenario", "DEM_scenario", "EDGE_scenario", "all_teEs")][ - , sum(value * i.value), by=c("period", "region", "GDP_scenario", "DEM_scenario", "EDGE_scenario", "all_in") - ] - data <- as.magpie(es_dem, spatial=2, temporal=1, datacol=7) - }else{ - data <- readSource("EDGETransport", subtype, convert = conv) - } + x <- readSource("EDGETransport", subtype) switch(subtype, - "logit_exponent" = { - weight = NULL - unit = "[-]" - description = "Logit exponent values for transport alternatives" + "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 <- 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 = "2005US$/(p|t)km" + description = "Capital cost (purchase) per energy service demand on CES level." }, - "harmonized_intensities" = { - weight = get_weight(data, weightInt) - unit = "Passenger transport: [EJ/Mpkm]; freight transport: [EJ/Mtkm]" - description = "Energy intensity for transport modes and fuel, harmonized on IEA balances" + "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 <- 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." }, - "value_time" = { - weight = get_weight(data, weightInt) - unit = "Passenger transport: [2005US$/pkm]; freight transport: [2005US$/tkm]" - description = "Value of time for passenger transport modes" - }, - "pref" = { - weight = get_weight(data, weightInt) - unit = "LDVs 4wheelers: inconvenience cost [2005US$/pkm]; all other modes: [-] share weight, a dimensionless parameter reflecting consumer preferences" - description = "Inconvenience cost reflecting availability of infrastructure" - }, - "ptab4W" = { + "f35_demByTech" = { weight = NULL - unit = "[-]" - description = "LDVs 4wheelers: factors for the inconvenience costs." - }, - "price_nonmot" = { - weight = get_weight(data, weightInt) - unit = "Passenger transport: [2005US$/pkm]; freight transport: [2005US$/tkm]" - description = "Price for non motorized transport modes (Walking; Cycling)" + unit = "TWa" + description = "Final energy demand on CES level." }, - "UCD_NEC_iso" = { - weight = get_weight(data, weightInt) - unit = "Passenger transport: [2005US$/pkm]; freight transport: [2005US$/tkm]" - description = "Non energy costs for all motorized transport modes, both total and purchase for LDVs" + "f29_trpdemand" = { + weight = NULL + unit = "trillion pkm/trillion tkm" + description = "Energy service demand on CES level." }, - "loadFactor" = { - weight = get_weight(data, weightInt) - unit = "Passenger transport: [pass/veh]; freight transport: [ton/veh]" - description = "Load factor for all motorized transport modes" + "CAPEXandNonFuelOPEX" = { + gdp <- calcOutput("GDP", aggregate = FALSE)[,,"gdp_SSP2"] + weight = gdp |> time_interpolate(getYears(x)) + unit = "2005US$/(p|t)km" + description = "Capital cost (purchase) and non-fuel operational costs on technology level." }, - "annual_mileage" = { - weight = get_weight(data, weightInt) - unit = "km/veh/year" - description = "Annual mileage for selected transport modes" + "scenSpecPrefTrends" = { + gdp <- calcOutput("GDP", aggregate = FALSE)[,,"gdp_SSP2"] + weight = gdp |> time_interpolate(getYears(x)) + unit = "-" + description = "Scenario specific preference trends on technology level." }, - "esCapCost" = { - weight = get_weight(data, weightInt) - unit = "Passenger transport [2005US$/pkm]; freight transport: [2005US$/tkm]" - description = "Transport ES demand trajectories for the CES tree." + "scenSpecLoadFactor" = { + gdp <- calcOutput("GDP", aggregate = FALSE)[,,"gdp_SSP2"] + weight = gdp |> time_interpolate(getYears(x)) + unit = "-" + description = "Scenario specific load factor on technology level." }, - "fe2es" = { - weight = get_weight(data, weightInt) - unit = "Passenger transport [trn pkm/Twa], freight transport [trn tkm/Twa]" - description = "Energy efficiency of CES level nodes for Transport." + "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." }, - "pm_trp_demand" = { - weight = NULL - unit = "Passenger transport [trn pkm], freight transport [trn tkm]" - description = "CES level transport demand." + "initialIncoCosts" = { + gdp <- calcOutput("GDP", aggregate = FALSE)[,,"gdp_SSP2"] + weight = gdp |> time_interpolate(getYears(x)) + unit = "2005US$/(p|t)km" + description = "Initial inconvenience cost values." }, - "fe_demand_tech" = { - weight = NULL - unit = "TWa" - description = "FE demand divided by technologies for different ES on the CES level." + "annualMileage" = { + gdp <- calcOutput("GDP", aggregate = FALSE)[,,"gdp_SSP2"] + weight = gdp |> time_interpolate(getYears(x)) + unit = "vehkm/yr" + description = "Annual vehicle km traveled." }, - "pm_fe_demand_EDGETbased" = { - weight = NULL - unit = "EJ" - description = "UE demand divided by technologies for different ES on the CES level." - }) + "timeValueCosts" = { + gdp <- calcOutput("GDP", aggregate = FALSE)[,,"gdp_SSP2"] + weight = gdp |> time_interpolate(getYears(x)) + unit = "2005US$/(p|t)km" + description = "Value of time cost equivalent." + } + ) - return(list(x = data, + return(list(x = x, weight = weight, unit = unit, description = description)) diff --git a/R/calcEU_ReferenceScenario.R b/R/calcEU_ReferenceScenario.R index d06ac50d..f5cf15c5 100644 --- a/R/calcEU_ReferenceScenario.R +++ b/R/calcEU_ReferenceScenario.R @@ -12,7 +12,7 @@ calcEU_ReferenceScenario <- function() { weights <- x weights[, , ] <- NA - weights[, , "Price|Secondary Energy|Electricity (US$2005/GJ)"] <- 1 + weights[, , "Price|Secondary Energy|Electricity (EUR2013/GJ)"] <- 1 return(list( x = x, weight = weights, mixed_aggregation = TRUE, diff --git a/R/calcIO.R b/R/calcIO.R index b89efce5..2e32c08e 100644 --- a/R/calcIO.R +++ b/R/calcIO.R @@ -102,6 +102,15 @@ calcIO <- function(subtype = c("input", "output", "output_biomass", "trade", # read in data and convert from ktoe to EJ data <- readSource("IEA", subtype = ieaSubtype) * 4.1868e-5 + # Correct transport reporting issue in IEA data for NONBIODIES.MARBUNK in RUS + # FE is reported in 1990 and 2010 but not in the years in between. This cause problems in the harmonization of EDGE-Transport + # and the IEA data in 2005 as there is no MARBUNK demand at all for REF regions. + data["RUS", seq(1990, 2010, 1), "NONBIODIES.MARBUNK"] <- + data["RUS", c(1990, 2010),"NONBIODIES.MARBUNK"]|> time_interpolate(seq(1990, 2010, 1)) + #Adjust totals + data["RUS", seq(1991, 2009, 1),"TOTAL.MARBUNK"] <- + data["RUS", seq(1991, 2009, 1),"TOTAL.MARBUNK"] + data["RUS", seq(1991, 2009, 1), "NONBIODIES.MARBUNK"] + ieamatch <- read.csv2(mapping, stringsAsFactors = FALSE, na.strings = "") # add total buildings electricity demand (feelb = feelcb + feelhpb + feelrhb) diff --git a/R/convertEDGETransport.R b/R/convertEDGETransport.R index a7591619..9a16041b 100644 --- a/R/convertEDGETransport.R +++ b/R/convertEDGETransport.R @@ -1,51 +1,25 @@ #' Convert EDGEtransport #' -#' Ship EDGETransport data through, as already on ISO level -#' -#' @param subtype EDGE entries -#' @param x MAgPIE object containing EDGE values at ISO country resolution -#' @return EDGETransport data as MAgPIE object aggregated to ISO level -#' @author Marianna Rottoli -#' +#' @param subtype REMIND/iterative EDGE-T input data subtypes +#' @param x MAgPIE object containing EDGE-T values in 21 region resolution +#' @return REMIND/iterative EDGE-T input data as MAgPIE object disaggregated to ISO level #' @importFrom data.table setDT -#' -convertEDGETransport = function(x, subtype) { - `.` <- CountryCode <- RegionCode <- NULL - if (subtype %in% c("esCapCost", "fe_demand_tech", "fe2es", "UCD_NEC_iso", "harmonized_intensities", "value_time", "pref", "loadFactor", "annual_mileage", "f35_bunkers_fe")) { - ## magpie object creates NA whenever the initial dt is not symmetric (entry absent in ISO1 but exists in ISO2) - ## the NAs are therefore converted to 0 - x[is.na(x)] <- 0 - } - ## load mapping - mappingfile <- setDT(toolGetMapping("regionmapping_21_EU11.csv",type="regional", - where = "mappingfolder"))[, .(iso = CountryCode, region = RegionCode)] - ## for intensive values, the weight is NULL - if (subtype %in% c("fe2es", "UCD_NEC_iso", "harmonized_intensities", "value_time", "pref", "loadFactor", "annual_mileage", "shares_LDV_transport", "price_nonmot", "esCapCost")) { - x = toolAggregate(x = x, rel = mappingfile, weight = NULL, from = "region", to = "iso") - } - - ## for extensive values and the edge_esm module, the weight is ES - if (subtype == "fe_demand_tech") { - wgt = readSource("EDGETransport", subtype ="demISO") - ## rename the columns of the weight - x = toolAggregate(x = x, weight = wgt, rel = mappingfile, from = "region", to = "iso") - } - - ## for extensive values and the complex module, the weight is GDP - if (subtype == "pm_fe_demand_EDGETbased") { - gdp <- calcOutput("GDP", aggregate = F)[,,"gdp_SSP2"] - ## interpolate missing time steps - gdp <- time_interpolate(gdp, getYears(x)) - - ## rename the columns of the weight - getSets(gdp) <- c("iso", "year", "variable") - x = toolAggregate(x = x, weight = gdp, rel = mappingfile, from = "region", to = "iso") - } +#' @importFrom madrat toolAggregate +#' @author Johanna Hoppe +convertEDGETransport = function(x, subtype) { - if (subtype %in% c("shares_LDV_transport")) { + 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"] + 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.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) @@ -53,8 +27,7 @@ convertEDGETransport = function(x, subtype) { #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") - } - - result = x + result <- x + } return(result) } diff --git a/R/fullREMIND.R b/R/fullREMIND.R index f339c193..a930784a 100644 --- a/R/fullREMIND.R +++ b/R/fullREMIND.R @@ -2,7 +2,9 @@ #' #' Function that produces the complete regional data set required for the #' REMIND model. -#' +#' @importFrom madrat madratAttach +#' @importFrom magrittr %>% +#' @importFrom quitte cartesian madrat_mule #' @author Lavinia Baumstark #' @seealso #' \code{\link{readSource}},\code{\link{getCalculations}},\code{\link{calcOutput}} @@ -16,36 +18,32 @@ fullREMIND <- function() { rem_years <- seq(2005, 2150, 5) rem_years_hist <- seq(1990, 2150, 5) - # Enable madrat caching for edgeTransport - madrat::madratAttach("edgeTransport") + madratAttach("edgeTransport") # enable madrat caching for edgeTransport #-------------- macro-economic parameters ----------------------------------------------------------- calcOutput("Population", years = rem_years_hist, round = 8, file = "f_pop.cs3r") calcOutput("Labour", years = rem_years, round = 8, file = "f_lab.cs3r") - calcOutput("GDP", years = rem_years_hist, round = 8, file = "f_gdp.cs3r") + calcOutput("GDP", years = rem_years_hist, round = 8, file = "f_gdp.cs3r") calcOutput("RatioPPP2MER", round = 8, file = "pm_shPPPMER.cs4r") calcOutput("MacroInvestments", round = 8, file = "p01_boundInvMacro.cs4r") - calcOutput("FETaxes", subtype = "taxes", round = 2, file = "f21_tau_fe_tax.cs4r") - calcOutput("FETaxes", subtype = "subsidies", round = 2, file = "f21_tau_fe_sub.cs4r") + calcOutput("FETaxes", subtype = "taxes", round = 2, file = "f21_tau_fe_tax.cs4r") + calcOutput("FETaxes", subtype = "subsidies", round = 2, file = "f21_tau_fe_sub.cs4r") calcOutput("TaxConvergence", round = 2, file = "f21_tax_convergence.cs4r") calcOutput("TaxLimits", subtype = "maxFeSubsidy", round = 2, file = "f21_max_fe_sub.cs4r") calcOutput("TaxLimits", subtype = "maxPeSubsidy", round = 2, file = "f21_max_pe_sub.cs4r") calcOutput("TaxLimits", subtype = "propFeSubsidy", round = 2, file = "f21_prop_fe_sub.cs4r") - calcOutput("PETaxes", subtype = "subsidies", round = 2, file = "f21_tau_pe_sub.cs4r") - # Not default, overwritten with 0 - calcOutput("TaxXport", round = 2, file = "p21_tau_xpres_tax.cs4r") + calcOutput("PETaxes", subtype = "subsidies", round = 2, file = "f21_tau_pe_sub.cs4r") + calcOutput("TaxXport", round = 2, file = "p21_tau_xpres_tax.cs4r") # not default, overwritten with 0 calcOutput("Capital", signif = 4, file = "f29_capitalQuantity.cs4r") - # Exogenous demand scenarios activated by cm_exogDem_scen - calcOutput("ExogDemScen", round = 8, file = "p47_exogDemScen.cs4r") - calcOutput(type = "Steel_Projections", - subtype = "secondary.steel.max.share", - file = "p37_steel_secondary_max_share.cs4r", - match.steel.historic.values = TRUE, - match.steel.estimates = "IEA_ETP", - China_Production = readSource(type = "ExpertGuess", - subtype = "Chinese_Steel_Production", - convert = FALSE) %>% - quitte::madrat_mule()) + calcOutput("ExogDemScen", round = 8, file = "p47_exogDemScen.cs4r") # exogenous demand scenarios activated by cm_exogDem_scen + calcOutput( + type = "Steel_Projections", subtype = "secondary.steel.max.share", + file = "p37_steel_secondary_max_share.cs4r", + match.steel.historic.values = TRUE, match.steel.estimates = "IEA_ETP", + China_Production = readSource(type = "ExpertGuess", + subtype = "Chinese_Steel_Production", + convert = FALSE) %>% + madrat_mule()) calcOutput("FEdemand", signif = 4, file = "f_fedemand.cs4r") @@ -72,31 +70,31 @@ fullREMIND <- function() { calcOutput("KLWdamage", subtype = "maxGMT", round = 8, file = "f50_KLW_df_maxGMT.cs4r", aggregate = FALSE) #-------------- emission parameter ------------------------------------------------------------------ - calcOutput("EconometricEmiParameter", round = 5, file = "p_emineg_econometric.cs3r") - calcOutput("EmissionsTe", round = 5, file = "p_boundEmi.cs4r") - calcOutput("HistEmissions", subtype = "sector", round = 8, file = "p_histEmiSector.cs4r") - calcOutput("HistEmissions", subtype = "MAC", round = 8, file = "p_histEmiMac.cs4r") - calcOutput("EmiCO2LandUse", round = 5, file = "p_macPolCO2luc.cs4r") - calcOutput("MacBaseLandUse", subtype = "DirectlyFromMAgPIE", round = 5, file = "f_macBaseMagpie.cs4r") - calcOutput("MacBaseLandUse", subtype = "Exogenous", round = 5, file = "f_macBaseExo.cs4r") - calcOutput("MACCsCO2", round = 5, file = "p_abatparam_CO2.cs4r", aggregate = FALSE) - calcOutput("EmiMac", round = 5, file = "p_macBase2005.cs4r") - calcOutput("EmiMac1990", round = 5, file = "p_macBase1990.cs4r") - calcOutput("MACCbaseN2O", round = 5, file = "p_macBaseVanv.cs4r") - calcOutput("MACCsCH4", round = 6, file = "p_abatparam_CH4.cs4r") - calcOutput("MACCsN2O", round = 6, file = "p_abatparam_N2O.cs4r") - calcOutput("FGas", round = 6, file = "f_emiFgas.cs4r") - calcOutput("EmiFossilFuelExtr", round = 6, file = "p_emiFossilFuelExtr.cs4r") - calcOutput("Region2MAGICC", round = 6, file = "p_regi_2_MAGICC_regions.cs3r") - calcOutput("EmiPollutantExo", subtype = "AviationShipping", round = 6, file = "f11_emiAPexoGlob.cs4r", aggregate = FALSE) - calcOutput("EmiPollutantExo", subtype = "Waste", round = 6, file = "f11_emiAPexo.cs4r") - calcOutput("EmiAirPollLandUse", round = 6, file = "f11_emiAPexoAgricult.cs4r") - calcOutput("GAINSEmi", subtype = "emissions", round = 5, file = "emi_gains.cs4r") - calcOutput("GAINSEmi", subtype = "emission_factors", round = 5, file = "ef_gains.cs4r") - calcOutput("GAINSEmi", subtype = "emissions_starting_values", round = 5, file = "f11_emiAPexsolve.cs4r") - calcOutput("EmissionFactors", subtype = "emission_factors", round = 5, file = "f11_emiFacAP.cs4r", warnNA = TRUE) - calcOutput("EmissionFactorsFeedstocks", round = 5, file = "f_nechem_emissionFactors.cs4r") - calcOutput("EmiLULUCFCountryAcc", subtype = "UNFCCC", round = 5, file = "p_EmiLULUCFCountryAcc.cs4r") + calcOutput("EconometricEmiParameter", round = 5, file = "p_emineg_econometric.cs3r") + calcOutput("EmissionsTe", round = 5, file = "p_boundEmi.cs4r") + calcOutput("HistEmissions", subtype = "sector", round = 8, file = "p_histEmiSector.cs4r") + calcOutput("HistEmissions", subtype = "MAC", round = 8, file = "p_histEmiMac.cs4r") + calcOutput("EmiCO2LandUse", round = 5, file = "p_macPolCO2luc.cs4r") + calcOutput("MacBaseLandUse", subtype = "DirectlyFromMAgPIE", round = 5, file = "f_macBaseMagpie.cs4r") + calcOutput("MacBaseLandUse", subtype = "Exogenous", round = 5, file = "f_macBaseExo.cs4r") + calcOutput("MACCsCO2", round = 5, file = "p_abatparam_CO2.cs4r", aggregate = FALSE) + calcOutput("EmiMac", round = 5, file = "p_macBase2005.cs4r") + calcOutput("EmiMac1990", round = 5, file = "p_macBase1990.cs4r") + calcOutput("MACCbaseN2O", round = 5, file = "p_macBaseVanv.cs4r") + calcOutput("MACCsCH4", round = 6, file = "p_abatparam_CH4.cs4r") + calcOutput("MACCsN2O", round = 6, file = "p_abatparam_N2O.cs4r") + calcOutput("FGas", round = 6, file = "f_emiFgas.cs4r") + calcOutput("EmiFossilFuelExtr", round = 6, file = "p_emiFossilFuelExtr.cs4r") + calcOutput("Region2MAGICC", round = 6, file = "p_regi_2_MAGICC_regions.cs3r") + calcOutput("EmiPollutantExo", subtype = "AviationShipping", round = 6, file = "f11_emiAPexoGlob.cs4r", aggregate = FALSE) + calcOutput("EmiPollutantExo", subtype = "Waste", round = 6, file = "f11_emiAPexo.cs4r") + calcOutput("EmiAirPollLandUse", round = 6, file = "f11_emiAPexoAgricult.cs4r") + calcOutput("GAINSEmi", subtype = "emissions", round = 5, file = "emi_gains.cs4r") + calcOutput("GAINSEmi", subtype = "emission_factors", round = 5, file = "ef_gains.cs4r") + calcOutput("GAINSEmi", subtype = "emissions_starting_values", round = 5, file = "f11_emiAPexsolve.cs4r") + calcOutput("EmissionFactors", subtype = "emission_factors", warnNA = TRUE, round = 5, file = "f11_emiFacAP.cs4r") + calcOutput("EmissionFactorsFeedstocks", round = 5, file = "f_nechem_emissionFactors.cs4r") + calcOutput("EmiLULUCFCountryAcc", subtype = "UNFCCC", round = 5, file = "p_EmiLULUCFCountryAcc.cs4r") #-------------- energy/technology parameters --------------------------------------------------------- calcOutput("PotentialHydro", round = 3, file = "f_maxProdGradeRegiHydro.cs3r") @@ -118,9 +116,10 @@ fullREMIND <- function() { calcOutput("ShareIndFE", round = 3, file = "p37_shIndFE.cs3r") calcOutput("nonEnergyIndFE", round = 8, file = "f37_fedemand_NonEnergyIndst.cs4r") calcOutput("Clinker_to_cement_ratio", round = 2, file = "p37_clinker-to-cement-ratio.cs3r") - # Delete the 'dummy' line + # delete the 'dummy' line system(paste0('sed -i "/dummy/d" ', getConfig()$outputfolder, "/p37_clinker-to-cement-ratio.cs3r")) + calcOutput("Capacity", subtype = "capacityByTech", round = 6, file = "p_histCap.cs3r") # will be deleted after the merge of REMIND-EU calcOutput("Capacity", subtype = "capacityByTech", round = 6, file = "pm_histCap.cs3r") calcOutput("Capacity", subtype = "capacityByTech_windoff", round = 6, file = "pm_histCap_windoff.cs3r") calcOutput("Capacity", subtype = "capacityByPE", round = 6, file = "p_PE_histCap.cs3r") @@ -135,22 +134,6 @@ fullREMIND <- function() { calcOutput("CCScapacity", subtype = "projections", round = 8, file = "pm_boundCapCCS.cs4r") calcOutput("CCSbounds", round = 8, file = "p_boundCapCCSindicator.cs4r") calcOutput("LimitCCS", round = 8, file = "pm_dataccs.cs3r") - calcOutput('Industry_CCS_limits', - a1 = 0.3, a2 = 0.15, installation_minimum = 1, - stage_weight = c('Operational' = 1, - 'In construction' = 1, - 'Advanced development' = 0.5, - 'Early development' = 0.2), - signif = 3, file = 'f37_indCCSlimit_default.cs4r', - years = seq(2005, 2050, 5)) - calcOutput('Industry_CCS_limits', - a1 = 0.5, a2 = 0.25, installation_minimum = 1, - stage_weight = c('Operational' = 1, - 'In construction' = 1, - 'Advanced development' = 0.8, - 'Early development' = 0.5), - signif = 3, file = 'f37_indCCSlimit_high.cs4r', - years = seq(2005, 2050, 5)) calcOutput("BiomassPrices", round = 6, file = "f30_bioen_price.cs4r") calcOutput("ResFor2ndBioengery", years = rem_years, round = 5, file = "p30_biolcResidues.cs3r") calcOutput("1stBioDem", subtype = "ethanol_oils", years = rem_years, round = 5, file = "p30_bio1stgen.cs3r") @@ -175,24 +158,19 @@ fullREMIND <- function() { calcOutput("PlasticsEoL", round = 5, file = "f_incinerationShares.cs4r") #--------------- EDGE Transport --------------------------------------------------------------------- - calcOutput("TransportGDPshare", round = 6, file = "f35_transportGDPshare.cs4r") - - calcOutput("EDGETransport", subtype = "value_time", file = "value_time.cs4r") - calcOutput("EDGETransport", subtype = "harmonized_intensities", file = "harmonized_intensities.cs4r") - calcOutput("EDGETransport", subtype = "price_nonmot", file = "price_nonmot.cs4r") - calcOutput("EDGETransport", subtype = "pref", file = "pref.cs4r") - calcOutput("EDGETransport", subtype = "UCD_NEC_iso", file = "UCD_NEC_iso.cs4r") - calcOutput("EDGETransport", subtype = "loadFactor", file = "loadFactor.cs4r") - calcOutput("EDGETransport", subtype = "fe_demand_tech", file = "fe_demand_tech.cs4r") - calcOutput("EDGETransport", subtype = "fe2es", file = "fe2es.cs4r") - calcOutput("EDGETransport", subtype = "esCapCost", file = "esCapCost.cs4r") - calcOutput("EDGETransport", subtype = "pm_trp_demand", file = "pm_trp_demand.cs4r") - calcOutput("EDGETransport", subtype = "pm_fe_demand_EDGETbased", file = "pm_fe_demand_EDGETbased.cs4r") - calcOutput("EDGETransport", subtype = "annual_mileage", file = "annual_mileage.cs4r") - - # Not to be aggregated as global - calcOutput("EDGETransport", subtype = "logit_exponent", aggregate = FALSE, file = "logit_exponent.cs4r") - calcOutput("EDGETransport", subtype = "ptab4W", aggregate = FALSE, file = "ptab4W.cs4r") + calcOutput("TransportGDPshare", round = 6, file = "f35_transportGDPshare.cs4r") + + calcOutput("EDGETransport", subtype = "f35_esCapCost", file = "f35_esCapCost.cs4r") + calcOutput("EDGETransport", subtype = "f35_fe2es", file = "f35_fe2es.cs4r") + calcOutput("EDGETransport", subtype = "f35_demByTech", file = "f35_demByTech.cs4r") + calcOutput("EDGETransport", subtype = "f29_trpdemand", file = "f29_trpdemand.cs4r") + calcOutput("EDGETransport", subtype = "CAPEXandNonFuelOPEX", file = "CAPEXandNonFuelOPEX.cs4r") + calcOutput("EDGETransport", subtype = "scenSpecPrefTrends", file = "scenSpecPrefTrends.cs4r") + calcOutput("EDGETransport", subtype = "scenSpecLoadFactor", file = "scenSpecLoadFactor.cs4r") + calcOutput("EDGETransport", subtype = "scenSpecEnIntensity", file = "scenSpecEnIntensity.cs4r") + calcOutput("EDGETransport", subtype = "initialIncoCosts", file = "initialIncoCosts.cs4r") + calcOutput("EDGETransport", subtype = "annualMileage", file = "annualMileage.cs4r") + calcOutput("EDGETransport", subtype = "timeValueCosts", file = "timeValueCosts.cs4r") #---------------policy parameters-------------------------------------------------------------------- calcOutput("EmiTarget", sources = "UNFCCC_NDC", subtype = "Ghgshare2005", round = 4, file = "fm_2005shareTarget.cs3r") diff --git a/R/readEDGETransport.R b/R/readEDGETransport.R index d44bcd52..0c5e01c9 100644 --- a/R/readEDGETransport.R +++ b/R/readEDGETransport.R @@ -1,378 +1,119 @@ -#' Read EDGETransport inputs -#' -#' Read-in EDGETransport inputs csv file as magclass object +#' Read REMIND/EDGE-T iterative input data #' +#' Run EDGE-Transport Standalone in all used scenario combinations to supply input data +#' to REMIND and the iterative EDGE-T script #' #' @return magpie object of EDGEtransport iterative inputs -#' @author Marianna Rottoli, Alois Dirnaichner +#' @author Johanna Hoppe #' @seealso \code{\link{readSource}} -#' @param subtype logit_exponents, SW, pref, ptab4W, value_time, harmonized_intensities, price_nonmot, UCD_NEC_iso, loadFactor, esCapCost, fe_demand_tech, shares_LDV_transport, demISO, annual_mileage +#' @param subtype REMIND/iterative EDGE-T input data subtypes #' #' @examples -#' \dontrun{ a <- readSource(type="EDGETransport") +#' \dontrun{ a <- readSource(type = "EDGETransport") #' } -#' @importFrom data.table data.table rbindlist fread setcolorder := setnames setkeyv - -readEDGETransport <- function(subtype = "logit_exponent") { - ## mask variable for code checks - vehicle_type <- EDGE_scenario <- GDP_scenario <- DEM_scenario <- value <- year <- sharetype <- - EJ_Mpkm_final <- varname <- fuel <- region <- iso <- node <- totdem <- `.`<- - category <- tall <- all_in <- price_component <- NULL - - ## load the data from EDGE-T - EDGETrData = calcOutput("EDGETrData", aggregate = F) - EDGETrData_all=list() - - ## all data.tables can be combined directly - for (i in c("fe_demand_tech", "fe2es", "esCapCost", "shares_LDV_transport", - "demISO", "price_nonmot", "harmonized_intensities", "UCD_NEC_iso", - "loadFactor", "annual_mileage", "ptab4W")) { - EDGETrData_all[[i]] <- rbindlist( - lapply(seq(1,length(EDGETrData)), - function(x) { - EDGETrData[[x]][[i]] - return(EDGETrData[[x]][[i]]) - }), use.names=TRUE) - } - - ## sub-lists have to be dealt with separately - for (j in c("logit_params", "vot_data", "pref_data", "complexdem")) { - for (i in names(EDGETrData[[1]][[j]])) { - EDGETrData_all[[j]][[i]] <- rbindlist( - lapply(seq(1,length(EDGETrData)), - function(x) { - EDGETrData[[x]][[j]][[i]] - return(EDGETrData[[x]][[j]][[i]]) - }), use.names=TRUE) - } - } - - create_copy_demscens <- function(dt) { - setkeyv(dt, c("DEM_scenario", "GDP_scenario", "EDGE_scenario")) - ## Workaround for NAVIGATE: copy-create demand scenarios which we do not supply by EDGE-T - dt <- rbind(dt, - dt[.("gdp_SSP2EU", "gdp_SSP2EU", "NAV_ele"), nomatch=NULL][ - , DEM_scenario := "gdp_SSP2EU_NAV_ele"], - dt[.("gdp_SSP2EU", "gdp_SSP2EU", "NAV_tec"), nomatch=NULL][ - , DEM_scenario := "gdp_SSP2EU_NAV_tec"], - dt[.("gdp_SSP2EU_demRedStrong", "gdp_SSP2EU", "NAV_act"), nomatch=NULL][ - , DEM_scenario := "gdp_SSP2EU_NAV_act"], - dt[.("gdp_SSP2EU_demRedStrong", "gdp_SSP2EU", "NAV_all"), nomatch=NULL][ - , DEM_scenario := "gdp_SSP2EU_NAV_all"], - dt[.("gdp_SSP2EU_demRedStrong", "gdp_SSP2EU", "NAV_lce"), nomatch=NULL][ - , DEM_scenario := "gdp_SSP2EU_NAV_lce"], - dt[.("gdp_SSP2EU_demRedWeak", "gdp_SSP2EU", "CAMP_lscWeak"), nomatch=NULL][ - , DEM_scenario := "gdp_SSP2EU_CAMP_weak"], - dt[.("gdp_SSP2EU_demRedStrong", "gdp_SSP2EU", "CAMP_lscStrong"), nomatch=NULL][ - , DEM_scenario := "gdp_SSP2EU_CAMP_strong"] +#' @importFrom tidyr expand_grid +#' @importFrom dplyr bind_rows +#' @importFrom data.table data.table rbindlist := setnames setkeyv + +readEDGETransport <- function(subtype) { + + ############################################################# + ## Define all scenario combinations for which + ## input data should be generated + ############################################################# + + allScens <- bind_rows( + ## for all "default" SSP variants we ship the whole zoo of standard + ## EDGE-T scenarios + expand_grid( + SSPscen = c("SSP1", "SSP2", "SSP5", "SSP2EU", "SDP"), + transportPolScen = c("Mix1", "Mix2", "Mix3", "Mix4"), + isICEban = c(TRUE, FALSE), + demScen = c("default")), + # Specific project scenarios + tribble( + ~SSPscen, ~transportPolScen, ~isICEban, ~demScen, + 'SSP2', 'Mix1', FALSE, 'SSP2EU_demRedStrong', + 'SSP2', 'Mix2', FALSE, 'SSP2EU_demRedStrong', + 'SSP2', 'Mix3', TRUE, 'SSP2EU_demRedStrong', + 'SSP2', 'Mix4', TRUE, 'SSP2EU_demRedStrong', + 'SDP_EI', 'Mix4', TRUE, 'default', + 'SDP_MC', 'Mix4', TRUE, 'default', + 'SDP_RC', 'Mix3', TRUE, 'default', + 'SSP2EU', 'HydrHype4', TRUE, 'default', + 'SSP2EU', 'ECEMF_HighEl_HighEff', TRUE, 'default', + 'SSP2EU', 'ECEMF_HighEl_LifestCha', TRUE, 'SSP2EU_demRedStrong', + 'SSP2EU', 'ECEMF_HighEl_ModEff', TRUE, 'default', + 'SSP2EU', 'ECEMF_HighH2_HighEff', TRUE, 'default', + 'SSP2EU', 'ECEMF_HighH2_LifestCha', TRUE, 'SSP2EU_demRedStrong', + 'SSP2EU', 'ECEMF_HighH2_ModEff', TRUE, 'default', + 'SSP2EU', 'NAV_act', FALSE, 'SSP2EU_demRedStrong', + 'SSP2EU', 'NAV_tec', FALSE, 'default', + 'SSP2EU', 'NAV_ele', TRUE, 'default', + 'SSP2EU', 'NAV_all', TRUE, 'SSP2EU_demRedStrong', + 'SSP2EU', 'NAV_lce', FALSE, 'SSP2EU_demRedStrong', + 'SSP2EU', 'CAMP_lscWeak', TRUE, 'SSP2EU_demRedWeak', + 'SSP2EU', 'CAMP_lscStrong', TRUE, 'SSP2EU_demRedStrong' ) - setkeyv(dt, "DEM_scenario") - dt[.("gdp_SSP2EU_demRedStrong"), DEM_scenario := "gdp_SSP2_lowEn"] - scens <- unique(dt$DEM_scenario) + ) + + # generate list from data frame rows + allScens <- split(allScens, seq(nrow(allScens))) + + ############################################################# + ## Run EDGE-Transport SA with all scenario combinations + ############################################################# + + EdgeTransportSAdata <- lapply(allScens, + function(x) { + calcOutput(type = "EdgeTransportSA", + aggregate = FALSE, + supplementary = FALSE, + SSPscen = x[["SSPscen"]], + transportPolScen = x[["transportPolScen"]], + isICEban = x[["isICEban"]], + demScen = x[["demScen"]], + isTransportReported = FALSE, + isREMINDinputReported = TRUE, + isStored = FALSE) + }) + + types <- unique(unlist(lapply(EdgeTransportSAdata, names))) + # Bind rows of equally named subtypes + EdgeTransportSAdata <- lapply(types, function(type, outerList) { + listOfDataTables <- lapply(outerList, function(innerList) innerList[[type]]) + result <- rbindlist(listOfDataTables) + }, EdgeTransportSAdata) + + EdgeTransportSAdata <- setNames(EdgeTransportSAdata, types) + + ############################################################# + ## Rename EDGE-Transport demScens and map to REMIND demScens + ## that are applied to all sectors simultaneously + ############################################################# + translateEdgeTransportDemScentoREMIND <- function(dt) { + dt[DEM_scenario == "gdp_SSP2EU" & EDGE_scenario == "NAV_ele", DEM_scenario := "gdp_SSP2EU_NAV_ele"] + dt[DEM_scenario == "gdp_SSP2EU" & EDGE_scenario == "NAV_tec", DEM_scenario := "gdp_SSP2EU_NAV_tec"] + dt[DEM_scenario == "gdp_SSP2EU_demRedStrong" & EDGE_scenario == "NAV_act", DEM_scenario := "gdp_SSP2EU_NAV_act"] + dt[DEM_scenario == "gdp_SSP2EU_demRedStrong" & EDGE_scenario == "NAV_all", DEM_scenario := "gdp_SSP2EU_NAV_all"] + dt[DEM_scenario == "gdp_SSP2EU_demRedStrong" & EDGE_scenario == "NAV_lce", DEM_scenario := "gdp_SSP2EU_NAV_lce"] + dt[DEM_scenario == "gdp_SSP2EU_demRedWeak" & EDGE_scenario == "CAMP_lscWeak", DEM_scenario := "gdp_SSP2EU_CAMP_weak"] + dt[DEM_scenario == "gdp_SSP2EU_demRedStrong" & EDGE_scenario == "CAMP_lscStrong", DEM_scenario := "gdp_SSP2EU_CAMP_strong"] + dt[DEM_scenario == "gdp_SSP2EU_demRedStrong" & EDGE_scenario == "Mix1", DEM_scenario := "gdp_SSP2_lowEn"] + dt[DEM_scenario == "gdp_SSP2EU_demRedStrong" & EDGE_scenario == "Mix2", DEM_scenario := "gdp_SSP2_lowEn"] + dt[DEM_scenario == "gdp_SSP2EU_demRedStrong" & EDGE_scenario == "Mix3ICEban", DEM_scenario := "gdp_SSP2_lowEn"] + dt[DEM_scenario == "gdp_SSP2EU_demRedStrong" & EDGE_scenario == "Mix4ICEban", DEM_scenario := "gdp_SSP2_lowEn"] return(dt) } + EdgeTransportSAdata <- lapply(EdgeTransportSAdata, translateEdgeTransportDemScentoREMIND) + ############################################################# + ## Create magpie object for every subtype + ############################################################# - compress_magpie <- function(dt, ...) { - dt <- create_copy_demscens(dt) - setkeyv(dt, c("EDGE_scenario", "DEM_scenario", "GDP_scenario")) - mdata <- NULL - for (i in unique(dt$EDGE_scenario)) { - for (j in unique(dt$DEM_scenario)) { - for (k in unique(dt$GDP_scenario)) { - tmp <- dt[.(i, j, k), nomatch=NULL] - if(nrow(tmp) > 0) { - mdata <- mbind( - mdata, as.magpie(tmp, ...)) - } - } - } - } - return(mdata) - - } - - switch(subtype, - - "logit_exponent" = { - ## do not call with convert=T, there is only global data! - tmp_dfs <- EDGETrData_all$logit_params - - for (i in names(tmp_dfs)) { - tmp_dfs[[i]]$varname <- i - } - - - tmp_dfs <- rbindlist(tmp_dfs, fill= TRUE) - tmp_dfs[is.na(tmp_dfs)] <- "tmp" - - tmp_dfs=tmp_dfs[, vehicle_type := gsub("\\.", "DOT", vehicle_type)] - - setnames(tmp_dfs, old = "logit.exponent", new = "logitexp") - setcolorder(tmp_dfs, c("GDP_scenario", "DEM_scenario", "EDGE_scenario", - "sector", "subsector_L3", "subsector_L2", "subsector_L1", - "vehicle_type", "varname", "logitexp")) - ## concatenate multiple magpie objects each one containing one - ## SSP realization to avoid large objects - mdata <- compress_magpie(tmp_dfs, datacol = 10) - - }, - - "pref" = { - tmp_dfs <- EDGETrData_all$pref_data - - for (i in names(tmp_dfs)) { - tmp_dfs[[i]]$varname <- i - } - - tmp_dfs <- rbindlist(tmp_dfs, fill= TRUE) - ## remove empty years (combinations of region-vehicles that are not present) - tmp_dfs <- tmp_dfs[!is.na(year)] - ## NAs in categories meant to be empty should be replaced - tmp_dfs[is.na(tmp_dfs)] <- "tmp" - tmp_dfs[, value := as.numeric(value)] - tmp_dfs=tmp_dfs[, vehicle_type := gsub("\\.", "DOT", vehicle_type)] - setcolorder(tmp_dfs, c("GDP_scenario", "DEM_scenario", "EDGE_scenario", "region", - "year", "sector", "subsector_L3", "subsector_L2", "subsector_L1", - "vehicle_type", "technology", "logit_type", "varname", "value")) - ## concatenate multiple magpie objects each one containing one SSP realization to avoid large objects - mdata <- compress_magpie(tmp_dfs, spatial = 4, temporal = 5, datacol = 14) - - }, - - - - "value_time" = { - tmp_dfs <- EDGETrData_all$vot_data - - for (i in names(tmp_dfs)) { - tmp_dfs[[i]]$varname <- i - } - - tmp_dfs <- rbindlist(tmp_dfs, fill= TRUE) - tmp_dfs[is.na(tmp_dfs)] <- "tmp" - - tmp_dfs=tmp_dfs[, vehicle_type := gsub("\\.", "DOT", vehicle_type)] - setcolorder(tmp_dfs, c("GDP_scenario", "DEM_scenario", "EDGE_scenario", "region", - "year", "sector", "subsector_L3", "subsector_L2", "subsector_L1", - "vehicle_type", "varname", "time_price")) - setnames(tmp_dfs, old ="time_price", new ="value") - - ## concatenate multiple magpie objects each one containing one SSP realization to avoid large objects - mdata <- compress_magpie(tmp_dfs, spatial = 4, temporal = 5, datacol = 12) - - }, - - "harmonized_intensities" = { - tmp <- EDGETrData_all$harmonized_intensities - tmp = tmp[!is.na(EJ_Mpkm_final)] - tmp$varname <- subtype - - tmp=tmp[, vehicle_type := gsub("\\.", "DOT", vehicle_type)] - setcolorder(tmp, c("GDP_scenario", "DEM_scenario", "EDGE_scenario", "region", "year", - "sector", "subsector_L3", "subsector_L2", "subsector_L1", "vehicle_type", - "technology", "varname", "sector_fuel", "EJ_Mpkm_final")) - setnames(tmp, old ="EJ_Mpkm_final", new ="value") - ## concatenate multiple magpie objects each one containing one SSP realization to avoid large objects - mdata <- compress_magpie(tmp, spatial = 4, temporal = 5, datacol = 14) - - }, - - "price_nonmot" = { - tmp <- EDGETrData_all$price_nonmot - tmp$varname <- subtype - tmp=tmp[, vehicle_type := gsub("\\.", "DOT", vehicle_type)] - setcolorder(tmp, c("GDP_scenario", "DEM_scenario", "EDGE_scenario", "region", "year", - "sector", "subsector_L3", "subsector_L2", "subsector_L1", "vehicle_type", - "technology", "varname", "tot_price")) - setnames(tmp, old ="tot_price", new ="value") - - ## concatenate multiple magpie objects each one containing one SSP realization to avoid large objects - mdata <- compress_magpie(tmp, spatial = 4, temporal = 5, datacol = 13) - - }, - - "UCD_NEC_iso" = { - tmp <- EDGETrData_all$UCD_NEC_iso - tmp[price_component == "Capital costs (purchase)", price_component := "Capital_costs_purchase"] - tmp$varname <- subtype - tmp=tmp[, vehicle_type := gsub("\\.", "DOT", vehicle_type)] - setcolorder(tmp, c("GDP_scenario", "DEM_scenario", "EDGE_scenario", "region", "year", - "vehicle_type", "technology", "price_component", "varname", "non_fuel_price")) - setnames(tmp, old ="non_fuel_price", new ="value") - - ## concatenate multiple magpie objects each one containing one SSP realization to avoid large objects - mdata <- compress_magpie(tmp, spatial = 4, temporal = 5, datacol = 10) - - }, - - "loadFactor" = { - tmp <- EDGETrData_all$loadFactor - tmp=tmp[, vehicle_type := gsub("\\.", "DOT", vehicle_type)] - tmp$varname <- subtype - setcolorder(tmp, c("GDP_scenario", "DEM_scenario", "EDGE_scenario", "region", "year", - "vehicle_type", "varname", "loadFactor")) - setnames(tmp, old ="loadFactor", new ="value") - mdata <- compress_magpie(tmp, spatial = 4, temporal = 5, datacol = 8) - }, - - "fe2es" = { - - tmp <- EDGETrData_all$fe2es - tmp <- tmp[tall>1990] - ## concatenate multiple magpie objects each one containing one SSP realization to avoid large objects - mdata <- compress_magpie(tmp, spatial = 2, temporal = 1, datacol = 7) - - }, - - "esCapCost" = { - tmp <- EDGETrData_all$esCapCost - tmp <- tmp[tall>1965] - ## concatenate multiple magpie objects each one containing one SSP realization to avoid large objects - mdata <- compress_magpie(tmp, spatial = 2, temporal = 1, datacol = 7) - - }, - - "fe_demand_tech" = { - tmp <- EDGETrData_all$fe_demand_tech - tmp <- tmp[tall>1990] - - ## concatenate multiple magpie objects each one containing one SSP realization to avoid large objects - mdata <- compress_magpie(tmp, spatial = 2, temporal = 1, datacol = 9) - }, - - "demISO" = { - tmp <- EDGETrData_all$demISO - ## adapt database with compatible column names and values - setnames(tmp, old = c("sector", "tech_output"), new = c("all_in", "value")) - tmp[all_in == "trn_freight", all_in := "entrp_frgt_sm"] - tmp[all_in == "trn_shipping_intl", all_in := "entrp_frgt_lo"] - tmp[all_in == "trn_pass", all_in := "entrp_pass_sm"] - tmp[all_in == "trn_aviation_intl", all_in := "entrp_pass_lo"] - ## TODO check if really we expect the same value for all technologies within a node (as it is now calculated) - tmp = tmp[year == 2010] - tmp[, value := round(value)] - tmp = tmp[, .(value = sum(value)), - by = c("iso", "all_in", "GDP_scenario", "DEM_scenario", "EDGE_scenario")] - ## get all the needed dimensions - map = data.table(all_in = c("entrp_frgt_lo", "entrp_frgt_sm", "entrp_frgt_sm", "entrp_frgt_sm", - "entrp_frgt_sm", "entrp_pass_lo", "entrp_pass_sm", "entrp_pass_sm", - "entrp_pass_sm", "entrp_pass_sm", "entrp_pass_sm"), - all_enty = c("fedie", "fedie", "feelt", "fegat", "feh2t", "fedie", "fedie", - "feelt", "fegat", "feh2t", "fepet"), - all_teEs = c("te_esdie_frgt_lo", "te_esdie_frgt_sm", "te_eselt_frgt_sm", - "te_esgat_frgt_sm", "te_esh2t_frgt_sm", "te_esdie_pass_lo", - "te_esdie_pass_sm", "te_eselt_pass_sm","te_esgat_pass_sm", - "te_esh2t_pass_sm", "te_espet_pass_sm")) - tmp = merge(tmp, map, by = "all_in", all = TRUE, allow.cartesian = T) - tmp = tmp[, c("GDP_scenario", "DEM_scenario", "EDGE_scenario", "iso", "all_in", - "all_enty", "all_teEs", "value")] - - ## concatenate multiple magpie objects each one containing one SSP realization to avoid large objects - mdata <- compress_magpie(tmp, spatial = 4, datacol = 8) - }, - - "shares_LDV_transport" = { - tmp <- EDGETrData_all$shares_LDV_transport - tmp[, varname := subtype] - tmp = data.table::melt(tmp, id.vars = c("GDP_scenario", "DEM_scenario", "EDGE_scenario", - "region", "year", "varname")) - setnames(tmp, old = "variable", new = "sharetype") - tmp[, c("sharetype", "year") := list(as.character(sharetype), as.character(year))] - setcolorder(tmp, c("GDP_scenario", "DEM_scenario", "EDGE_scenario", "region", "year", - "sharetype", "varname", "value")) - - ## concatenate multiple magpie objects each one containing one SSP realization to avoid large objects - mdata <- compress_magpie(tmp, spatial = 4, temporal = 5, datacol = 8) - }, - - - "pm_fe_demand_EDGETbased" = { - tmp = EDGETrData_all$complexdem$FEdem - tmp <- tmp[year>1965] - ## extract only Mix1 and Mix1Wise (this subtype is only needed for calibration purposes) - tmp = tmp[grepl("Mix1", EDGE_scenario)] - ## convert from final energy to useful energy - tmp[fuel == "BEV", totdem := totdem*3] ## battery electric LDV - tmp[fuel == "FCEV" & node == "LDV", totdem := totdem*2.5] ## FCEV vehicles LDV - tmp[fuel == "FCEV" & node == "HDV", totdem := totdem*1.5] ## FCEV vehicles HDV - tmp[grepl("Electric", fuel) & node == "HDV", totdem := totdem*2.5] ## battery electric HDV - ## summarize according to the CES category - tmp = tmp[,.(value = sum(totdem)), by = .(GDP_scenario, DEM_scenario, EDGE_scenario, - region, year, node)] - ## rename the CES nodes - tmp[node == "LDV", node := "ueLDVt"] - tmp[node == "HDV", node := "ueHDVt"] - tmp[node == "Electric Trains", node := "ueelTt"] - ## extend to time steps necessary for the input demand trend - tmp = rmndt::approx_dt(tmp, - xdata = c(seq(1993, 2010, 1), seq(2015, 2150, 5)), - xcol = "year", - ycol = "value", - idxcols = c("GDP_scenario", "DEM_scenario", "EDGE_scenario", "region", "node"), - extrapolate = TRUE) - ## set cols order - setcolorder(tmp, c("GDP_scenario", "DEM_scenario", "EDGE_scenario", "region", - "year", "node", "value")) - ## concatenate multiple magpie objects each one containing one SSP realization to avoid large objects - mdata <- compress_magpie(tmp, spatial = 4, temporal = 5, datacol = 7) - }, - - "annual_mileage" = { - tmp <- EDGETrData_all$annual_mileage - tmp[, varname := subtype] - tmp=tmp[, vehicle_type := gsub("\\.", "DOT", vehicle_type)] - tmp$varname <- subtype - setcolorder(tmp, c("GDP_scenario", "DEM_scenario", "EDGE_scenario", "region", - "year", "vehicle_type", "varname", "annual_mileage")) - setnames(tmp, old ="annual_mileage", new ="value") - mdata <- compress_magpie(tmp, spatial = 4, temporal = 5, datacol = 8) - }, - - "ptab4W" = { - tmp <- EDGETrData_all$ptab4W - tmp[, varname := subtype] - tmp$varname <- subtype - setcolorder(tmp, c("GDP_scenario", "DEM_scenario", "EDGE_scenario", "param", - "varname", "value")) - mdata <- compress_magpie(tmp, datacol = 6) - }, - - "f35_bunkers_fe" = { - ## used only in transport complex. - ## warning: currently assumes bunkers trajectories as fixed to the first trajectory found for "gdp_SSP2". Therefore bunkers are assumed unchanged in all gdp scenarios. - tmp = EDGETrData_all$complexdem$iso_FEdem - ## select only bunkers - tmp = tmp[category == "Bunkers",] - ## summarize according to the CES category - tmp = tmp[,.(value = sum(totdem)), by = .(GDP_scenario, DEM_scenario, EDGE_scenario, iso, year)] - ## extend to necessary time steps - tmp = rmndt::approx_dt(tmp, - xdata = seq(2005, 2150, 5), - xcol = "year", - ycol = "value", - idxcols = c("GDP_scenario", "DEM_scenario", "EDGE_scenario", "iso"), - extrapolate = TRUE) - ## create magpie object - tmp_data <- compress_magpie(tmp, spatial = 4, temporal = 5, datacol = 6) - tmp_data <- tmp_data[,, "Mix1"] - # for EU regions use JRC data instead - JRC_reg <- c("MLT","EST","CYP","LVA","LTU","LUX","SVK","SVN","HRV","BGR","HUN","ROU","FIN","DNK","IRL","CZE","GRC","AUT","PRT","SWE","BEL","NLD","POL","ESP","ITA","GBR","FRA","DEU") - JRC <- calcOutput("JRC_IDEES", subtype="Transport", aggregate = FALSE) - JRC_bunkers <- JRC[JRC_reg,intersect(getYears(tmp_data), getYears(JRC)), - "FE|Transport|Bunkers (EJ/yr)"] - # for years after 2015 assume bunkers constant - tmp_data[JRC_reg, getYears(tmp_data)[getYears(tmp_data, as.integer = TRUE)>2015],] <- - JRC_bunkers[JRC_reg,2015,] - # for years lower or equal to 2015 assume bunkers equal to JRC historical values - tmp_data[JRC_reg, getYears(tmp_data)[getYears(tmp_data, as.integer = TRUE)<=2015],] <- - JRC_bunkers[JRC_reg,getYears(tmp_data)[getYears(tmp_data, as.integer = TRUE)<=2015],] - mdata <- tmp_data - }, + validSubtypes <- names(EdgeTransportSAdata) + if (!subtype %in% validSubtypes) stop(sprintf("Subtype %s is not valid for EDGETransport.", subtype)) - { - ## default - stop(sprintf("Subtype %s is not valid for EDGETransport.", subtype)) - }) + magpieobj <- as.magpie(EdgeTransportSAdata[[subtype]]) - return(mdata) + return(magpieobj) } diff --git a/README.md b/README.md index 4d0b4678..e35ebd2a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # MadRat REMIND Input Data Package -R package **mrremind**, version **0.182.10** +R package **mrremind**, version **0.183.1** [![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.183.1, . 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.182.10}, + note = {R package version 0.183.1}, url = {https://github.com/pik-piam/mrremind}, } ``` diff --git a/man/calcEDGETrData.Rd b/man/calcEDGETrData.Rd deleted file mode 100644 index 72b9aad2..00000000 --- a/man/calcEDGETrData.Rd +++ /dev/null @@ -1,25 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/calcEDGETrData.R -\name{calcEDGETrData} -\alias{calcEDGETrData} -\title{Runs EDGE-T model} -\usage{ -calcEDGETrData() -} -\value{ -list of EDGEtransport iterative inputs -} -\description{ -Runs EDGE-T model -} -\examples{ -\dontrun{ a <- calcOutput(type="EDGETrData", aggregate = F) -} - -} -\seealso{ -\code{\link{readEDGETransport}}, \code{\link[madrat]{calcOutput}} -} -\author{ -Marianna Rottoli -} diff --git a/man/calcEDGETransport.Rd b/man/calcEDGETransport.Rd index 0830bc49..295070a4 100644 --- a/man/calcEDGETransport.Rd +++ b/man/calcEDGETransport.Rd @@ -4,25 +4,24 @@ \alias{calcEDGETransport} \title{Prepare EDGETransport inputs} \usage{ -calcEDGETransport(subtype = "logit_exponent") +calcEDGETransport(subtype) } \arguments{ -\item{subtype}{refer to the code for a list of allowed subtypes.} +\item{subtype}{REMIND/iterative EDGE-T input data subtypes} } \value{ -magpie object of EDGEtransport iterative inputs +REMIND/iterative EDGE-T input data for all scenario combinations } \description{ Prepare EDGETransport inputs } \examples{ -\dontrun{ a <- calcOutput(type="EDGETransport", subtype="logit_exponent", aggregate=F) +\dontrun{ a <- calcOutput(type = "EDGETransport", subtype = "CAPEXandNonFuelOPEX", aggregate = F) } - } \seealso{ \code{\link{readSource}} } \author{ -Alois Dirnaichner, Marianna Rottoli +Johanna Hoppe } diff --git a/man/convertEDGETransport.Rd b/man/convertEDGETransport.Rd index 0a982de0..7d13d37c 100644 --- a/man/convertEDGETransport.Rd +++ b/man/convertEDGETransport.Rd @@ -7,16 +7,16 @@ convertEDGETransport(x, subtype) } \arguments{ -\item{x}{MAgPIE object containing EDGE values at ISO country resolution} +\item{x}{MAgPIE object containing EDGE-T values in 21 region resolution} -\item{subtype}{EDGE entries} +\item{subtype}{REMIND/iterative EDGE-T input data subtypes} } \value{ -EDGETransport data as MAgPIE object aggregated to ISO level +REMIND/iterative EDGE-T input data as MAgPIE object disaggregated to ISO level } \description{ -Ship EDGETransport data through, as already on ISO level +Convert EDGEtransport } \author{ -Marianna Rottoli +Johanna Hoppe } diff --git a/man/readEDGETransport.Rd b/man/readEDGETransport.Rd index e8663c63..21d8cff7 100644 --- a/man/readEDGETransport.Rd +++ b/man/readEDGETransport.Rd @@ -2,26 +2,27 @@ % Please edit documentation in R/readEDGETransport.R \name{readEDGETransport} \alias{readEDGETransport} -\title{Read EDGETransport inputs} +\title{Read REMIND/EDGE-T iterative input data} \usage{ -readEDGETransport(subtype = "logit_exponent") +readEDGETransport(subtype) } \arguments{ -\item{subtype}{logit_exponents, SW, pref, ptab4W, value_time, harmonized_intensities, price_nonmot, UCD_NEC_iso, loadFactor, esCapCost, fe_demand_tech, shares_LDV_transport, demISO, annual_mileage} +\item{subtype}{REMIND/iterative EDGE-T input data subtypes} } \value{ magpie object of EDGEtransport iterative inputs } \description{ -Read-in EDGETransport inputs csv file as magclass object +Run EDGE-Transport Standalone in all used scenario combinations to supply input data +to REMIND and the iterative EDGE-T script } \examples{ -\dontrun{ a <- readSource(type="EDGETransport") +\dontrun{ a <- readSource(type = "EDGETransport") } } \seealso{ \code{\link{readSource}} } \author{ -Marianna Rottoli, Alois Dirnaichner +Johanna Hoppe }