Skip to content

Commit c83685d

Browse files
committed
Merge branch 'master' of https://github.com/pik-piam/mrremind into struct
2 parents f0884c0 + 6e2ae37 commit c83685d

13 files changed

Lines changed: 82 additions & 142 deletions

.buildlibrary

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ValidationKey: '55213360'
1+
ValidationKey: '55242005'
22
AcceptedWarnings:
33
- Invalid URL: .*
44
- 'Warning: package ''.*'' was built under R version'

CITATION.cff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ cff-version: 1.2.0
22
message: If you use this software, please cite it using the metadata from this file.
33
type: software
44
title: 'mrremind: MadRat REMIND Input Data Package'
5-
version: 0.268.0
6-
date-released: '2026-05-29'
5+
version: 0.268.1
6+
date-released: '2026-06-01'
77
abstract: The mrremind packages contains data preprocessing for the REMIND model.
88
authors:
99
- family-names: Baumstark

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Type: Package
22
Package: mrremind
33
Title: MadRat REMIND Input Data Package
4-
Version: 0.268.0
5-
Date: 2026-05-29
4+
Version: 0.268.1
5+
Date: 2026-06-01
66
Authors@R: c(
77
person("Lavinia", "Baumstark", , "lavinia@pik-potsdam.de", role = c("aut", "cre")),
88
person("Renato", "Rodrigues", role = "aut"),

R/calcFEShares.R

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,44 @@
11
#' FE Share parameters used in REMIND
22
#'
3-
#' @param subtype 'ind_coal' for the share of coal used in industry. 'ind_bio' for the share of biomass used in industry
3+
#' @param subtype 'ind_coal' for the share of coal used in industry.
4+
#' 'ind_bio' for the share of biomass used in industry
45
#' @param scenario Vector of strings. Used here only to optimize madrat cache usage,
5-
#' as in the end only the 2005 FEdemand value is actually used - which is equal across scenarios.
6+
#' as in the end only the 2005 FE demand value is actually used - which is equal across scenarios.
67
#' @author Antoine Levesque
78
#'
89
calcFEShares <- function(subtype, scenario) {
9-
if (! subtype %in% c("ind_coal", "ind_bio", "ind_liq")) {
10+
11+
if (!subtype %in% c("ind_coal", "ind_bio", "ind_liq")) {
1012
stop("Unknown subtype.")
1113
}
1214

13-
edge_buildings <- calcOutput("IOEdgeBuildings", subtype = "output_EDGE_buildings", aggregate = FALSE)
15+
edge_buildings <- calcOutput("IOEdgeBuildings", subtype = "output_EDGE_buildings",
16+
aggregate = FALSE)
1417
output <- calcOutput("IO", subtype = "output", corrected = TRUE, aggregate = FALSE)
15-
# Get FEdemand data for 2005 (equal across scenarios, so just pick SSP2).
16-
## Keep scenario selection as is (this optimizes madrat cache usage).
17-
fe_demand <- calcOutput("FEdemand", scenario = scenario, aggregate = FALSE)[, 2005, "SSP2"] %>% collapseNames()
1818

1919
if (subtype == "ind_coal") {
2020
share <- 1 - dimSums(edge_buildings[, 2005, "coal"]) / output[, 2005, "pecoal.sesofos.coaltr"]
2121
weight <- output[, 2005, "pecoal.sesofos.coaltr"]
2222
descr <- glue::glue("share of coal used in industry (computed by retrieving buildings uses, i.e., considering \\
2323
transport and ONONSPEC are null)")
24-
}
25-
26-
if (subtype == "ind_bio") {
24+
} else if (subtype == "ind_bio") {
2725
share <- 1 - dimSums(edge_buildings[, 2005, c("biomod", "biotrad")]) /
2826
dimSums(output[, 2005, c("pebiolc.sesobio.biotr", "pebiolc.sesobio.biotrmod")], dim = 3)
2927
weight <- dimSums(output[, 2005, c("pebiolc.sesobio.biotr", "pebiolc.sesobio.biotrmod")], dim = 3)
3028
descr <- glue::glue("share of biomass used in industry (computed by retrieving buildings uses, i.e., considering \\
3129
transport and ONONSPEC are null)")
32-
}
30+
} else if (subtype == "ind_liq") {
31+
32+
# Get FE demand data for 2005 (equal across scenarios, so just pick SSP2).
33+
## Keep scenario selection as is (this optimizes madrat cache usage).
34+
35+
fe_dem_build <- calcOutput("FeDemandBuildings", subtype = "FE", scenario = scenario, aggregate = FALSE)
36+
fe_dem_ind <- calcOutput("FeDemandIndustry", scenarios = scenario, aggregate = FALSE)[, , "SSP2"]
37+
38+
fehoi <- dimSums(fe_dem_ind[, 2005, c("feli_cement", "feli_chemicals", "feli_steel", "feli_otherInd")], dim = 3)
3339

34-
if (subtype == "ind_liq") {
35-
fehoi <- dimSums(fe_demand[, 2005, c("feli_cement", "feli_chemicals", "feli_steel", "feli_otherInd")])
36-
share <- fehoi / (fehoi + fe_demand[, 2005, c("fehob")])
37-
weight <- (fehoi + fe_demand[, 2005, c("fehob")])
40+
share <- fehoi / (fehoi + fe_dem_build[, 2005, "SSP2.none.fehob"])
41+
weight <- (fehoi + fe_dem_build[, 2005, "SSP2.none.fehob"])
3842
descr <- "share of stationary heating oil used in industry"
3943
}
4044

R/calcFEdemand.R

Lines changed: 0 additions & 29 deletions
This file was deleted.

R/calcFeDemandBuildings.R

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#' Returns the EDGE-Buildings data as REMIND variables
22
#'
3-
#' @param subtype either "FE", "FE_buildings", or "UE_buildings"
3+
#' @param subtype either "FE", or "UE"
44
#' @param scenario A string (or vector of strings) designating the scenario(s) to be returned.
55
#'
66
#' @author Robin Hasse
@@ -12,33 +12,26 @@ calcFeDemandBuildings <- function(subtype, scenario) {
1212
# end of history
1313
eoh <- 2025
1414

15-
if (!subtype %in% c("FE", "FE_buildings", "UE_buildings")) {
15+
if (!subtype %in% c("FE", "UE")) {
1616
stop(paste0("Unsupported subtype: ", subtype))
1717
}
1818

1919
## Replace any calls to scenario groups such as "SSPs" and "SSP2IndiaDEAs", to calls of the individual scenarios.
2020
scenario <- mrdrivers::toolReplaceShortcuts(scenario) %>% unique()
2121

2222
# Data Processing ----
23-
ononspec <- calcOutput("FeDemandONONSPEC", scenario = scenario, eoh = eoh,
24-
aggregate = FALSE)
23+
ononspec <- calcOutput("FeDemandONONSPEC", scenario = scenario, eoh = eoh, aggregate = FALSE)
2524
buildings <- readSource("EdgeBuildings", subtype = "FE", subset = scenario)
2625

2726
# Aggregate to 5-year averages to suppress volatility
2827
buildings <- toolAggregateTimeSteps(buildings)
2928
ononspec <- toolAggregateTimeSteps(ononspec)
3029

31-
if (subtype == "FE") {
32-
# Drop RCP dimension (use fixed RCP)
33-
buildings <- mselect(buildings, rcp = "none") %>% collapseDim(dim = "rcp")
34-
35-
} else {
36-
# For each scenario add the rcp scenarios present in buildings to stationary
37-
ononspec <- do.call(mbind, lapply(scenario, function(scen) {
38-
rcps <- getItems(mselect(buildings, scenario = scen), dim = "rcp")
39-
toolAddDimensions(mselect(ononspec, scenario = scen), dimVals = rcps, dimName = "rcp", dimCode = 3.2)
40-
}))
41-
}
30+
# For each scenario add the rcp scenarios present in buildings to stationary
31+
ononspec <- do.call(mbind, lapply(scenario, function(scen) {
32+
rcps <- getItems(mselect(buildings, scenario = scen), dim = "rcp")
33+
toolAddDimensions(mselect(ononspec, scenario = scen), dimVals = rcps, dimName = "rcp", dimCode = 3.2)
34+
}))
4235

4336
# Extrapolate years missing in buildings, but existing in stationary
4437
buildings <- time_interpolate(buildings,
@@ -52,29 +45,21 @@ calcFeDemandBuildings <- function(subtype, scenario) {
5245
name = "mappingEDGEBuildingsToREMIND.csv",
5346
where = "mrremind")
5447

55-
if (subtype == "FE") {
56-
57-
remindVars <- unique(mapping$REMINDitems_out)
58-
remindDims <- quitte::cartesian(getNames(data, dim = "scenario"), remindVars)
59-
60-
} else {
48+
remindVars <- filter(mapping, grepl("^fe..b$|^feel..b$|^feelcb$", .data$REMINDitems_out))
49+
remindVars <- unique(remindVars$REMINDitems_out)
6150

62-
remindVars <- filter(mapping, grepl("^fe..b$|^feel..b$|^feelcb$", .data$REMINDitems_out))
63-
remindVars <- unique(remindVars$REMINDitems_out)
64-
65-
# Extend mapping for Useful Energy
66-
if (subtype == "UE_buildings") {
67-
mapping <- mapping %>%
68-
mutate(EDGE_buildings_items = gsub("_fe$", "_ue", .data[["EDGE_buildings_items"]]),
69-
REMINDitems_out = gsub("^fe", "ue", .data[["REMINDitems_out"]])) %>%
70-
rbind(mapping)
71-
remindVars <- gsub("^fe", "ue", remindVars)
72-
}
73-
74-
scenarioRcp <- unique(gsub("^(.*\\..*)\\..*$", "\\1", getItems(data, dim = 3)))
75-
remindDims <- quitte::cartesian(scenarioRcp, remindVars)
51+
# Extend mapping for Useful Energy
52+
if (subtype == "UE") {
53+
mapping <- mapping %>%
54+
mutate(EDGE_buildings_items = gsub("_fe$", "_ue", .data[["EDGE_buildings_items"]]),
55+
REMINDitems_out = gsub("^fe", "ue", .data[["REMINDitems_out"]])) %>%
56+
rbind(mapping)
57+
remindVars <- gsub("^fe", "ue", remindVars)
7658
}
7759

60+
scenarioRcp <- unique(gsub("^(.*\\..*)\\..*$", "\\1", getItems(data, dim = 3)))
61+
remindDims <- quitte::cartesian(scenarioRcp, remindVars)
62+
7863
# Apply Mapping
7964
remind <- new.magpie(cells_and_regions = getItems(data, dim = 1),
8065
years = getYears(data),
@@ -93,20 +78,18 @@ calcFeDemandBuildings <- function(subtype, scenario) {
9378

9479
# Prepare Output
9580
## Change item names back from UE to FE
96-
if (subtype == "UE_buildings") {
81+
if (subtype == "UE") {
9782
getItems(remind, "item") <- gsub("^ue", "fe", getItems(remind, "item"))
9883
}
9984

10085
description <- switch(subtype,
101-
FE = "final energy demand in buildings and industry (stationary)",
102-
FE_buildings = "final energy demand in buildings",
103-
UE_buildings = "useful energy demand in buildings"
86+
FE = "final energy demand in buildings",
87+
UE = "useful energy demand in buildings"
10488
)
10589

10690
outputStructure <- switch(subtype,
107-
FE = "^(SSP[1-5].*|SDP.*)\\.(fe|ue)",
108-
FE_buildings = "^(SSP[1-5]|SDP).*\\..*\\.fe.*b$",
109-
UE_buildings = "^(SSP[1-5]|SDP).*\\..*\\.fe.*b$"
91+
FE = "^(SSP[1-5]|SDP).*\\..*\\.fe.*b$",
92+
UE = "^(SSP[1-5]|SDP).*\\..*\\.fe.*b$"
11093
)
11194

11295
list(x = remind,

R/fullREMIND.R

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,10 @@ fullREMIND <- function() {
5353
match.steel.historic.values = TRUE,
5454
match.steel.estimates = "IEA_ETP"
5555
)
56-
calcOutput("FEdemand", scenario = feDemScen, signif = 4, file = "f_fedemand.cs4r")
57-
calcOutput("FeDemandBuildings",
58-
subtype = "FE_buildings",
59-
scenario = feDemScen,
60-
round = 8,
61-
file = "f_fedemand_build.cs4r")
62-
calcOutput("FeDemandBuildings",
63-
subtype = "UE_buildings",
64-
scenario = feDemScen,
65-
round = 8,
66-
file = "f36_uedemand_build.cs4r")
56+
57+
calcOutput("FeDemandIndustry", scenarios = feDemScen, signif = 4, file = "f_fedemandInd.cs4r")
58+
calcOutput("FeDemandBuildings", subtype = "FE", scenario = feDemScen, round = 8, file = "f_fedemandBuild.cs4r")
59+
calcOutput("FeDemandBuildings", subtype = "UE", scenario = feDemScen, round = 8, file = "f36_uedemand_build.cs4r")
6760
calcOutput("ChemicalFeedstocksShare", round = 2, file = "p37_chemicals_feedstock_share.cs4r")
6861
calcOutput("Floorspace", scenario = feDemScen, onlyTotal = TRUE, round = 1, file = "p36_floorspace_scen.cs4r")
6962
calcOutput("Floorspace", scenario = feDemScen, round = 1, file = "f36_floorspace_scen.cs4r")

R/toolCalcEnergyProj.R

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
#' @author Felix Schreyer
66
#' @param subtype "FE" (Total final energy consumption), "SE|Electricity" (SE electricity generation)
77
#' @param subset GDP scenario to use
8-
#' @param scenario set of GDP scenarios to use for calcFEDemand calculation (trigger standard cache in this function)
8+
#' @param scenario set of GDP scenarios to use for calcFeDemandBuildings and calcFeDemandIndustry
9+
#' calculation (trigger standard cache in this function)
910
#' @param years target years for projection
1011
#' @seealso [convertNewClimate()]
1112

@@ -32,7 +33,7 @@ toolCalcEnergyProj <- function(subtype, subset, scenario, years = seq(2020, 2050
3233
# function get historical energy data for 2020
3334
.getHistData <- function(subtype, AvgSeveralYears) {
3435
# get historical FE and SE data from IEA energy balances
35-
IEA <- calcOutput("FE", ieaVersion = "default", aggregate = F)
36+
IEA <- calcOutput("FE", ieaVersion = "default", aggregate = FALSE)
3637

3738
# add items to calculate historical FE demand or historical SE generation
3839
if (subtype == "FE") {
@@ -62,19 +63,21 @@ toolCalcEnergyProj <- function(subtype, subset, scenario, years = seq(2020, 2050
6263
FETransport <- calcOutput("EDGETransport", subtype = "f35_demByTech")
6364
# filter for SSP2 scenario and Mix1 EDGE scenario
6465
FETransport <- collapseNames(mselect(FETransport, GDP_scenario = subset, DEM_scenario = subset, EDGE_scenario = "Mix1"))
66+
6567
# buildings and industry FE demand from EDGE-B and EDGE-I (in EJ/yr)
66-
FEBuildIndustry <- calcOutput("FEdemand", scenario = scenario , signif = 4)
67-
# filter for SSP2 scenario
68-
FEBuildIndustry <- collapseNames(FEBuildIndustry[, , subset])
68+
FEBuild <- calcOutput("FeDemandBuildings", subtype = "FE", scenario = scenario, signif = 4)[, , subset][, , "none"] %>%
69+
collapseNames()
70+
FEIndustry <- calcOutput("FeDemandIndustry", scenarios = scenario, signif = 4)[, , subset]
71+
6972
# define CES inputs over which to sum for respective FE demand
7073
if (subtype == "FE") {
7174
# for FE projection, get FE trend of total FE
7275
input.fe.build <- c("feelcb", "feelhpb", "feelrhb", "fegab", "fehob", "fesob", "feheb")
7376
input.fe.indst <- c(
74-
grep("fe.*steel", getNames(FEBuildIndustry), value = T),
75-
grep("fe.*cement", getNames(FEBuildIndustry), value = T),
76-
grep("fe.*chem", getNames(FEBuildIndustry), value = T),
77-
grep("fe.*otherInd", getNames(FEBuildIndustry), value = T)
77+
grep("fe.*steel", getNames(FEIndustry), value = TRUE),
78+
grep("fe.*cement", getNames(FEIndustry), value = TRUE),
79+
grep("fe.*chem", getNames(FEIndustry), value = TRUE),
80+
grep("fe.*otherInd", getNames(FEIndustry), value = TRUE)
7881
)
7982
input.fe.trans <- getNames(FETransport)
8083
} else if (subtype == "SE|Electricity") {
@@ -89,11 +92,13 @@ toolCalcEnergyProj <- function(subtype, subset, scenario, years = seq(2020, 2050
8992
}
9093

9194
# common years across EDGE outputs
92-
common.years <- intersect(getYears(FEBuildIndustry), getYears(FETransport))
95+
common.years <- intersect(
96+
getYears(FEIndustry), intersect(getYears(FEBuild), getYears(FETransport))
97+
)
9398

9499
# sum FE demand across sectors per REMIND region
95-
FeTotal <- dimSums(FEBuildIndustry[, common.years, input.fe.build], dim = 3) +
96-
dimSums(FEBuildIndustry[, common.years, input.fe.indst], dim = 3) +
100+
FeTotal <- dimSums(FEBuild[, common.years, input.fe.build], dim = 3) +
101+
dimSums(FEIndustry[, common.years, input.fe.indst], dim = 3) +
97102
dimSums(FETransport[, common.years, input.fe.trans], dim = 3) * 31.536 # convert TWa/yr to EJ/yr
98103
# calculate FE trend of target year with respect to 2020
99104
FeTrend <- collapseDim(FeTotal[, years, ] / FeTotal[, "y2020", ])
@@ -108,7 +113,7 @@ toolCalcEnergyProj <- function(subtype, subset, scenario, years = seq(2020, 2050
108113
# function to calculate difference in GDP trend between country and REMIND region
109114
.computeGDPTrendDiff <- function(subset, years, MaxThreshold) {
110115
# GDP on country-level
111-
GDP_country <- calcOutput("GDP", scenario = subset, years = years, aggregate = F)
116+
GDP_country <- calcOutput("GDP", scenario = subset, years = years, aggregate = FALSE)
112117
# GDP on REMIND region-level
113118
GDP_region <- calcOutput("GDP", scenario = subset, years = years)
114119
# get regionmapping
@@ -123,14 +128,13 @@ toolCalcEnergyProj <- function(subtype, subset, scenario, years = seq(2020, 2050
123128
GDPTrendDiff[GDPTrendDiff < -MaxThreshold] <- -MaxThreshold
124129
GDPTrendDiff[GDPTrendDiff > MaxThreshold] <- MaxThreshold
125130

126-
127131
return(GDPTrendDiff)
128132
}
129133

130134
### main function ----
131135

132136
# 1. get historical energy data for 2020 ----
133-
xHist <- .getHistData(subtype, AvgSeveralYears = T)
137+
xHist <- .getHistData(subtype, AvgSeveralYears = TRUE)
134138
# 2. calculate FE trend on level of REMIND regions based on EDGE data ----
135139
FeTrend <- .computeFeTrend(subtype, subset, years)
136140
# 3. calculate difference in GDP trend between country and REMIND region ----

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MadRat REMIND Input Data Package
22

3-
R package **mrremind**, version **0.268.0**
3+
R package **mrremind**, version **0.268.1**
44

55
[![R build status](https://github.com/pik-piam/mrremind/workflows/check/badge.svg)](https://github.com/pik-piam/mrremind/actions) [![codecov](https://codecov.io/gh/pik-piam/mrremind/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/mrremind) [![r-universe](https://pik-piam.r-universe.dev/badges/mrremind)](https://pik-piam.r-universe.dev/builds)
66

@@ -39,17 +39,17 @@ In case of questions / problems please contact Lavinia Baumstark <lavinia@pik-po
3939

4040
To cite package **mrremind** in publications use:
4141

42-
Baumstark L, Rodrigues R, Levesque A, Oeser J, Bertram C, Mouratiadou I, Malik A, Schreyer F, Soergel B, Rottoli M, Mishra A, Dirnaichner A, Pehl M, Giannousakis A, Klein D, Strefler J, Feldhaus L, Brecha R, Rauner S, Dietrich J, Bi S, Benke F, Weigmann P, Richters O, Hasse R, Fuchs S, Mandaroux R, Koch J, Abrahao G, Dorndorf T (2026). "mrremind: MadRat REMIND Input Data Package." Version: 0.268.0, <https://github.com/pik-piam/mrremind>.
42+
Baumstark L, Rodrigues R, Levesque A, Oeser J, Bertram C, Mouratiadou I, Malik A, Schreyer F, Soergel B, Rottoli M, Mishra A, Dirnaichner A, Pehl M, Giannousakis A, Klein D, Strefler J, Feldhaus L, Brecha R, Rauner S, Dietrich J, Bi S, Benke F, Weigmann P, Richters O, Hasse R, Fuchs S, Mandaroux R, Koch J, Abrahao G, Dorndorf T (2026). "mrremind: MadRat REMIND Input Data Package." Version: 0.268.1, <https://github.com/pik-piam/mrremind>.
4343

4444
A BibTeX entry for LaTeX users is
4545

4646
```latex
4747
@Misc{,
4848
title = {mrremind: MadRat REMIND Input Data Package},
4949
author = {Lavinia Baumstark and Renato Rodrigues and Antoine Levesque and Julian Oeser and Christoph Bertram and Ioanna Mouratiadou and Aman Malik and Felix Schreyer and Bjoern Soergel and Marianna Rottoli and Abhijeet Mishra and Alois Dirnaichner and Michaja Pehl and Anastasis Giannousakis and David Klein and Jessica Strefler and Lukas Feldhaus and Regina Brecha and Sebastian Rauner and Jan Philipp Dietrich and Stephen Bi and Falk Benke and Pascal Weigmann and Oliver Richters and Robin Hasse and Sophie Fuchs and Rahel Mandaroux and Johannes Koch and Gabriel Abrahao and Tabea Dorndorf},
50-
date = {2026-05-29},
50+
date = {2026-06-01},
5151
year = {2026},
5252
url = {https://github.com/pik-piam/mrremind},
53-
note = {Version: 0.268.0},
53+
note = {Version: 0.268.1},
5454
}
5555
```

man/calcFEShares.Rd

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)