From e84c16e03cb12c44b62d9177038ff3cc71437bf5 Mon Sep 17 00:00:00 2001 From: Falk Benke Date: Mon, 22 Jan 2024 13:43:20 +0100 Subject: [PATCH 01/10] remove Navigate and Campaigners scenarios from industry and transport --- R/calcFEdemand.R | 13 +++++++++++++ R/calcFeDemandBuildings.R | 13 +++++++++++-- R/calcFeDemandIndustry.R | 19 ------------------- R/convertStationary.R | 24 +++--------------------- R/readStationary.R | 7 +++---- 5 files changed, 30 insertions(+), 46 deletions(-) diff --git a/R/calcFEdemand.R b/R/calcFEdemand.R index 9b5310c7..26607251 100644 --- a/R/calcFEdemand.R +++ b/R/calcFEdemand.R @@ -6,6 +6,19 @@ calcFEdemand <- function() { feIndustry <- calcOutput("FeDemandIndustry", warnNA = FALSE, aggregate = FALSE) feTransport <- calcOutput("FeDemandTransport", warnNA = FALSE, aggregate = FALSE) + # duplicate scenarios ---- + + # add Navigate and Campaigners scenarios to industry and transport to match buildings scenarios by duplication + duplicateScens <- paste0("gdp_SSP2EU_", c("NAV_act", "NAV_ele", "NAV_tec", "NAV_lce", "NAV_all", "CAMP_weak", "CAMP_strong")) + + feTransport <- mbind(feTransport, do.call(mbind, lapply(duplicateScens, function(to) { + setItems(feTransport[, , "gdp_SSP2EU"], 3.1, to) + }))) + + feIndustry <- mbind(feIndustry, do.call(mbind, lapply(duplicateScens, function(to) { + setItems(feIndustry[, , "gdp_SSP2EU"], 3.1, to) + }))) + # add up industry and buildings contributions to stationary stationaryItems <- c("fehes", "feh2s") feStationary <- feIndustry[, , stationaryItems] + feBuildings[, , stationaryItems] diff --git a/R/calcFeDemandBuildings.R b/R/calcFeDemandBuildings.R index 2d5a3512..b38d8636 100644 --- a/R/calcFeDemandBuildings.R +++ b/R/calcFeDemandBuildings.R @@ -22,10 +22,19 @@ calcFeDemandBuildings <- function(subtype) { buildings <- toolAggregateTimeSteps(buildings) stationary <- toolAggregateTimeSteps(stationary) + # add scenarios to stationary to match buildings scenarios by duplication + duplicateScens <- paste0("SSP2EU_", c("NAV_act", "NAV_ele", "NAV_tec", "NAV_lce", "NAV_all", "CAMP_weak", "CAMP_strong")) + stationary <- mbind(stationary, do.call(mbind, lapply(duplicateScens, function(to) { + setItems(stationary[, , "SSP2EU"], 3.1, to) + }))) + if (subtype == "FE") { + # drop RCP dimension (use fixed RCP) buildings <- mselect(buildings, rcp = "fixed", collapseNames = TRUE) + } else { + # rename RCP scenarios in buildings rcps <- paste0("rcp", gsub("p", "", getItems(buildings, "rcp"))) rcps <- gsub("rcpfixed", "none", rcps) @@ -33,6 +42,7 @@ calcFeDemandBuildings <- function(subtype) { # expand stationary to all RCP scenarios stationary <- toolAddDimensions(x = stationary, dimVals = rcps, dimName = "rcp", dimCode = 3.2) + } # extrapolate years missing in buildings, but existing in stationary @@ -123,8 +133,7 @@ calcFeDemandBuildings <- function(subtype) { # remove missing NAVIGATE scenarios if (subtype %in% c("FE_buildings", "UE_buildings")) { - remind <- remind[, , grep("SSP2EU_(NAV|CAMP)_[a-z]*\\.rcp", getItems(remind, 3), value = TRUE), - invert = TRUE] + remind <- remind[, , grep("SSP2EU_(NAV|CAMP)_[a-z]*\\.rcp", getItems(remind, 3), value = TRUE), invert = TRUE] } # change the scenario names for consistency with REMIND sets diff --git a/R/calcFeDemandIndustry.R b/R/calcFeDemandIndustry.R index 54ffce53..4390285e 100644 --- a/R/calcFeDemandIndustry.R +++ b/R/calcFeDemandIndustry.R @@ -1605,27 +1605,8 @@ calcFeDemandIndustry <- function(use_ODYM_RECC = FALSE) { remind <- mbind(remind, industry_subsectors_en, industry_subsectors_ue) - # ---- _ duplicate SSP2EU scenarios of industry for Navigate and Campaigners scenarios ---- - - industryItems <- grep("(.*i$)|chemicals|steel|otherInd|cement", - getItems(remind, 3.2), value = TRUE) - nonIndustryItems <- setdiff(getItems(remind, 3.2), industryItems) - duplScenarios <- grep("SSP2EU_(NAV|CAMP)_", getItems(remind, 3.1), value = TRUE) - nonDuplScenarios <- setdiff(getItems(remind, 3.1), duplScenarios) - remind <- mbind( - mselect(remind, scenario = nonDuplScenarios), - mselect(remind, scenario = duplScenarios, item = nonIndustryItems), - toolAddDimensions(x = mselect(remind, scenario = "gdp_SSP2EU", item = industryItems, - collapseNames = TRUE), - dimVals = c(paste0("gdp_SSP2EU_NAV_", c("act", "tec", "ele", "lce", "all")), - paste0("gdp_SSP2EU_CAMP_", c("weak", "strong"))), - dimName = "scenario", - dimCode = 3.1) - ) - # ---- _ prepare output ---- - return(list( x = remind, weight = NULL, diff --git a/R/convertStationary.R b/R/convertStationary.R index 93203b4a..a7c01f8e 100644 --- a/R/convertStationary.R +++ b/R/convertStationary.R @@ -9,29 +9,11 @@ convertStationary <- function(x) { addSSPnames <- function(x) { do.call("mbind", lapply(c(paste0("SSP", c(1:5, "2EU", "2_lowEn")), - paste0("SDP", c("", "_EI", "_RC", "_MC")), - paste0("SSP2EU_NAV_", c("act", "tec", "ele", "lce", "all")), - paste0("SSP2EU_CAMP_", c("weak", "strong"))), + paste0("SDP", c("", "_EI", "_RC", "_MC"))), function(s) setNames(x, paste(s, getNames(x), sep = ".")) )) } - duplScens <- function(x, scens = NULL) { - if (is.null(scens)) { - scens <- list( - gdp_SSP2EU = paste0("gdp_SSP2EU_", - c("NAV_act", "NAV_ele", "NAV_tec", "NAV_lce", "NAV_all", - "CAMP_weak", "CAMP_strong")), - gdp_SSP2 = "gdp_SSP2_lowEn" - ) - } - mbind(x, do.call(mbind, lapply(names(scens), function(from) { - do.call(mbind, lapply(scens[[from]], function(to) { - setItems(x[, , from], 3, to) - })) - }))) - } - renameExtraWeights <- function(magObj, magWeight, mapping) { do.call("mbind", lapply(mapping[["EDGEitems"]], function(itemIN) { if (itemIN %in% getNames(magObj, dim = "item")) { @@ -84,9 +66,9 @@ convertStationary <- function(x) { #--- Load the Weights #--- First load the GDP data. Set average2020 to False to get yearly data as far as possible. wg <- calcOutput("GDP", average2020 = FALSE, aggregate = FALSE) - # duplicate SSP2 for SSP2_lowEn an SSP2EU for Navigate and Campaigners scenarios - wg <- duplScens(wg) getNames(wg) <- gsub("gdp_", "", getNames(wg)) + # duplicate SSP2 for SSP2_lowEn + wg <- mbind(wg, setItems(wg[, , "SSP2"], 3, "SSP2_lowEn")) #--- Then load the final energy data diff --git a/R/readStationary.R b/R/readStationary.R index 556ec489..e654281e 100644 --- a/R/readStationary.R +++ b/R/readStationary.R @@ -8,9 +8,7 @@ readStationary <- function() { scenarios <- list( SSPs = paste0("SSP", 1:5), - SSP2s = paste0("SSP2", c("EU", "_lowEn", - paste0("EU_NAV_", c("act", "tec", "ele", "lce", "all")), - paste0("EU_CAMP_", c("weak", "strong")))), + SSP2s = paste0("SSP2", c("EU", "_lowEn")), SDPs = paste0("SDP", c("", "_EI", "_MC", "_RC"))) data <- read.magpie("EDGE_TradMod.cs4r") @@ -29,8 +27,9 @@ readStationary <- function() { x = mselect(data, scenario = "SSP1", collapseNames = TRUE), dimVals = scenarios$SDPs, dimName = "scenario", - dimCode = 3.1) + dimCode = 3.1 ) + ) if ("scenario" %in% getSets(data)) { data <- mselect(data, scenario = Reduce(c, scenarios)) From a1dd00c8ad68a8e4de350b72fdfca01f554bf00b Mon Sep 17 00:00:00 2001 From: Falk Benke Date: Wed, 7 Feb 2024 18:19:34 +0100 Subject: [PATCH 02/10] remove calcCapacityEV --- R/calcCapacityEV.R | 30 ------------------------------ R/convertIEA_EV.R | 45 --------------------------------------------- R/fullREMIND.R | 7 +++---- R/readIEA_EV.R | 34 ---------------------------------- 4 files changed, 3 insertions(+), 113 deletions(-) delete mode 100644 R/calcCapacityEV.R delete mode 100644 R/convertIEA_EV.R delete mode 100644 R/readIEA_EV.R diff --git a/R/calcCapacityEV.R b/R/calcCapacityEV.R deleted file mode 100644 index f3c6044e..00000000 --- a/R/calcCapacityEV.R +++ /dev/null @@ -1,30 +0,0 @@ -#' CapacityEV -#' calculate capacity of EV -#' -#' @return magpie object -#' @author Lavinia Baumstark -#' @seealso \code{\link{calcOutput}} -#' @examples -#' -#' \dontrun{ a <- calcOutput(type="CapacityEV") -#' } -#' - - -calcCapacityEV <- function() { - - x <- readSource("IEA_EV",subtype="combStock") - # convert unit - # 1Mio cars = 1/650 cap = 0.00154 - x <- x/650000 - # set all NA to 0 - x[is.na(x)] <- 0 - - getNames(x) <- NULL - - return(list(x = x, - weight = NULL, - unit = "TWa", - description = "capacity of electric vehicles")) - -} diff --git a/R/convertIEA_EV.R b/R/convertIEA_EV.R deleted file mode 100644 index fd754b8c..00000000 --- a/R/convertIEA_EV.R +++ /dev/null @@ -1,45 +0,0 @@ -#' Convert IEA_EV -#' -#' Convert IEA_EV on ISO country level. -#' -#' -#' @param x MAgPIE object containing IEA_EV country resolution -#' @return Krausmann data as MAgPIE object aggregated/disaggregated to country -#' level -#' @author Lavinia Baumstark, Christoph Bertram -#' @seealso \code{\link{readIEA_EV}} -#' @examples -#' \dontrun{ -#' a <- convertIEA_EV(x) -#' } -#' -convertIEA_EV <- function(x) { - # remove global data - x <- x["Total", , , invert = TRUE] - # make extra object for other countries - y <- x["Others", , ] - # delete other countries - x <- x["Others", , , invert = TRUE] - # rename countries into ISO - getItems(x, dim = 1) <- toolCountry2isocode(getItems(x, dim = 1)) - # distribute rest on remaining countries with GDP as weight - GDP2015 <- calcOutput("GDPPast", aggregate = F)[, "y2015", ] - getSets(GDP2015)[1] <- "region" - # additional countries - oth <- setdiff(getItems(GDP2015, dim = 1), getItems(x, dim = 1)) - # region mapping from Other to all remaining countries - map <- data.frame(reg = rep("Others", length(oth)), region = oth) - # downscale data of others to remaining countries, using GDP as weight - y <- toolAggregate(y, map, - from = "reg", to = "region", dim = 1, - weight = GDP2015[oth, , ] - ) - # combine data - x <- mbind(x, y) - # fill missing countries - x <- toolCountryFill(x, fill = 0) - # set all NA to 0 - x[is.na(x)] <- 0 - - return(x) -} diff --git a/R/fullREMIND.R b/R/fullREMIND.R index 93517015..d2d13c2c 100644 --- a/R/fullREMIND.R +++ b/R/fullREMIND.R @@ -127,13 +127,12 @@ fullREMIND <- function() { calcOutput("FEShares", subtype = "ind_bio", round = 5, file = "p_share_ind_fesos_bio.cs4r") calcOutput("FEShares", subtype = "ind_liq", round = 5, file = "p_share_ind_fehos.cs4r") calcOutput("Solar", round = 5, file = "f_dataRegiSolar.cs3r") - calcOutput("CapacityEV", round = 8, file = "pm_boundCapEV.cs4r") calcOutput("CapacityNuclear", round = 5, file = "pm_NuclearConstraint.cs4r") calcOutput("CCScapacity", round = 8, file = "pm_boundCapCCS.cs4r") calcOutput("CCSbounds", round = 8, file = "p_boundCapCCSindicator.cs4r") calcOutput("LimitCCS", round = 8, file = "pm_dataccs.cs3r") - calcOutput("TranspEff", round = 8, file = "f35_transp_eff.cs3r") - calcOutput("VintagesTransport", round = 8, file = "f35_factorVintages.cs3r") + calcOutput("TranspEff", round = 8, file = "f35_transp_eff.cs3r") # TODO delete + calcOutput("VintagesTransport", round = 8, file = "f35_factorVintages.cs3r") # TODO delete 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") @@ -171,7 +170,7 @@ fullREMIND <- function() { 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 = "f35_bunkers_fe", file = "f35_bunkers_fe.cs4r") + calcOutput("EDGETransport", subtype = "f35_bunkers_fe", file = "f35_bunkers_fe.cs4r") # TODO delete calcOutput("EDGETransport", subtype = "annual_mileage", file = "annual_mileage.cs4r") # not to be aggregated as global diff --git a/R/readIEA_EV.R b/R/readIEA_EV.R deleted file mode 100644 index 852c0ff6..00000000 --- a/R/readIEA_EV.R +++ /dev/null @@ -1,34 +0,0 @@ -#' Read IEA_EV -#' -#' Read-in IEA_EV -#' -#' -#' @return IEA data on electric vehicles as magpie object -#' @author Lavinia Baumstark, Christoph Bertram -#' @seealso \code{\link{readSource}} -#' @param subtype Which data: combSales, combStock, bevSales, bevStock, phevSales, or phevStock -#' @examples -#' \dontrun{ -#' a <- readSource(type = "IEA_EV") -#' } -#' @importFrom readxl read_excel -#' -#' -readIEA_EV <- function(subtype) { - - # use file from 2019 GEVO, with additional 2019 numbers from 2020 GEVO - file <- "GlobalEVOutlook2019-2020_TableA1-A6.xlsx" - subtypes <- c("combSales", "combStock", "bevSales", "bevStock", "phevSales", "phevStock") - - if (!subtype %in% subtypes) { - stop( - "Invalid subtype -- supported subtypes are: ", - paste(subtypes, collapse = ", ") - ) - } - ev <- read_excel(file, sheet = subtype, skip = 1, col_types = c("text", rep("numeric", 15))) - names(ev)[1] <- "region" - ev <- as.data.frame(ev) - ev <- as.magpie(ev, spatial = 1, datacol = 2) - return(ev) -} From b876cf944ddd7d96a22b4c3e4a9dca1736bcbff0 Mon Sep 17 00:00:00 2001 From: Falk Benke Date: Wed, 7 Feb 2024 18:34:03 +0100 Subject: [PATCH 03/10] remove calcVintagesTransport --- R/calcVintagesTransport.R | 16 ------------ R/convertREMIND_11Regi.R | 52 +++++++++++++++++++-------------------- R/fullREMIND.R | 1 - R/readREMIND_11Regi.R | 23 ++++++++--------- 4 files changed, 36 insertions(+), 56 deletions(-) delete mode 100644 R/calcVintagesTransport.R diff --git a/R/calcVintagesTransport.R b/R/calcVintagesTransport.R deleted file mode 100644 index fbe1f828..00000000 --- a/R/calcVintagesTransport.R +++ /dev/null @@ -1,16 +0,0 @@ - - -calcVintagesTransport <- function(){ - - x <- readSource("REMIND_11Regi", subtype = "vintage") - x[is.na(x)] <- 1 - - w <- calcOutput("IO",subtype="output",aggregate=FALSE)[,2005,getNames(x,dim=2)] - w <- dimSums(w,dim=c(3.1,3.2)) - - return(list(x = x, - weight = w, - unit = "none", - description = "vintages, installed capacities")) -} - diff --git a/R/convertREMIND_11Regi.R b/R/convertREMIND_11Regi.R index e8751b83..1ec63ad6 100644 --- a/R/convertREMIND_11Regi.R +++ b/R/convertREMIND_11Regi.R @@ -1,22 +1,22 @@ #' Converts REMIND regional data -#' +#' #' @param x MAgPIE object to be converted #' @param subtype Name of the regional data, e.g. "p4", "biomass", "ch4waste", "tradecost", "pe2se", "xpres_tax", "deltacapoffset", capacityFactorRules", "taxConvergence", "maxFeSubsidy", "maxPeSubsidy", "propFeSubsidy", "fossilExtractionCoeff", "uraniumExtractionCoeff", "RLDCCoefficientsLoB", "RLDCCoefficientsPeak", "earlyRetirementAdjFactor" #' @return A MAgPIE object containing country disaggregated data #' @author original: not defined - capacity factor, tax, fossil and RLDC changes: Renato Rodrigues #' @examples -#' +#' #' \dontrun{ a <- convertREMIND_11Regi(x,subtype="capacityFactorGlobal") #' } -#' +#' convertREMIND_11Regi <- function(x,subtype) { - + if(subtype == "p4" | subtype == "biomass" | subtype == "tradecost" | - subtype == "pe2se" | subtype == "xpres_tax" | subtype == "storageFactor" | subtype == "transpEff" | subtype == "shareIndFE" | - subtype == "residuesShare" | subtype == "vintage" | subtype=="ffPolyRent" | subtype == "earlyRetirementAdjFactor" ){ + subtype == "pe2se" | subtype == "xpres_tax" | subtype == "storageFactor" | subtype == "transpEff" | subtype == "shareIndFE" | + subtype == "residuesShare" | subtype=="ffPolyRent" | subtype == "earlyRetirementAdjFactor" ){ # No weighting for spatial aggregation - y <- toolAggregate(x, "regionmappingREMIND.csv", weight=NULL) + y <- toolAggregate(x, "regionmappingREMIND.csv", weight=NULL) } else if (subtype == "ch4waste" | subtype == "AP_starting_values") { pop <- calcOutput("Population",years=2005,aggregate=FALSE)[,,"pop_SSP2"] y <- toolAggregate(x,"regionmappingREMIND.csv",weight=pop) @@ -34,8 +34,8 @@ convertREMIND_11Regi <- function(x,subtype) { # Replacing NA values with zero x[is.na(x)] <- 0 # Converting old Region data to country data - y <- toolAggregate(x, mapping, weight=NULL) - # Filling missing country data with zero values to avoid convert error check + y <- toolAggregate(x, mapping, weight=NULL) + # Filling missing country data with zero values to avoid convert error check y <- toolCountryFill(y,fill=0) } else if (subtype == "fossilExtractionCoeff"){ # weight @@ -43,12 +43,12 @@ convertREMIND_11Regi <- function(x,subtype) { gas <- readSource("BGR", subtype="gas")[,,"Remaining_Potential"] coal <- readSource("BGR", subtype="coal")[,,"Remaining_Potential"] BGRData <- list(lowOil = oil, medOil = oil, highOil = oil, lowGas = gas, medGas = gas, highGas = gas, lowCoal = coal, medCoal = coal, highCoal = coal) - # filling all countries weights and adding a very small weight to countries with no remaining potential to estimate a very step cost curve in this case + # filling all countries weights and adding a very small weight to countries with no remaining potential to estimate a very step cost curve in this case weight <- lapply(BGRData, function(df){ - df <- toolCountryFill(df,fill=0) - df[df == 0] <- 1E-20 + df <- toolCountryFill(df,fill=0) + df[df == 0] <- 1E-20 return(df) - }) + }) # mapping - original REMIND region mapping (11 regions) mapping <- toolGetMapping(type = "regional", name = "regionmappingREMIND.csv", where = "mappingfolder") # maxExtraction (upper x limit for function estimation) @@ -56,11 +56,11 @@ convertREMIND_11Regi <- function(x,subtype) { upperBoundMaxExtraction <- toolAggregate(upperBoundMaxExtractionPerCountry, mapping, weight=NULL) # return magpie list of country disaggregated coefficients countryCoeff <- suppressWarnings(toolCubicFunctionDisaggregate(x,weight,rel=mapping,xUpperBound=upperBoundMaxExtraction)) - # add dimension with the name of the pe on the magpie objects + # add dimension with the name of the pe on the magpie objects output <- lapply(seq_along(countryCoeff), function(i) { out <- add_dimension(countryCoeff[[i]], dim = 3.1, nm = names(countryCoeff)[i]) }) - names(output) <- names(countryCoeff) + names(output) <- names(countryCoeff) # merge all magpie objects into a single one y <- mbind(output) } else if (subtype == "uraniumExtractionCoeff") { @@ -70,14 +70,14 @@ convertREMIND_11Regi <- function(x,subtype) { x[,,"peur.xi3"] <- ( (300/1000)* 3 ** 1.8) / ((x[,,"peur.xi3"]* 14 /4.154) * 3) ** 2 x[,,"peur.xi4"] <- 0 # weight - BGRuranium <- readSource("BGR", subtype="uranium")[,,"Remaining_Potential"] # Remaining extraction potential per country - BGRuranium <- toolCountryFill(BGRuranium,fill=0) + BGRuranium <- readSource("BGR", subtype="uranium")[,,"Remaining_Potential"] # Remaining extraction potential per country + BGRuranium <- toolCountryFill(BGRuranium,fill=0) BGRuranium[BGRuranium == 0] <- 1E-3 # assigning small uranium extraction potential for countries with none to help the curves estimation weight <- list(peur = BGRuranium) # mapping - original REMIND region mapping (11 regions) mapping <- toolGetMapping(type = "regional", name = "regionmappingREMIND.csv", where = "mappingfolder") # maxExtraction (upper x limit for function estimation) - weightmaxExtraction <- toolAggregate(BGRuranium, mapping, weight=NULL) + weightmaxExtraction <- toolAggregate(BGRuranium, mapping, weight=NULL) totalWeightMaxExtraction <- as.numeric(colSums(weightmaxExtraction)) upperBoundMaxExtraction <- 23* ( weightmaxExtraction/totalWeightMaxExtraction ) # 23 -> from s31_max_disp_peur -> max global "maximum amount of cumulative uranium production in Megatonnes of metal uranium (U3O8, the stuff that is traded at 40-60US$/lb)." upperBoundMaxExtraction <- add_dimension(upperBoundMaxExtraction, dim = 3.1, add = "pe", nm = "peur") @@ -104,33 +104,33 @@ convertREMIND_11Regi <- function(x,subtype) { y <- toolAggregate(x, "regionmappingREMIND.csv", weight=w) # SB & NB edit 2019/09/11: Increase SSP5 oil max cumulative extraction in USA and CAZ by 20% based on calibration with the SSP IAM project 2017 y[c("USA","CAN","AUS","NZL","HMD","SPM"),,"peoil.max.highOil"] <- y[c("USA","CAN","AUS","NZL","HMD","SPM"),,"peoil.max.highOil"] * (1 + 0.2) - + #SB & NB edit 2019/11/18: # Increase SSP5 max cumulative coal extraction for USA and CAZ by 20% - y[c("USA","CAN","AUS","NZL","HMD","SPM"),,"pecoal.max.highCoal"] <- + y[c("USA","CAN","AUS","NZL","HMD","SPM"),,"pecoal.max.highCoal"] <- y[c("USA","CAN","AUS","NZL","HMD","SPM"),,"pecoal.max.highCoal"] * (1 + 0.2) - + } else if (subtype == "gridFactor") { y <- x } else if (subtype == "ccs") { # use total land area as weight - area <- calcOutput("LanduseInitialisation",aggregate=FALSE)[,2005,] + area <- calcOutput("LanduseInitialisation",aggregate=FALSE)[,2005,] # sum over 3.dimension area <- dimSums(area,dim=3) getYears(area) <- NULL y <- toolAggregate(x, "regionmappingREMIND.csv", weight=area) } else if (subtype=="RLDCCoefficientsLoB") { # Converting old Region data to country data - # setting country coefficient values equal to region that it belonged - y <- toolAggregate(x, "regionmappingREMIND.csv", weight=NULL) + # setting country coefficient values equal to region that it belonged + y <- toolAggregate(x, "regionmappingREMIND.csv", weight=NULL) # setting country absciss value equal to original region values weighted by the PE use of the country (should be replaced by extraction quantities data) fe <- calcOutput("FE",aggregate=FALSE) z <- toolAggregate(x, "regionmappingREMIND.csv", weight=fe[,2005,"FE (EJ/yr)"]) y[,,c("1.p00","2.p00","3.p00","4.p00")] <- z[,,c("1.p00","2.p00","3.p00","4.p00")] } else if (subtype=="RLDCCoefficientsPeak") { # Converting old Region data to country data - # setting country coefficient values equal to region that it belonged - y <- toolAggregate(x, "regionmappingREMIND.csv", weight=NULL) + # setting country coefficient values equal to region that it belonged + y <- toolAggregate(x, "regionmappingREMIND.csv", weight=NULL) # setting country absciss value equal to original region values weighted by the PE use of the country (should be replaced by extraction quantities data) fe <- calcOutput("FE",aggregate=FALSE) z <- toolAggregate(x, "regionmappingREMIND.csv", weight=fe[,2005,"FE (EJ/yr)"]) diff --git a/R/fullREMIND.R b/R/fullREMIND.R index d2d13c2c..f142de98 100644 --- a/R/fullREMIND.R +++ b/R/fullREMIND.R @@ -132,7 +132,6 @@ fullREMIND <- function() { calcOutput("CCSbounds", round = 8, file = "p_boundCapCCSindicator.cs4r") calcOutput("LimitCCS", round = 8, file = "pm_dataccs.cs3r") calcOutput("TranspEff", round = 8, file = "f35_transp_eff.cs3r") # TODO delete - calcOutput("VintagesTransport", round = 8, file = "f35_factorVintages.cs3r") # TODO delete 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") diff --git a/R/readREMIND_11Regi.R b/R/readREMIND_11Regi.R index ccad5cf3..ba605111 100644 --- a/R/readREMIND_11Regi.R +++ b/R/readREMIND_11Regi.R @@ -1,19 +1,19 @@ #' Read REMIND region dependent data -#' +#' #' Read-in an csv files that contains regional data -#' +#' #' @param subtype Name of the regional data, e.g. "p4", "biomass", "ch4waste", "tradecost", "pe2se", "xpres_tax", "deltacapoffset", "capacityFactorGlobal", "capacityFactorRules", "residuesShare", "taxConvergence", "maxFeSubsidy", "maxPeSubsidy", "propFeSubsidy", "fossilExtractionCoeff", "uraniumExtractionCoeff", "RLDCCoefficientsLoB", "RLDCCoefficientsPeak", "earlyRetirementAdjFactor" #' @return magpie object of region dependent data #' @author original: not defined, capacity factor, tax, fossil and RLDC changes: Renato Rodrigues #' @seealso \code{\link{readSource}} #' @examples -#' +#' #' \dontrun{ a <- readSource(type="REMIND_11Regi",subtype="capacityFactorGlobal") #' } readREMIND_11Regi<- function(subtype) { - + if (subtype == "p4") { x <- read.csv("EconometricEmissionParameter_p4.csv",sep=";",row.names=1) x <- as.magpie(x) @@ -72,16 +72,13 @@ readREMIND_11Regi<- function(subtype) { } else if (subtype=="gridFactor") { x <- read.csv("homogenous_regions_for grids.csv", sep=";") x$X <- NULL - x <- as.magpie(x,datacol=2) + x <- as.magpie(x,datacol=2) } else if (subtype=="AP_starting_values") { x <- read.csv("f11_emiAPexsolve.cs4r", sep=",", skip = 1, header = F) x <- as.magpie(x,datacol=6) - } else if (subtype=="vintage") { - x <- read.csv("factorVintage.csv",sep=";") - x <- as.magpie(x,spatial=1,datacol=3) } else if (subtype=="ccs") { x <- read.csv("p_dataccs.csv",sep=";") - x <- as.magpie(x,spatial=1,datacol=2) + x <- as.magpie(x,spatial=1,datacol=2) } else if (subtype=="ffPolyRent") { x <- read.csv("ffPolyRent.csv",sep=";") x <- as.magpie(x,spatial=1,datacol=5) @@ -93,7 +90,7 @@ readREMIND_11Regi<- function(subtype) { #removing the X string added to the column names because how the read.table call inside the read.csv function converts column name numbers to valid variable strings (by using check.names) colnames(x) <- gsub("^X", "", colnames(x)) x <- as.magpie(x,spatial=1,temporal=0,datacol=3) - #JPN SSP5 gas extraction zero-order coeff was originally negative. + #JPN SSP5 gas extraction zero-order coeff was originally negative. x["JPN",,"highGas.0"] <- 0 } else if (subtype=="uraniumExtractionCoeff") { x <- read.csv("uranium_extraction_cost_eq_coefficients.csv",sep=";") @@ -103,14 +100,14 @@ readREMIND_11Regi<- function(subtype) { x <- as.magpie(x,spatial=1,temporal=0,datacol=3) } else if (subtype=="RLDCCoefficientsPeak") { x <- read.csv("RLDC_Coefficients_Peak.csv",sep=";") - x <- as.magpie(x,spatial=1,temporal=0,datacol=3) + x <- as.magpie(x,spatial=1,temporal=0,datacol=3) } else if (subtype=="earlyRetirementAdjFactor") { y <- read.csv("earlyRetirementAdjFactor.csv",sep=";",skip=5) - x <- as.magpie(y,spatial=1,temporal=0,datacol=2) + x <- as.magpie(y,spatial=1,temporal=0,datacol=2) x <- setNames(x,colnames(y)[-1]) } else if (subtype=="nashWeight") { x <- read.csv("nash_weights.csv",sep=";") - x <- as.magpie(x,spatial=1,datacol=2) + x <- as.magpie(x,spatial=1,datacol=2) } else { stop("Not a valid subtype!") } From 0abbeb50fb000bd96d87a4183b038afc12cb5aee Mon Sep 17 00:00:00 2001 From: Falk Benke Date: Wed, 7 Feb 2024 18:37:07 +0100 Subject: [PATCH 04/10] remove calcTranspEff --- R/calcTranspEff.R | 30 ------------------------------ R/convertREMIND_11Regi.R | 2 +- R/fullREMIND.R | 1 - R/readREMIND_11Regi.R | 4 ---- 4 files changed, 1 insertion(+), 36 deletions(-) delete mode 100644 R/calcTranspEff.R diff --git a/R/calcTranspEff.R b/R/calcTranspEff.R deleted file mode 100644 index d98daf9d..00000000 --- a/R/calcTranspEff.R +++ /dev/null @@ -1,30 +0,0 @@ -#' calcTranspEff -#' calculate Transport efficiency -#' -#' @return magpie object -#' @author Julian Oeser -#' @seealso \code{\link{calcOutput}} -#' @examples -#' -#' \dontrun{ a <- calcOutput(type="TranspEff") -#' } -#' - - -calcTranspEff <- function(){ - - x <- readSource("REMIND_11Regi", subtype = "transpEff") - ## the data is provided for energy service per "fossil-fuel equivalents". - ## to obtain the ES for a given motive energy, we have to divide by - ## tank-to-wheel efficiencies - #x[,, "Eff_Pass_LDV"] <- x[,, "Eff_Pass_LDV"] / 0.22 - #x[,, c("Eff_Pass_nonLDV", "Eff_Freight")] <- x[,, c("Eff_Pass_nonLDV", "Eff_Freight")] / 0.24 - weights <- calcOutput("FE", aggregate = FALSE, years=2005)[,,"FE|Transport (EJ/yr)"] - - - - return(list(x = x, - weight = weights, - unit = "range 0..1, bn pkm/EJ", - description = "regionalized transport mode shares and efficiencies")) -} diff --git a/R/convertREMIND_11Regi.R b/R/convertREMIND_11Regi.R index 1ec63ad6..bb95b567 100644 --- a/R/convertREMIND_11Regi.R +++ b/R/convertREMIND_11Regi.R @@ -13,7 +13,7 @@ convertREMIND_11Regi <- function(x,subtype) { if(subtype == "p4" | subtype == "biomass" | subtype == "tradecost" | - subtype == "pe2se" | subtype == "xpres_tax" | subtype == "storageFactor" | subtype == "transpEff" | subtype == "shareIndFE" | + subtype == "pe2se" | subtype == "xpres_tax" | subtype == "storageFactor" | subtype == "shareIndFE" | subtype == "residuesShare" | subtype=="ffPolyRent" | subtype == "earlyRetirementAdjFactor" ){ # No weighting for spatial aggregation y <- toolAggregate(x, "regionmappingREMIND.csv", weight=NULL) diff --git a/R/fullREMIND.R b/R/fullREMIND.R index f142de98..e82c06fa 100644 --- a/R/fullREMIND.R +++ b/R/fullREMIND.R @@ -131,7 +131,6 @@ fullREMIND <- function() { calcOutput("CCScapacity", round = 8, file = "pm_boundCapCCS.cs4r") calcOutput("CCSbounds", round = 8, file = "p_boundCapCCSindicator.cs4r") calcOutput("LimitCCS", round = 8, file = "pm_dataccs.cs3r") - calcOutput("TranspEff", round = 8, file = "f35_transp_eff.cs3r") # TODO delete 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") diff --git a/R/readREMIND_11Regi.R b/R/readREMIND_11Regi.R index ba605111..81734d16 100644 --- a/R/readREMIND_11Regi.R +++ b/R/readREMIND_11Regi.R @@ -50,10 +50,6 @@ readREMIND_11Regi<- function(subtype) { } else if (subtype=="residuesShare") { x <- read.csv("residuesShare.csv", row.names = 1) x <- as.magpie(x,datacol=4) - } else if (subtype=="transpEff") { - x <- read.csv2("transpEff.csv", stringsAsFactors = FALSE) - x[,2:5] <- apply(x[,2:5], 2, as.numeric) - x <- as.magpie(x, datacol=2) } else if (subtype=="shareIndFE") { x <- read.csv("shareIndustyFE.csv", sep=";",skip=3) x <- as.magpie(x,datacol=3) From 6af1c46023563754fa75de6942b514e4ee4cbd83 Mon Sep 17 00:00:00 2001 From: Falk Benke Date: Wed, 7 Feb 2024 18:39:34 +0100 Subject: [PATCH 05/10] f35_bunkers_fe.cs4r --- R/calcEDGETransport.R | 5 ----- R/fullREMIND.R | 1 - 2 files changed, 6 deletions(-) diff --git a/R/calcEDGETransport.R b/R/calcEDGETransport.R index a059eb01..6bd3dbb6 100644 --- a/R/calcEDGETransport.R +++ b/R/calcEDGETransport.R @@ -124,11 +124,6 @@ calcEDGETransport <- function(subtype = "logit_exponent") { weight = NULL unit = "EJ" description = "UE demand divided by technologies for different ES on the CES level." - }, - "f35_bunkers_fe" = { - weight = NULL - unit = "EJ" - description = "Bunkers FE trajectory from edge-t." }) return(list(x = data, diff --git a/R/fullREMIND.R b/R/fullREMIND.R index e82c06fa..a934265b 100644 --- a/R/fullREMIND.R +++ b/R/fullREMIND.R @@ -168,7 +168,6 @@ fullREMIND <- function() { 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 = "f35_bunkers_fe", file = "f35_bunkers_fe.cs4r") # TODO delete calcOutput("EDGETransport", subtype = "annual_mileage", file = "annual_mileage.cs4r") # not to be aggregated as global From b62353e231a8d2f760ad571cf11924a49467f89d Mon Sep 17 00:00:00 2001 From: Falk Benke Date: Mon, 12 Feb 2024 14:40:17 +0100 Subject: [PATCH 06/10] add version update check --- .github/workflows/check.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 870f216e..33f49b89 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -49,6 +49,10 @@ jobs: shell: Rscript {0} run: lucode2:::validkey(stopIfInvalid = TRUE) + - name: Verify that lucode2::buildLibrary was successful + shell: Rscript {0} + run: lucode2:::isVersionUpdated() + - name: Checks shell: Rscript {0} run: | From b794b732bb91157bf1967582a04d4ec949fbf6a0 Mon Sep 17 00:00:00 2001 From: Falk Benke Date: Tue, 13 Feb 2024 17:52:24 +0100 Subject: [PATCH 07/10] adjust description based on IEA version --- .github/workflows/check.yaml | 4 ---- R/calcFE.R | 3 ++- R/calcIO.R | 6 ++++-- R/calcPE.R | 16 +++++++++++----- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 33f49b89..870f216e 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -49,10 +49,6 @@ jobs: shell: Rscript {0} run: lucode2:::validkey(stopIfInvalid = TRUE) - - name: Verify that lucode2::buildLibrary was successful - shell: Rscript {0} - run: lucode2:::isVersionUpdated() - - name: Checks shell: Rscript {0} run: | diff --git a/R/calcFE.R b/R/calcFE.R index 1415f137..bfdf04c8 100644 --- a/R/calcFE.R +++ b/R/calcFE.R @@ -27,7 +27,8 @@ calcFE <- function(source = "IEA", scenario_proj = "SSP2", ieaVersion = "default colnames(map) <- gsub("io", "names_in", colnames(map)) # Give description - descript <- "IEA Final Energy Data based on 2022 version of IEA Energy Balances" + ieaYear <- if (ieaVersion == "default") 2022 else 2023 + descript <- paste0("IEA Final Energy Data based on ", ieaYear, " version of IEA Energy Balances") #------ PROCESS DATA ------------------------------------------ # select data that have names diff --git a/R/calcIO.R b/R/calcIO.R index 07626369..ac14d9b8 100644 --- a/R/calcIO.R +++ b/R/calcIO.R @@ -83,6 +83,7 @@ calcIO <- function(subtype = c("input", "output", "output_biomass", "trade", } ieaSubtype <- if (ieaVersion == "default") "EnergyBalances" else "EnergyBalances-latest" + ieaYear <- if (ieaVersion == "default") 2022 else 2023 # read in data and convert from ktoe to EJ data <- readSource("IEA", subtype = ieaSubtype) * 4.1868e-5 @@ -177,7 +178,8 @@ calcIO <- function(subtype = c("input", "output", "output_biomass", "trade", # In order to split the REMIND technology biotr between biotr and biotrmod, # We use the traditional biomass split for EDGE buildings and divide by the total quantity of FE biomass - edgeBio <- calcOutput("IOEdgeBuildings", subtype = "output_EDGE_buildings", ieaVersion = ieaVersion, aggregate = FALSE) + edgeBio <- calcOutput("IOEdgeBuildings", subtype = "output_EDGE_buildings", + ieaVersion = ieaVersion, aggregate = FALSE) feBio <- calcOutput("IO", subtype = "output_biomass", ieaVersion = ieaVersion, aggregate = FALSE) shareBiotrad <- edgeBio[, , "biotrad"] / (feBio[, , "sesobio.fesob.tdbiosob"] + feBio[, , "sesobio.fesoi.tdbiosoi"]) shareBiotrad[is.na(shareBiotrad)] <- 0 @@ -237,5 +239,5 @@ calcIO <- function(subtype = c("input", "output", "output_biomass", "trade", } return(list(x = reminditems, weight = NULL, unit = "EJ", - description = "IEA SE Output Data based on 2022 edition of IEA World Energy Balances")) + description = paste0("IEA SE Output Data based on ", ieaYear, " edition of IEA World Energy Balances"))) } diff --git a/R/calcPE.R b/R/calcPE.R index ec8b18a2..d347cb72 100644 --- a/R/calcPE.R +++ b/R/calcPE.R @@ -29,10 +29,14 @@ calcPE <- function(subtype = "IEA", ieaVersion = "default") { getNames(x) <- paste0(getNames(x), " (EJ/yr)") # add loss to electricity - x[, , "PE|Coal|Electricity (EJ/yr)"] <- x[, , "PE|Coal|Electricity (EJ/yr)"] + x[, , "PE|Coal|Electricity|Loss (EJ/yr)"] - x[, , "PE|Biomass|Electricity (EJ/yr)"] <- x[, , "PE|Biomass|Electricity (EJ/yr)"] + x[, , "PE|Biomass|Electricity|Loss (EJ/yr)"] - x[, , "PE|Gas|Electricity (EJ/yr)"] <- x[, , "PE|Gas|Electricity (EJ/yr)"] + x[, , "PE|Gas|Electricity|Loss (EJ/yr)"] - x <- x[, , c("PE|Coal|Electricity|Loss (EJ/yr)", "PE|Biomass|Electricity|Loss (EJ/yr)", "PE|Gas|Electricity|Loss (EJ/yr)"), invert = TRUE] + x[, , "PE|Coal|Electricity (EJ/yr)"] <- x[, , "PE|Coal|Electricity (EJ/yr)"] + + x[, , "PE|Coal|Electricity|Loss (EJ/yr)"] + x[, , "PE|Biomass|Electricity (EJ/yr)"] <- x[, , "PE|Biomass|Electricity (EJ/yr)"] + + x[, , "PE|Biomass|Electricity|Loss (EJ/yr)"] + x[, , "PE|Gas|Electricity (EJ/yr)"] <- x[, , "PE|Gas|Electricity (EJ/yr)"] + + x[, , "PE|Gas|Electricity|Loss (EJ/yr)"] + x <- x[, , c("PE|Coal|Electricity|Loss (EJ/yr)", "PE|Biomass|Electricity|Loss (EJ/yr)", + "PE|Gas|Electricity|Loss (EJ/yr)"), invert = TRUE] # add more variables x <- mbind(x, setNames(dimSums(x[, , "PE|", pmatch = TRUE], dim = 3), "PE (EJ/yr)")) @@ -41,9 +45,11 @@ calcPE <- function(subtype = "IEA", ieaVersion = "default") { x <- mbind(x, setNames(dimSums(x[, , "PE|Gas", pmatch = TRUE], dim = 3), "PE|Gas (EJ/yr)")) x <- mbind(x, setNames(dimSums(x[, , "PE|Biomass", pmatch = TRUE], dim = 3), "PE|Biomass (EJ/yr)")) + ieaYear <- if (ieaVersion == "default") 2022 else 2023 return(list(x = x, weight = NULL, unit = "EJ", - description = "IEA Primary Energy Data based on 2022 version of IEA Energy Balances")) + description = paste0("IEA Primary Energy Data based on ", ieaYear, + " version of IEA Energy Balances"))) } else if (subtype == "IEA_WEO") { From f81a8e91fe62ebb631fa7473d32365722cbb794a Mon Sep 17 00:00:00 2001 From: Falk Benke Date: Thu, 15 Feb 2024 12:34:07 +0100 Subject: [PATCH 08/10] remove transport subsidies --- R/calcTransportSubsidies.R | 40 -------------------------------------- R/fullREMIND.R | 1 - 2 files changed, 41 deletions(-) delete mode 100644 R/calcTransportSubsidies.R diff --git a/R/calcTransportSubsidies.R b/R/calcTransportSubsidies.R deleted file mode 100644 index 5324d4c0..00000000 --- a/R/calcTransportSubsidies.R +++ /dev/null @@ -1,40 +0,0 @@ -#' @title calc transport subsidies -#' @description provides transport subsidies -#' -#' @return magpie object of the transport subsidies data -#' @author Renato Rodrigues -#' @examples -#' -#' \dontrun{ -#' calcOutput("TransportSubsidies") -#' } -#' - -calcTransportSubsidies <- function(){ - - transpSub <- readSource(type="TransportSubsidies") - - # mapping subsidies to technologies in remind - map <- c("BEV"="apCarElT", "FCEV"="apCarH2T") - - # setting subsidy to average between private and legal entities subsidies - out <- setNames(dimSums(transpSub[,,names(map)],dim=3.1)/2,as.vector(map)) - - # convert subsidies from euros to trillions of dollares - # inflation dollars: 1 $2005 eq to 1.3504 $2020 - # exchange rate 2020: 1 euro = 1.12 dollar - # conversion from US$2005 to EUR2020: inflation/exchange rate = 1.3504/1.12 = 1.205714286 - out <- (out/1.205714286)/10^12 - - # convert from cars to total (650 million cars in the World) - out <- out*650*10^6 - - #weight: using 2020 light duty vehicles final energy as weight - fe <- calcOutput("FEdemand", aggregate = FALSE)[,2020,"gdp_SSP2.ueLDVt"] - - return(list(x=out, weight=fe, - unit="trillion U.S. dollar", - description="Total transport subsidies for BEV (apCarElT) and FCEV (apCarH2T)" - )) - -} diff --git a/R/fullREMIND.R b/R/fullREMIND.R index a934265b..97396908 100644 --- a/R/fullREMIND.R +++ b/R/fullREMIND.R @@ -186,5 +186,4 @@ fullREMIND <- function() { calcOutput("EffortSharingRefEmi", subtype = "EEA_GHG", round = 6, file = "p47_ESR_GHG_referenceEmissions.cs4r") calcOutput("EffortSharingRefEmi", subtype = "REMIND_CO2", round = 6, file = "p47_ESR_CO2_referenceEmissions.cs4r") calcOutput("ETSRefEmi", subtype = "EEA_GHG", round = 6, file = "p47_ETS_GHG_referenceEmissions.cs4r") - calcOutput("TransportSubsidies", round = 8, file = "f21_vehiclesSubsidies.cs4r") } From 45a269f28084c8d8e47a8f7bcc2c9922b9404b59 Mon Sep 17 00:00:00 2001 From: Falk Benke Date: Thu, 15 Feb 2024 12:34:13 +0100 Subject: [PATCH 09/10] increment version --- .buildlibrary | 3 ++- CITATION.cff | 4 ++-- DESCRIPTION | 4 ++-- README.md | 6 +++--- man/calcCapacityEV.Rd | 28 ---------------------------- man/calcTranspEff.Rd | 28 ---------------------------- man/convertIEA_EV.Rd | 30 ------------------------------ man/readIEA_EV.Rd | 28 ---------------------------- 8 files changed, 9 insertions(+), 122 deletions(-) delete mode 100644 man/calcCapacityEV.Rd delete mode 100644 man/calcTranspEff.Rd delete mode 100644 man/convertIEA_EV.Rd delete mode 100644 man/readIEA_EV.Rd diff --git a/.buildlibrary b/.buildlibrary index 57dbc864..0ff02c3e 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '34746870' +ValidationKey: '347699371768' AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' - 'Warning: namespace ''.*'' is not available and has been replaced' @@ -11,3 +11,4 @@ AcceptedNotes: - Imports includes .* non-default packages. AutocreateReadme: yes allowLinterWarnings: yes +enforceVersionUpdate: yes diff --git a/CITATION.cff b/CITATION.cff index 53a0818a..e1a27efb 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.175.8 -date-released: '2024-02-12' +version: 0.175.8.9001 +date-released: '2024-02-15' abstract: The mrremind packages contains data preprocessing for the REMIND model. authors: - family-names: Baumstark diff --git a/DESCRIPTION b/DESCRIPTION index 05fbedda..c580cceb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: mrremind Title: MadRat REMIND Input Data Package -Version: 0.175.8 -Date: 2024-02-12 +Version: 0.175.8.9001 +Date: 2024-02-15 Authors@R: c( person("Lavinia", "Baumstark", , "lavinia@pik-potsdam.de", role = c("aut", "cre")), person("Renato", "Rodrigues", role = "aut"), diff --git a/README.md b/README.md index 7f4458c5..4437db80 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # MadRat REMIND Input Data Package -R package **mrremind**, version **0.175.8** +R package **mrremind**, version **0.175.8.9001** [![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 (2024). _mrremind: MadRat REMIND Input Data Package_. R package version 0.175.8.9001, . 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}, year = {2024}, - note = {R package version 0.175.8}, + note = {R package version 0.175.8.9001}, url = {https://github.com/pik-piam/mrremind}, } ``` diff --git a/man/calcCapacityEV.Rd b/man/calcCapacityEV.Rd deleted file mode 100644 index 3d059a2e..00000000 --- a/man/calcCapacityEV.Rd +++ /dev/null @@ -1,28 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/calcCapacityEV.R -\name{calcCapacityEV} -\alias{calcCapacityEV} -\title{CapacityEV -calculate capacity of EV} -\usage{ -calcCapacityEV() -} -\value{ -magpie object -} -\description{ -CapacityEV -calculate capacity of EV -} -\examples{ - -\dontrun{ a <- calcOutput(type="CapacityEV") -} - -} -\seealso{ -\code{\link{calcOutput}} -} -\author{ -Lavinia Baumstark -} diff --git a/man/calcTranspEff.Rd b/man/calcTranspEff.Rd deleted file mode 100644 index 943636f5..00000000 --- a/man/calcTranspEff.Rd +++ /dev/null @@ -1,28 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/calcTranspEff.R -\name{calcTranspEff} -\alias{calcTranspEff} -\title{calcTranspEff -calculate Transport efficiency} -\usage{ -calcTranspEff() -} -\value{ -magpie object -} -\description{ -calcTranspEff -calculate Transport efficiency -} -\examples{ - -\dontrun{ a <- calcOutput(type="TranspEff") -} - -} -\seealso{ -\code{\link{calcOutput}} -} -\author{ -Julian Oeser -} diff --git a/man/convertIEA_EV.Rd b/man/convertIEA_EV.Rd deleted file mode 100644 index 7711f4be..00000000 --- a/man/convertIEA_EV.Rd +++ /dev/null @@ -1,30 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/convertIEA_EV.R -\name{convertIEA_EV} -\alias{convertIEA_EV} -\title{Convert IEA_EV} -\usage{ -convertIEA_EV(x) -} -\arguments{ -\item{x}{MAgPIE object containing IEA_EV country resolution} -} -\value{ -Krausmann data as MAgPIE object aggregated/disaggregated to country -level -} -\description{ -Convert IEA_EV on ISO country level. -} -\examples{ -\dontrun{ -a <- convertIEA_EV(x) -} - -} -\seealso{ -\code{\link{readIEA_EV}} -} -\author{ -Lavinia Baumstark, Christoph Bertram -} diff --git a/man/readIEA_EV.Rd b/man/readIEA_EV.Rd deleted file mode 100644 index e0fa1714..00000000 --- a/man/readIEA_EV.Rd +++ /dev/null @@ -1,28 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/readIEA_EV.R -\name{readIEA_EV} -\alias{readIEA_EV} -\title{Read IEA_EV} -\usage{ -readIEA_EV(subtype) -} -\arguments{ -\item{subtype}{Which data: combSales, combStock, bevSales, bevStock, phevSales, or phevStock} -} -\value{ -IEA data on electric vehicles as magpie object -} -\description{ -Read-in IEA_EV -} -\examples{ -\dontrun{ -a <- readSource(type = "IEA_EV") -} -} -\seealso{ -\code{\link{readSource}} -} -\author{ -Lavinia Baumstark, Christoph Bertram -} From c0f2a17635011d1be4baf02daf2965eb5fbe31bc Mon Sep 17 00:00:00 2001 From: Falk Benke Date: Thu, 15 Feb 2024 14:12:43 +0100 Subject: [PATCH 10/10] remove no longer needed items from calcCapacityfactor --- R/calcCapacityFactor.R | 153 +++++++++++++++++-------------------- R/readREMIND_11Regi.R | 168 +++++++++++++++++++++-------------------- 2 files changed, 156 insertions(+), 165 deletions(-) diff --git a/R/calcCapacityFactor.R b/R/calcCapacityFactor.R index 7d0d030e..e89d9491 100644 --- a/R/calcCapacityFactor.R +++ b/R/calcCapacityFactor.R @@ -4,97 +4,92 @@ #' @author Renato Rodrigues, Stephen Bi #' @importFrom plyr round_any #' @examples -#' #' \dontrun{ #' calcOutput("CapacityFactor") #' } #' - -calcCapacityFactor <- function(){ - - - - +calcCapacityFactor <- function() { ### calculation of coal power capacity factor GWh_2_EJ <- 3.6e-6 # Read capacity factor inputs - global <- readSource("REMIND_11Regi", subtype="capacityFactorGlobal", convert = FALSE) + global <- readSource("REMIND_11Regi", subtype = "capacityFactorGlobal", convert = FALSE) + + # remove no longer used items + notUsed <- c("apcarelt", "aptrnelt", "apcarh2t", "apcarpet", "apcardit", "apcardiefft", "apcardieffH2t") + global <- global[, , notUsed, invert = TRUE] + # Set coal plant capacity factor long-term assumption to 50% (down from 60%) - global[,,"pc"] <- 0.5 + global[, , "pc"] <- 0.5 # Read capacity factor rules - rules <- readSource("REMIND_11Regi", subtype="capacityFactorRules") + rules <- readSource("REMIND_11Regi", subtype = "capacityFactorRules") # Creating new MAgPIE object to store the final capacity values - output <- new.magpie(getRegions(rules),seq(2005,2150,5),getNames(global)) - + output <- new.magpie(getRegions(rules), seq(2005, 2150, 5), getNames(global)) # Merging global and rules values # Filling MagPIE object with global values - output[,,getNames(global)] <- global[,,getNames(global)] - + output[, , getNames(global)] <- global[, , getNames(global)] ### Global Coal Plant Tracker Calcs ### # Read coal capacity and generation data to derive historical capacity factor rules # Read generation data from Energy Balances - coalgen_c <- calcOutput("IO",subtype="output",aggregate = F)[,,"pecoal.seel"] - coalgen_c <- dimSums(coalgen_c,dim=3) - map <- toolGetMapping(getConfig("regionmapping"),type="regional", where = "mappingfolder") - coalgen_R <- toolAggregate(coalgen_c,map,weight=NULL) + coalgen_c <- calcOutput("IO", subtype = "output", aggregate = FALSE)[, , "pecoal.seel"] + coalgen_c <- dimSums(coalgen_c, dim = 3) + map <- toolGetMapping(getConfig("regionmapping"), type = "regional", where = "mappingfolder") + coalgen_R <- toolAggregate(coalgen_c, map, weight = NULL) getNames(coalgen_c) <- "pc" getNames(coalgen_R) <- "pc" - #Read coal capacity data from GCPT - hist_cap_coal_c <- readSource("GCPT",subtype="historical",convert=F) - hist_cap_coal_R <- toolAggregate(hist_cap_coal_c,rel=map,weight=NULL) - - #Calculate historical 5-year average capacity factors by country - coal_factor_c <- new.magpie(getRegions(hist_cap_coal_c),years = seq(2005, round_any(max(getYears(coalgen_c, as.integer = TRUE)), 5, f = floor)),names="pc",fill=0) - coal_factor_R <- new.magpie(getRegions(hist_cap_coal_R),years = getYears(coal_factor_c),names="pc",fill=0) - for (i in getYears(coal_factor_c,as.integer=TRUE)) { - if ((i+2) %in% getYears(coalgen_c,as.integer=TRUE)) { - coal_factor_c[,i,] <- dimSums(coalgen_c[,(i-2):(i+2),],dim=2)/(dimSums(hist_cap_coal_c[,(i-2):(i+2),],dim=2)*365*24 * GWh_2_EJ) - coal_factor_R[,i,] <- dimSums(coalgen_R[,(i-2):(i+2),],dim=2)/(dimSums(hist_cap_coal_R[,(i-2):(i+2),],dim=2)*365*24 * GWh_2_EJ) - #coal_factor_c[,i,][which(dimSums(hist_cap_coal_c[,(i-2):(i+2),],dim=2)==0)] <- 0 - # If latest available data falls in year 4 of a 5-year timestep - }else if ((i+1) %in% getYears(coalgen_c,as.integer=TRUE)) { + # Read coal capacity data from GCPT + hist_cap_coal_c <- readSource("GCPT", subtype = "historical", convert = FALSE) + hist_cap_coal_R <- toolAggregate(hist_cap_coal_c, rel = map, weight = NULL) + + # Calculate historical 5-year average capacity factors by country + coal_factor_c <- new.magpie(getRegions(hist_cap_coal_c), years = seq(2005, round_any(max(getYears(coalgen_c, as.integer = TRUE)), 5, f = floor)), names = "pc", fill = 0) + coal_factor_R <- new.magpie(getRegions(hist_cap_coal_R), years = getYears(coal_factor_c), names = "pc", fill = 0) + for (i in getYears(coal_factor_c, as.integer = TRUE)) { + if ((i + 2) %in% getYears(coalgen_c, as.integer = TRUE)) { + coal_factor_c[, i, ] <- dimSums(coalgen_c[, (i - 2):(i + 2), ], dim = 2) / (dimSums(hist_cap_coal_c[, (i - 2):(i + 2), ], dim = 2) * 365 * 24 * GWh_2_EJ) + coal_factor_R[, i, ] <- dimSums(coalgen_R[, (i - 2):(i + 2), ], dim = 2) / (dimSums(hist_cap_coal_R[, (i - 2):(i + 2), ], dim = 2) * 365 * 24 * GWh_2_EJ) + # If latest available data falls in year 4 of a 5-year timestep + } else if ((i + 1) %in% getYears(coalgen_c, as.integer = TRUE)) { # Special treatment of 2020 due to COVID-19: half-weight 2020 - if (i==2020) { - coal_factor_c[,i,] <- (dimSums(coalgen_c[,(i-2):(i+1),],dim=2) - 0.5 * dimSums(coalgen_c[,(i),],dim=2)) / - ((dimSums(hist_cap_coal_c[,(i-2):(i+1),],dim=2) + dimSums(hist_cap_coal_c[,(i+1),],dim=2))*365*24 * GWh_2_EJ) - coal_factor_R[,i,] <- (dimSums(coalgen_R[,(i-2):(i+1),],dim=2) + dimSums(coalgen_R[,(i+1),],dim=2)) / - ((dimSums(hist_cap_coal_R[,(i-2):(i+1),],dim=2) - 0.5 * dimSums(hist_cap_coal_R[,(i),],dim=2))*365*24 * GWh_2_EJ) - # For other timesteps, just use a 4-year average - }else { - coal_factor_c[,i,] <- dimSums(coalgen_c[,(i-2):(i+1),],dim=2) / (dimSums(hist_cap_coal_c[,(i-2):(i+1),],dim=2)*365*24 * GWh_2_EJ) - coal_factor_R[,i,] <- dimSums(coalgen_R[,(i-2):(i+1),],dim=2) / (dimSums(hist_cap_coal_R[,(i-2):(i+1),],dim=2)*365*24 * GWh_2_EJ) + if (i == 2020) { + coal_factor_c[, i, ] <- (dimSums(coalgen_c[, (i - 2):(i + 1), ], dim = 2) - 0.5 * dimSums(coalgen_c[, (i), ], dim = 2)) / + ((dimSums(hist_cap_coal_c[, (i - 2):(i + 1), ], dim = 2) + dimSums(hist_cap_coal_c[, (i + 1), ], dim = 2)) * 365 * 24 * GWh_2_EJ) + coal_factor_R[, i, ] <- (dimSums(coalgen_R[, (i - 2):(i + 1), ], dim = 2) + dimSums(coalgen_R[, (i + 1), ], dim = 2)) / + ((dimSums(hist_cap_coal_R[, (i - 2):(i + 1), ], dim = 2) - 0.5 * dimSums(hist_cap_coal_R[, (i), ], dim = 2)) * 365 * 24 * GWh_2_EJ) + # For other timesteps, just use a 4-year average + } else { + coal_factor_c[, i, ] <- dimSums(coalgen_c[, (i - 2):(i + 1), ], dim = 2) / (dimSums(hist_cap_coal_c[, (i - 2):(i + 1), ], dim = 2) * 365 * 24 * GWh_2_EJ) + coal_factor_R[, i, ] <- dimSums(coalgen_R[, (i - 2):(i + 1), ], dim = 2) / (dimSums(hist_cap_coal_R[, (i - 2):(i + 1), ], dim = 2) * 365 * 24 * GWh_2_EJ) } - # If latest available data falls in the middle of a timestep - }else { + # If latest available data falls in the middle of a timestep + } else { # if only data until 2020 is available, assign a double-weight to 2018 and 2019 - if (i==2020) { - coal_factor_c[,i,] <- (dimSums(coalgen_c[,(i-2):i,],dim=2) + dimSums(coalgen_c[,(i-2):(i-1),],dim=2)) / - ((dimSums(hist_cap_coal_c[,(i-2):i,],dim=2) + dimSums(hist_cap_coal_c[,(i-2):(i-1),],dim=2))*365*24 * GWh_2_EJ) - coal_factor_R[,i,] <- (dimSums(coalgen_R[,(i-2):i,],dim=2) + dimSums(coalgen_R[,(i-2):(i-1),],dim=2)) / - ((dimSums(hist_cap_coal_R[,(i-2):i,],dim=2) + dimSums(hist_cap_coal_R[,(i-2):(i-1),],dim=2))*365*24 * GWh_2_EJ) - # For other timesteps, assign triple-weight to final year - # Valid assumption for 2015 capacity factors - }else { - coal_factor_c[,i,] <- (dimSums(coalgen_c[,(i-2):i,],dim=2) + 2*coalgen_c[,i,]) / - ((dimSums(hist_cap_coal_c[,(i-2):i,],dim=2) + 2*hist_cap_coal_c[,i,])*365*24 * GWh_2_EJ) - coal_factor_R[,i,] <- (dimSums(coalgen_R[,(i-2):i,],dim=2) + 2*coalgen_R[,i,]) / - ((dimSums(hist_cap_coal_R[,(i-2):i,],dim=2) + 2*hist_cap_coal_R[,i,])*365*24 * GWh_2_EJ) + if (i == 2020) { + coal_factor_c[, i, ] <- (dimSums(coalgen_c[, (i - 2):i, ], dim = 2) + dimSums(coalgen_c[, (i - 2):(i - 1), ], dim = 2)) / + ((dimSums(hist_cap_coal_c[, (i - 2):i, ], dim = 2) + dimSums(hist_cap_coal_c[, (i - 2):(i - 1), ], dim = 2)) * 365 * 24 * GWh_2_EJ) + coal_factor_R[, i, ] <- (dimSums(coalgen_R[, (i - 2):i, ], dim = 2) + dimSums(coalgen_R[, (i - 2):(i - 1), ], dim = 2)) / + ((dimSums(hist_cap_coal_R[, (i - 2):i, ], dim = 2) + dimSums(hist_cap_coal_R[, (i - 2):(i - 1), ], dim = 2)) * 365 * 24 * GWh_2_EJ) + # For other timesteps, assign triple-weight to final year + # Valid assumption for 2015 capacity factors + } else { + coal_factor_c[, i, ] <- (dimSums(coalgen_c[, (i - 2):i, ], dim = 2) + 2 * coalgen_c[, i, ]) / + ((dimSums(hist_cap_coal_c[, (i - 2):i, ], dim = 2) + 2 * hist_cap_coal_c[, i, ]) * 365 * 24 * GWh_2_EJ) + coal_factor_R[, i, ] <- (dimSums(coalgen_R[, (i - 2):i, ], dim = 2) + 2 * coalgen_R[, i, ]) / + ((dimSums(hist_cap_coal_R[, (i - 2):i, ], dim = 2) + 2 * hist_cap_coal_R[, i, ]) * 365 * 24 * GWh_2_EJ) } - #coal_factor_c[,i,][which(hist_cap_coal_c[,i,]==0)] <- 0 } - #Replace countries without coal power with regional capacity factor. - coal_factor_c[,i,][which(!is.finite(coal_factor_c[,i,]))] <- - coal_factor_R[map$RegionCode[which(map$CountryCode %in% getRegions(coal_factor_c)[which(!is.finite(coal_factor_c[,i,]))])],i,] + # Replace countries without coal power with regional capacity factor. + coal_factor_c[, i, ][which(!is.finite(coal_factor_c[, i, ]))] <- + coal_factor_R[map$RegionCode[which(map$CountryCode %in% getRegions(coal_factor_c)[which(!is.finite(coal_factor_c[, i, ]))])], i, ] # The derived coal capacity factors for Bosnia, Ireland and Myanmar are > 1 in some years for as yet unclear reasons. - coal_factor_c[,i,][which(coal_factor_c[,i,]>1)] <- max(coal_factor_c[,i,][which(coal_factor_c[,i,]<1)]) + coal_factor_c[, i, ][which(coal_factor_c[, i, ] > 1)] <- max(coal_factor_c[, i, ][which(coal_factor_c[, i, ] < 1)]) } - #Derive coal capacity factor rule assumptions for 2020 - 2035 (linear convergence of historical trends to global default) + # Derive coal capacity factor rule assumptions for 2020 - 2035 (linear convergence of historical trends to global default) hist_yr <- "y2015" start_yr <- "y2020" end_yr <- "y2030" @@ -102,37 +97,29 @@ calcCapacityFactor <- function(){ coal_factor_c_years <- intersect(getYears(coal_factor_c), getYears(output)) coal_factor_c_years <- coal_factor_c_years[coal_factor_c_years < start_yr] - output[,getYears(output)[getYears(output) < start_yr],"pc"] <- - coal_factor_c[,coal_factor_c_years,] + output[, getYears(output)[getYears(output) < start_yr], "pc"] <- + coal_factor_c[, coal_factor_c_years, ] - output[,getYears(output)[which(getYears(output)>=conv_yr)],"pc"] <- global[,,"pc"] - slope <- (output[,conv_yr,'pc'] - output[,hist_yr,'pc']) / (as.numeric(gsub("y","",conv_yr)) - as.numeric(gsub("y","",hist_yr))) - for (t in getYears(output)[which(getYears(output)>=start_yr & getYears(output)<=end_yr)]) { - output[,t,"pc"] <- output[,hist_yr,"pc"] + slope * (as.numeric(gsub("y","",t)) - as.numeric(gsub("y","",hist_yr))) + output[, getYears(output)[which(getYears(output) >= conv_yr)], "pc"] <- global[, , "pc"] + slope <- (output[, conv_yr, "pc"] - output[, hist_yr, "pc"]) / (as.numeric(gsub("y", "", conv_yr)) - as.numeric(gsub("y", "", hist_yr))) + for (t in getYears(output)[which(getYears(output) >= start_yr & getYears(output) <= end_yr)]) { + output[, t, "pc"] <- output[, hist_yr, "pc"] + slope * (as.numeric(gsub("y", "", t)) - as.numeric(gsub("y", "", hist_yr))) } # Overwriting MAgPie object with rules values - output[getRegions(rules),getYears(rules),getNames(rules)] <- ifelse(rules[getRegions(rules),getYears(rules),getNames(rules)]!=0, rules[getRegions(rules),getYears(rules),getNames(rules)], output[getRegions(rules),getYears(rules),getNames(rules)]) - - # Convergence and lin.convergence functions are not working... - # output[,getYears(output)[which(getYears(output)>=hist_yr & getYears(output)<=conv_yr)],"pc"] <- - # convergence(origin=output[,getYears(output)[which(getYears(output)>=hist_yr & getYears(output)<=conv_yr)],"pc"], - # aim=as.numeric(global[,,"pc"]),start_year=start_yr,end_year=conv_yr) - # Define weight aggregation for capacity factors - # using final energy as a proxy for the existent capacity factor to weight the capacity factor aggregation (it should be changed if the information about the existent capacity factor become available in the future) - + output[getRegions(rules), getYears(rules), getNames(rules)] <- ifelse(rules[getRegions(rules), getYears(rules), getNames(rules)] != 0, rules[getRegions(rules), getYears(rules), getNames(rules)], output[getRegions(rules), getYears(rules), getNames(rules)]) # change coal capacity factor in Germany to reflect observed decrease in coal electricity in recent years, note: to be checked whether necessary for other regions as well # https://static.agora-energiewende.de/fileadmin/Projekte/2021/2020_01_Jahresauswertung_2020/200_A-EW_Jahresauswertung_2020_WEB.pdf - output["DEU",c("y2020","y2025"),"pc"] = 0.43 - output["DEU",c("y2030"),"pc"] = 0.4 + output["DEU", c("y2020", "y2025"), "pc"] <- 0.43 + output["DEU", c("y2030"), "pc"] <- 0.4 - weight <- calcOutput("FE",source="IEA",aggregate=FALSE)[,2015,"FE (EJ/yr)"] + weight <- calcOutput("FE", source = "IEA", aggregate = FALSE)[, 2015, "FE (EJ/yr)"] # Return regions aggregation weighted by final energy - return(list(x=output, weight=weight, - unit="% of capacity", - description="Installed capacity availability - capacity factor (fraction of the year that a plant is running)" + return(list( + x = output, weight = weight, + unit = "% of capacity", + description = "Installed capacity availability - capacity factor (fraction of the year that a plant is running)" )) - } diff --git a/R/readREMIND_11Regi.R b/R/readREMIND_11Regi.R index 81734d16..465e89ab 100644 --- a/R/readREMIND_11Regi.R +++ b/R/readREMIND_11Regi.R @@ -3,107 +3,111 @@ #' #' Read-in an csv files that contains regional data #' -#' @param subtype Name of the regional data, e.g. "p4", "biomass", "ch4waste", "tradecost", "pe2se", "xpres_tax", "deltacapoffset", "capacityFactorGlobal", "capacityFactorRules", "residuesShare", "taxConvergence", "maxFeSubsidy", "maxPeSubsidy", "propFeSubsidy", "fossilExtractionCoeff", "uraniumExtractionCoeff", "RLDCCoefficientsLoB", "RLDCCoefficientsPeak", "earlyRetirementAdjFactor" +#' @param subtype Name of the regional data, e.g. "p4", "biomass", "ch4waste", +#' "tradecost", "pe2se", "xpres_tax", "deltacapoffset", "capacityFactorGlobal", +#' "capacityFactorRules", "residuesShare", "taxConvergence", "maxFeSubsidy", +#' "maxPeSubsidy", "propFeSubsidy", "fossilExtractionCoeff", "uraniumExtractionCoeff", +#' "RLDCCoefficientsLoB", "RLDCCoefficientsPeak", "earlyRetirementAdjFactor" #' @return magpie object of region dependent data #' @author original: not defined, capacity factor, tax, fossil and RLDC changes: Renato Rodrigues #' @seealso \code{\link{readSource}} #' @examples -#' -#' \dontrun{ a <- readSource(type="REMIND_11Regi",subtype="capacityFactorGlobal") +#' \dontrun{ +#' a <- readSource(type = "REMIND_11Regi", subtype = "capacityFactorGlobal") #' } - -readREMIND_11Regi<- function(subtype) { +readREMIND_11Regi <- function(subtype) { if (subtype == "p4") { - x <- read.csv("EconometricEmissionParameter_p4.csv",sep=";",row.names=1) + x <- read.csv("EconometricEmissionParameter_p4.csv", sep = ";", row.names = 1) x <- as.magpie(x) } else if (subtype == "biomass") { x <- read_excel("biomass.xlsx") - x <- as.magpie(x,datacol=4) + x <- as.magpie(x, datacol = 4) } else if (subtype == "ch4waste") { - x <- read.csv("emimac0_ch4waste.csv",sep=";",row.names=1) + x <- read.csv("emimac0_ch4waste.csv", sep = ";", row.names = 1) x <- as.magpie(x) - } else if (subtype== "tradecost") { - x <- read.csv("LueckenDiss_TradeCost.csv", sep=";",row.names=1) + } else if (subtype == "tradecost") { + x <- read.csv("LueckenDiss_TradeCost.csv", sep = ";", row.names = 1) x <- as.magpie(x) - } else if (subtype=="pe2se") { - x <- read.csv("tax_pe2se_sub.csv",sep=";") - x <- as.magpie(x,datacol=2) - } else if (subtype=="xpres_tax") { - x <- read.csv("p21_tau_xpres_tax.csv",sep=";") - x <- as.magpie(x,datacol=2) + } else if (subtype == "pe2se") { + x <- read.csv("tax_pe2se_sub.csv", sep = ";") + x <- as.magpie(x, datacol = 2) + } else if (subtype == "xpres_tax") { + x <- read.csv("p21_tau_xpres_tax.csv", sep = ";") + x <- as.magpie(x, datacol = 2) getYears(x) <- "y2005" getNames(x) <- "peoil" - } else if (subtype=="deltacapoffset") { - x <- read.csv("p_adj_deltacapoffset.csv",sep=";") - x <- as.magpie(x,datacol=2) - } else if (subtype=="capacityFactorGlobal") { - x <- read.csv("f_cf-global.csv",sep=";") + } else if (subtype == "deltacapoffset") { + x <- read.csv("p_adj_deltacapoffset.csv", sep = ";") + x <- as.magpie(x, datacol = 2) + } else if (subtype == "capacityFactorGlobal") { + x <- read.csv("f_cf-global.csv", sep = ";") x[x$Tech == "rockgrind", "Tech"] <- "weathering" - x <- as.magpie(x,datacol=2) - } else if (subtype=="capacityFactorRules") { - x <- read.csv("f_cf-rules.csv",sep=";") - x <- as.magpie(x,datacol=4) - } else if (subtype=="storageFactor") { - x <- read.csv("storageFactor.csv",sep=";") - x <- as.magpie(x,datacol=2) - } else if (subtype=="residuesShare") { + x <- as.magpie(x, datacol = 2) + } else if (subtype == "capacityFactorRules") { + x <- read.csv("f_cf-rules.csv", sep = ";") + x <- as.magpie(x, datacol = 4) + } else if (subtype == "storageFactor") { + x <- read.csv("storageFactor.csv", sep = ";") + x <- as.magpie(x, datacol = 2) + } else if (subtype == "residuesShare") { x <- read.csv("residuesShare.csv", row.names = 1) - x <- as.magpie(x,datacol=4) - } else if (subtype=="shareIndFE") { - x <- read.csv("shareIndustyFE.csv", sep=";",skip=3) - x <- as.magpie(x,datacol=3) - } else if (subtype=="taxConvergence") { - x <- read.csv("tax_convergence.csv",sep=";") - x <- as.magpie(x,datacol=4) - } else if (subtype=="maxFeSubsidy") { - x <- read.csv("max_FE_subsidy.csv",sep=";") - x <- as.magpie(x,datacol=4) - } else if (subtype=="maxPeSubsidy") { - x <- read.csv("max_PE_subsidy.csv",sep=";") - x <- as.magpie(x,datacol=4) - } else if (subtype=="propFeSubsidy") { - x <- read.csv("prop_FE_subsidy.csv",sep=";") - x <- as.magpie(x,datacol=4) - } else if (subtype=="gridFactor") { - x <- read.csv("homogenous_regions_for grids.csv", sep=";") + x <- as.magpie(x, datacol = 4) + } else if (subtype == "shareIndFE") { + x <- read.csv("shareIndustyFE.csv", sep = ";", skip = 3) + x <- as.magpie(x, datacol = 3) + } else if (subtype == "taxConvergence") { + x <- read.csv("tax_convergence.csv", sep = ";") + x <- as.magpie(x, datacol = 4) + } else if (subtype == "maxFeSubsidy") { + x <- read.csv("max_FE_subsidy.csv", sep = ";") + x <- as.magpie(x, datacol = 4) + } else if (subtype == "maxPeSubsidy") { + x <- read.csv("max_PE_subsidy.csv", sep = ";") + x <- as.magpie(x, datacol = 4) + } else if (subtype == "propFeSubsidy") { + x <- read.csv("prop_FE_subsidy.csv", sep = ";") + x <- as.magpie(x, datacol = 4) + } else if (subtype == "gridFactor") { + x <- read.csv("homogenous_regions_for grids.csv", sep = ";") x$X <- NULL - x <- as.magpie(x,datacol=2) - } else if (subtype=="AP_starting_values") { - x <- read.csv("f11_emiAPexsolve.cs4r", sep=",", skip = 1, header = F) - x <- as.magpie(x,datacol=6) - } else if (subtype=="ccs") { - x <- read.csv("p_dataccs.csv",sep=";") - x <- as.magpie(x,spatial=1,datacol=2) - } else if (subtype=="ffPolyRent") { - x <- read.csv("ffPolyRent.csv",sep=";") - x <- as.magpie(x,spatial=1,datacol=5) - } else if (subtype=="ffPolyCumEx") { - x <- read.csv("ffPolyCumEx.csv",sep=";") - x <- as.magpie(x,spatial=1,datacol=5) - } else if (subtype=="fossilExtractionCoeff") { - x <- read.csv("fossil_extraction_cost_eq_coefficients.csv",sep=";") - #removing the X string added to the column names because how the read.table call inside the read.csv function converts column name numbers to valid variable strings (by using check.names) + x <- as.magpie(x, datacol = 2) + } else if (subtype == "AP_starting_values") { + x <- read.csv("f11_emiAPexsolve.cs4r", sep = ",", skip = 1, header = FALSE) + x <- as.magpie(x, datacol = 6) + } else if (subtype == "ccs") { + x <- read.csv("p_dataccs.csv", sep = ";") + x <- as.magpie(x, spatial = 1, datacol = 2) + } else if (subtype == "ffPolyRent") { + x <- read.csv("ffPolyRent.csv", sep = ";") + x <- as.magpie(x, spatial = 1, datacol = 5) + } else if (subtype == "ffPolyCumEx") { + x <- read.csv("ffPolyCumEx.csv", sep = ";") + x <- as.magpie(x, spatial = 1, datacol = 5) + } else if (subtype == "fossilExtractionCoeff") { + x <- read.csv("fossil_extraction_cost_eq_coefficients.csv", sep = ";") + # removing the X string added to the column names because how the read.table call inside + # the read.csv function converts column name numbers to valid variable strings (by using check.names) colnames(x) <- gsub("^X", "", colnames(x)) - x <- as.magpie(x,spatial=1,temporal=0,datacol=3) - #JPN SSP5 gas extraction zero-order coeff was originally negative. - x["JPN",,"highGas.0"] <- 0 - } else if (subtype=="uraniumExtractionCoeff") { - x <- read.csv("uranium_extraction_cost_eq_coefficients.csv",sep=";") - x <- as.magpie(x,spatial=1,temporal=0,datacol=3) - } else if (subtype=="RLDCCoefficientsLoB") { - x <- read.csv("RLDC_Coefficients_LoB.csv",sep=";") - x <- as.magpie(x,spatial=1,temporal=0,datacol=3) - } else if (subtype=="RLDCCoefficientsPeak") { - x <- read.csv("RLDC_Coefficients_Peak.csv",sep=";") - x <- as.magpie(x,spatial=1,temporal=0,datacol=3) - } else if (subtype=="earlyRetirementAdjFactor") { - y <- read.csv("earlyRetirementAdjFactor.csv",sep=";",skip=5) - x <- as.magpie(y,spatial=1,temporal=0,datacol=2) - x <- setNames(x,colnames(y)[-1]) - } else if (subtype=="nashWeight") { - x <- read.csv("nash_weights.csv",sep=";") - x <- as.magpie(x,spatial=1,datacol=2) + x <- as.magpie(x, spatial = 1, temporal = 0, datacol = 3) + # JPN SSP5 gas extraction zero-order coeff was originally negative. + x["JPN", , "highGas.0"] <- 0 + } else if (subtype == "uraniumExtractionCoeff") { + x <- read.csv("uranium_extraction_cost_eq_coefficients.csv", sep = ";") + x <- as.magpie(x, spatial = 1, temporal = 0, datacol = 3) + } else if (subtype == "RLDCCoefficientsLoB") { + x <- read.csv("RLDC_Coefficients_LoB.csv", sep = ";") + x <- as.magpie(x, spatial = 1, temporal = 0, datacol = 3) + } else if (subtype == "RLDCCoefficientsPeak") { + x <- read.csv("RLDC_Coefficients_Peak.csv", sep = ";") + x <- as.magpie(x, spatial = 1, temporal = 0, datacol = 3) + } else if (subtype == "earlyRetirementAdjFactor") { + y <- read.csv("earlyRetirementAdjFactor.csv", sep = ";", skip = 5) + x <- as.magpie(y, spatial = 1, temporal = 0, datacol = 2) + x <- setNames(x, colnames(y)[-1]) + } else if (subtype == "nashWeight") { + x <- read.csv("nash_weights.csv", sep = ";") + x <- as.magpie(x, spatial = 1, datacol = 2) } else { stop("Not a valid subtype!") }