Skip to content

Commit

Permalink
Merge pull request #602 from fbenke-pik/warnings
Browse files Browse the repository at this point in the history
Remove luscale dependency
  • Loading branch information
fbenke-pik authored Dec 13, 2024
2 parents 91b3802 + 6f89d5d commit 590cfa2
Show file tree
Hide file tree
Showing 14 changed files with 163 additions and 125 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '40942800'
ValidationKey: '40962870'
AcceptedWarnings:
- Invalid URL: .*
- 'Warning: package ''.*'' was built under R version'
Expand Down
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cff-version: 1.2.0
message: If you use this software, please cite it using the metadata from this file.
type: software
title: 'mrremind: MadRat REMIND Input Data Package'
version: 0.204.0
version: 0.204.1
date-released: '2024-12-13'
abstract: The mrremind packages contains data preprocessing for the REMIND model.
authors:
Expand Down
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: mrremind
Title: MadRat REMIND Input Data Package
Version: 0.204.0
Version: 0.204.1
Date: 2024-12-13
Authors@R: c(
person("Lavinia", "Baumstark", , "[email protected]", role = c("aut", "cre")),
Expand Down Expand Up @@ -47,7 +47,6 @@ Imports:
edgeTransport (>= 2.9.0),
GDPuc (>= 1.3.0),
ggplot2,
luscale,
madrat (>= 3.7.1),
magclass (>= 6.16.1),
magrittr,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export(calcHRE)
export(calcIEA_ETP)
export(calcIEA_EVOutlook)
export(calcIEA_WorldEnergyOutlook)
export(calcIRENA)
export(calcOtherFossilInElectricity)
export(calcPlasticsEoL)
export(calcProjectPipelines)
Expand Down
164 changes: 75 additions & 89 deletions R/calcCapacity.R

Large diffs are not rendered by default.

22 changes: 1 addition & 21 deletions R/calcHistorical.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,6 @@ calcHistorical <- function() {
# remove duplicates from LU_FAO_EmisAg
LU_FAO_EmisAg <- LU_FAO_EmisAg[, , which(!duplicated(getNames(LU_FAO_EmisAg)))]

# Capacities historical data ====

# IRENA capacities - technologies: "csp", "geohdr", "hydro", "spv", "wind"

# Read IRENA renewables capacity data
IRENAcap <- readSource(type = "IRENA", subtype = "Capacity")[, , c("Concentrated solar power",
"Geothermal", "Renewable hydropower",
"Solar photovoltaic", "Wind")]
IRENAcap <- IRENAcap * 1E-03 # converting MW to GW
mapping <- data.frame(
IRENA_techs = c("Concentrated solar power", "Geothermal", "Renewable hydropower", "Solar photovoltaic", "Wind"),
REMIND_var = c("Cap|Electricity|Solar|CSP (GW)", "Cap|Electricity|Geothermal (GW)",
"Cap|Electricity|Hydro (GW)", "Cap|Electricity|Solar|PV (GW)",
"Cap|Electricity|Wind (GW)"), stringsAsFactors = FALSE
)
# renaming technologies to REMIND naming convention
IRENAcap <- luscale::rename_dimnames(IRENAcap, dim = 3, query = mapping, from = "IRENA_techs", to = "REMIND_var")
IRENAcap <- mbind(IRENAcap, setNames(IRENAcap[, , "Cap|Electricity|Solar|CSP (GW)"] +
IRENAcap[, , "Cap|Electricity|Solar|PV (GW)"], "Cap|Electricity|Solar (GW)"))
IRENAcap <- add_dimension(IRENAcap, dim = 3.1, add = "model", nm = "IRENA")

# Region specific historical data ====

Expand Down Expand Up @@ -204,7 +184,7 @@ calcHistorical <- function() {
varlist <- list(
fe_iea, fe_weo, pe_iea, pe_weo, trade, pop, gdp,
ceds, primap, cdiac, LU_EDGAR_LU, LU_CEDS,
LU_FAO_EmisLUC, LU_FAO_EmisAg, LU_PRIMAPhist, IRENAcap,
LU_FAO_EmisLUC, LU_FAO_EmisAg, LU_PRIMAPhist,
EEA_GHGSectoral, EEA_GHGTotal, Emi_Reference,
worldsteel, USGS_cement
)
Expand Down
4 changes: 2 additions & 2 deletions R/calcIEA_WorldEnergyOutlook.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ calcIEA_WorldEnergyOutlook <- function() { # nolint
}

x <- toolAggregate(data,
dim = 3.2, rel = map, from = "from",
to = "to", partrel = TRUE, verbosity = 2
dim = 3.2, rel = map, from = "from",
to = "to", partrel = TRUE, verbosity = 2
)

return(x)
Expand Down
42 changes: 42 additions & 0 deletions R/calcIRENA.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#' Calculate REMIND variables from historical IRENA capacities.
#'
#' @author Falk Benke
#' @export
calcIRENA <- function() {

data <- readSource(type = "IRENA", subtype = "Capacity")[, , c(
"Concentrated solar power",
"Geothermal", "Renewable hydropower",
"Solar photovoltaic", "Wind"
)]

# converting MW to GW
data <- data * 1E-03

mapping <- data.frame(
IRENA_techs =
c("Concentrated solar power", "Geothermal", "Renewable hydropower", "Solar photovoltaic", "Wind"),
REMIND_var =
c(
"Cap|Electricity|Solar|CSP (GW)", "Cap|Electricity|Geothermal (GW)", "Cap|Electricity|Hydro (GW)",
"Cap|Electricity|Solar|PV (GW)", "Cap|Electricity|Wind (GW)"
), stringsAsFactors = FALSE
)

data <- madrat::toolAggregate(data, mapping, dim = 3, from = "IRENA_techs", to = "REMIND_var")

data <- mbind(
data,
setNames(
data[, , "Cap|Electricity|Solar|CSP (GW)"] + data[, , "Cap|Electricity|Solar|PV (GW)"],
"Cap|Electricity|Solar (GW)"
)
)

return(list(
x = data,
weight = NULL,
unit = "GW",
description = "IRENA capacities for technologies csp, geohdr, hydro, spv, wind"
))
}
2 changes: 1 addition & 1 deletion R/calcPE.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ calcPE <- function(subtype = "IEA", ieaVersion = "default") {
map <- map[map$io %in% getNames(data), ]
x <- data[, , map$io]
# aggregate from the IO names to the reporting names.
x <- luscale::speed_aggregate(x, map, dim = 3, from = "io", to = "input")
x <- madrat::toolAggregate(x, map, dim = 3, from = "io", to = "input")
# rename entries of data to match the reporting names
getNames(x) <- paste0(getNames(x), " (EJ/yr)")

Expand Down
14 changes: 11 additions & 3 deletions R/convertEdgeBuildings.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,17 @@ convertEdgeBuildings <- function(x, subtype = "FE") {
wfe <- wfe[, getYears(x), getNames(x, dim = "item")]

# Disaggregate and fill the gaps
xadd <- toolAggregate(x, mappingfile, weight = wfe,
from = region_col,
to = iso_col)

weightSum <- toolAggregate(wfe, mappingfile, from = region_col, to = iso_col, dim = 1)

# only throw the zeroWeight warning in toolAggregate, when any weights are zero,
# but the corresponding data in x is not 0, as only in these cases the total sum of
# the magpie object is actually changed
shouldWarn <- ifelse(any(weightSum[x != 0] == 0), "warn", "allow")

xadd <- toolAggregate(x, mappingfile, weight = wfe, from = region_col, to = iso_col,
zeroWeight = shouldWarn)

result <- toolCountryFill(xadd, 0, verbosity = 2)

# Attribute the growth in water heating demand of the EDGE Region OCD to TUR,
Expand Down
9 changes: 9 additions & 0 deletions R/fullVALIDATIONREMIND.R
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,15 @@ fullVALIDATIONREMIND <- function(rev = 0) {
writeArgs = list(scenario = "historical")
)

# IRENA Capacities ----

calcOutput(
type = "IRENA", file = valfile,
aggregate = columnsForAggregation, append = TRUE, warnNA = FALSE,
try = FALSE, years = years,
writeArgs = list(scenario = "historical", model = "IRENA")
)

# JRC IDEES ----

calcOutput(
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MadRat REMIND Input Data Package

R package **mrremind**, version **0.204.0**
R package **mrremind**, version **0.204.1**

[![CRAN status](https://www.r-pkg.org/badges/version/mrremind)](https://cran.r-project.org/package=mrremind) [![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)

Expand Down Expand Up @@ -39,7 +39,7 @@ In case of questions / problems please contact Lavinia Baumstark <lavinia@pik-po

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

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 (2024). _mrremind: MadRat REMIND Input Data Package_. R package version 0.204.0, <https://github.com/pik-piam/mrremind>.
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 (2024). _mrremind: MadRat REMIND Input Data Package_. R package version 0.204.1, <https://github.com/pik-piam/mrremind>.

A BibTeX entry for LaTeX users is

Expand All @@ -48,7 +48,7 @@ A BibTeX entry for LaTeX users is
title = {mrremind: MadRat REMIND Input Data Package},
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},
year = {2024},
note = {R package version 0.204.0},
note = {R package version 0.204.1},
url = {https://github.com/pik-piam/mrremind},
}
```
3 changes: 1 addition & 2 deletions man/calcCapacity.Rd

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

14 changes: 14 additions & 0 deletions man/calcIRENA.Rd

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

0 comments on commit 590cfa2

Please sign in to comment.