Skip to content

Commit

Permalink
Merge pull request #480 from fschreyer/Summations
Browse files Browse the repository at this point in the history
correct additional_summations_check file and resolve minor summations inconsistencies for hydrogen/CCU variables
  • Loading branch information
fschreyer authored Oct 10, 2023
2 parents e402160 + aa1e523 commit 7704bba
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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", , "[email protected]", role = c("aut", "cre")),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 11 additions & 2 deletions R/reportEmi.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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 ----
Expand Down
41 changes: 38 additions & 3 deletions R/reportSE.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {

Expand Down Expand Up @@ -363,27 +364,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
Expand Down Expand Up @@ -415,6 +426,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(!!sym("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
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -49,7 +49,7 @@ In case of questions / problems please contact Renato Rodrigues <renato.rodrigue

To cite package **remind2** in publications use:

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.0, <URL: https://github.com/pik-piam/remind2>.
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, <https://github.com/pik-piam/remind2>.

A BibTeX entry for LaTeX users is

Expand All @@ -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},
}
```
22 changes: 17 additions & 5 deletions inst/extdata/additional_summation_checks.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,27 +26,30 @@ 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
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
Expand All @@ -59,13 +63,15 @@ 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
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
Expand All @@ -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
Expand All @@ -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

0 comments on commit 7704bba

Please sign in to comment.