From b405ce80ac04a92e958047578edef680e742dc4c Mon Sep 17 00:00:00 2001 From: Felix Schreyer Date: Mon, 9 Oct 2023 14:15:27 +0200 Subject: [PATCH 1/5] correct and update additional summations csv file --- inst/extdata/additional_summation_checks.csv | 22 +++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/inst/extdata/additional_summation_checks.csv b/inst/extdata/additional_summation_checks.csv index b676de07..a693231a 100644 --- a/inst/extdata/additional_summation_checks.csv +++ b/inst/extdata/additional_summation_checks.csv @@ -10,6 +10,7 @@ FE|Industry|Steel|++|Primary; FE|Industry|Steel|Primary|Electricity;1 # total FE secondary steel production;; FE|Industry|Steel|++|Secondary; FE|Industry|Steel|Secondary|Electricity;1 ;; +# total GHG emissions by sectors with separation into gross and negative emissions;; Emi|GHG;Emi|GHG|Gross|Energy|Supply|Electricity;1 Emi|GHG;Emi|GHG|Gross|Energy|Supply|Non-electric;1 Emi|GHG;Emi|GHG|Energy|Demand|+|Buildings;1 @@ -25,20 +26,22 @@ Emi|GHG;Emi|CO2|CDR|DACCS;1 Emi|GHG;Emi|CO2|CDR|Industry CCS|Synthetic Fuels;1 Emi|GHG;Emi|CO2|CDR|EW;1 ;; -Emi|CO2;Emi|CO2|+|Land-Use Change;1 -Emi|CO2;Emi|CO2|+|Industrial Processes;1 +# total CO2 emissions by sectors with separation into gross and negative emissions;; +Emi|CO2;Emi|CO2|Gross|Energy|Supply|+|Electricity;1 +Emi|CO2;Emi|CO2|Gross|Energy|Supply|Non-electric;1 Emi|CO2;Emi|CO2|Energy|Demand|+|Transport;1 Emi|CO2;Emi|CO2|Gross|Energy|Demand|+|Industry;1 Emi|CO2;Emi|CO2|Energy|Demand|+|Buildings;1 Emi|CO2;Emi|CO2|Energy|Demand|+|CDR;1 -Emi|CO2;Emi|CO2|Gross|Energy|Supply|Non-electric;1 -Emi|CO2;Emi|CO2|Gross|Energy|Supply|+|Electricity;1 +Emi|CO2;Emi|CO2|+|Land-Use Change;1 +Emi|CO2;Emi|CO2|+|Industrial Processes;1 Emi|CO2;Emi|CO2|CDR|BECCS;1 Emi|CO2;Emi|CO2|CDR|Industry CCS|Synthetic Fuels;1 Emi|CO2;Emi|CO2|CDR|DACCS;1 Emi|CO2;Emi|CO2|CDR|EW;1 -Emi|GHG;Emi|CO2|+|Energy;1 ;; +# total GHG emissions by CO2 sectors and non-CO2 gases;; +Emi|GHG 1;Emi|CO2|+|Energy;1 Emi|GHG 1;Emi|CO2|+|Industrial Processes;1 Emi|GHG 1;Emi|CO2|+|Land-Use Change;1 Emi|GHG 1;Emi|GHG|+|CH4;1 @@ -46,6 +49,7 @@ Emi|GHG 1;Emi|GHG|+|N2O;1 Emi|GHG 1;Emi|GHG|+|F-Gases;1 Emi|GHG 1;Emi|CO2|+|non-BECCS CDR;1 ;; +# cumulated total CO2 emissions by sectors with separation into gross and negative emissions;; Emi|CO2|Cumulated;Emi|CO2|Cumulated|Land-Use Change;1 Emi|CO2|Cumulated;Emi|CO2|Cumulated|Industrial Processes;1 Emi|CO2|Cumulated;Emi|CO2|Cumulated|Energy|Demand|Transport;1 @@ -59,6 +63,7 @@ Emi|CO2|Cumulated;Emi|CO2|Cumulated|CDR|Industry CCS|Synthetic Fuels;1 Emi|CO2|Cumulated;Emi|CO2|Cumulated|CDR|DACCS;1 Emi|CO2|Cumulated;Emi|CO2|Cumulated|CDR|EW;1 ;; +# total CDR;; Emi|CO2|CDR;Emi|CO2|CDR|Land-Use Change;1 Emi|CO2|CDR;Emi|CO2|CDR|BECCS|Pe2Se;1 Emi|CO2|CDR;Emi|CO2|CDR|BECCS|Industry;1 @@ -66,6 +71,7 @@ Emi|CO2|CDR;Emi|CO2|CDR|Industry CCS|Synthetic Fuels;1 Emi|CO2|CDR;Emi|CO2|CDR|DACCS;1 Emi|CO2|CDR;Emi|CO2|CDR|EW;1 ;; +# check balance of SE|Electricity electricity generation with the electricity demand variables by sector;; SE|Electricity;SE|Input|Electricity|Hydrogen|Synthetic Fuels|+|Liquids;1 SE|Electricity;SE|Input|Electricity|Hydrogen|Synthetic Fuels|+|Gases;1 SE|Electricity;SE|Input|Electricity|Hydrogen|direct FE H2;1 @@ -75,6 +81,9 @@ SE|Electricity;SE|Input|Electricity|Industry;1 SE|Electricity;SE|Input|Electricity|Transport;1 SE|Electricity;SE|Input|Electricity|CDR;1 SE|Electricity;SE|Input|Electricity|Self Consumption Energy System;1 +SE|Electricity;SE|Input|Electricity|PE Production;1 +;; +# check balance of SE|Hydrogen hydrogen generation with the hydrogen demand variables by sector;; SE|Hydrogen;FE|Industry|+|Hydrogen;1 SE|Hydrogen;FE|Buildings|+|Hydrogen;1 SE|Hydrogen;FE|Transport|+|Hydrogen;1 @@ -83,6 +92,9 @@ SE|Hydrogen;SE|Input|Hydrogen|Electricity|+|Normal Turbines;1 SE|Hydrogen;SE|Input|Hydrogen|Electricity|+|Forced VRE Turbines;1 SE|Hydrogen;SE|Input|Hydrogen|Synthetic Fuels|+|Liquids;1 SE|Hydrogen;SE|Input|Hydrogen|Synthetic Fuels|+|Gases;1 +SE|Hydrogen;SE|Input|Hydrogen|Other Energy System Consumption;1 ;; +# check balance of carbon sources and carbon sinks for carbon management variables;; Carbon Management|Carbon Capture;Carbon Management|Storage;1 Carbon Management|Carbon Capture;Carbon Management|Usage;1 +Carbon Management|Carbon Capture;Carbon Management|Venting of Captured Carbon;1 From 0e97ce5d6606b9ddb1e68f54ba30cf283ca91dfb Mon Sep 17 00:00:00 2001 From: Felix Schreyer Date: Mon, 9 Oct 2023 14:16:45 +0200 Subject: [PATCH 2/5] add carbon management variable for venting of captured CO2 to emissions reporting --- R/reportEmi.R | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/R/reportEmi.R b/R/reportEmi.R index 2d2f77d9..61b3c7c2 100644 --- a/R/reportEmi.R +++ b/R/reportEmi.R @@ -180,7 +180,7 @@ reportEmi <- function(gdx, output = NULL, regionSubsetList = NULL, t = c(seq(200 # CO2 released by CCU vm_co2CCUshort <- readGDX(gdx, "vm_co2CCUshort", field = "l", restore_zeros = F)[, t, ] - # helper variable to release captured CO2 in no CCU capacities are standing anymore to take the captured CO2 + # variable to release captured CO2 when no CCU capacities are standing anymore vent captured CO2 v_co2capturevalve <- readGDX(gdx, "v_co2capturevalve", field = "l", restore_zeros = F)[, t, ] # CO2 captured per industry subsector @@ -993,6 +993,8 @@ reportEmi <- function(gdx, output = NULL, regionSubsetList = NULL, t = c(seq(200 # (also adding first and second product emissions of coupled production technologies) + ### carbon capture + # calculate captured CO2 per pe2se technology sel_pm_emifac_pe2seCCO2 <- if(getSets(pm_emifac)[[6]] == "emiAll"){ mselect(pm_emifac, all_te = pe2se$all_te, emiAll = "cco2") @@ -1308,7 +1310,14 @@ reportEmi <- function(gdx, output = NULL, regionSubsetList = NULL, t = c(seq(200 } - + ### venting of captured carbon ---- + # This occurs when carbon capture capacities are still operating, + # while CCS/CCU capacities are deprecated and reach end of their lifetime. + # Then, captured carbon needs to be vented to the atmosphere. + out <- mbind(out, + # venting of captured carbon + setNames(dimSums(v_co2capturevalve, dim = 3, na.rm = T) * GtC_2_MtCO2, + "Carbon Management|Venting of Captured Carbon (Mt CO2/yr)")) ### carbon usage ---- From 14f6586b364e4b12ce8b100d5ddc6ea70e0377aa Mon Sep 17 00:00:00 2001 From: Felix Schreyer Date: Mon, 9 Oct 2023 14:18:32 +0200 Subject: [PATCH 3/5] add hydrogen demand variable for other energy system consumption based on vm_demSeOth in SE reporting --- R/reportSE.R | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/R/reportSE.R b/R/reportSE.R index a5e29c15..ea9efc35 100644 --- a/R/reportSE.R +++ b/R/reportSE.R @@ -363,27 +363,37 @@ reportSE <- function(gdx, regionSubsetList = NULL, t = c(seq(2005, 2060, 5), seq "SE|Gases|Hydrogen|Net Imports (EJ/yr)")) } - ## FS: SE Demand Reporting + # SE Demand Flows ---- + # SE|Input|X|Y variables denote the demand of energy carrier X + # flowing into sector/production of Y. - # FE production vm_demFeSector <- readGDX(gdx, "vm_demFeSector", field = "l", restore_zeros = F)[, y, ] * pm_conv_TWa_EJ vm_demFeSector[is.na(vm_demFeSector)] <- 0 # SE demand vm_demSe <- readGDX(gdx, "vm_demSe", field = "l", restore_zeros = F)[, y, ] * pm_conv_TWa_EJ + # SE demand of specific energy system technologies + vm_demSeOth <- readGDX(gdx, "vm_demSeOth", field = "l", restore_zeros = F)[, y, ] * pm_conv_TWa_EJ # conversion efficiency pm_eta_conv <- readGDX(gdx, "pm_eta_conv", field = "l", restore_zeros = F)[, y, ] + # hydrogen used for electricity production via H2 turbines tmp1 <- mbind(tmp1, setNames(dimSums(mselect(vm_demSe, all_enty = "seh2", all_enty1 = "seel"), dim = 3), "SE|Input|Hydrogen|Electricity (EJ/yr)"), setNames(dimSums(mselect(vm_demSe, all_enty = "seh2", all_enty1 = "seel", all_te = "h2turb"), dim = 3), "SE|Input|Hydrogen|Electricity|+|Normal Turbines (EJ/yr)"), setNames(dimSums(mselect(vm_demSe, all_enty = "seh2", all_enty1 = "seel", all_te = "h2turbVRE"), dim = 3), "SE|Input|Hydrogen|Electricity|+|Forced VRE Turbines (EJ/yr)") ) + # hydrogen used for synthetic fuels tmp1 <- mbind(tmp1, setNames(dimSums(mselect(vm_demSe, all_enty = "seh2", all_enty1 = c("seliqsyn", "segasyn"), all_te = c("MeOH", "h22ch4")), dim = 3), "SE|Input|Hydrogen|Synthetic Fuels (EJ/yr)"), setNames(dimSums(mselect(vm_demSe, all_enty = "seh2", all_enty1 = "seliqsyn", all_te = "MeOH"), dim = 3), "SE|Input|Hydrogen|Synthetic Fuels|+|Liquids (EJ/yr)"), setNames(dimSums(mselect(vm_demSe, all_enty = "seh2", all_enty1 = "segasyn", all_te = "h22ch4"), dim = 3), "SE|Input|Hydrogen|Synthetic Fuels|+|Gases (EJ/yr)") - ) + ) + # hydrogen used for other energy system technologies subsumed in vm_demSeOth + # e.g. co-firing of h2 in csp + tmp1 <- mbind(tmp1, + setNames(dimSums(mselect(vm_demSeOth, all_enty = "seh2"), dim = 3), + "SE|Input|Hydrogen|Other Energy System Consumption (EJ/yr)")) # SE electricity use From 227ddd68c814c275566321e505e8691c3db4fb2c Mon Sep 17 00:00:00 2001 From: Felix Schreyer Date: Mon, 9 Oct 2023 14:19:25 +0200 Subject: [PATCH 4/5] add electricity demand variable for electricity used for fuel production in SE reporting --- R/reportSE.R | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/R/reportSE.R b/R/reportSE.R index ea9efc35..f6f65912 100644 --- a/R/reportSE.R +++ b/R/reportSE.R @@ -425,6 +425,30 @@ reportSE <- function(gdx, regionSubsetList = NULL, t = c(seq(2005, 2060, 5), seq (dimSums(CoeffOwnConsSeel_woCCS[, , "geohe"] * prodOwnCons[, , "geohe"], dim = 3)), "SE|Input|Electricity|Self Consumption Energy System|Central Ground Heat Pump (EJ/yr)")) + # electricity for fuel extraction, e.g. electricity used for oil and gas extraction + pm_fuExtrOwnCons <- readGDX(gdx, "pm_fuExtrOwnCons", restore_zeros = F) + vm_fuExtr <- readGDX(gdx, "vm_fuExtr", field = "l", restore_zeros = F)[,y,] + pe2rlf <- readGDX(gdx, "pe2rlf") + pe2rlfemi <- pe2rlf %>% filter(all_enty %in% getNames(pm_fuExtrOwnCons, dim=2)) + + + + # calculate electricity for fuel extraction as in q32_balSe + # by multiplying fuel consumption of extraction with extraction quantities + tmp1 <- mbind(tmp1, + setNames( + # sum over all PE carriers and extraction grades + dimSums( + # sum over pm_fuExtrOwnCons to reduce all_enty dimensions + dimSums(mselect( pm_fuExtrOwnCons, all_enty = "seel"), dim = 3.1) + * vm_fuExtr[,,getNames(pm_fuExtrOwnCons, dim=2)], dim=3) + * pm_conv_TWa_EJ, + "SE|Input|Electricity|PE Production (EJ/yr)")) + + # set to zero in 2005 as the fuel production electricity demand is not included in the SE balance equation in this year + # due to incompatibilities with the InitialCap module + tmp1[,"y2005","SE|Input|Electricity|PE Production (EJ/yr)"] <- 0 + # share of electrolysis H2 in total H2 p_shareElec_H2 <- collapseNames(tmp1[, , "SE|Hydrogen|+|Electricity (EJ/yr)"] / tmp1[, , "SE|Hydrogen (EJ/yr)"]) p_shareElec_H2[is.na(p_shareElec_H2)] <- 0 From aa1e523ec7a3e583643f3330a89c69db77f75568 Mon Sep 17 00:00:00 2001 From: Felix Schreyer Date: Mon, 9 Oct 2023 17:10:32 +0200 Subject: [PATCH 5/5] upgrade library version --- .buildlibrary | 2 +- CITATION.cff | 2 +- DESCRIPTION | 2 +- NAMESPACE | 1 + R/reportSE.R | 3 ++- README.md | 6 +++--- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.buildlibrary b/.buildlibrary index 7ce312dc..3e417fda 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '219956800' +ValidationKey: '219976439' AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' - 'Warning: namespace ''.*'' is not available and has been replaced' diff --git a/CITATION.cff b/CITATION.cff index 4726ec1d..c920ca0b 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -2,7 +2,7 @@ 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.120.0 +version: 1.120.1 date-released: '2023-10-09' abstract: Contains the REMIND-specific routines for data and model output manipulation. authors: diff --git a/DESCRIPTION b/DESCRIPTION index 4126d634..95d15894 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: remind2 Title: The REMIND R package (2nd generation) -Version: 1.120.0 +Version: 1.120.1 Date: 2023-10-09 Authors@R: c( person("Renato", "Rodrigues", , "renato.rodrigues@pik-potsdam.de", role = c("aut", "cre")), diff --git a/NAMESPACE b/NAMESPACE index 9ab877f3..52ff200d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -278,6 +278,7 @@ importFrom(reshape2,melt) importFrom(rlang,.data) importFrom(rlang,.env) importFrom(rlang,is_empty) +importFrom(rlang,sym) importFrom(rlang,syms) importFrom(rmarkdown,render) importFrom(rmndt,approx_dt) diff --git a/R/reportSE.R b/R/reportSE.R index f6f65912..474a4775 100644 --- a/R/reportSE.R +++ b/R/reportSE.R @@ -22,6 +22,7 @@ #' @importFrom gdx readGDX #' @importFrom magclass mselect getSets getSets<- getYears dimSums getNames<- mbind #' @importFrom abind abind +#' @importFrom rlang sym reportSE <- function(gdx, regionSubsetList = NULL, t = c(seq(2005, 2060, 5), seq(2070, 2110, 10), 2130, 2150)) { @@ -429,7 +430,7 @@ reportSE <- function(gdx, regionSubsetList = NULL, t = c(seq(2005, 2060, 5), seq pm_fuExtrOwnCons <- readGDX(gdx, "pm_fuExtrOwnCons", restore_zeros = F) vm_fuExtr <- readGDX(gdx, "vm_fuExtr", field = "l", restore_zeros = F)[,y,] pe2rlf <- readGDX(gdx, "pe2rlf") - pe2rlfemi <- pe2rlf %>% filter(all_enty %in% getNames(pm_fuExtrOwnCons, dim=2)) + pe2rlfemi <- pe2rlf %>% filter(!!sym("all_enty") %in% getNames(pm_fuExtrOwnCons, dim=2)) diff --git a/README.md b/README.md index d848ffc7..373c0925 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # The REMIND R package (2nd generation) -R package **remind2**, version **1.120.0** +R package **remind2**, version **1.120.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,7 +49,7 @@ In case of questions / problems please contact Renato Rodrigues . +Rodrigues R, Baumstark L, Benke F, Dietrich J, Dirnaichner A, 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 (2023). _remind2: The REMIND R package (2nd generation)_. R package version 1.120.1, . A BibTeX entry for LaTeX users is @@ -58,7 +58,7 @@ A BibTeX entry for LaTeX users is 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 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}, year = {2023}, - note = {R package version 1.120.0}, + note = {R package version 1.120.1}, url = {https://github.com/pik-piam/remind2}, } ```