Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/pik-piam/mrremind into we…
Browse files Browse the repository at this point in the history
…o-ref
  • Loading branch information
fbenke-pik committed Aug 28, 2024
2 parents 80bbdf4 + c02a561 commit 79f32dc
Show file tree
Hide file tree
Showing 18 changed files with 527 additions and 141 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '36687448'
ValidationKey: '37105140'
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
- 'Warning: namespace ''.*'' is not available and has been replaced'
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:
- id: mixed-line-ending

- repo: https://github.com/lorenzwalthert/precommit
rev: 7910e0323d7213f34275a7a562b9ef0fde8ce1b9 # frozen: v0.4.2
rev: bae853d82da476eee0e0a57960ee6b741a3b3fb7 # frozen: v0.4.3
hooks:
- id: parsable-R
- id: deps-in-desc
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: 'mrremind: MadRat REMIND Input Data Package'
version: 0.184.1
date-released: '2024-07-24'
version: 0.186.0
date-released: '2024-08-14'
abstract: The mrremind packages contains data preprocessing for the REMIND model.
authors:
- family-names: Baumstark
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: mrremind
Title: MadRat REMIND Input Data Package
Version: 0.184.1
Date: 2024-07-24
Version: 0.186.0
Date: 2024-08-14
Authors@R: c(
person("Lavinia", "Baumstark", , "[email protected]", role = c("aut", "cre")),
person("Renato", "Rodrigues", role = "aut"),
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export(calcIndustry_Value_Added)
export(calcODYM_RECC)
export(calcOtherFossilInElectricity)
export(calcPlasticsEoL)
export(calcProjectPipelines)
export(calcShareIndFE)
export(calcSteelStock)
export(calcSteel_Projections)
Expand All @@ -45,6 +46,7 @@ export(convertUBA)
export(convertUNFCCC)
export(convertUNIDO)
export(convertUSGS)
export(exportThresholds)
export(filter_historical_mif)
export(readADVANCE_WP2)
export(readAGEB)
Expand Down
2 changes: 1 addition & 1 deletion R/calcCCScapacity.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ calcCCScapacity <- function(subtype) {
x = x,
weight = NULL,
unit = "MtCO2/yr",
description = "CCS capacitiy derived from IEA CCUS project database"
description = "CCS capacity derived from IEA CCUS project database"
))
}
8 changes: 7 additions & 1 deletion R/calcGlobalEnergyMonitor.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#' Calculate REMIND variables from Global Energy Monitor
#' Calc capacities from Global Energy Monitor
#'
#' Calculate near-term expectations of capacities for use in fullVALIDATION.R
#'
#' @md
#' @return A [`magpie`][magclass::magclass] object.
Expand All @@ -13,6 +15,10 @@ calcGlobalEnergyMonitor <- function() {
# set 0s in other CHA countries than China to approximate CHA as China
x[c("HKG", "MAC", "TWN"), , ] <- 0

# ASSUMPTION: sum over all statuses
# this means that all planned projects will be realized!
x <- dimSums(x, dim = "status")

return(list(
x = x,
weight = NULL,
Expand Down
191 changes: 191 additions & 0 deletions R/calcProjectPipelines.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
#' calc Project Pipelines
#'
#' Calculate the expected near-term deployment of technologies based on
#' projects that are currently either being built or in a planning stage
#' for some technologies multiple sources are available
#'
#' @author Pascal Weigmann
#'
#' @param subtype choose technology `biomass`, `coal`, `geothermal`, `hydro`,
#' `nuclear`, `solar`, `wind` or `CCS`
#'
#' @export
calcProjectPipelines <- function(subtype) {
# CCS ####
# Discussion about CCS assumptions
# https://gitlab.pik-potsdam.de/REMIND/committed/-/issues/1
if (subtype == "CCS") {

x <- readSource("IEA_CCUS", subtype = "pipeline")

# take away 50% of capacities from Norway and UK and shift to EUR
x[c("NOR", "GBR"), , ] <- x[c("NOR", "GBR"), , ] * 0.5

mapping <- toolGetMapping("extramapping_EU27.csv",
where = "mappingfolder", type = "regional") %>%
filter(.data$EU27_map == "EU27")
eu27 <- unique(mapping$CountryCode)

# sum up EU27 capacities and add half of Norway / UK capacities
eu27Pool <-
dimSums(x[eu27, , ], dim = 1) + dimSums(x[c("NOR", "GBR"), , ], dim = 1)
getItems(eu27Pool, dim = 1) <- "EU27"

# distribute EU27 pool to the countries according to GDP
gdp <- calcOutput("GDP", aggregate = FALSE)[eu27, 2020, "gdp_SSP2EU"]
eu27Pool <- toolAggregate(eu27Pool,
rel = mapping, weight = gdp,
from = "EU27_map", to = "CountryCode")
x[eu27, , ] <- eu27Pool

# ASSUMPTION: no projects are under way in Brasil which means all thresholds are equal
# to avoid this, add manually an upper estimate of what could still be planned in BRA
x["BRA", 2025:2029, "Carbon Management|Storage.planned"] <-
x["BRA", 2025:2029, "Carbon Management|Storage.planned"] + 2
x["BRA", 2030, "Carbon Management|Storage.planned"] <-
x["BRA", 2030, "Carbon Management|Storage.planned"] + 10


# formulation of upper and lower bounds for the near-term validation
x <- mbind(
x,
# ASSUMPTION: min_red = operational
setNames(x[, , "Carbon Management|Storage.operational"],
"Carbon Management|Storage.min_red"),

# ASSUMPTION: min_yel = operational + 0.5*construction
setNames(x[, , "Carbon Management|Storage.operational"] +
x[, , "Carbon Management|Storage.construction"]*0.5,
"Carbon Management|Storage.min_yel"),

# ASSUMPTION: max_yel = operational + construction + 0.3*planned
setNames(x[, , "Carbon Management|Storage.operational"] +
x[, , "Carbon Management|Storage.construction"] +
x[, , "Carbon Management|Storage.planned"]*0.3,
"Carbon Management|Storage.max_yel"),

# ASSUMPTION: max_red = operational + construction + planned
setNames(x[, , "Carbon Management|Storage.operational"] +
x[, , "Carbon Management|Storage.construction"] +
x[, , "Carbon Management|Storage.planned"],
"Carbon Management|Storage.max_red"))

# meta data
x <- add_dimension(x, dim = 3.1, add = "model", nm = "IEA CCUS")
x <- add_dimension(x, dim = 3.4, add = "unit", nm = "MtCO2/yr")
unit <- "MtCO2/yr"
description <- "CCS project pipeline from IEA CCUS project database"

# Hydro ####
# Discussion about Hydro assumptions
# https://gitlab.pik-potsdam.de/REMIND/committed/-/issues/2
} else if (subtype == "hydro") {
# without pumped storage
x <- readSource("GlobalEnergyMonitor")
x <- x[, , "Hydro", pmatch = T]

x <- mbind(x,
# ASSUMPTION: min_red = operating
setNames(x[, , "operating"],
"GlobalEnergyMonitor.Cap|Electricity|Hydro.min_red.GW"),

# ASSUMPTION: min_yel = operating + 0.5*construction + 0.2*pre-construction
setNames(x[, , "operating"] +
x[, , "construction"]*0.5 +
x[, , "pre-construction"]*0.2,
"GlobalEnergyMonitor.Cap|Electricity|Hydro.min_yel.GW"),

# ASSUMPTION: max_yel = operating + construction + 0.8*pre-construction + 0.3*announced
setNames(x[, , "operating"] +
x[, , "construction"] +
x[, , "pre-construction"]*0.8 +
x[, , "announced"]*0.3,
"GlobalEnergyMonitor.Cap|Electricity|Hydro.max_yel.GW"),

# ASSUMPTION: max_red = operating + construction + pre-construction + announced
setNames(x[, , "operating"] +
x[, , "construction"] +
x[, , "pre-construction"] +
x[, , "announced"],
"GlobalEnergyMonitor.Cap|Electricity|Hydro.max_red.GW")
)

# meta data
unit <- "GW"
description <- "Hydro project pipeline from GEM"

# TODO: coming up next
# # Biomass ####
# } else if (subtype == "biomass") {
# x <- readSource("GlobalEnergyMonitor")
# x <- x[, , "Biomass", pmatch = T]
#
#
# # meta data
# unit <- "GW"
# description <- "Biomass project pipeline from GEM"
#
# # Nuclear ####
# } else if (subtype == "nuclear") {
# x <- readSource("GlobalEnergyMonitor")
# x <- x[, , "Nuclear", pmatch = T]
#
#
#
# # meta data
# unit <- "GW"
# description <- "Nuclear project pipeline from GEM"
#
# # Coal ####
# } else if (subtype == "coal") {
# x <- readSource("GlobalEnergyMonitor")
# x <- x[, , "Coal", pmatch = T]
#
#
#
# # meta data
# unit <- "GW"
# description <- "Coal project pipeline from GEM"
#
# # Geothermal ####
# } else if (subtype == "geothermal") {
# x <- readSource("GlobalEnergyMonitor")
# x <- x[, , "Geothermal", pmatch = T]
#
#
#
# # meta data
# unit <- "GW"
# description <- "Geothermal project pipeline from GEM"
# # Solar ####
# } else if (subtype == "solar") {
# x <- readSource("GlobalEnergyMonitor")
# x <- x[, , "Solar", pmatch = T]
#
# # meta data
# unit <- "GW"
# description <- "Solar project pipeline from GEM"
#
# # Wind ####
# } else if (subtype == "wind") {
# x <- readSource("GlobalEnergyMonitor")
# x <- x[, , "Wind", pmatch = T]
#
# #
#
#
# # meta data
# unit <- "GW"
# description <- "Wind project pipeline from GEM"
#
}

x <- x[ ,c(2025, 2030), ]

return(list(
x = x,
unit = unit,
weight = NULL,
description = description
))
}
2 changes: 1 addition & 1 deletion R/convertGlobalEnergyMonitor.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
#' @export
convertGlobalEnergyMonitor <- function(x) {
getItems(x, dim = 1) <- toolCountry2isocode(getItems(x, dim = 1))
x <- toolCountryFill(x, no_remove_warning = "KOS", verbosity = 2)
x <- toolCountryFill(x, no_remove_warning = "KOS", verbosity = 2, fill = 0)
return(x)
}
76 changes: 76 additions & 0 deletions R/exportThresholds.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#' export validation thresholds
#'
#' assemble near-term thresholds from project pipelines and potentially other
#' data sources and export them to a file
#'
#' @author Pascal Weigmann
#' @param type choose either "config" to export thresholds as used in the
#' validationConfig or "full" to export all pipeline data
#' @param years choose years to include, currenty only 2025 and 2030 are
#' available, if NULL uses all available years
#' @export
exportThresholds <- function(type = "config", years = NULL) {

# get region mappings for aggregation ----
# Determines all regions data should be aggregated to by examining the columns
# of the `regionmapping` and `extramappings` currently configured.
rel <- "global" # always compute global aggregate
for (mapping in c(getConfig("regionmapping"), getConfig("extramappings"))) {
columns <- setdiff(
colnames(toolGetMapping(mapping, "regional")),
c("X", "CountryCode")
)

if (any(columns %in% rel)) {
warning(
"The following column(s) from ", mapping,
" exist in another mapping an will be ignored: ",
paste(columns[columns %in% rel], collapse = ", ")
)
}
rel <- unique(c(rel, columns))
}

columnsForAggregation <- gsub(
"RegionCode", "region",
paste(rel, collapse = "+")
)

# the following magclass objects are expected to have the dimensions "status"
# as dim 3.3
ccs <- calcOutput("ProjectPipelines", subtype = "CCS",
aggregate = columnsForAggregation, round = 3,
warnNA = FALSE, try = FALSE, years = years)

hydro <- calcOutput("ProjectPipelines", subtype = "hydro",
aggregate = columnsForAggregation, round = 3,
warnNA = FALSE, try = FALSE, years = years)

# combine and export data to madrat output folder
out <- mbind(ccs, hydro)
if (type == "full") {
# write report containing all available data, including all statuses and
# thresholds attached to "variable"
outfile <- "pipelines.mif"
as.quitte(out) %>%
mutate(variable = paste(variable, status, sep = "|")) %>%
select(-scenario, -status) %>%
as.magpie() %>%
write.report(file = paste0(getConfig("outputfolder"), "/", outfile))

} else if (type == "config") {
# write report containing only the "min/max" thresholds in extra columns
# (as used in a validationConfig)
outfile <- "thresholds.mif"
out[, , c("min_", "max_"), pmatch = TRUE] %>%
as.quitte() %>%
pivot_wider(names_from = "status") %>%
select(-scenario) %>%
write.csv(file = paste0(getConfig("outputfolder"), "/", outfile),
row.names = FALSE, quote = FALSE)

} else {
warning("`type` must be either `full` or `config`")
}

}
Loading

0 comments on commit 79f32dc

Please sign in to comment.