Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add SE|Electricity and Cap|Electricity variables to reporting #435

Merged
merged 2 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '217876120'
ValidationKey: '217984806'
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.114.0
date-released: '2023-07-20'
version: 1.114.1
date-released: '2023-07-28'
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.114.0
Date: 2023-07-20
Version: 1.114.1
Date: 2023-07-28
Authors@R: c(
person("Renato", "Rodrigues", , "[email protected]", role = c("aut", "cre")),
person("Lavinia", "Baumstark", role = "aut"),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ importFrom(magclass,is.magpie)
importFrom(magclass,lowpass)
importFrom(magclass,magpie_expand)
importFrom(magclass,mbind)
importFrom(magclass,mcalc)
importFrom(magclass,mselect)
importFrom(magclass,ndata)
importFrom(magclass,new.magpie)
Expand Down
92 changes: 88 additions & 4 deletions R/reportCrossVariables.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' Read in GDX and calculate variables that need variables produced by other report*.R functions, used in convGDX2MIF.R for the
#' reporting
#' Read in GDX and calculate variables that need variables produced by other
#' report*.R functions, used in convGDX2MIF.R for the reporting
#'
#' Read in GDX and calculate variables that need variables produced by other report*.R functions
#'
Expand All @@ -12,15 +12,16 @@
#' @param t temporal resolution of the reporting, default:
#' t=c(seq(2005,2060,5),seq(2070,2110,10),2130,2150)
#'
#' @author Lavinia Baumstark
#' @author Lavinia Baumstark, Falk Benke
#' @examples
#'
#' \dontrun{reportCrossVariables(gdx)}
#'
#' @export
#' @importFrom assertr assert not_na
#' @importFrom gdx readGDX
#' @importFrom magclass getYears getRegions mbind setNames dimSums mselect new.magpie setYears
#' @importFrom magclass getYears getRegions mbind setNames dimSums mselect
#' new.magpie setYears mcalc
#' @importFrom luscale speed_aggregate
#' @importFrom tibble as_tibble
#' @importFrom tidyselect everything
Expand Down Expand Up @@ -383,5 +384,88 @@ reportCrossVariables <- function(gdx, output = NULL, regionSubsetList = NULL,
)
}

# add adjusted electricity from coal and other fossils ----
# read in projected electricity from waste and other fossils using energy demands from IEA Energy Balances.
projections <- read.csv(system.file("extdata", "se_otherfoss.cs4r", package = "remind2"),
sep = ",", skip = 0, header = FALSE
) %>%
mutate(!!sym("V4") := as.numeric(!!sym("V4"))) %>%
as.magpie(temporal = 1, spatial = 2)

# add global values
tmp <- dimSums(projections, dim = 1)
tmp <- setItems(tmp, 1, "GLO")
projections <- mbind(projections, tmp)

# check if all required regions are in projections, otherwise skip
if (length(setdiff(getItems(out, dim = 1), getItems(projections, dim = 1))) == 0) {
# if projections have more regions, remove extra regions
if (length(setdiff(getItems(projections, dim = 1), getItems(out, dim = 1))) > 0) {
projections <- projections[intersect(getItems(projections, dim = 1), getItems(out, dim = 1)), , ]
}

y <- intersect(getYears(projections), getYears(out))
out <- mbind(out, projections[, y, ])

# SE|Electricity|Other Fossil|Other Fossil Adjusted = min(
# SE|Electricity|Coal|w/o CC, SE|Electricity|Other Fossil|Projected);
tmp <- mbind(
output[, , "SE|Electricity|Coal|w/o CC (EJ/yr)"],
out[, , "SE|Electricity|Other Fossil|Projected (EJ/yr)"]
)
tmp <- mcalc(tmp, `SE|Electricity|Other Fossil|Other Fossil Adjusted (EJ/yr)` ~
ifelse(`SE|Electricity|Coal|w/o CC (EJ/yr)` < `SE|Electricity|Other Fossil|Projected (EJ/yr)`,
`SE|Electricity|Coal|w/o CC (EJ/yr)`, `SE|Electricity|Other Fossil|Projected (EJ/yr)`
),
append = FALSE
)
out <- mbind(out, tmp)

# SE|Electricity|Coal|w/o CC|Other Fossil Adjusted = SE|Electricity|Coal|w/o CC -
# SE|Electricity|Other Fossil|Other Fossil Adjusted;
tmp <- output[, , "SE|Electricity|Coal|w/o CC (EJ/yr)"] -
out[, , "SE|Electricity|Other Fossil|Other Fossil Adjusted (EJ/yr)"]
tmp[tmp < 0] <- 0
tmp <- setItems(tmp, 3, "SE|Electricity|Coal|w/o CC|Other Fossil Adjusted (EJ/yr)")
out <- mbind(out, tmp)

# SE|Electricity|Coal|Other Fossil Adjusted = SE|Electricity|Coal -
# SE|Electricity|Other Fossil|Other Fossil Adjusted;
tmp <- output[, , "SE|Electricity|Coal (EJ/yr)"] -
out[, , "SE|Electricity|Other Fossil|Other Fossil Adjusted (EJ/yr)"]
tmp[tmp < 0] <- 0
tmp <- setItems(tmp, 3, "SE|Electricity|Coal|Other Fossil Adjusted (EJ/yr)")
out <- mbind(out, tmp)

# OtherFossilShare = SE|Electricity|Other Fossil|Other Fossil Adjusted /
# SE|Electricity|Coal|w/o CC;
share <- out[, , "SE|Electricity|Other Fossil|Other Fossil Adjusted (EJ/yr)"] /
output[, , "SE|Electricity|Coal|w/o CC (EJ/yr)"]
share[is.na(share)] <- 0
share <- setItems(share, 3, "OtherFossilShare")

# Cap|Electricity|Other Fossil|Other Fossil Adjusted = Cap|Electricity|Coal|w/o CC * OtherFossilShare;
tmp <- output[, , "Cap|Electricity|Coal|w/o CC (GW)"] * share
tmp <- setItems(tmp, 3, "Cap|Electricity|Other Fossil|Other Fossil Adjusted (GW)")
out <- mbind(out, tmp)

# Cap|Electricity|Coal|w/o CC|Other Fossil Adjusted = Cap|Electricity|Coal|w/o CC -
# Cap|Electricity|Other Fossil|Other Fossil Adjusted;
tmp <- output[, , "Cap|Electricity|Coal|w/o CC (GW)"] -
out[, , "Cap|Electricity|Other Fossil|Other Fossil Adjusted (GW)"]
tmp <- setItems(tmp, 3, "Cap|Electricity|Coal|w/o CC|Other Fossil Adjusted (GW)")
out <- mbind(out, tmp)

# Cap|Electricity|Coal|Other Fossil Adjusted = Cap|Electricity|Coal -
# Cap|Electricity|Other Fossil|Other Fossil Adjusted;
tmp <- output[, , "Cap|Electricity|Coal (GW)"] -
out[, , "Cap|Electricity|Other Fossil|Other Fossil Adjusted (GW)"]
tmp <- setItems(tmp, 3, "Cap|Electricity|Coal|Other Fossil Adjusted (GW)")
out <- mbind(out, tmp)
} else {
warning("`SE|Electricity|Coal|Other Fossil Adjusted` and related variables
could not be calculated for this regional resolution")
}

return(out)
}
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.114.0**
R package **remind2**, version **1.114.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 (2023). _remind2: The REMIND R package (2nd generation)_. R package version 1.114.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 (2023). _remind2: The REMIND R package (2nd generation)_. R package version 1.114.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},
year = {2023},
note = {R package version 1.114.0},
note = {R package version 1.114.1},
url = {https://github.com/pik-piam/remind2},
}
```
Loading
Loading