Skip to content

Commit

Permalink
change gdx ref naming, fix aggregation in reportPrices
Browse files Browse the repository at this point in the history
  • Loading branch information
orichters committed Jun 7, 2023
1 parent f9286b0 commit a3670c6
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '216772896'
ValidationKey: '217006800'
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.111.2
date-released: '2023-06-03'
version: 1.112.0
date-released: '2023-06-07'
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.111.2
Date: 2023-06-03
Version: 1.112.0
Date: 2023-06-07
Authors@R: c(
person("Renato", "Rodrigues", , "renato.rodrigues@pik-potsdam.de", role = c("aut", "cre")),
person("Lavinia", "Baumstark", role = "aut"),
Expand Down
2 changes: 1 addition & 1 deletion R/colorScenConf.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ colorScenConf <- function(fileList = "", remindPath = ".", expanddata = FALSE) {
try(cfg$gms[["regionmapping"]] <- cfg$regionmapping)
try(cfg$gms[["inputRevision"]] <- cfg$inputRevision)

if (fileList == "") {
if (fileList == "" || length(fileList) == 0) {
cat("Specify folder with .csv files. The script also searches in subdirectories.\n")
cat(paste0("Press enter to use current: ", getwd(), ".\n"))
folder <- getLine()
Expand Down
22 changes: 11 additions & 11 deletions R/convGDX2MIF.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@
#'
#'
#' @param gdx a GDX as created by readGDX, or the file name of a gdx
#' @param gdx_ref reference-gdx for policy costs, a GDX as created by readGDX, or the file name of a gdx
#' @param gdx_ref reference-gdx for < cm_startyear, used for fixing the prices to this scenario
#' @param file name of the mif file which will be written, if no name is
#' provided a magpie object containing all the reporting information is
#' returned
#' @param scenario scenario name that is used in the *.mif reporting
#' @param t temporal resolution of the reporting, default:
#' t=c(seq(2005,2060,5),seq(2070,2110,10),2130,2150)
#' @param gdx_refprices reference-gdx for < cm_startyear, used for fixing the prices to this scenario
#' @param gdx_refpolicycost reference-gdx for policy costs, a GDX as created by readGDX, or the file name of a gdx
#' @author Lavinia Baumstark
#' @examples
#'
#' \dontrun{convGDX2MIF(gdx,gdx_ref,file="REMIND_generic_default.csv",scenario="default")}
#' \dontrun{convGDX2MIF(gdx,gdx_refpolicycost,file="REMIND_generic_default.csv",scenario="default")}
#'
#' @export
#' @importFrom gdx readGDX
#' @importFrom magclass mbind write.report

convGDX2MIF <- function(gdx, gdx_ref = NULL, file = NULL, scenario = "default",
t = c(seq(2005, 2060, 5), seq(2070, 2110, 10), 2130, 2150),
gdx_refprices = NULL) {
gdx_refpolicycost = gdx_ref) {

# Define region subsets
regionSubsetList <- toolRegionSubsets(gdx)
Expand Down Expand Up @@ -70,7 +70,7 @@ convGDX2MIF <- function(gdx, gdx_ref = NULL, file = NULL, scenario = "default",
message("running reportTechnology...")
output <- mbind(output,reportTechnology(gdx,output,regionSubsetList,t)[,t,]) # needs output from reportSE
message("running reportPrices...")
output <- mbind(output,reportPrices(gdx,output,regionSubsetList,t,gdx_ref = gdx_refprices)[,t,]) # needs output from reportSE, reportFE, reportEmi, reportExtraction, reportMacroEconomy
output <- mbind(output,reportPrices(gdx,output,regionSubsetList,t,gdx_ref = gdx_ref)[,t,]) # needs output from reportSE, reportFE, reportEmi, reportExtraction, reportMacroEconomy
message("running reportCosts...")
output <- mbind(output,reportCosts(gdx,output,regionSubsetList,t)[,t,]) # needs output from reportEnergyInvestment, reportPrices, reportEnergyInvestments
message("running reportTax...")
Expand All @@ -82,22 +82,22 @@ 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_ref)) {
if (file.exists(gdx_ref)) {
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_ref,"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_ref)), "/", basename(gdx_ref), "...")
output <- mbind(output,reportPolicyCosts(gdx,gdx_ref,regionSubsetList,t)[,t,])
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."))
}
} 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."))
}
} else {
warning(paste0("File ",gdx_ref," not found. Did not execute 'reportPolicyCosts'! If a policy costs reporting is desired, please use the 'policyCosts' output.R script."))
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."))
}
}

Expand Down
28 changes: 12 additions & 16 deletions R/reportPrices.R
Original file line number Diff line number Diff line change
Expand Up @@ -699,8 +699,9 @@ reportPrices <- function(gdx, output=NULL, regionSubsetList=NULL,
out.reporting <- lowpass(out.reporting)
# reset values for years smaller than cm_startyear to avoid inconsistencies in cm_startyear - 5
if (! is.null(gdx_ref)) {
message("reportPrices loads price for < cm_startyear from gdx_ref.")
priceRef <- try(reportPrices(gdx_ref, output = NULL, regionSubsetList = regionSubsetList, t = t))
fixedyears <- getYears(out)[getYears(out, as.integer = TRUE) < as.integer(cm_startyear)]
fixedyears <- getYears(out)[getYears(out, as.integer = TRUE) < cm_startyear]
if (! inherits(priceRef, "try-error") && length(fixedyears) > 0) {
out.reporting[, fixedyears, ] <- priceRef[getRegions(out), fixedyears, getNames(out)]
}
Expand Down Expand Up @@ -919,6 +920,16 @@ reportPrices <- function(gdx, output=NULL, regionSubsetList=NULL,
"Price|Final Energy|Industry|Solids (US$2005/GJ)" = "FE|Industry|Solids (EJ/yr)"
)

# transport-specific mappings depending on realization
if (module2realisation["transport",2] == "complex") {
int2ext <- c(int2ext,
"Price|Final Energy|Transport|Liquids|HDV (US$2005/GJ)" = "FE|Transport|non-LDV|Liquids (EJ/yr)",
"Price|Final Energy|Transport|Liquids|LDV (US$2005/GJ)" = "FE|Transport|LDV|Liquids (EJ/yr)")
} else if (module2realisation["transport",2] == "edge_esm") {
int2ext <- c(int2ext,
"Price|Final Energy|Transport|Liquids|HDV (US$2005/GJ)" = "FE|Transport|Diesel Liquids (EJ/yr)",
"Price|Final Energy|Transport|Liquids|LDV (US$2005/GJ)" = "FE|Transport|Pass|Liquids (EJ/yr)")
}

## add weights definition for region aggregation for FE prices that were added automatically
if(length(pm_FEPrice_by_FE) > 0) {
Expand All @@ -936,21 +947,6 @@ reportPrices <- function(gdx, output=NULL, regionSubsetList=NULL,
int2ext <- c(int2ext, vars)
}

# transport-specific mappings depending on realization

if (module2realisation["transport",2] == "complex") {
int2ext <- c(int2ext,
"Price|Final Energy|Transport|Liquids|HDV (US$2005/GJ)" = "FE|Transport|non-LDV|Liquids (EJ/yr)",
"Price|Final Energy|Transport|Liquids|LDV (US$2005/GJ)" = "FE|Transport|LDV|Liquids (EJ/yr)")
} else if (module2realisation["transport",2] == "edge_esm") {
int2ext <- c(int2ext,
"Price|Final Energy|Transport|Liquids|HDV (US$2005/GJ)" = "FE|Transport|Diesel Liquids (EJ/yr)",
"Price|Final Energy|Transport|Liquids|LDV (US$2005/GJ)" = "FE|Transport|Pass|Liquids (EJ/yr)",
"Price|Final Energy|Transport|Gases (US$2005/GJ)" = "FE|Transport|Gases (EJ/yr)")
}



## moving averages and rawdata
avgs <- getNames(out.lowpass)
rawdata <- getNames(out.rawdata)
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.111.2**
R package **remind2**, version **1.112.0**

[![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.111.2, <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.112.0, <URL: 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.111.2},
note = {R package version 1.112.0},
url = {https://github.com/pik-piam/remind2},
}
```
8 changes: 4 additions & 4 deletions man/convGDX2MIF.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/test-convGDX2mif.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ test_that("Test if REMIND reporting is produced as it should and check data inte
for (gdxPath in gdxPaths) {
numberOfMifs <- numberOfMifs + 1
message("Running convGDX2MIF(", gdxPath, ")...")
mifContent <- convGDX2MIF(gdxPath, gdx_ref = gdxPath)
mifContent <- convGDX2MIF(gdxPath, gdx_refpolicycost = gdxPath)
message("Checking integrity of created MIF...")
checkIntegrity(mifContent, gdxPath)
magclass::write.report(
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-piamInterfaces-Ariadne.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test_that("Test if REMIND reporting produces mandatory variables for Ariadne rep
mode = "wb", quiet = TRUE
)

mif <- convGDX2MIF(gdxPath, gdx_ref = gdxPath)
mif <- convGDX2MIF(gdxPath, gdx_refpolicycost = gdxPath)

computedVariables <- getItems(mif, dim = 3.3)

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-piamInterfaces-NAVIGATE.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test_that("Test if REMIND reporting produces mandatory variables for NAVIGATE re
mode = "wb", quiet = TRUE
)

mif <- convGDX2MIF(gdxPath, gdx_ref = gdxPath)
mif <- convGDX2MIF(gdxPath, gdx_refpolicycost = gdxPath)

computedVariables <- getItems(mif, dim = 3.3)

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-piamInterfaces-NGFS.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test_that("Test if REMIND reporting produces mandatory variables for NGFS report
mode = "wb", quiet = TRUE
)

mif <- convGDX2MIF(gdxPath, gdx_ref = gdxPath)
mif <- convGDX2MIF(gdxPath, gdx_refpolicycost = gdxPath)

computedVariables <- getItems(mif, dim = 3.3)

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-piamInterfaces-SHAPE.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test_that("Test if REMIND reporting produces mandatory variables for SHAPE repor
mode = "wb", quiet = TRUE
)

mif <- convGDX2MIF(gdxPath, gdx_ref = gdxPath)
mif <- convGDX2MIF(gdxPath, gdx_refpolicycost = gdxPath)

computedVariables <- getItems(mif, dim = 3.3)

Expand Down

0 comments on commit a3670c6

Please sign in to comment.