Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/pik-piam/remind2 into win…
Browse files Browse the repository at this point in the history
…dOffshore
  • Loading branch information
lecfab committed Sep 16, 2024
2 parents 023132c + c9ccfb4 commit ab6fbfa
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 943 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '229962240'
ValidationKey: '230562992'
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.152.0
date-released: '2024-08-27'
version: 1.154.2
date-released: '2024-09-10'
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.152.0
Date: 2024-08-27
Version: 1.154.2
Date: 2024-09-10
Authors@R: c(
person("Renato", "Rodrigues", , "[email protected]", role = c("aut", "cre")),
person("Lavinia", "Baumstark", role = "aut"),
Expand Down
92 changes: 47 additions & 45 deletions R/reportCosts.R

Large diffs are not rendered by default.

946 changes: 129 additions & 817 deletions R/reportEmi.R

Large diffs are not rendered by default.

73 changes: 6 additions & 67 deletions R/reportFE.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,47 +83,21 @@ reportFE <- function(gdx, regionSubsetList = NULL,
spatial = 2, restore_zeros = FALSE,
react = "silent")[, t, ] * TWa_2_EJ

if (length(vm_demFENonEnergySector) == 0) {
vm_demFENonEnergySector <- NULL
}

# only retain combinations of SE, FE, sector, and emiMkt which actually exist in the model (see qm_balFe)
vm_demFeSector <- vm_demFeSector[demFemapping]

# adding transport gas empty object to keep support to transport complex module
# TODO: can be removed because transport "complex" is not used anymore?
if(all(grep("fegat", getItems(vm_demFeSector, 3)) == 0)){
extended_vm_demFeSector <- new.magpie(getItems(vm_demFeSector, 1),
getItems(vm_demFeSector, 2),
c(getItems(vm_demFeSector, 3),
"segabio.fegat.trans.ETS",
"segafos.fegat.trans.ETS",
"segasyn.fegat.trans.ETS",
"segabio.fegat.trans.ES",
"segafos.fegat.trans.ES",
"segasyn.fegat.trans.ES",
"segabio.fegat.trans.other",
"segafos.fegat.trans.other",
"segasyn.fegat.trans.other"),
fill=0,
sets = getSets(vm_demFeSector))
extended_vm_demFeSector[, , c(getItems(vm_demFeSector, 3))] <-
vm_demFeSector[, , c(getItems(vm_demFeSector, 3))]
vm_demFeSector <- extended_vm_demFeSector
}

# only retain combinations of SE, FE, te which actually exist in the model (qm_balFe)
vm_prodFe <- vm_prodFe[se2fe]

# FE demand per industry subsector
o37_demFeIndSub <- readGDX(gdx, "o37_demFeIndSub", restore_zeros = FALSE,
format = "first_found", react = 'silent')
if (!(is.null(o37_demFeIndSub) | 0 == length(o37_demFeIndSub))) {
o37_demFeIndSub <- o37_demFeIndSub[,t,]
o37_demFeIndSub[is.na(o37_demFeIndSub)] <- 0
# convert to EJ
o37_demFeIndSub <- o37_demFeIndSub * TWa_2_EJ
}



####### Realisation specific Variables ##########
Expand All @@ -150,7 +124,6 @@ reportFE <- function(gdx, regionSubsetList = NULL,


# calculate FE non-energy use and FE without non-energy use
if (!is.null(vm_demFENonEnergySector)) {
vm_demFENonEnergySector <- mselect(vm_demFENonEnergySector[demFemapping],
all_enty1 = entyFe2sector2emiMkt_NonEn$all_enty,
emi_sectors = entyFe2sector2emiMkt_NonEn$emi_sectors,
Expand All @@ -159,7 +132,7 @@ reportFE <- function(gdx, regionSubsetList = NULL,
# calculate FE without non-energy use
vm_demFeSector_woNonEn <- vm_demFeSector
vm_demFeSector_woNonEn[,,getNames(vm_demFENonEnergySector )] <- vm_demFeSector[,,getNames(vm_demFENonEnergySector )]-vm_demFENonEnergySector
}


# ---- FE total production (incl. non-energy use) ------
out <- mbind(out,
Expand Down Expand Up @@ -658,9 +631,6 @@ reportFE <- function(gdx, regionSubsetList = NULL,

# Industry Module ----
## FE demand ----
if (!(is.null(o37_demFeIndSub) | 0 == length(o37_demFeIndSub))) {
# this reporting is only available for GDXs which have the reporting
# parameter o37_demFeIndSub

# Big ol' table of variables to report, along with indices into
# o37_demFeIndSub to select the right sets. Indices can be either literal
Expand Down Expand Up @@ -896,7 +866,7 @@ reportFE <- function(gdx, regionSubsetList = NULL,
.select_sum_name_multiply(o37_ProdIndRoute, .mixer_to_selector(mixer), factor=1e3))) # factor 1e3 converts Gt/yr to Mt/yr
}
}
}


#--- Transport reporting ---

Expand Down Expand Up @@ -955,7 +925,6 @@ reportFE <- function(gdx, regionSubsetList = NULL,

#--- CDR ---

if(cdr_mod == "portfolio") {
v33_FEdemand <- readGDX(gdx, name=c("v33_FEdemand"), field="l", restore_zeros=F)[,t,] * TWa_2_EJ
# KK: Mappings from gams set names to names in mifs. If new CDR methods are added to REMIND, please add
# the method to CDR_te_list: "<method name in REMIND>"="<method name displayed in reporting>"
Expand All @@ -975,35 +944,9 @@ reportFE <- function(gdx, regionSubsetList = NULL,
variable_name))
}
}
}

if(cdr_mod != "off" && cdr_mod != "portfolio"){ # compatibility with the CDR module before portfolio was added
vm_otherFEdemand <- readGDX(gdx,name=c("vm_otherFEdemand"),field="l",format="first_found")[,t,]*TWa_2_EJ

s33_rockgrind_fedem <- readGDX(gdx,"s33_rockgrind_fedem", react = "silent")
if (is.null(s33_rockgrind_fedem)){
s33_rockgrind_fedem <- new.magpie("GLO",NULL,fill=0)
}
v33_grindrock_onfield <- readGDX(gdx,name=c("v33_grindrock_onfield"),field="l",format="first_found",react = "silent")[,t,]
if (is.null(v33_grindrock_onfield)){
v33_grindrock_onfield <- new.magpie(getRegions(vm_otherFEdemand),getYears(vm_otherFEdemand),fill=0)
}

out <- mbind(out,
setNames(vm_otherFEdemand[,,"feh2s"], "FE|CDR|DAC|+|Hydrogen (EJ/yr)"),
setNames(vm_otherFEdemand[,,"fegas"], "FE|CDR|DAC|+|Gases (EJ/yr)"),
setNames(vm_otherFEdemand[,,"fehes"], "FE|CDR|DAC|+|Heat (EJ/yr)"),
setNames(vm_otherFEdemand[,,"fedie"], "FE|CDR|EW|+|Diesel (EJ/yr)"),
setNames(s33_rockgrind_fedem*dimSums(v33_grindrock_onfield[,,],dim=3,na.rm=T), "FE|CDR|EW|+|Electricity (EJ/yr)")
)
out <- mbind(out,
setNames(out[,,"FE|CDR|+|Electricity (EJ/yr)"] - out[,,"FE|CDR|EW|+|Electricity (EJ/yr)"], "FE|CDR|DAC|+|Electricity (EJ/yr)")
)
out <- mbind(out,
setNames(out[,,"FE|CDR|DAC|+|Hydrogen (EJ/yr)"] + out[,,"FE|CDR|DAC|+|Gases (EJ/yr)"] + out[,,"FE|CDR|DAC|+|Electricity (EJ/yr)"] + out[,,"FE|CDR|DAC|+|Heat (EJ/yr)"], "FE|CDR|++|DAC (EJ/yr)"),
setNames(out[,,"FE|CDR|EW|+|Diesel (EJ/yr)"] + out[,,"FE|CDR|EW|+|Electricity (EJ/yr)"], "FE|CDR|++|EW (EJ/yr)")
)
}

#--- Additional Variables

Expand Down Expand Up @@ -1048,8 +991,7 @@ reportFE <- function(gdx, regionSubsetList = NULL,
out[out < 0] <- 0
}

# report feedstocks use by carrier when available
if (!is.null(vm_demFENonEnergySector)) {
# report feedstocks use by carrier
# FE non-energy use variables
out <- mbind(out,
setNames(dimSums(vm_demFENonEnergySector, dim=3),
Expand Down Expand Up @@ -1195,12 +1137,9 @@ reportFE <- function(gdx, regionSubsetList = NULL,
warning(e)
}
)
}

### FE w/o non-energy and w/o bunkers ----

# only try to add variables if non-energy use variables are available
if ("FE|Non-energy Use (EJ/yr)" %in% getNames(out)) {
### FE w/o non-energy and w/o bunkers ----

out <- mbind(
out,
Expand Down Expand Up @@ -1256,7 +1195,7 @@ reportFE <- function(gdx, regionSubsetList = NULL,
out[, , "FE|w/o Non-energy Use|Solids|+|Biomass (EJ/yr)"],
"FE|w/o Bunkers|w/o Non-energy Use|Solids|Biomass (EJ/yr)")
)
}



### Regional Aggregation ----
Expand Down
8 changes: 4 additions & 4 deletions R/switchValuesScenConf.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' searches all scenario config files of REMIND directory for a switch and prints the occurences
#'
#' @param switchname string with switch that is searched in scenario config files.
#' If NULL, prints all switches with only one value in main.gms and scenario config files
#' If NULL or '', prints all switches with only one value in main.gms and scenario config files
#' @param directory path to REMIND directory
#' @author Oliver Richters
#' @importFrom gms readDefaultConfig
Expand All @@ -10,8 +10,8 @@
#' @export
switchValuesScenConf <- function(switchname = NULL, directory = ".") {
csvfiles <- Sys.glob(c(file.path(directory, "scenario_config*.csv"),
file.path(directory, "config", "scenario_config*.csv"),
file.path(directory, "config", "*", "scenario_config*.csv")))
file.path(directory, "config", "scenario_config*.csv"),
file.path(directory, "config", "*", "scenario_config*.csv")))
maingmsdirectory <- directory
if (! file.exists(file.path(directory, "main.gms")) && file.exists(file.path(dirname(directory), "main.gms"))) {
maingmsdirectory <- dirname(directory)
Expand All @@ -27,7 +27,7 @@ switchValuesScenConf <- function(switchname = NULL, directory = ".") {
message("\n### No main.gms found in directory ", maingmsdirectory, ". Please specify REMIND directory.")
return(NULL)
}
if (is.null(switchname)) {
if (is.null(switchname) || switchname == "") {
message("\n### Printing all switches with only one value in main.gms and ",
length(csvfiles), " scenario config files:")
switchesUniqueValue <- NULL
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.152.0**
R package **remind2**, version **1.154.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,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, 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, Rüter T (2024). _remind2: The REMIND R package (2nd generation)_. R package version 1.152.0, <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, Rüter T (2024). _remind2: The REMIND R package (2nd generation)_. R package version 1.154.2, <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 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 and Tonn Rüter},
year = {2024},
note = {R package version 1.152.0},
note = {R package version 1.154.2},
url = {https://github.com/pik-piam/remind2},
}
```
2 changes: 1 addition & 1 deletion man/reportEmi.Rd

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

2 changes: 1 addition & 1 deletion man/switchValuesScenConf.Rd

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

0 comments on commit ab6fbfa

Please sign in to comment.