diff --git a/.buildlibrary b/.buildlibrary index ee3c3941..c7eaa3e3 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '2495988' +ValidationKey: '2684630' AutocreateReadme: yes AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' diff --git a/CITATION.cff b/CITATION.cff index 6535d994..08e76215 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: 'mrindustry: input data generation for the REMIND industry module' -version: 1.2.1 -date-released: '2026-06-24' +version: 1.3.0 +date-released: '2026-07-17' abstract: The mrindustry packages contains data preprocessing for the REMIND model. authors: - family-names: Benke diff --git a/DESCRIPTION b/DESCRIPTION index 1518f70b..3a7d9ae0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: mrindustry Title: input data generation for the REMIND industry module -Version: 1.2.1 -Date: 2026-06-24 +Version: 1.3.0 +Date: 2026-07-17 Authors@R: c( person(given = "Falk", family = "Benke", email = "benke@pik-potsdam.de", role = c("aut", "cre")), @@ -55,3 +55,4 @@ Suggests: testthat, Encoding: UTF-8 Config/roxygen2/version: 8.0.0 +RoxygenNote: 7.3.3 diff --git a/R/convertStegmann2022.R b/R/convertStegmann2022.R index 5cb534de..8d81c555 100644 --- a/R/convertStegmann2022.R +++ b/R/convertStegmann2022.R @@ -1,18 +1,25 @@ #' @title convertStegmann2022 #' @description Converts data from Stegmann2022 #' @param x unconverted magpie object from read-script +#' @param subtype Character. "FEweighted" disaggregates all variables based on +#' FE; "PopWeighted" disaggregates all variables based on Population. #' #' @return magpie object with a completed dataset. #' -convertStegmann2022 <- function(x) { +convertStegmann2022 <- function(x, subtype) { x <- x[c("World"), , , invert = TRUE] regmapping <- toolGetMapping("regionmapping_IMAGE_PBL_Stegmann2022.csv", where = "mrremind", type = "regional") - fe <- calcOutput("FE", aggregate = FALSE)[unique(regmapping$CountryCode), 2016, "FE (EJ/yr)"] - - out <- toolAggregate(x, regmapping, from = "RegionAbbreviation", to = "CountryCode", weight = fe) + if (subtype == "PopWeighted") { + weight <- calcOutput("Population", scenario = "SSP2", aggregate = FALSE)[unique(regmapping$CountryCode), getYears(x), ] + } else if (subtype == "FEweighted") { + weight <- calcOutput("FE", aggregate = FALSE)[unique(regmapping$CountryCode), 2016, "FE (EJ/yr)"] + } else { + stop("Unknown subtype '", subtype, "'. Use 'PopWeighted' or 'FEweighted'.") + } + out <- toolAggregate(x, regmapping, from = "RegionAbbreviation", to = "CountryCode", weight = weight) out <- toolCountryFill(out, fill = 0, verbosity = 2) return(out) diff --git a/R/readIEA_Petrochem.R b/R/readIEA_Petrochem.R index 55ffacf9..386bdc06 100644 --- a/R/readIEA_Petrochem.R +++ b/R/readIEA_Petrochem.R @@ -14,6 +14,7 @@ #' \item RouteCTS: Fig 5.10 Petro Prod Route CTS (Clean Technology Scenario) for HVCs, Ammonia, Methanol #' \item production3type: Fig 4.1 Petrochem Production for HVCs, Ammonia, Methanol #' \item production5type: Fig A.1 Petrochem Prod Region for Ethylene, Propylene, BTX, Ammonia, Methanol +#' \item plastics: Fig 4.2 Production of key thermoplastics in the RTS #' } #' #' Different products to read. Available types are: @@ -99,6 +100,12 @@ readIEA_Petrochem <- function(subtype) { ColumnsName = "Route", ColumnsRange = c(3:7) ), + "plastics" = list( + sheet_name = "Fig 4.2 Prod Thermoplastics RTS", + ranges = c(All = "A1:I16"), + ColumnsName = "Year", + ColumnsRange = c(2:16) + ), stop("Invalid subtype combination") ) @@ -128,11 +135,10 @@ readIEA_Petrochem <- function(subtype) { # --------------------------------------------------------------------------- # Set Column Names and Clean Data # - Use the first row as column names, ensure they are unique and syntactically valid, - # and rename the first column to "Country". Remove the first row afterwards. + # Remove the first row afterwards. # --------------------------------------------------------------------------- colnames(data) <- as.character(unlist(data[1, ])) colnames(data) <- make.names(colnames(data), unique = TRUE) - colnames(data)[1] <- "Country" data <- data[-1, ] # --------------------------------------------------------------------------- @@ -150,7 +156,13 @@ readIEA_Petrochem <- function(subtype) { # - Replace NA values with 0. # - Add the concatenated subtype string as a comment to the object. # --------------------------------------------------------------------------- - data <- as.magpie(data, spatial = 1, temporal = 2) + if (subtype[1] == "plastics") { + colnames(data)[1] <- "type" + data <- as.magpie(data, temporal = 2) + } else { + colnames(data)[1] <- "Country" + data <- as.magpie(data, spatial = 1, temporal = 2) + } data[is.na(data)] <- 0 subtype <- paste(subtype, collapse = "_") getComment(data) <- subtype diff --git a/R/readStegmann2022.R b/R/readStegmann2022.R index 09f1c9df..f2cfc1ba 100644 --- a/R/readStegmann2022.R +++ b/R/readStegmann2022.R @@ -8,10 +8,13 @@ #' Link to SI: #' https://static-content.springer.com/esm/art%3A10.1038%2Fs41586-022-05422-5/MediaObjects/41586_2022_5422_MOESM1_ESM.xlsx #nolint #' +#' @param subtype Character. "FEweighted" disaggregates all variables based on +#' FE; "PopWeighted" disaggregates all variables based on Population +#' (case distinction in convertStegmann2022) #' @return a magpie object of the data -#' @author Falk Benke, Simón Moreno +#' @author Falk Benke, Simón Moreno, Leonie Schweiger #' -readStegmann2022 <- function() { +readStegmann2022 <- function(subtype) { readxl::read_xlsx("41586_2022_5422_MOESM1_ESM.xlsx", sheet = "Data") %>% tidyr::pivot_longer(tidyselect::starts_with("2"), names_to = "period") %>% as.magpie(spatial = "Region", temporal = "period", tidy = TRUE) diff --git a/README.md b/README.md index 93207156..bf714b95 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # input data generation for the REMIND industry module -R package **mrindustry**, version **1.2.1** +R package **mrindustry**, version **1.3.0** [![R build status](https://github.com/pik-piam/mrindustry/workflows/check/badge.svg)](https://github.com/pik-piam/mrindustry/actions) [![codecov](https://codecov.io/gh/pik-piam/mrindustry/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/mrindustry) [![r-universe](https://pik-piam.r-universe.dev/badges/mrindustry)](https://pik-piam.r-universe.dev/builds) @@ -39,7 +39,7 @@ In case of questions / problems please contact Falk Benke To cite package **mrindustry** in publications use: -Benke F, Dürrwächter J, Rodrigues R, Moreno-Leiva S, Baumstark L, Pehl M, Weiss B (2026). "mrindustry: input data generation for the REMIND industry module." Version: 1.2.1, . +Benke F, Dürrwächter J, Rodrigues R, Moreno-Leiva S, Baumstark L, Pehl M, Weiss B (2026). "mrindustry: input data generation for the REMIND industry module." Version: 1.3.0, . A BibTeX entry for LaTeX users is @@ -47,9 +47,9 @@ A BibTeX entry for LaTeX users is @Misc{, title = {mrindustry: input data generation for the REMIND industry module}, author = {Falk Benke and Jakob Dürrwächter and Renato Rodrigues and Simón Moreno-Leiva and Lavinia Baumstark and Michaja Pehl and Bennet Weiss}, - date = {2026-06-24}, + date = {2026-07-17}, year = {2026}, url = {https://github.com/pik-piam/mrindustry}, - note = {Version: 1.2.1}, + note = {Version: 1.3.0}, } ``` diff --git a/man/convertStegmann2022.Rd b/man/convertStegmann2022.Rd index df5cf82b..ebfb3719 100644 --- a/man/convertStegmann2022.Rd +++ b/man/convertStegmann2022.Rd @@ -4,10 +4,13 @@ \alias{convertStegmann2022} \title{convertStegmann2022} \usage{ -convertStegmann2022(x) +convertStegmann2022(x, subtype) } \arguments{ \item{x}{unconverted magpie object from read-script} + +\item{subtype}{Character. "FEweighted" disaggregates all variables based on +FE; "PopWeighted" disaggregates all variables based on Population.} } \value{ magpie object with a completed dataset. diff --git a/man/readIEA_Petrochem.Rd b/man/readIEA_Petrochem.Rd index ffba9435..da037df1 100644 --- a/man/readIEA_Petrochem.Rd +++ b/man/readIEA_Petrochem.Rd @@ -14,6 +14,7 @@ readIEA_Petrochem(subtype) \item RouteCTS: Fig 5.10 Petro Prod Route CTS (Clean Technology Scenario) for HVCs, Ammonia, Methanol \item production3type: Fig 4.1 Petrochem Production for HVCs, Ammonia, Methanol \item production5type: Fig A.1 Petrochem Prod Region for Ethylene, Propylene, BTX, Ammonia, Methanol + \item plastics: Fig 4.2 Production of key thermoplastics in the RTS } Different products to read. Available types are: diff --git a/man/readStegmann2022.Rd b/man/readStegmann2022.Rd index e6211414..97f2768f 100644 --- a/man/readStegmann2022.Rd +++ b/man/readStegmann2022.Rd @@ -4,7 +4,12 @@ \alias{readStegmann2022} \title{Read PlasticsEoL} \usage{ -readStegmann2022() +readStegmann2022(subtype) +} +\arguments{ +\item{subtype}{Character. "FEweighted" disaggregates all variables based on +FE; "PopWeighted" disaggregates all variables based on Population +(case distinction in convertStegmann2022)} } \value{ a magpie object of the data @@ -19,5 +24,5 @@ Link to SI: https://static-content.springer.com/esm/art%3A10.1038%2Fs41586-022-05422-5/MediaObjects/41586_2022_5422_MOESM1_ESM.xlsx #nolint } \author{ -Falk Benke, Simón Moreno +Falk Benke, Simón Moreno, Leonie Schweiger }