diff --git a/.buildlibrary b/.buildlibrary index fe07bac2..57dbc864 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '34720077' +ValidationKey: '34746870' AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' - 'Warning: namespace ''.*'' is not available and has been replaced' diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2f134668..243f46a1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,7 +15,7 @@ repos: - id: mixed-line-ending - repo: https://github.com/lorenzwalthert/precommit - rev: v0.3.2.9025 + rev: v0.4.0 hooks: - id: parsable-R - id: deps-in-desc diff --git a/CITATION.cff b/CITATION.cff index bd2ee3fa..53a0818a 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.7 -date-released: '2024-02-08' +version: 0.175.8 +date-released: '2024-02-12' abstract: The mrremind packages contains data preprocessing for the REMIND model. authors: - family-names: Baumstark diff --git a/DESCRIPTION b/DESCRIPTION index 4f6f1d16..05fbedda 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: mrremind Title: MadRat REMIND Input Data Package -Version: 0.175.7 -Date: 2024-02-08 +Version: 0.175.8 +Date: 2024-02-12 Authors@R: c( person("Lavinia", "Baumstark", , "lavinia@pik-potsdam.de", role = c("aut", "cre")), person("Renato", "Rodrigues", role = "aut"), diff --git a/R/calcFE.R b/R/calcFE.R index 9bfd45cc..1415f137 100644 --- a/R/calcFE.R +++ b/R/calcFE.R @@ -6,15 +6,14 @@ #' @importFrom stats na.omit #' @param source "IEA" or "IEA_WEO" #' @param scenario_proj "SSP2" by default unless overwritten +#' @param ieaVersion Release version of IEA data, either 'default' (vetted and used in REMIND) +#' or 'latest'. - -calcFE <- function(source = "IEA", scenario_proj = "SSP2") { +calcFE <- function(source = "IEA", scenario_proj = "SSP2", ieaVersion = "default") { #------ READ-IN DATA---------------------------------------- if (source == "IEA") { - data <- calcOutput("IO", subtype = "output", aggregate = FALSE) - - # remove period where only 0s appear - data <- data[, 2021, , invert = T] + data <- calcOutput("IO", subtype = "output", ieaVersion = ieaVersion, + aggregate = FALSE) mapping <- toolGetMapping(type = "sectoral", name = "structuremappingIO_reporting.csv", @@ -28,7 +27,7 @@ calcFE <- function(source = "IEA", scenario_proj = "SSP2") { colnames(map) <- gsub("io", "names_in", colnames(map)) # Give description - descript <- "IEA Final Energy Data based on 2017 version of IEA Energy Balances" + descript <- "IEA Final Energy Data based on 2022 version of IEA Energy Balances" #------ PROCESS DATA ------------------------------------------ # select data that have names @@ -129,7 +128,6 @@ calcFE <- function(source = "IEA", scenario_proj = "SSP2") { } else if (source == "IEA_WEO") { data <- readSource(type = "IEA_WEO", subtype = "FE") regions <- toolGetMapping(getConfig()[1], where = "mappingfolder", type = "regional") - # regions <- unique(regions$RegionCode) # gdp of all countries in 2015 gdp <- calcOutput("GDPPast", years = 2015, aggregate = FALSE) @@ -140,7 +138,7 @@ calcFE <- function(source = "IEA", scenario_proj = "SSP2") { var <- getNames(data)[1] data_new <- new.magpie(getRegions(data), years = getYears(data), names = getNames(data), fill = NA) for (i in regions$CountryCode) { - if (!is.na(data[i, "y2010", var]) & gdp[i, , ] > 0.9 * dimSums(gdp[regions[regions$RegionCode == regions[regions$CountryCode == i, ]$RegionCode, ]$CountryCode, , ], dim = 1)) { + if (!is.na(data[i, "y2010", var]) && gdp[i, , ] > 0.9 * dimSums(gdp[regions[regions$RegionCode == regions[regions$CountryCode == i, ]$RegionCode, ]$CountryCode, , ], dim = 1)) { data_new[i, , ] <- data[i, , ] countries <- regions[regions$RegionCode == regions[regions$CountryCode == i, ]$RegionCode, ]$CountryCode data_new[setdiff(countries, i), , ] <- 0 # countries other than the "main" country @@ -151,9 +149,7 @@ calcFE <- function(source = "IEA", scenario_proj = "SSP2") { data <- data_new data <- data[, , ] * 4.1868e-2 # Mtoe to EJ - # data <- collapseNames(data) - # vars <- c("Coal","Oil","Gas") - # data <- data[,,vars,pmatch=T] + # converting to remind convention getNames(data) <- gsub(pattern = "Final Energy", replacement = "FE", x = getNames(data)) getNames(data) <- paste0(getNames(data), " (EJ/yr)") diff --git a/R/calcHistorical.R b/R/calcHistorical.R index 747630ea..ffa6611d 100644 --- a/R/calcHistorical.R +++ b/R/calcHistorical.R @@ -6,7 +6,7 @@ calcHistorical <- function() { # Final Energy - fe_iea <- calcOutput("FE", source = "IEA", aggregate = FALSE) + fe_iea <- calcOutput("FE", source = "IEA", ieaVersion = "latest", aggregate = FALSE) fe_iea <- add_dimension(fe_iea, dim = 3.1, add = "model", nm = "IEA") fe_weo <- calcOutput("FE", source = "IEA_WEO", aggregate = FALSE) @@ -15,7 +15,7 @@ calcHistorical <- function() { fe_weo <- add_dimension(fe_weo, dim = 3.1, add = "model", nm = "IEA_WEO") # Primary Energy - pe_iea <- calcOutput("PE", subtype = "IEA", aggregate = FALSE) + pe_iea <- calcOutput("PE", subtype = "IEA", ieaVersion = "latest", aggregate = FALSE) pe_iea <- add_dimension(pe_iea, dim = 3.1, add = "model", nm = "IEA") pe_weo <- calcOutput("PE", subtype = "IEA_WEO", aggregate = FALSE) diff --git a/R/calcIO.R b/R/calcIO.R index 99e9a5d6..07626369 100644 --- a/R/calcIO.R +++ b/R/calcIO.R @@ -11,6 +11,8 @@ #' #' @md #' @param subtype Data subtype. See default argument for possible values. +#' @param ieaVersion Release version of IEA data, either 'default' +#' (vetted and used in REMIND) or 'latest'. #' @return IEA data as MAgPIE object aggregated to country level #' @author Anastasis Giannousakis #' @seealso \code{\link{calcOutput}} @@ -24,7 +26,9 @@ #' @importFrom tidyr unite #' @importFrom tidyselect all_of calcIO <- function(subtype = c("input", "output", "output_biomass", "trade", - "input_Industry_subsectors", "output_Industry_subsectors", "IEA_output", "IEA_input")) { + "input_Industry_subsectors", "output_Industry_subsectors", + "IEA_output", "IEA_input"), + ieaVersion = "default") { subtype <- match.arg(subtype) switch( subtype, @@ -74,8 +78,14 @@ calcIO <- function(subtype = c("input", "output", "output_biomass", "trade", mapping <- toolGetMapping(type = "sectoral", name = mapping, where = where, returnPathOnly = TRUE) + if (!(ieaVersion %in% c("default", "latest"))) { + stop("Invalid parameter `ieaVersion`. Must be either 'default' or 'latest'") + } + + ieaSubtype <- if (ieaVersion == "default") "EnergyBalances" else "EnergyBalances-latest" + # read in data and convert from ktoe to EJ - data <- readSource("IEA", subtype = "EnergyBalances") * 4.1868e-5 + data <- readSource("IEA", subtype = ieaSubtype) * 4.1868e-5 ieamatch <- read.csv2(mapping, stringsAsFactors = FALSE, na.strings = "") @@ -94,29 +104,31 @@ calcIO <- function(subtype = c("input", "output", "output_biomass", "trade", threshold = 1e-2) # warn if dimensions not present in the mapping have been added to the data new_product_flows <- tibble( - text = setdiff(getNames(data), names_data_before)) %>% - separate('text', c('product', 'flow'), sep = '\\.') %>% + text = setdiff(getNames(data), names_data_before) + ) %>% + separate("text", c("product", "flow"), sep = "\\.") %>% anti_join( ieamatch %>% as_tibble() %>% - select(product = 'iea_product', flow = 'iea_flows'), + select(product = "iea_product", flow = "iea_flows"), - c('product', 'flow') + c("product", "flow") ) %>% - unite('text', c('product', 'flow'), sep = '.') %>% - pull('text') + unite("text", c("product", "flow"), sep = ".") %>% + pull("text") if (!is_empty(new_product_flows)) { - warning('Product/flow combinations not present in mapping added by ', - 'fix_IEA_data_for_Industry_subsectors():\n', - paste(new_product_flows, collapse = '\n')) + warning("Product/flow combinations not present in mapping added by ", + "fix_IEA_data_for_Industry_subsectors():\n", + paste(new_product_flows, collapse = "\n") + ) } # FIXME remove product/flow combinations from the mapping that have been # removed from the data while replacing coke oven and blast furnace outputs ieamatch <- ieamatch %>% as_tibble() %>% - filter(paste(.data$iea_product, .data$iea_flows, sep = '.') + filter(paste(.data$iea_product, .data$iea_flows, sep = ".") %in% getNames(data)) } @@ -126,7 +138,7 @@ calcIO <- function(subtype = c("input", "output", "output_biomass", "trade", select(all_of(c("iea_product", "iea_flows", "Weight", target))) %>% na.omit() %>% unite("target", all_of(target), sep = ".", remove = FALSE) %>% - unite('product.flow', c('iea_product', 'iea_flows'),sep = '.') %>% + unite("product.flow", c("iea_product", "iea_flows"), sep = ".") %>% filter(!!sym("product.flow") %in% getNames(data)) magpieNames <- ieamatch[["target"]] %>% unique() @@ -144,20 +156,20 @@ calcIO <- function(subtype = c("input", "output", "output_biomass", "trade", function(item) { product_flow <- ieamatch %>% filter(item == .data$target) %>% - pull('product.flow') + pull("product.flow") weights <- ieamatch %>% filter(item == .data$target) %>% - pull('Weight') %>% + pull("Weight") %>% as.numeric() - tmp <- dimSums( data[,,product_flow] + tmp <- dimSums(data[, , product_flow] * setNames(as.magpie(weights), product_flow), dim = 3, na.rm = TRUE) getNames(tmp) <- item return(tmp) - }) + }) ) # Split residential Biomass into traditional and modern biomass depending upon the income per capita @@ -165,8 +177,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", aggregate = FALSE) - feBio <- calcOutput("IO", subtype = "output_biomass", 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 reminditems <- mbind(reminditems, @@ -225,5 +237,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 2017 edition of IEA World Energy Balances")) + description = "IEA SE Output Data based on 2022 edition of IEA World Energy Balances")) } diff --git a/R/calcPE.R b/R/calcPE.R index 8ec80eab..ec8b18a2 100644 --- a/R/calcPE.R +++ b/R/calcPE.R @@ -1,84 +1,88 @@ -calcPE <- function(subtype = "IEA") { - - if (subtype == "IEA"){ - - data <- calcOutput("IO",subtype="input",aggregate=FALSE) - - mapping <- toolGetMapping(type = "sectoral", - name = "structuremappingIO_reporting.csv", - where = "mrremind", returnPathOnly = TRUE) - target = c("input") - - ### calculate data - map <- read.csv2(mapping, stringsAsFactors = FALSE, na.strings ="" ) - #delete NAs rows - map = map[c("io",target)] %>% na.omit() - - # select data that have names - map = map[map$io %in% getNames(data),] - x <- data[,,map$io] - #aggregate from the IO names to the reporting names. - x <- luscale::speed_aggregate(x, map, dim = 3, from = "io", to = "input") - # rename entries of data to match the rporting names - getNames(x) <- paste0(getNames(x)," (EJ/yr)") - - # add loss to eletricity - 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)")) - x <- mbind(x,setNames(dimSums(x[,,"PE|Coal",pmatch=TRUE],dim=3),"PE|Coal (EJ/yr)")) - x <- mbind(x,setNames(dimSums(x[,,"PE|Oil",pmatch=TRUE],dim=3),"PE|Oil (EJ/yr)")) - 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)")) - - - return(list(x=x,weight=NULL,unit="EJ", - description="IEA Primary Energy Data based on 2014 version of IEA Energy Balances")) - } - if (subtype=="IEA_WEO"){ - - data <- readSource(type = "IEA_WEO",subtype = "PE") - data <- collapseNames(data) - regions <- toolGetMapping(getConfig()[1], where = "mappingfolder",type = "regional") - #regions <- unique(regions$RegionCode) - - # gdp of all countries in 2015 - gdp <- calcOutput("GDPPast",aggregate = F) - gdp <- gdp[,"y2015",] - - # if 2015 gdp of a country is 90% of the GDP of the region to which it belongs - # include result. If not, display it as NA - - var <- getNames(data)[1] - data_new <- new.magpie(getRegions(data),years = getYears(data),names = getNames(data),fill=NA) - for (i in regions$CountryCode){ - if (!is.na(data[i,"y2010",var]) & gdp[i,,]> 0.9*dimSums(gdp[regions[regions$RegionCode==regions[regions$CountryCode==i,]$RegionCode,]$CountryCode,,],dim = 1)) - { data_new[i,,] <- data[i,,] - countries <- regions[regions$RegionCode==regions[regions$CountryCode==i,]$RegionCode,]$CountryCode - data_new[setdiff(countries,i),,] <- 0 # countries other than the "main" country +#' Computes Primary Energy variables +#' +#' @param subtype source for calculation, either "IEA" or "IEA_WEO" +#' @param ieaVersion Release version of IEA data, either 'default' (vetted and used in REMIND) +#' or 'latest'. +#' @return a magclass object +calcPE <- function(subtype = "IEA", ieaVersion = "default") { + + if (subtype == "IEA") { + + data <- calcOutput("IO", subtype = "input", ieaVersion = ieaVersion, aggregate = FALSE) + + mapping <- toolGetMapping(type = "sectoral", + name = "structuremappingIO_reporting.csv", + where = "mrremind", returnPathOnly = TRUE) + target <- c("input") + + ### calculate data + map <- read.csv2(mapping, stringsAsFactors = FALSE, na.strings = "") + # delete NAs rows + map <- map[c("io", target)] %>% na.omit() + + # select data that have names + map <- map[map$io %in% getNames(data), ] + x <- data[, , map$io] + # aggregate from the IO names to the reporting names. + x <- luscale::speed_aggregate(x, map, dim = 3, from = "io", to = "input") + # rename entries of data to match the reporting names + 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] + + # add more variables + x <- mbind(x, setNames(dimSums(x[, , "PE|", pmatch = TRUE], dim = 3), "PE (EJ/yr)")) + x <- mbind(x, setNames(dimSums(x[, , "PE|Coal", pmatch = TRUE], dim = 3), "PE|Coal (EJ/yr)")) + x <- mbind(x, setNames(dimSums(x[, , "PE|Oil", pmatch = TRUE], dim = 3), "PE|Oil (EJ/yr)")) + 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)")) + + + return(list(x = x, weight = NULL, unit = "EJ", + description = "IEA Primary Energy Data based on 2022 version of IEA Energy Balances")) + + } else if (subtype == "IEA_WEO") { + + data <- readSource(type = "IEA_WEO", subtype = "PE") + data <- collapseNames(data) + regions <- toolGetMapping(getConfig()[1], where = "mappingfolder", type = "regional") + + # gdp of all countries in 2015 + gdp <- calcOutput("GDPPast", aggregate = FALSE) + gdp <- gdp[, "y2015", ] + + # if 2015 gdp of a country is 90% of the GDP of the region to which it belongs + # include result. If not, display it as NA + + var <- getNames(data)[1] + data_new <- new.magpie(getRegions(data), years = getYears(data), names = getNames(data), fill = NA) + for (i in regions$CountryCode) { + if (!is.na(data[i, "y2010", var]) && gdp[i, , ] > 0.9 * + dimSums(gdp[regions[regions$RegionCode == regions[regions$CountryCode == i, ]$RegionCode, ]$CountryCode, , ], dim = 1)) { + data_new[i, , ] <- data[i, , ] + countries <- regions[regions$RegionCode == regions[regions$CountryCode == i, ]$RegionCode, ]$CountryCode + data_new[setdiff(countries, i), , ] <- 0 # countries other than the "main" country # get zero value so that aggregation can be done - } + } } - data <- data_new - data <- data[,,]*4.1868e-2 # Mtoe to EJ - #data <- collapseNames(data) - #vars <- c("Coal","Oil","Gas") - #data <- data[,,vars,pmatch=T] - # converting to remind convention - getNames(data) <- gsub(pattern = "Primary Energy",replacement = "PE",x = getNames(data)) - getNames(data) <- gsub(pattern = "PE\\|Electricity\\|Gas",replacement = "PE|Gas|Electricity",getNames(data)) - getNames(data) <- gsub(pattern = "PE\\|Electricity\\|Coal",replacement = "PE|Coal|Electricity",getNames(data)) - getNames(data) <- gsub(pattern = "PE\\|Electricity\\|Oil",replacement = "PE|Oil|Electricity",getNames(data)) - getNames(data) <- paste0(getNames(data)," (EJ/yr)") - # data <- collapseNames(data) - } + data <- data_new + data <- data[, , ] * 4.1868e-2 # Mtoe to EJ + # converting to remind convention + getNames(data) <- gsub(pattern = "Primary Energy", replacement = "PE", x = getNames(data)) + getNames(data) <- gsub(pattern = "PE\\|Electricity\\|Gas", replacement = "PE|Gas|Electricity", getNames(data)) + getNames(data) <- gsub(pattern = "PE\\|Electricity\\|Coal", replacement = "PE|Coal|Electricity", getNames(data)) + getNames(data) <- gsub(pattern = "PE\\|Electricity\\|Oil", replacement = "PE|Oil|Electricity", getNames(data)) + getNames(data) <- paste0(getNames(data), " (EJ/yr)") - return(list(x=data,weight=NULL,unit="EJ", - description="IEA Primary Energy Data based on IEA WEO 2019")) + return(list(x = data, weight = NULL, unit = "EJ", + description = "IEA Primary Energy Data based on IEA WEO 2019")) + } else { + stop("Not a valid subtype! Must be either 'IEA' or 'IEA_WEO'") } +} diff --git a/R/calcTaxLimits.R b/R/calcTaxLimits.R index fe0da39f..b1cc8808 100644 --- a/R/calcTaxLimits.R +++ b/R/calcTaxLimits.R @@ -1,45 +1,49 @@ #' @title calc Tax Limits -#' @description tax and subsidies maximum levels. The tax limits serve as a work around to avoid excess of subsidy levels that could cause problems on the REMIND model solution. These files should be removed or replaced once a better way to handle this issue is introduced to the REMIND model formulation or once better yearly and country subsidy level data is available for the primary and final energies. +#' @description tax and subsidies maximum levels. The tax limits serve as a work +#' around to avoid excess of subsidy levels that could cause problems on the REMIND +#' model solution. These files should be removed or replaced once a better way +#' to handle this issue is introduced to the REMIND model formulation or once +#' better yearly and country subsidy level data is available for the primary +#' and final energies. #' -#' @param subtype Name of the subsidy data type limit, e.g. "maxFeSubsidy" for maximum final energy subsidy,"maxPeSubsidy" for maximum primary energy subsidy or "propFeSubsidy" for proportional cap for final energy subsidy +#' @param subtype Name of the subsidy data type limit, e.g. "maxFeSubsidy" for +#' maximum final energy subsidy,"maxPeSubsidy" for maximum primary energy subsidy +#' or "propFeSubsidy" for proportional cap for final energy subsidy #' @return magpie object of the subtype tax limit #' @author Renato Rodrigues #' @examples -#' -#' \dontrun{ +#' \dontrun{ #' calcOutput("TaxLimits") #' } -#' +#' +calcTaxLimits <- function(subtype) { + + if (!(subtype %in% c("maxFeSubsidy", "maxPeSubsidy", "propFeSubsidy"))) { + stop("the argument subtype must be in c('maxFeSubsidy','maxPeSubsidy', 'propFeSubsidy')") + } -calcTaxLimits <- function(subtype){ - - if (!(subtype %in% c("maxFeSubsidy","maxPeSubsidy", "propFeSubsidy"))) stop("the argument subtype must be in c('maxFeSubsidy','maxPeSubsidy', 'propFeSubsidy')") - - if(subtype == "maxFeSubsidy") { + if (subtype == "maxFeSubsidy") { # Read max final energy subsidy levels - output <- readSource("REMIND_11Regi", subtype="maxFeSubsidy")[,,c("fegas","fehos","fesos")] - description <- "maximum final energy subsidy levels (in $/Gj) from REMIND version prior to rev. 5429" + output <- readSource("REMIND_11Regi", subtype = "maxFeSubsidy")[, , c("fegas", "fehos", "fesos")] + description <- "maximum final energy subsidy levels (in $/Gj) from REMIND version prior to rev. 5429" # using final energy to weight the max subsidy levels - weight <- calcOutput("FE",aggregate=FALSE)[,2005,"FE (EJ/yr)"] - } else if(subtype == "maxPeSubsidy"){ + weight <- calcOutput("FE", aggregate = FALSE)[, 2005, "FE (EJ/yr)"] + } else if (subtype == "maxPeSubsidy") { # Read max primary energy subsidy levels - output <- readSource("REMIND_11Regi", subtype="maxPeSubsidy") - description <- "maximum primary energy subsidy levels (in $/Gj) to provide plausible upper bound: 40$/barrel ~ 8 $/GJ" + output <- readSource("REMIND_11Regi", subtype = "maxPeSubsidy") + description <- "maximum primary energy subsidy levels (in $/Gj) to provide plausible upper bound: 40$/barrel ~ 8 $/GJ" # using primary energy to weight the max subsidy levels - weight <- calcOutput("PE",aggregate=FALSE)[,2005,"PE (EJ/yr)"] - } else if(subtype == "propFeSubsidy"){ + weight <- calcOutput("PE", aggregate = FALSE)[, 2005, "PE (EJ/yr)"] + } else if (subtype == "propFeSubsidy") { # Read proportional adjustment final energy subsidy levels - output <- readSource("REMIND_11Regi", subtype="propFeSubsidy")[,,c("fehoi")] + output <- readSource("REMIND_11Regi", subtype = "propFeSubsidy")[, , c("fehoi")] getNames(output) <- c("fehos") - description <- "subsidy proportional cap to avoid liquids increasing dramatically" + description <- "subsidy proportional cap to avoid liquids increasing dramatically" # average weight - weight <- new.magpie(getRegions(output),getYears(output),getNames(output),fill=1) + weight <- new.magpie(getItems(output, dim = 1), getYears(output), getNames(output), fill = 1) } - + # Return tax convergence levels aggregated to selected REMIND regions - return(list(x=output, weight=weight, - unit="$/GJ", - description=description - )) - + return(list(x = output, weight = weight, unit = "$/GJ", description = description)) + } diff --git a/R/calcTrade.R b/R/calcTrade.R index 726911d2..b1cbffa7 100644 --- a/R/calcTrade.R +++ b/R/calcTrade.R @@ -1,25 +1,28 @@ - +#' Computes Trade variables based on latest IEA data available +#' +#' @return a magclass object calcTrade <- function() { - - x <- calcOutput("IO",subtype="trade",aggregate=FALSE) - - # Xport - Mport - mapping <- list("peoil.Mport" = "Trade|Imports|Oil (EJ/yr)", - "peoil.Xport" = "Trade|Exports|Oil (EJ/yr)", - "pecoal.Mport" = "Trade|Imports|Coal (EJ/yr)", - "pecoal.Xport" = "Trade|Exports|Coal (EJ/yr)", - "pegas.Mport" = "Trade|Imports|Gas (EJ/yr)", - "pegas.Xport" = "Trade|Exports|Gas (EJ/yr)") - - # rename 3. dimension - getNames(x) <- mapping[getNames(x)] - - # Trade = Xport - Mport - x <- mbind(x,setNames(x[,,"Trade|Exports|Oil (EJ/yr)"] - x[,,"Trade|Imports|Oil (EJ/yr)"], "Trade|Oil (EJ/yr)")) - x <- mbind(x,setNames(x[,,"Trade|Exports|Coal (EJ/yr)"] - x[,,"Trade|Imports|Coal (EJ/yr)"], "Trade|Coal (EJ/yr)")) - x <- mbind(x,setNames(x[,,"Trade|Exports|Gas (EJ/yr)"] - x[,,"Trade|Imports|Gas (EJ/yr)"], "Trade|Gas (EJ/yr)")) - + x <- calcOutput("IO", subtype = "trade", ieaVersion = "latest", aggregate = FALSE) + + # Xport - Mport + mapping <- list( + "peoil.Mport" = "Trade|Imports|Oil (EJ/yr)", + "peoil.Xport" = "Trade|Exports|Oil (EJ/yr)", + "pecoal.Mport" = "Trade|Imports|Coal (EJ/yr)", + "pecoal.Xport" = "Trade|Exports|Coal (EJ/yr)", + "pegas.Mport" = "Trade|Imports|Gas (EJ/yr)", + "pegas.Xport" = "Trade|Exports|Gas (EJ/yr)" + ) + + # rename 3. dimension + getNames(x) <- mapping[getNames(x)] + + x <- mbind(x, setNames(x[, , "Trade|Exports|Oil (EJ/yr)"] - x[, , "Trade|Imports|Oil (EJ/yr)"], "Trade|Oil (EJ/yr)")) + x <- mbind(x, setNames(x[, , "Trade|Exports|Coal (EJ/yr)"] - x[, , "Trade|Imports|Coal (EJ/yr)"], "Trade|Coal (EJ/yr)")) + x <- mbind(x, setNames(x[, , "Trade|Exports|Gas (EJ/yr)"] - x[, , "Trade|Imports|Gas (EJ/yr)"], "Trade|Gas (EJ/yr)")) - return(list(x=x,weight=NULL,unit="EJ", - description="IEA Final Energy Data based on 2014 version of IEA Energy Balances")) + return(list( + x = x, weight = NULL, unit = "EJ", + description = "IEA Final Energy Data based on 2023 version of IEA Energy Balances" + )) } diff --git a/README.md b/README.md index 11e3a040..7f4458c5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # MadRat REMIND Input Data Package -R package **mrremind**, version **0.175.7** +R package **mrremind**, version **0.175.8** [![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, . 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.7}, + note = {R package version 0.175.8}, url = {https://github.com/pik-piam/mrremind}, } ``` diff --git a/man/calcFE.Rd b/man/calcFE.Rd index 00f2bc9e..82a4d878 100644 --- a/man/calcFE.Rd +++ b/man/calcFE.Rd @@ -5,12 +5,15 @@ \title{Calculates FE historical from IEA energy balances, projections from EDGE, and historical values from IEA WEO 2019} \usage{ -calcFE(source = "IEA", scenario_proj = "SSP2") +calcFE(source = "IEA", scenario_proj = "SSP2", ieaVersion = "default") } \arguments{ \item{source}{"IEA" or "IEA_WEO"} \item{scenario_proj}{"SSP2" by default unless overwritten} + +\item{ieaVersion}{Release version of IEA data, either 'default' (vetted and used in REMIND) +or 'latest'.} } \description{ Calculates FE historical from IEA energy balances, projections from EDGE, and historical diff --git a/man/calcIO.Rd b/man/calcIO.Rd index faf089a0..c04c97ee 100644 --- a/man/calcIO.Rd +++ b/man/calcIO.Rd @@ -6,11 +6,15 @@ \usage{ calcIO( subtype = c("input", "output", "output_biomass", "trade", "input_Industry_subsectors", - "output_Industry_subsectors", "IEA_output", "IEA_input") + "output_Industry_subsectors", "IEA_output", "IEA_input"), + ieaVersion = "default" ) } \arguments{ \item{subtype}{Data subtype. See default argument for possible values.} + +\item{ieaVersion}{Release version of IEA data, either 'default' +(vetted and used in REMIND) or 'latest'.} } \value{ IEA data as MAgPIE object aggregated to country level diff --git a/man/calcPE.Rd b/man/calcPE.Rd new file mode 100644 index 00000000..ef3ed693 --- /dev/null +++ b/man/calcPE.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/calcPE.R +\name{calcPE} +\alias{calcPE} +\title{Computes Primary Energy variables} +\usage{ +calcPE(subtype = "IEA", ieaVersion = "default") +} +\arguments{ +\item{subtype}{source for calculation, either "IEA" or "IEA_WEO"} + +\item{ieaVersion}{Release version of IEA data, either 'default' (vetted and used in REMIND) +or 'latest'.} +} +\value{ +a magclass object +} +\description{ +Computes Primary Energy variables +} diff --git a/man/calcTaxLimits.Rd b/man/calcTaxLimits.Rd index 338f4b80..21f287f3 100644 --- a/man/calcTaxLimits.Rd +++ b/man/calcTaxLimits.Rd @@ -7,17 +7,23 @@ calcTaxLimits(subtype) } \arguments{ -\item{subtype}{Name of the subsidy data type limit, e.g. "maxFeSubsidy" for maximum final energy subsidy,"maxPeSubsidy" for maximum primary energy subsidy or "propFeSubsidy" for proportional cap for final energy subsidy} +\item{subtype}{Name of the subsidy data type limit, e.g. "maxFeSubsidy" for +maximum final energy subsidy,"maxPeSubsidy" for maximum primary energy subsidy +or "propFeSubsidy" for proportional cap for final energy subsidy} } \value{ magpie object of the subtype tax limit } \description{ -tax and subsidies maximum levels. The tax limits serve as a work around to avoid excess of subsidy levels that could cause problems on the REMIND model solution. These files should be removed or replaced once a better way to handle this issue is introduced to the REMIND model formulation or once better yearly and country subsidy level data is available for the primary and final energies. +tax and subsidies maximum levels. The tax limits serve as a work +around to avoid excess of subsidy levels that could cause problems on the REMIND +model solution. These files should be removed or replaced once a better way +to handle this issue is introduced to the REMIND model formulation or once +better yearly and country subsidy level data is available for the primary +and final energies. } \examples{ - -\dontrun{ +\dontrun{ calcOutput("TaxLimits") } diff --git a/man/calcTrade.Rd b/man/calcTrade.Rd new file mode 100644 index 00000000..2961d847 --- /dev/null +++ b/man/calcTrade.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/calcTrade.R +\name{calcTrade} +\alias{calcTrade} +\title{Computes Trade variables based on latest IEA data available} +\usage{ +calcTrade() +} +\value{ +a magclass object +} +\description{ +Computes Trade variables based on latest IEA data available +}