From 3fc3ed28172f20a404ae94edbafe45d841400a72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tonn=20R=C3=BCter?= Date: Tue, 17 Dec 2024 13:42:10 +0100 Subject: [PATCH 1/8] Added p11_emiAPexsolve.gdx as possible file name --- R/reportEmiAirPol.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/reportEmiAirPol.R b/R/reportEmiAirPol.R index ec75510b..2c44a60a 100644 --- a/R/reportEmiAirPol.R +++ b/R/reportEmiAirPol.R @@ -84,9 +84,9 @@ reportEmiAirPol <- function(gdx,regionSubsetList=NULL,t=c(seq(2005,2060,5),seq(2 ## sets ttot <- as.numeric(readGDX(gdx, name=c("ttot"), format="first_found")) ## parameter - pm_emiAPexsolve <- readGDX(gdx, name=c("pm_emiAPexsolve"), field="l", format="first_found")[,ttot,] - pm_emiAPexo <- readGDX(gdx, name=c("pm_emiAPexo"), field="l", format="first_found")[,ttot,airpollutants] - pm_emiAPexoGlob <- readGDX(gdx, name=c("pm_emiAPexoGlob"), field="l", format="first_found")[,ttot,airpollutants] + pm_emiAPexsolve <- readGDX(gdx, name = c("p11_emiAPexsolve", "pm_emiAPexsolve"), field = "l", format = "first_found")[, ttot, ] + pm_emiAPexo <- readGDX(gdx, name = c("p11_emiAPexo", "pm_emiAPexo"), field = "l", format = "first_found")[, ttot, airpollutants] + pm_emiAPexoGlob <- readGDX(gdx, name = c("p11_emiAPexoGlob", "pm_emiAPexoGlob"), field = "l", format = "first_found")[, ttot, airpollutants] ####### prepare parameter ######################## magclass::getNames(pm_emiAPexsolve) <- gsub("SOx","so2",magclass::getNames(pm_emiAPexsolve)) From 5124f334374c7e04ae9db86d9bf08703bffa47a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tonn=20R=C3=BCter?= Date: Tue, 17 Dec 2024 14:40:46 +0100 Subject: [PATCH 2/8] Adapted 'pm_X' vars to new prefix 'p11_X' --- R/reportEmiAirPol.R | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/R/reportEmiAirPol.R b/R/reportEmiAirPol.R index 2c44a60a..90408bd6 100644 --- a/R/reportEmiAirPol.R +++ b/R/reportEmiAirPol.R @@ -37,7 +37,7 @@ reportEmiAirPol <- function(gdx,regionSubsetList=NULL,t=c(seq(2005,2060,5),seq(2 airpollutants <- c("so2","bc","oc","CO","VOC","NOx","NH3") ######### internal function ########### - generateReportingEmiAirPol <- function(pollutant,i_emiAPexsolve=pm_emiAPexsolve,i_emiAPexo=pm_emiAPexo){ + generateReportingEmiAirPol <- function(pollutant,i_emiAPexsolve=p11_emiAPexsolve,i_emiAPexo=p11_emiAPexo){ poll_rep <- toupper(pollutant) tmp <- NULL @@ -84,13 +84,13 @@ reportEmiAirPol <- function(gdx,regionSubsetList=NULL,t=c(seq(2005,2060,5),seq(2 ## sets ttot <- as.numeric(readGDX(gdx, name=c("ttot"), format="first_found")) ## parameter - pm_emiAPexsolve <- readGDX(gdx, name = c("p11_emiAPexsolve", "pm_emiAPexsolve"), field = "l", format = "first_found")[, ttot, ] - pm_emiAPexo <- readGDX(gdx, name = c("p11_emiAPexo", "pm_emiAPexo"), field = "l", format = "first_found")[, ttot, airpollutants] - pm_emiAPexoGlob <- readGDX(gdx, name = c("p11_emiAPexoGlob", "pm_emiAPexoGlob"), field = "l", format = "first_found")[, ttot, airpollutants] + p11_emiAPexsolve <- readGDX(gdx, name = c("p11_emiAPexsolve", "pm_emiAPexsolve"), field = "l", format = "first_found")[, ttot, ] + p11_emiAPexo <- readGDX(gdx, name = c("p11_emiAPexo", "pm_emiAPexo"), field = "l", format = "first_found")[, ttot, airpollutants] + p11_emiAPexoGlob <- readGDX(gdx, name = c("p11_emiAPexoGlob", "pm_emiAPexoGlob"), field = "l", format = "first_found")[, ttot, airpollutants] ####### prepare parameter ######################## - magclass::getNames(pm_emiAPexsolve) <- gsub("SOx","so2",magclass::getNames(pm_emiAPexsolve)) - magclass::getNames(pm_emiAPexsolve) <- gsub("NMVOC","VOC",magclass::getNames(pm_emiAPexsolve)) + magclass::getNames(p11_emiAPexsolve) <- gsub("SOx","so2",magclass::getNames(p11_emiAPexsolve)) + magclass::getNames(p11_emiAPexsolve) <- gsub("NMVOC","VOC",magclass::getNames(p11_emiAPexsolve)) ####### calculate reporting parameters ############ # Loop over air pollutants and call reporting generating function @@ -107,8 +107,8 @@ reportEmiAirPol <- function(gdx,regionSubsetList=NULL,t=c(seq(2005,2060,5),seq(2 poll_rep <- toupper(pollutant) tmp <- NULL # Add Aviation and Int. Shipping emissions - tmp <- mbind(tmp,setNames(pm_emiAPexoGlob["GLO",,"InternationalShipping"][,,pollutant],paste0("Emi|",poll_rep,"|Energy Demand|Transport|International Shipping (Mt ",poll_rep,"/yr)")), - setNames(pm_emiAPexoGlob["GLO",,"Aviation"][,,pollutant], paste0("Emi|",poll_rep,"|Energy Demand|Transport|Aviation (Mt ",poll_rep,"/yr)")) + tmp <- mbind(tmp,setNames(p11_emiAPexoGlob["GLO",,"InternationalShipping"][,,pollutant],paste0("Emi|",poll_rep,"|Energy Demand|Transport|International Shipping (Mt ",poll_rep,"/yr)")), + setNames(p11_emiAPexoGlob["GLO",,"Aviation"][,,pollutant], paste0("Emi|",poll_rep,"|Energy Demand|Transport|Aviation (Mt ",poll_rep,"/yr)")) ) tmp1 <- new.magpie(getRegions(out),getYears(out),magclass::getNames(tmp),fill=0) tmp1["GLO",,] <- tmp["GLO",,] From 6b90ffcc008fb2aba486bdab8d63f224f90f5b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tonn=20R=C3=BCter?= Date: Tue, 17 Dec 2024 14:52:15 +0100 Subject: [PATCH 3/8] Removed unused conversion factors --- R/reportEmiAirPol.R | 4 ---- 1 file changed, 4 deletions(-) diff --git a/R/reportEmiAirPol.R b/R/reportEmiAirPol.R index 90408bd6..e53116f2 100644 --- a/R/reportEmiAirPol.R +++ b/R/reportEmiAirPol.R @@ -76,10 +76,6 @@ reportEmiAirPol <- function(gdx,regionSubsetList=NULL,t=c(seq(2005,2060,5),seq(2 return(tmp) } - ####### conversion factors ########## - pm_conv_TWa_EJ <- 31.536 - conv_MtSO2_to_MtS <- 1/2 # 32/(32+2*16) - ####### read in needed data ######### ## sets ttot <- as.numeric(readGDX(gdx, name=c("ttot"), format="first_found")) From c1c6d11b54f52a9bb78f2ac494175fa20fe6f0d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tonn=20R=C3=BCter?= Date: Tue, 17 Dec 2024 15:35:29 +0100 Subject: [PATCH 4/8] Don't import getRegions, replace with getItems --- R/reportEmiAirPol.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/reportEmiAirPol.R b/R/reportEmiAirPol.R index e53116f2..18d59306 100644 --- a/R/reportEmiAirPol.R +++ b/R/reportEmiAirPol.R @@ -20,7 +20,7 @@ #' #' @export #' @importFrom gdx readGDX -#' @importFrom magclass collapseNames getNames<- mbind setNames new.magpie getRegions getYears mbind setYears getItems<- +#' @importFrom magclass collapseNames getNames<- mbind setNames new.magpie getYears mbind setYears getItems reportEmiAirPol <- function(gdx,regionSubsetList=NULL,t=c(seq(2005,2060,5),seq(2070,2110,10),2130,2150)){ # Get realisation name @@ -106,7 +106,7 @@ reportEmiAirPol <- function(gdx,regionSubsetList=NULL,t=c(seq(2005,2060,5),seq(2 tmp <- mbind(tmp,setNames(p11_emiAPexoGlob["GLO",,"InternationalShipping"][,,pollutant],paste0("Emi|",poll_rep,"|Energy Demand|Transport|International Shipping (Mt ",poll_rep,"/yr)")), setNames(p11_emiAPexoGlob["GLO",,"Aviation"][,,pollutant], paste0("Emi|",poll_rep,"|Energy Demand|Transport|Aviation (Mt ",poll_rep,"/yr)")) ) - tmp1 <- new.magpie(getRegions(out),getYears(out),magclass::getNames(tmp),fill=0) + tmp1 <- new.magpie(getItems(out, dim = 1), getYears(out), magclass::getNames(tmp), fill = 0) tmp1["GLO",,] <- tmp["GLO",,] out <- mbind(out,tmp1) # Aggregation: Transport and Energy Supply From e47ed229b0b297b2366b3768af928bee4c38eb2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tonn=20R=C3=BCter?= Date: Tue, 17 Dec 2024 15:37:50 +0100 Subject: [PATCH 5/8] Removed magclass:: prefix for getNames calls --- R/reportEmiAirPol.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/reportEmiAirPol.R b/R/reportEmiAirPol.R index 18d59306..97505663 100644 --- a/R/reportEmiAirPol.R +++ b/R/reportEmiAirPol.R @@ -85,8 +85,8 @@ reportEmiAirPol <- function(gdx,regionSubsetList=NULL,t=c(seq(2005,2060,5),seq(2 p11_emiAPexoGlob <- readGDX(gdx, name = c("p11_emiAPexoGlob", "pm_emiAPexoGlob"), field = "l", format = "first_found")[, ttot, airpollutants] ####### prepare parameter ######################## - magclass::getNames(p11_emiAPexsolve) <- gsub("SOx","so2",magclass::getNames(p11_emiAPexsolve)) - magclass::getNames(p11_emiAPexsolve) <- gsub("NMVOC","VOC",magclass::getNames(p11_emiAPexsolve)) + getNames(p11_emiAPexsolve) <- gsub("SOx","so2",getNames(p11_emiAPexsolve)) + getNames(p11_emiAPexsolve) <- gsub("NMVOC","VOC",getNames(p11_emiAPexsolve)) ####### calculate reporting parameters ############ # Loop over air pollutants and call reporting generating function @@ -106,7 +106,7 @@ reportEmiAirPol <- function(gdx,regionSubsetList=NULL,t=c(seq(2005,2060,5),seq(2 tmp <- mbind(tmp,setNames(p11_emiAPexoGlob["GLO",,"InternationalShipping"][,,pollutant],paste0("Emi|",poll_rep,"|Energy Demand|Transport|International Shipping (Mt ",poll_rep,"/yr)")), setNames(p11_emiAPexoGlob["GLO",,"Aviation"][,,pollutant], paste0("Emi|",poll_rep,"|Energy Demand|Transport|Aviation (Mt ",poll_rep,"/yr)")) ) - tmp1 <- new.magpie(getItems(out, dim = 1), getYears(out), magclass::getNames(tmp), fill = 0) + tmp1 <- new.magpie(getItems(out, dim = 1), getYears(out), getNames(tmp), fill = 0) tmp1["GLO",,] <- tmp["GLO",,] out <- mbind(out,tmp1) # Aggregation: Transport and Energy Supply From b624b992ffe4a90790e5e4fcbf6a112ceaf1ecf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tonn=20R=C3=BCter?= Date: Tue, 17 Dec 2024 16:09:19 +0100 Subject: [PATCH 6/8] Re-formatted --- R/reportEmiAirPol.R | 205 +++++++++++++++++++++++++++----------------- 1 file changed, 127 insertions(+), 78 deletions(-) diff --git a/R/reportEmiAirPol.R b/R/reportEmiAirPol.R index 97505663..7182b77e 100644 --- a/R/reportEmiAirPol.R +++ b/R/reportEmiAirPol.R @@ -16,59 +16,63 @@ #' @author Antoine Levesque, Jerome Hilaire #' @seealso \code{\link{convGDX2MIF}} #' @examples -#' \dontrun{reportEmiAirPol(gdx)} +#' \dontrun{ +#' reportEmiAirPol(gdx) +#' } #' #' @export #' @importFrom gdx readGDX #' @importFrom magclass collapseNames getNames<- mbind setNames new.magpie getYears mbind setYears getItems -reportEmiAirPol <- function(gdx,regionSubsetList=NULL,t=c(seq(2005,2060,5),seq(2070,2110,10),2130,2150)){ - +reportEmiAirPol <- function(gdx, regionSubsetList = NULL, t = c(seq(2005, 2060, 5), seq(2070, 2110, 10), 2130, 2150)) { # Get realisation name realisation <- readGDX(gdx, "module2realisation") - realisation <- realisation[which(realisation[,1] == "aerosols"),2] + realisation <- realisation[which(realisation[, 1] == "aerosols"), 2] ######### initialisation ########### tmp <- NULL out <- NULL - if (! realisation == "exoGAINS") stop("not allowed air pollution realization.") + if (!realisation == "exoGAINS") stop("not allowed air pollution realization.") ######### initialisation ########### - airpollutants <- c("so2","bc","oc","CO","VOC","NOx","NH3") + airpollutants <- c("so2", "bc", "oc", "CO", "VOC", "NOx", "NH3") ######### internal function ########### - generateReportingEmiAirPol <- function(pollutant,i_emiAPexsolve=p11_emiAPexsolve,i_emiAPexo=p11_emiAPexo){ + generateReportingEmiAirPol <- function(pollutant, i_emiAPexsolve = p11_emiAPexsolve, i_emiAPexo = p11_emiAPexo) { poll_rep <- toupper(pollutant) tmp <- NULL # reduce to the pollutant - emiAPexsolve <- collapseNames(i_emiAPexsolve[,,pollutant]) - emiAPexo <- collapseNames(i_emiAPexo[,,pollutant]) + emiAPexsolve <- collapseNames(i_emiAPexsolve[, , pollutant]) + emiAPexo <- collapseNames(i_emiAPexo[, , pollutant]) getSets(emiAPexo) <- getSets(emiAPexsolve) # add indprocess to indst - emiAPexsolve[,,"indst"] <- emiAPexsolve[,,"indst"] + emiAPexsolve[,,"indprocess"] + emiAPexsolve[, , "indst"] <- emiAPexsolve[, , "indst"] + emiAPexsolve[, , "indprocess"] # Replace REMIND sector names by reporting ones - mapping = data.frame( + mapping <- data.frame( remind = c("power", "indst", "res", "trans", "solvents", "extraction"), - reporting = c(paste0("Emi|", poll_rep, "|Energy Supply|Electricity (Mt ", poll_rep, "/yr)"), - paste0("Emi|", poll_rep, "|Energy Demand|Industry (Mt ", poll_rep, "/yr)"), - paste0("Emi|", poll_rep, "|Energy Demand|Buildings (Mt ", poll_rep, "/yr)"), - paste0("Emi|", poll_rep, "|Energy Demand|Transport|Ground Trans (Mt ", poll_rep, "/yr)"), - paste0("Emi|", poll_rep, "|Solvents (Mt ", poll_rep, "/yr)"), - paste0("Emi|", poll_rep, "|Energy Supply|Extraction (Mt ", poll_rep, "/yr)"))) - - emiAPexsolve <- setNames(emiAPexsolve[,,mapping$remind],as.character(mapping$reporting)) - - tmp <- - mbind(emiAPexsolve, - setNames(emiAPexo[,,"AgWasteBurning"], paste0("Emi|",poll_rep,"|Land Use|Agricultural Waste Burning (Mt ",poll_rep,"/yr)")), - setNames(emiAPexo[,,"Agriculture"], paste0("Emi|",poll_rep,"|Land Use|Agriculture (Mt ",poll_rep,"/yr)")), - setNames(emiAPexo[,,"ForestBurning"], paste0("Emi|",poll_rep,"|Land Use|Forest Burning (Mt ",poll_rep,"/yr)")), - setNames(emiAPexo[,,"GrasslandBurning"],paste0("Emi|",poll_rep,"|Land Use|Savannah Burning (Mt ",poll_rep,"/yr)")), - setNames(emiAPexo[,,"Waste"], paste0("Emi|",poll_rep,"|Waste (Mt ",poll_rep,"/yr)"))) - + reporting = c( + paste0("Emi|", poll_rep, "|Energy Supply|Electricity (Mt ", poll_rep, "/yr)"), + paste0("Emi|", poll_rep, "|Energy Demand|Industry (Mt ", poll_rep, "/yr)"), + paste0("Emi|", poll_rep, "|Energy Demand|Buildings (Mt ", poll_rep, "/yr)"), + paste0("Emi|", poll_rep, "|Energy Demand|Transport|Ground Trans (Mt ", poll_rep, "/yr)"), + paste0("Emi|", poll_rep, "|Solvents (Mt ", poll_rep, "/yr)"), + paste0("Emi|", poll_rep, "|Energy Supply|Extraction (Mt ", poll_rep, "/yr)") + ) + ) + + emiAPexsolve <- setNames(emiAPexsolve[, , mapping$remind], as.character(mapping$reporting)) + + tmp <- mbind( + emiAPexsolve, + setNames(emiAPexo[, , "AgWasteBurning"], paste0("Emi|", poll_rep, "|Land Use|Agricultural Waste Burning (Mt ", poll_rep, "/yr)")), + setNames(emiAPexo[, , "Agriculture"], paste0("Emi|", poll_rep, "|Land Use|Agriculture (Mt ", poll_rep, "/yr)")), + setNames(emiAPexo[, , "ForestBurning"], paste0("Emi|", poll_rep, "|Land Use|Forest Burning (Mt ", poll_rep, "/yr)")), + setNames(emiAPexo[, , "GrasslandBurning"], paste0("Emi|", poll_rep, "|Land Use|Savannah Burning (Mt ", poll_rep, "/yr)")), + setNames(emiAPexo[, , "Waste"], paste0("Emi|", poll_rep, "|Waste (Mt ", poll_rep, "/yr)")) + ) # Set NAs to 0 tmp[is.na(tmp)] <- 0 @@ -78,70 +82,115 @@ reportEmiAirPol <- function(gdx,regionSubsetList=NULL,t=c(seq(2005,2060,5),seq(2 ####### read in needed data ######### ## sets - ttot <- as.numeric(readGDX(gdx, name=c("ttot"), format="first_found")) + ttot <- as.numeric(readGDX(gdx, name = c("ttot"), format = "first_found")) ## parameter - p11_emiAPexsolve <- readGDX(gdx, name = c("p11_emiAPexsolve", "pm_emiAPexsolve"), field = "l", format = "first_found")[, ttot, ] - p11_emiAPexo <- readGDX(gdx, name = c("p11_emiAPexo", "pm_emiAPexo"), field = "l", format = "first_found")[, ttot, airpollutants] - p11_emiAPexoGlob <- readGDX(gdx, name = c("p11_emiAPexoGlob", "pm_emiAPexoGlob"), field = "l", format = "first_found")[, ttot, airpollutants] + p11_emiAPexsolve <- readGDX( + gdx, + name = c("p11_emiAPexsolve", "pm_emiAPexsolve"), field = "l", format = "first_found" + )[, ttot, ] + p11_emiAPexo <- readGDX( + gdx, + name = c("p11_emiAPexo", "pm_emiAPexo"), field = "l", format = "first_found" + )[, ttot, airpollutants] + p11_emiAPexoGlob <- readGDX( + gdx, + name = c("p11_emiAPexoGlob", "pm_emiAPexoGlob"), field = "l", format = "first_found" + )[, ttot, airpollutants] ####### prepare parameter ######################## - getNames(p11_emiAPexsolve) <- gsub("SOx","so2",getNames(p11_emiAPexsolve)) - getNames(p11_emiAPexsolve) <- gsub("NMVOC","VOC",getNames(p11_emiAPexsolve)) + getNames(p11_emiAPexsolve) <- gsub("SOx", "so2", getNames(p11_emiAPexsolve)) + getNames(p11_emiAPexsolve) <- gsub("NMVOC", "VOC", getNames(p11_emiAPexsolve)) ####### calculate reporting parameters ############ # Loop over air pollutants and call reporting generating function out <- do.call("mbind", lapply(airpollutants, generateReportingEmiAirPol)) # Add global values - out <- mbind(out, dimSums(out,dim=1)) + out <- mbind(out, dimSums(out, dim = 1)) # add other region aggregations - if (!is.null(regionSubsetList)) + if (!is.null(regionSubsetList)) { out <- mbind(out, calc_regionSubset_sums(out, regionSubsetList)) + } # Loop over air pollutants and add some variables for (pollutant in airpollutants) { - poll_rep <- toupper(pollutant) - tmp <- NULL - # Add Aviation and Int. Shipping emissions - tmp <- mbind(tmp,setNames(p11_emiAPexoGlob["GLO",,"InternationalShipping"][,,pollutant],paste0("Emi|",poll_rep,"|Energy Demand|Transport|International Shipping (Mt ",poll_rep,"/yr)")), - setNames(p11_emiAPexoGlob["GLO",,"Aviation"][,,pollutant], paste0("Emi|",poll_rep,"|Energy Demand|Transport|Aviation (Mt ",poll_rep,"/yr)")) - ) - tmp1 <- new.magpie(getItems(out, dim = 1), getYears(out), getNames(tmp), fill = 0) - tmp1["GLO",,] <- tmp["GLO",,] - out <- mbind(out,tmp1) - # Aggregation: Transport and Energy Supply - out <- mbind(out, - setNames(dimSums(out[,, - c(paste0("Emi|",poll_rep,"|Energy Demand|Transport|Ground Trans (Mt ",poll_rep,"/yr)"), - paste0("Emi|",poll_rep,"|Energy Demand|Transport|International Shipping (Mt ",poll_rep,"/yr)"), - paste0("Emi|",poll_rep,"|Energy Demand|Transport|Aviation (Mt ",poll_rep,"/yr)"))],dim = 3), - paste0("Emi|",poll_rep,"|Energy Demand|Transport (Mt ",poll_rep,"/yr)")), - setNames(dimSums(out[,, - c(paste0("Emi|",poll_rep,"|Energy Supply|Electricity (Mt ",poll_rep,"/yr)"), - paste0("Emi|",poll_rep,"|Energy Supply|Extraction (Mt ",poll_rep,"/yr)"))],dim = 3), - paste0("Emi|",poll_rep,"|Energy Supply (Mt ",poll_rep,"/yr)")) - ) - # Aggregation: Energy Demand + Energy Supply, Land Use - out <- mbind(out, - setNames(dimSums(out[,,c(paste0("Emi|",poll_rep,"|Energy Demand|Industry (Mt ",poll_rep,"/yr)"), - paste0("Emi|",poll_rep,"|Energy Demand|Buildings (Mt ",poll_rep,"/yr)"), - paste0("Emi|",poll_rep,"|Energy Demand|Transport (Mt ",poll_rep,"/yr)"), - paste0("Emi|",poll_rep,"|Energy Supply (Mt ",poll_rep,"/yr)"))],dim = 3), - paste0("Emi|",poll_rep,"|Energy Supply and Demand (Mt ",poll_rep,"/yr)")), - setNames(dimSums(out[,,c(paste0("Emi|",poll_rep,"|Land Use|Savannah Burning (Mt ",poll_rep,"/yr)"), - paste0("Emi|",poll_rep,"|Land Use|Forest Burning (Mt ",poll_rep,"/yr)"), - paste0("Emi|",poll_rep,"|Land Use|Agriculture (Mt ",poll_rep,"/yr)"), - paste0("Emi|",poll_rep,"|Land Use|Agricultural Waste Burning (Mt ",poll_rep,"/yr)"))],dim = 3), - paste0("Emi|",poll_rep,"|Land Use (Mt ",poll_rep,"/yr)")) - ) - # Compute total - out <- mbind(out, - setNames(dimSums(out[,,c(paste0("Emi|",poll_rep,"|Energy Supply and Demand (Mt ",poll_rep,"/yr)"), - paste0("Emi|",poll_rep,"|Solvents (Mt ",poll_rep,"/yr)"), - paste0("Emi|",poll_rep,"|Land Use (Mt ",poll_rep,"/yr)"), - paste0("Emi|",poll_rep,"|Waste (Mt ",poll_rep,"/yr)"))],dim=3), - paste0("Emi|",poll_rep," (Mt ",poll_rep,"/yr)")) - ) + poll_rep <- toupper(pollutant) + tmp <- NULL + # Add Aviation and Int. Shipping emissions + tmp <- mbind( + tmp, + setNames( + p11_emiAPexoGlob["GLO", , "InternationalShipping"][, , pollutant], + paste0("Emi|", poll_rep, "|Energy Demand|Transport|International Shipping (Mt ", poll_rep, "/yr)") + ), + setNames( + p11_emiAPexoGlob["GLO", , "Aviation"][, , pollutant], + paste0("Emi|", poll_rep, "|Energy Demand|Transport|Aviation (Mt ", poll_rep, "/yr)") + ) + ) + tmp1 <- new.magpie(getItems(out, dim = 1), getYears(out), getNames(tmp), fill = 0) + tmp1["GLO", , ] <- tmp["GLO", , ] + out <- mbind(out, tmp1) + # Aggregation: Transport and Energy Supply + out <- mbind( + out, + setNames( + dimSums(out[ + , , + c( + paste0("Emi|", poll_rep, "|Energy Demand|Transport|Ground Trans (Mt ", poll_rep, "/yr)"), + paste0("Emi|", poll_rep, "|Energy Demand|Transport|International Shipping (Mt ", poll_rep, "/yr)"), + paste0("Emi|", poll_rep, "|Energy Demand|Transport|Aviation (Mt ", poll_rep, "/yr)") + ) + ], dim = 3), + paste0("Emi|", poll_rep, "|Energy Demand|Transport (Mt ", poll_rep, "/yr)") + ), + setNames( + dimSums(out[ + , , + c( + paste0("Emi|", poll_rep, "|Energy Supply|Electricity (Mt ", poll_rep, "/yr)"), + paste0("Emi|", poll_rep, "|Energy Supply|Extraction (Mt ", poll_rep, "/yr)") + ) + ], dim = 3), + paste0("Emi|", poll_rep, "|Energy Supply (Mt ", poll_rep, "/yr)") + ) + ) + # Aggregation: Energy Demand + Energy Supply, Land Use + out <- mbind( + out, + setNames( + dimSums(out[, , c( + paste0("Emi|", poll_rep, "|Energy Demand|Industry (Mt ", poll_rep, "/yr)"), + paste0("Emi|", poll_rep, "|Energy Demand|Buildings (Mt ", poll_rep, "/yr)"), + paste0("Emi|", poll_rep, "|Energy Demand|Transport (Mt ", poll_rep, "/yr)"), + paste0("Emi|", poll_rep, "|Energy Supply (Mt ", poll_rep, "/yr)") + )], dim = 3), + paste0("Emi|", poll_rep, "|Energy Supply and Demand (Mt ", poll_rep, "/yr)") + ), + setNames( + dimSums(out[, , c( + paste0("Emi|", poll_rep, "|Land Use|Savannah Burning (Mt ", poll_rep, "/yr)"), + paste0("Emi|", poll_rep, "|Land Use|Forest Burning (Mt ", poll_rep, "/yr)"), + paste0("Emi|", poll_rep, "|Land Use|Agriculture (Mt ", poll_rep, "/yr)"), + paste0("Emi|", poll_rep, "|Land Use|Agricultural Waste Burning (Mt ", poll_rep, "/yr)") + )], dim = 3), + paste0("Emi|", poll_rep, "|Land Use (Mt ", poll_rep, "/yr)") + ) + ) + # Compute total + out <- mbind( + out, + setNames( + dimSums(out[, , c( + paste0("Emi|", poll_rep, "|Energy Supply and Demand (Mt ", poll_rep, "/yr)"), + paste0("Emi|", poll_rep, "|Solvents (Mt ", poll_rep, "/yr)"), + paste0("Emi|", poll_rep, "|Land Use (Mt ", poll_rep, "/yr)"), + paste0("Emi|", poll_rep, "|Waste (Mt ", poll_rep, "/yr)") + )], dim = 3), + paste0("Emi|", poll_rep, " (Mt ", poll_rep, "/yr)") + ) + ) } getSets(out)[3] <- "variable" From 874a9a5f25a296672b466de66602259b93e92888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tonn=20R=C3=BCter?= Date: Tue, 17 Dec 2024 16:19:07 +0100 Subject: [PATCH 7/8] Rm'd setYears, restructured imports --- R/reportEmiAirPol.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/reportEmiAirPol.R b/R/reportEmiAirPol.R index 7182b77e..2ebe39e3 100644 --- a/R/reportEmiAirPol.R +++ b/R/reportEmiAirPol.R @@ -22,7 +22,7 @@ #' #' @export #' @importFrom gdx readGDX -#' @importFrom magclass collapseNames getNames<- mbind setNames new.magpie getYears mbind setYears getItems +#' @importFrom magclass new.magpie mbind getNames<- setNames collapseNames getYears getItems reportEmiAirPol <- function(gdx, regionSubsetList = NULL, t = c(seq(2005, 2060, 5), seq(2070, 2110, 10), 2130, 2150)) { # Get realisation name realisation <- readGDX(gdx, "module2realisation") From 8519c003de00832cace9be964bc578f762a9c39c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tonn=20R=C3=BCter?= Date: Wed, 18 Dec 2024 14:08:43 +0100 Subject: [PATCH 8/8] buildLibrary --- .buildlibrary | 3 ++- CITATION.cff | 4 ++-- DESCRIPTION | 4 ++-- README.md | 9 +++++---- man/loadCs2Data.Rd | 2 +- man/reportEmiAirPol.Rd | 4 +++- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/.buildlibrary b/.buildlibrary index b2228708..6321d0e7 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '233178540' +ValidationKey: '233291575' AcceptedWarnings: - .*following variables are expected in the piamInterfaces.* - Summation checks have revealed some gaps.* @@ -8,3 +8,4 @@ AutocreateReadme: yes allowLinterWarnings: yes enforceVersionUpdate: yes skipCoverage: yes +AutocreateCITATION: yes diff --git a/CITATION.cff b/CITATION.cff index 6c555bfc..139974ce 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: 'remind2: The REMIND R package (2nd generation)' -version: 1.162.0 -date-released: '2024-12-10' +version: 1.162.1 +date-released: '2024-12-18' abstract: Contains the REMIND-specific routines for data and model output manipulation. authors: - family-names: Rodrigues diff --git a/DESCRIPTION b/DESCRIPTION index 33331b65..6e05defd 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: remind2 Title: The REMIND R package (2nd generation) -Version: 1.162.0 -Date: 2024-12-10 +Version: 1.162.1 +Date: 2024-12-18 Authors@R: c( person("Renato", "Rodrigues", , "renato.rodrigues@pik-potsdam.de", role = c("aut", "cre")), person("Lavinia", "Baumstark", role = "aut"), diff --git a/README.md b/README.md index d1680ad6..56f4233e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # The REMIND R package (2nd generation) -R package **remind2**, version **1.162.0** +R package **remind2**, version **1.162.1** [![CRAN status](https://www.r-pkg.org/badges/version/remind2)](https://cran.r-project.org/package=remind2) [![R build status](https://github.com/pik-piam/remind2/workflows/check/badge.svg)](https://github.com/pik-piam/remind2/actions) [![codecov](https://codecov.io/gh/pik-piam/remind2/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/remind2) [![r-universe](https://pik-piam.r-universe.dev/badges/remind2)](https://pik-piam.r-universe.dev/builds) @@ -49,16 +49,17 @@ In case of questions / problems please contact Renato Rodrigues . +Rodrigues R, Baumstark L, Benke F, Dietrich J, Dirnaichner A, Duerrwaechter J, Führlich P, Giannousakis A, Hasse R, Hilaire J, Klein D, Koch J, Kowalczyk K, Levesque A, Malik A, Merfort A, Merfort L, Morena-Leiva S, Pehl M, Pietzcker R, Rauner S, Richters O, Rottoli M, Schötz C, Schreyer F, Siala K, Sörgel B, Spahr M, Strefler J, Verpoort P, Weigmann P, Rüter T (2024). "remind2: The REMIND R package (2nd generation)." Version: 1.162.1, . A BibTeX entry for LaTeX users is ```latex -@Manual{, +@Misc{, title = {remind2: The REMIND R package (2nd generation)}, author = {Renato Rodrigues and Lavinia Baumstark and Falk Benke and Jan Philipp Dietrich and Alois Dirnaichner and Jakob Duerrwaechter and Pascal Führlich and Anastasis Giannousakis and Robin Hasse and Jérome Hilaire and David Klein and Johannes Koch and Katarzyna Kowalczyk and Antoine Levesque and Aman Malik and Anne Merfort and Leon Merfort and Simón Morena-Leiva and Michaja Pehl and Robert Pietzcker and Sebastian Rauner and Oliver Richters and Marianna Rottoli and Christof Schötz and Felix Schreyer and Kais Siala and Björn Sörgel and Mike Spahr and Jessica Strefler and Philipp Verpoort and Pascal Weigmann and Tonn Rüter}, + date = {2024-12-18}, year = {2024}, - note = {R package version 1.162.0}, url = {https://github.com/pik-piam/remind2}, + note = {Version: 1.162.1}, } ``` diff --git a/man/loadCs2Data.Rd b/man/loadCs2Data.Rd index d081d3f9..6ea3e4d8 100644 --- a/man/loadCs2Data.Rd +++ b/man/loadCs2Data.Rd @@ -17,7 +17,7 @@ loadCs2Data( If the vector has names, those are used to refer to the scenarios in the output file.} -\item{mifHist}{\code{character(1)}. Path to historical mif.} +\item{mifHist}{\code{character(1)}. Path to historical mif or \code{NULL}.} \item{cfgScen, cfgDefault}{See section "YAML Parameters" in \link[=compareScenarios]{compareScenarios()}.} diff --git a/man/reportEmiAirPol.Rd b/man/reportEmiAirPol.Rd index 0864bf1b..9ea277e9 100644 --- a/man/reportEmiAirPol.Rd +++ b/man/reportEmiAirPol.Rd @@ -29,7 +29,9 @@ Read in air pollution emission information from GDX file, information used in convGDX2MIF.R for the reporting } \examples{ -\dontrun{reportEmiAirPol(gdx)} +\dontrun{ +reportEmiAirPol(gdx) +} } \seealso{