-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add new data source: Ember #327
Changes from all commits
a18b7c6
45841c2
f528d80
5743c0c
2e1ef04
4a12561
71d6018
d297a79
a19ab1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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.146.0 | ||
Date: 2022-10-17 | ||
Version: 0.147.0 | ||
Date: 2022-10-21 | ||
Authors@R: c( | ||
person("Lavinia", "Baumstark", , "[email protected]", role = c("aut", "cre")), | ||
person("Renato", "Rodrigues", role = "aut"), | ||
|
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#' @title calc Ember | ||
#' @description prepare the yearly Ember electricity data set | ||
#' To use only a part of the Ember data, call calcOutput("Ember", subtype = "...") | ||
#' and convert to TW if you want to use capacities as input data to REMIND. | ||
#' | ||
#' @param subtype data subtype. Either "capacity", "generation" or "all" | ||
#' | ||
#' @return A [`magpie`][magclass::magclass] object. | ||
#' | ||
#' @seealso [`calcOutput()`] | ||
#' | ||
#' @author Pascal Weigmann | ||
#' | ||
#' @importFrom madrat toolAggregate toolGetMapping | ||
#' @importFrom magclass collapseDim | ||
#' | ||
#' @export | ||
|
||
calcEmber <- function(subtype = "all") { | ||
|
||
# get Ember data | ||
x <- readSource("Ember") | ||
|
||
if (subtype == "capacity") { | ||
# choose only capacity variables | ||
x <- x[, , "GW"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do you need to treat "capacity" and "generation" special here and cannot always read in all? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah this is already the calc-function - got it |
||
description <- "Capacities from the yearly Ember electricity data set" | ||
|
||
} else if (subtype == "generation") { | ||
# choose only generation variables | ||
x <- x[, , "TWh"] | ||
description <- "Electricity generation from the yearly Ember electricity data set" | ||
|
||
} else if (subtype == "all") { | ||
# remove all variables with % as unit, as they are not used and make data preparation more complicated | ||
x <- x[, , "%", invert = TRUE] | ||
description <- "Capacities and electricity generation from the yearly Ember electricity data set" | ||
|
||
} else { | ||
stop("Not a valid subtype!") | ||
} | ||
|
||
# load and apply mapping to chosen variables | ||
map <- toolGetMapping("Mapping_Ember.csv", type = "reportingVariables") %>% | ||
filter(!is.na(!!sym("REMIND_Variable")), !!sym("REMIND_Variable") != "") # remove incomplete mapping rows | ||
|
||
# combine variable and unit in mapping | ||
map$REMIND_Variable_Unit <- paste0(map$REMIND_Variable, " (", map$REMIND_Unit, ")") | ||
|
||
# drop unit dimension as unit is now part of the variable name | ||
x <- collapseDim(x, dim = 3.2) | ||
|
||
# apply mapping - careful: units are changed already, values not converted yet | ||
x <- toolAggregate(x, dim = 3.1, rel = map, from = "Variable", | ||
to = "REMIND_Variable_Unit", partrel = TRUE, verbosity = 2) | ||
|
||
# convert values using factors from mapping | ||
for (var in getNames(x, dim = 1)) { | ||
x[, , var] <- x[, , var] * map[map$REMIND_Variable_Unit == var, "Factor"] | ||
} | ||
|
||
return(list(x = x, weight = NULL, unit = "various", description = description)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#' Convert Ember data | ||
#' | ||
#' @md | ||
#' @param x A [`magpie`][magclass::magclass] object returned from | ||
#' [`readHRE()`]. | ||
#' | ||
#' @return A [`magpie`][magclass::magclass] object. | ||
#' | ||
#' @author Pascal Weigmann | ||
#' | ||
#' @importFrom madrat toolCountryFill | ||
#' | ||
#' @export | ||
|
||
convertEmber <- function(x) { | ||
|
||
# add missing countries | ||
x <- toolCountryFill(x, fill = 0, verbosity = 2) | ||
|
||
# replace NA by 0 to enable aggregation over incomplete regions | ||
x[is.na(x)] <- 0 | ||
|
||
return(x) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#' Read Ember Yearly Electricity Data | ||
#' | ||
#' @return A [`magpie`][magclass::magclass] object. | ||
#' | ||
#' @author Pascal Weigmann | ||
#' | ||
#' @seealso [`readSource()`] | ||
#' @source https://ember-climate.org/data-catalogue/yearly-electricity-data/ | ||
#' | ||
#' @importFrom dplyr select | ||
#' @importFrom magclass as.magpie | ||
#' | ||
#' @export | ||
|
||
readEmber <- function() { | ||
filename <- "yearly_full_release_long_format.csv" | ||
df <- read.csv(filename) | ||
|
||
# filter out aggregated regions by only choosing rows that don't have a blank country.code | ||
df <- df[df$Country.code != "", ] | ||
|
||
# combine category columns to one variable column and rename according to madrat standard | ||
df$variable <- paste(df$Category, df$Subcategory, df$Variable, sep = "|") | ||
df <- select(df, c(region = "Country.code", | ||
year = "Year", | ||
variable = "variable", | ||
unit = "Unit", | ||
value = "Value")) | ||
|
||
# convert to magpie object | ||
x <- as.magpie(df, tidy = TRUE) | ||
|
||
return(x) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe another name would help understanding, what is happening, e.g. calcEmberCleaned ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I didn't plan to use another calc function for "Ember" but would just call
calcOutput("Ember", subtype = "capacity")
incalcCapacity()
for example. The only thing left to do there would be to convert to TW.