Skip to content

Commit

Permalink
merge upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
pweigmann committed Sep 27, 2024
2 parents e07019f + 324e824 commit 7d7790b
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '38484600'
ValidationKey: '38486525'
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 CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ message: If you use this software, please cite it using the metadata from this f
type: software
title: 'mrremind: MadRat REMIND Input Data Package'
version: 0.192.5
date-released: '2024-09-26'
date-released: '2024-09-27'
abstract: The mrremind packages contains data preprocessing for the REMIND model.
authors:
- family-names: Baumstark
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Type: Package
Package: mrremind
Title: MadRat REMIND Input Data Package
Version: 0.192.5
Date: 2024-09-26
Date: 2024-09-27
Authors@R: c(
person("Lavinia", "Baumstark", , "[email protected]", role = c("aut", "cre")),
person("Renato", "Rodrigues", role = "aut"),
Expand Down
13 changes: 6 additions & 7 deletions R/calcAGEB.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
#' @param subtype data subtype. Either "balances" ("Auswertungstabellen zur Energiebilanz Deutschland") or
#' "electricity" ("Bruttostromerzeugung in Deutschland nach Energieträgern")
#' @importFrom dplyr select mutate left_join
#' @importFrom rlang sym
#' @importFrom stats aggregate
#' @export
calcAGEB <- function(subtype = "balances") {
ageb <- readSource("AGEB", subtype = subtype)

mapping <- toolGetMapping("Mapping_AGEB_REMIND.csv", type = "reportingVariables", where = "mappingfolder") %>%
mutate("conversion" = as.numeric(!!sym("Factor")) * !!sym("Weight")) %>%
mapping <- toolGetMapping("Mapping_AGEB_REMIND.csv", type = "reportingVariables", where = "mrremind") %>%
mutate("conversion" = as.numeric(.data$Factor)) %>%
select("variable" = "AGEB_variable", "REMIND_variable", "conversion", "unit" = "Unit_AGEB", "Unit_REMIND") %>%
filter(!!sym("REMIND_variable") != "")
filter(.data$REMIND_variable != "")

x <- left_join(
ageb %>%
Expand All @@ -29,11 +28,11 @@ calcAGEB <- function(subtype = "balances") {
"unit" = "Data2", "value" = "Value"
),
mapping,
by = "variable"
by = "variable", relationship = "many-to-many"
) %>%
mutate(
"value" = !!sym("value") * !!sym("conversion"),
"REMIND_variable" = paste0(!!sym("REMIND_variable"), " (", !!sym("Unit_REMIND"), ")")
"value" = .data$value * .data$conversion,
"REMIND_variable" = paste0(.data$REMIND_variable, " (", .data$Unit_REMIND, ")")
) %>%
select("variable" = "REMIND_variable", "region", "year", "value")

Expand Down
53 changes: 37 additions & 16 deletions R/readAGEB.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,42 @@ readAGEB <- function(subtype = "balances") {
as.magpie() %>%
return()
} else if (subtype == "electricity") {
read_xlsx(
path = "STRERZ_Abg_02_2024_korr.xlsx",
sheet = "STRERZ (brutto)", col_names = TRUE,
col_types = c("text", rep("numeric", 34)),
range = "B3:AJ17", .name_repair = "minimal", na = c("k.A.")
) %>%
mutate("TWh" = gsub(", darunter:", "", !!sym("TWh"))) %>%
mutate("TWh" = gsub("- ", "", !!sym("TWh"))) %>%
mutate("TWh" = gsub("[0-9])", "", !!sym("TWh"))) %>%
mutate("variable" = paste0("9 Bruttostromerzeugung|", !!sym("TWh"))) %>%
select(-1) %>%
reshape2::melt(id.vars = c("variable"), variable.name = "period", value.name = "value") %>%
mutate("region" = "DEU", "unit" = "TWh") %>%
select("region", "period", "variable", "unit", "value") %>%
as.magpie() %>%
return()

sheets <- tibble(
sheet = c("STRERZ (brutto)", "STRERZ (netto)"),
prefix = c("9 Bruttostromerzeugung", "10 Nettostromerzeugung")
)

data <- NULL

for (i in seq(1:nrow(sheets))) {
tmp <- read_xlsx(
path = "STRERZ_Abg_02_2024_korr.xlsx",
sheet = sheets[["sheet"]][[i]],
col_names = TRUE,
col_types = c("text", rep("numeric", 34)),
range = "B3:AJ23", .name_repair = "minimal", na = c("k.A.")
) %>%
mutate("TWh" = gsub(", darunter:", "", .data$TWh)) %>%
mutate("TWh" = gsub("- ", "", .data$TWh)) %>%
mutate("TWh" = gsub("[0-9])", "", .data$TWh)) %>%
mutate("TWh" = trimws(.data$TWh))

tmp[12,"TWh"] <- "Erneuerbare, darunter Hausmüll"
tmp[16,"TWh"] <- "Sonstige, darunter Hausmüll"

tmp <- tmp %>%
mutate("variable" = paste0(sheets[["prefix"]][[i]], "|", .data$TWh)) %>%
select(-1) %>%
reshape2::melt(id.vars = c("variable"), variable.name = "period", value.name = "value") %>%
mutate("region" = "DEU", "unit" = "TWh") %>%
select("region", "period", "variable", "unit", "value")

data <- rbind(data, tmp)

}

return(as.magpie(data))

}
}
Loading

0 comments on commit 7d7790b

Please sign in to comment.