Skip to content

Commit

Permalink
merge upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardarosemann committed Feb 9, 2024
2 parents 22193a7 + b2b4af7 commit 2b94981
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '2239183459760'
ValidationKey: '223942984'
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
- 'Warning: namespace ''.*'' is not available and has been replaced'
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -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.133.1.9001
date-released: '2024-02-07'
version: 1.134.2
date-released: '2024-02-08'
abstract: Contains the REMIND-specific routines for data and model output manipulation.
authors:
- family-names: Rodrigues
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: remind2
Title: The REMIND R package (2nd generation)
Version: 1.133.1.9001
Date: 2024-02-07
Version: 1.134.2
Date: 2024-02-08
Authors@R: c(
person("Renato", "Rodrigues", , "[email protected]", role = c("aut", "cre")),
person("Lavinia", "Baumstark", role = "aut"),
Expand Down
37 changes: 22 additions & 15 deletions R/convGDX2MIF.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,30 @@ convGDX2MIF <- function(gdx, gdx_ref = NULL, file = NULL, scenario = "default",
output <- mbind(output,reportCrossVariables(gdx,output,regionSubsetList,t)[,t,])

# Report policy costs, if possible and sensible
if(!is.null(gdx_refpolicycost)) {
if (file.exists(gdx_refpolicycost)) {
gdp_scen <- try(readGDX(gdx,"cm_GDPscen",react ="error"),silent=T)
gdp_scen_ref <- try(readGDX(gdx_refpolicycost,"cm_GDPscen",react = "error"),silent=T)
if(!inherits(gdp_scen,"try-error") && !inherits(gdp_scen_ref,"try-error")){
if(gdp_scen[1]==gdp_scen_ref[1]){
message("running reportPolicyCosts, comparing to ", basename(dirname(gdx_refpolicycost)), "/", basename(gdx_refpolicycost), "...")
output <- mbind(output,reportPolicyCosts(gdx,gdx_refpolicycost,regionSubsetList,t)[,t,])
} else {
warning(paste0("The GDP scenario differs from that of the reference run. Did not execute 'reportPolicyCosts'! If a policy costs reporting is desired, please use the 'policyCosts' output.R script."))
}
if (!is.null(gdx_refpolicycost)) {
gdx_refpolicycost <- gdx
message("gdx_refpolicycost not defined, report 0 everywhere.")
}
if (file.exists(gdx_refpolicycost)) {
gdp_scen <- try(readGDX(gdx, "cm_GDPscen", react = "error"), silent = TRUE)
gdp_scen_ref <- try(readGDX(gdx_refpolicycost, "cm_GDPscen", react = "error"), silent = TRUE)
if (! inherits(gdp_scen, "try-error") && ! inherits(gdp_scen_ref, "try-error")) {
if (gdp_scen[1] == gdp_scen_ref[1]) {
file_refpolicycost <- paste0(basename(dirname(gdx_refpolicycost)), "/", basename(gdx_refpolicycost))
message("running reportPolicyCosts, comparing to ", file_refpolicycost, "...")
output <- mbind(output, reportPolicyCosts(gdx, gdx_refpolicycost, regionSubsetList, t)[,t,])
} else {
warning(paste0("A comparison of the GDP scenarios between this run and its reference run wasn't possible (old remind version). Therefore to avoid reporting unsensible policy costs, 'reportPolicyCosts' was not executed. If a policy costs reporting is required, please use the 'policyCosts' output.R script."))
warning("The GDP scenario differs from that of the reference run. Did not execute 'reportPolicyCosts'! ",
"If a policy costs reporting is desired, please use the 'policyCosts' output.R script.")
}
} else {
warning(paste0("File ",gdx_refpolicycost," not found. Did not execute 'reportPolicyCosts'! If a policy costs reporting is desired, please use the 'policyCosts' output.R script."))
warning("A comparison of the GDP scenarios between this run and its reference run wasn't possible (old remind version). ",
"Therefore to avoid reporting unsensible policy costs, 'reportPolicyCosts' was not executed. ",
"If a policy costs reporting is required, please use the 'policyCosts' output.R script.")
}
} else {
warning(paste0("File ", gdx_refpolicycost, " not found. Did not execute 'reportPolicyCosts'! ",
"If a policy costs reporting is desired, please use the 'policyCosts' output.R script."))
}

# reporting of SDP variables
Expand All @@ -128,7 +135,7 @@ convGDX2MIF <- function(gdx, gdx_ref = NULL, file = NULL, scenario = "default",

capture.output(
sumChecks <- checkSummations(
mifFile = output, outputDirectory = NULL,
mifFile = output, dataDumpFile = NULL, outputDirectory = NULL,
summationsFile = "extractVariableGroups",
absDiff = 1.5e-8, relDiff = 1e-8, roundDiff = TRUE
) %>%
Expand All @@ -137,7 +144,7 @@ convGDX2MIF <- function(gdx, gdx_ref = NULL, file = NULL, scenario = "default",
.reportSummationErrors()

capture.output(sumChecks <- checkSummations(
mifFile = output, outputDirectory = NULL,
mifFile = output, dataDumpFile = NULL, outputDirectory = NULL,
summationsFile = system.file('extdata/additional_summation_checks.csv',
package = 'remind2'),
absDiff = 1.5e-8, relDiff = 1e-8, roundDiff = TRUE) %>%
Expand Down
37 changes: 21 additions & 16 deletions R/reportEmi.R
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,6 @@ reportEmi <- function(gdx, output = NULL, regionSubsetList = NULL, t = c(seq(200
}




# calculate total energy supply and demand co2 emissions
out <- mbind(out,

Expand All @@ -496,14 +494,15 @@ reportEmi <- function(gdx, output = NULL, regionSubsetList = NULL, t = c(seq(200
setNames((dimSums(EmiFeCarrier, dim = 3)
# subtract industry CCS
- dimSums(vm_emiIndCCS[, , emiInd37_fuel], dim = 3)*p_share_CCS
# subtract synthetic and biogenic carbon contained in industrial feedstocks
# subtract synthetic and biogenic carbon contained in chemical feedstocks that don't return to the atmosphere (e.g. non-incinerated plastics)
- dimSums(plastic_CDR, dim=3)
)*GtC_2_MtCO2,
"Emi|CO2|Energy|+|Demand (Mt CO2/yr)")

)

# CO2 emissions from the end-of-life of carbon-bearing products

if (!is.null(vm_plasticsCarbon)) {
out <- mbind(out,
setNames(dimSums(vm_feedstockEmiUnknownFate, dim=3)* GtC_2_MtCO2,
Expand Down Expand Up @@ -1116,11 +1115,13 @@ if (!is.null(vm_plasticsCarbon)) {
setNames(
# vm_emiTeMkt is variable in REMIND closest to energy co2 emissions
(dimSums(sel_vm_emiTeMkt_co2, dim = 3)
# subtract non-BECCS CCU CO2 (i.e., non-CCS part of DAC)
# subtract non-BECCS CCU CO2 (i.e., non-CCS part of DAC (synfuels))
- (1 - p_share_CCS) * (-vm_emiCdrTeDetail[, , "dac"])
# deduce co2 captured by industrial processes which is not stored but used for CCU
# deduce co2 captured by industrial processes which is not stored but used for CCU (synfuels)
# -> gets accounted in industrial process emissions
- vm_emiIndCCS[, , "co2cement_process"]*(1-p_share_CCS)) * GtC_2_MtCO2,
- vm_emiIndCCS[, , "co2cement_process"]*(1-p_share_CCS)
# fixme: missing/wrong emissions
) * GtC_2_MtCO2,
"Emi|CO2|+|Energy (Mt CO2/yr)"))

### 2.2 Non-energy CO2 emissions ----
Expand Down Expand Up @@ -2558,6 +2559,7 @@ if (!is.null(vm_plasticsCarbon)) {

# (Note: The non-energy use variables are so far only available for REMIND-EU runs and industry fixed_shares)
# TODO: add non-energy use variables for all regionmappings and sector realizations
if (is.null(vm_demFENonEnergySector) && (module2realisation["industry", 2] == "fixed_shares")) {

# Note: Non-energy use emissions should not be confused with process emissions. Non-energy use emissions are emissions/carbon flow of FE carriers which are used as feedstocks in industry.
if ("FE|Non-energy Use|Industry (EJ/yr)" %in% getNames(output) &&
Expand Down Expand Up @@ -2680,7 +2682,7 @@ if (!is.null(vm_plasticsCarbon)) {
out <- mbind(out, out.wNonEn)

}

}
# add global values
out <- mbind(out, dimSums(out, dim = 1))
# add other region aggregations
Expand Down Expand Up @@ -2758,11 +2760,13 @@ if (!is.null(vm_plasticsCarbon)) {

}

# if non-energy use variables exist, also do bunker correction for variables w/o non-energy use
if ("FE|Non-energy Use|Industry (EJ/yr)" %in% getNames(output) &&
"FE|Non-energy Use|Industry|+|Liquids (EJ/yr)" %in% getNames(output) &&
"FE|Non-energy Use|Industry|+|Gases (EJ/yr)" %in% getNames(output) &&
"FE|Non-energy Use|Industry|+|Solids (EJ/yr)" %in% getNames(output)) {
# if non-energy use variables exist, also do bunker correction for variables
# w/o non-energy use
if ( "FE|Non-energy Use|Industry (EJ/yr)" %in% getNames(output)
&& "FE|Non-energy Use|Industry|+|Liquids (EJ/yr)" %in% getNames(output)
&& "FE|Non-energy Use|Industry|+|Gases (EJ/yr)" %in% getNames(output)
&& "FE|Non-energy Use|Industry|+|Solids (EJ/yr)" %in% getNames(output)
&& exists('emi.vars.wNonEn')) {

emi.vars.wBunkers.wNonEn <- intersect(emi.vars.wBunkers, emi.vars.wNonEn)

Expand All @@ -2786,10 +2790,11 @@ if (!is.null(vm_plasticsCarbon)) {
"Emi|CO2|LULUCF national accounting (Mt CO2/yr)" )

# add bunker correction for emissions variables with LULUCF national accounting and w/o non-energy use
if ("FE|Non-energy Use|Industry (EJ/yr)" %in% getNames(output) &&
"FE|Non-energy Use|Industry|+|Liquids (EJ/yr)" %in% getNames(output) &&
"FE|Non-energy Use|Industry|+|Gases (EJ/yr)" %in% getNames(output) &&
"FE|Non-energy Use|Industry|+|Solids (EJ/yr)" %in% getNames(output)) {
if ( "FE|Non-energy Use|Industry (EJ/yr)" %in% getNames(output)
&& "FE|Non-energy Use|Industry|+|Liquids (EJ/yr)" %in% getNames(output)
&& "FE|Non-energy Use|Industry|+|Gases (EJ/yr)" %in% getNames(output)
&& "FE|Non-energy Use|Industry|+|Solids (EJ/yr)" %in% getNames(output)
&& exists('emi.vars.wNonEn')) {

emi.vars.wBunkers <- c(emi.vars.wBunkers,
"Emi|GHG|w/o Non-energy Use|LULUCF national accounting (Mt CO2eq/yr)",
Expand Down
1 change: 1 addition & 0 deletions R/reportFE.R
Original file line number Diff line number Diff line change
Expand Up @@ -1761,6 +1761,7 @@ reportFE <- function(gdx, regionSubsetList = NULL,
out[,,"FE|Non-energy Use|Industry|Solids|+|Fossil (EJ/yr)"],
"FE|w/o Bunkers|w/o Non-energy Use|Solids|Fossil (EJ/yr)"))
}
### end of "### temporary (!) industry non-energy use reporting" for Ariadne

# in case the current non-energy use implementation creates negative values, set them to 0
if (any(out < 0)) {
Expand Down
10 changes: 9 additions & 1 deletion 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.133.1.9001**
R package **remind2**, version **1.134.2**

[![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,11 @@ In case of questions / problems please contact Renato Rodrigues <renato.rodrigue

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

<<<<<<< HEAD
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 (2024). _remind2: The REMIND R package (2nd generation)_. R package version 1.133.1.9001, <https://github.com/pik-piam/remind2>.
=======
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 (2024). _remind2: The REMIND R package (2nd generation)_. R package version 1.134.2, <URL: https://github.com/pik-piam/remind2>.
>>>>>>> b2b4af75788a807dea0a79e58451fc0b9eab6f3a
A BibTeX entry for LaTeX users is

Expand All @@ -58,7 +62,11 @@ 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 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},
year = {2024},
<<<<<<< HEAD
note = {R package version 1.133.1.9001},
=======
note = {R package version 1.134.2},
>>>>>>> b2b4af75788a807dea0a79e58451fc0b9eab6f3a
url = {https://github.com/pik-piam/remind2},
}
```
27 changes: 14 additions & 13 deletions inst/markdown/compareScenarios2/cs2_01_summary.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## GHG Emissions

```{r summary GHG emissions}
```{r GHG emissions}
tot <- "Emi|GHG"
items <- c(
"Emi|CO2|Energy",
Expand All @@ -17,9 +17,9 @@ items <- c(
showAreaAndBarPlots(data, items, tot, scales = "fixed")
```

## GHG by sector (w/ gross emissions, excl. negative emissions from CCS of non-fossil carbon)
## GHG by sector

```{r summary GHG by sector}
```{r GHG by sector (w/ gross emissions, excl. negative emissions from CCS of non-fossil carbon)}
tot <- "Emi|GHG"
items <- c(
"Emi|GHG|Gross|Energy|Supply|Electricity",
Expand All @@ -45,9 +45,9 @@ showAreaAndBarPlots(data, items, tot, scales = "fixed")
showAreaAndBarPlots(data, paste(items, "pCap"), paste(tot, "pCap"), scales = "fixed")
```

## CO2 by sector (w/ gross emissions, excl. negative emissions from CCS of non-fossil carbon)
## CO2 by sector

```{r CO2 by sector}
```{r CO2 by sector (w/ gross emissions, excl. negative emissions from CCS of non-fossil carbon)}
tot <- "Emi|CO2"
items <- c(
"Emi|CO2|Land-Use Change",
Expand All @@ -72,9 +72,9 @@ showAreaAndBarPlots(data, paste(items, "pCap"), paste(tot, "pCap"), scales = "fi
```


### CO2 cumulated by sector (w/ gross emissions, excl. negative emissions from CCS of non-fossil carbon)
### CO2 cumulated by sector

```{r CO2 cumulated by sector}
```{r CO2 cumulated by sector (w/ gross emissions, excl. negative emissions from CCS of non-fossil carbon)}
tot <- "Emi|CO2|Cumulated"
items <- c(
"Emi|CO2|Cumulated|Land-Use Change",
Expand Down Expand Up @@ -106,7 +106,7 @@ showAreaAndBarPlots(data, items, scales = "fixed")

## FE per capita (by sector, time domain, area plot)

```{r FE per capita area plot}
```{r FE per capita (by sector, time domain, area plot)}
items <- c(
"FE|Transport pCap",
"FE|Buildings pCap",
Expand All @@ -116,7 +116,7 @@ showAreaAndBarPlots(data, items, scales = "fixed")

## FE per capita (by sector, time domain, line graph)

```{r FE per capita line plot}
```{r FE per capita (by sector, time domain, line graph)}
dIea <- data %>%
# To make the plots less crowded, show only IEA historical data.
filter(scenario != "historical" | model == "IEA")
Expand All @@ -130,16 +130,17 @@ showMultiLinePlots(dIea, items, scales = "fixed")

## FE per capita (by sector, GDP)

```{r FE per capita}
```{r FE per capita (by sector, GDP)}
dIea <- data %>%
# To make the plots less crowded, show only IEA historical data.
filter(scenario != "historical" | model == "IEA")
showMultiLinePlotsByVariable(dIea, "FE pCap", "GDP|PPP pCap")
showMultiLinePlotsByVariable(dIea, "FE pCap", "GDP|PPP pCap", showGlobal = TRUE)
items <- c(
"FE|Transport pCap",
"FE|Buildings pCap",
"FE|Industry pCap")
showMultiLinePlotsByVariable(dIea, items, "GDP|PPP pCap", scales = "fixed")
showMultiLinePlotsByVariable(dIea, items, "GDP|PPP pCap", scales = "fixed", showGlobal = TRUE)
```

## FE by carrier
Expand Down Expand Up @@ -184,7 +185,7 @@ showAreaAndBarPlots(data, items, orderVars = "user", scales = "fixed")

## FE Industry by carrier (incl. non-energy use)

```{r FE Industry by carrier}
```{r FE Industry by carrier (incl. non-energy use)}
items <- c(
"FE|Industry|Electricity",
"FE|Industry|Hydrogen",
Expand Down
14 changes: 7 additions & 7 deletions inst/markdown/compareScenarios2/cs2_02_macro.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ walk(vars, showLinePlots, data = dPrice, scale = "fixed")
```{r FE Transport Prices}
carriers <- c("Solids", "Liquids", "Gases", "Hydrogen", "Heat", "Electricity")
vars <- intersect(paste0("Price|Final Energy|Transport|", carriers),
carrierslevels(dPrice$variable))
levels(dPrice$variable))
walk(vars, showLinePlots, data = dPrice, scale = "fixed")
```

Expand All @@ -204,19 +204,19 @@ vars <-
walk(vars, showLinePlots, data = data)
```

## FE intensity of GDP
## FE intensity of GDP_PPP, area plot

```{r FE intensity of GDP_PPP}
```{r FE intensity of GDP_PPP, area plot (by sector)}
items <- c(
"FE|Transport pGDP_PPP",
"FE|Buildings pGDP_PPP",
"FE|Industry pGDP_PPP")
showAreaAndBarPlots(data, items, scales = "fixed")
```

## FE intensity of GDP_PPP, linegraph (by pGDP_PPP)
## FE intensity of GDP_PPP, line plot

```{r FE intensity of GDP_PPP, linegraph}
```{r FE intensity of GDP_PPP, line plot (by sector)}
dIea <-
data %>%
# To make the plots less crowded, show only IEA historical data.
Expand Down Expand Up @@ -288,7 +288,7 @@ kayaRel <-
### Absolute

```{r Kaya Decomposition Absolute}
showMultiLinePlots(kaya, kayaVars)
showMultiLinePlots(kaya, kayaVars, NROW_NUM = 2)
walk(kayaVars, showRegiLinePlots, data = kaya)
```

Expand All @@ -297,7 +297,7 @@ cat("### Relative to ", refYear, "\n")
```

```{r Kaya Decomposition Relative}
showMultiLinePlots(kayaRel, kayaVars)
showMultiLinePlots(kayaRel, kayaVars, NROW_NUM = 2)
walk(kayaVars, showRegiLinePlots, data = kayaRel)
```

Expand Down
14 changes: 9 additions & 5 deletions inst/markdown/compareScenarios2/cs2_06_energy_services.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,17 @@ if ("UE|Buildings|Heating|Electricity|Heat pump pCap" %in% data[["variable"]]) {
items <- c(
"FE|Buildings|Heating",
"FE|Buildings|Appliances and Light",
"FE|Buildings|Cooking and Water",
"FE|Buildings|Cooking and Water")
showMultiLinePlots(data, items)
showMultiLinePlotsByVariable(data, items, "GDP|PPP pCap")
items <- c(
"FE|Buildings|Space Cooling",
"FE|Buildings|Space Heating")
showMultiLinePlots(data, items[1:3])
showMultiLinePlots(data, items[4:5])
showMultiLinePlotsByVariable(data, items[1:3], "GDP|PPP pCap")
showMultiLinePlotsByVariable(data, items[4:5], "GDP|PPP pCap")
showMultiLinePlots(data, items)
showMultiLinePlotsByVariable(data, items, "GDP|PPP pCap")
```


Expand Down
Loading

0 comments on commit 2b94981

Please sign in to comment.