Skip to content

Commit

Permalink
remove redundant parameter 'filterOutput'
Browse files Browse the repository at this point in the history
  • Loading branch information
fbenke-pik committed Feb 16, 2022
1 parent 7e2a612 commit d4ff0e3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
7 changes: 3 additions & 4 deletions R/calcIEA_ETP.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#'
#' @author Falk Benke
#'
#' @param filterOutput either "only_regi_meaningful" to filter variables that are too imprecise on regional level, or NULL
#' @param isValidation indicates if result will be used in validation (as opposed to generating input data)
#' @importFrom dplyr select mutate left_join
#' @importFrom madrat toolGetMapping
Expand All @@ -14,7 +13,7 @@
#' @importFrom stats aggregate na.pass
#' @export

calcIEA_ETP <- function(filterOutput = NULL, isValidation = FALSE) {
calcIEA_ETP <- function(aggregate, isValidation = FALSE) {

mapping <- toolGetMapping("Mapping_IEA_ETP.csv", type = "reportingVariables") %>%
filter(!is.na(!!sym("REMIND")), !!sym("REMIND") != "") %>%
Expand Down Expand Up @@ -55,8 +54,8 @@ calcIEA_ETP <- function(filterOutput = NULL, isValidation = FALSE) {
x <- aggregate(value ~ region + year + model + variable, x, sum, na.action = na.pass) %>%
as.magpie()


if (!is.null(filterOutput) && filterOutput == "only_regi_meaningful") {
# filter variables that are too imprecise on regional level
if (aggregate == "region") {
x <- x[, , c(
"Production|Industry|Cement (Mt/yr)",
"Production|Industry|Steel (Mt/yr"
Expand Down
12 changes: 7 additions & 5 deletions R/calcIEA_WEO_2021.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#'
#' @md
#' @return A [`magpie`][magclass::magclass] object.
#' @param subtype Either "GLO" or "regional", i.e. global or regional data from source
#' @param isValidation indicates if result will be used in validation (as opposed to generating input data)
#' @author Falk Benke
#' @importFrom dplyr select mutate left_join case_when
Expand All @@ -11,9 +10,12 @@
#' @importFrom rlang sym
#' @export

calcIEA_WEO_2021 <- function(subtype = "GLO", isValidation = FALSE) {
if (!subtype %in% c("GLO", "regional")) {
stop("Not a valid subtype! Must be either \"regional\" or \"GLO\"")
calcIEA_WEO_2021 <- function(aggregate, isValidation = FALSE) {

if (!aggregate %in% c("global", "region")) {
subtype = "global"
} else {
subtype = aggregate
}

mapping <- toolGetMapping("Mapping_IEA_WEO_2021.csv", type = "reportingVariables") %>%
Expand Down Expand Up @@ -58,7 +60,7 @@ calcIEA_WEO_2021 <- function(subtype = "GLO", isValidation = FALSE) {

x <- as.magpie(x, spatial = 1, temporal = 2, data = 5)

if (subtype == "GLO") {
if (subtype == "global") {
x <- add_columns(x, "Cap|Electricity|Biomass|w/o CC (GW)", dim = 3.2)
x[, , "Cap|Electricity|Biomass|w/o CC (GW)"] <- x[, , "Cap|Electricity|Biomass (GW)"] - x[, , "Cap|Electricity|Biomass|w/ CC (GW)"]

Expand Down
10 changes: 5 additions & 5 deletions R/convertIEA_WEO_2021.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#' Disaggregates IEA WEO 2021 Data
#' @param x MAgPIE object to be converted
#' @return A [`magpie`][magclass::magclass] object.
#' @param subtype Either "GLO" or "regional"
#' @param subtype Either "global" or "region"
#' @author Falk Benke
#' @importFrom madrat getISOlist
#'

convertIEA_WEO_2021 <- function(x, subtype = "GLO") {
convertIEA_WEO_2021 <- function(x, subtype = "global") {
PE <- calcOutput("PE", aggregate = FALSE)
if (subtype == "GLO") {
if (subtype == "global") {

# for now, we only have complete data on global level
x.world <- x["World", , ]
Expand All @@ -25,7 +25,7 @@ convertIEA_WEO_2021 <- function(x, subtype = "GLO") {
weight <- PE[, 2016, "PE (EJ/yr)"]
x.world <- toolAggregate(x.world, rel = mapping_world, weight = weight)
return(x.world)
} else if (subtype == "regional") {
} else if (subtype == "region") {
.removeNaRegions <- function(x) {
remove <- magpply(x, function(y) all(is.na(y)), MARGIN = 1)
return(x[!remove, , ])
Expand Down Expand Up @@ -124,6 +124,6 @@ convertIEA_WEO_2021 <- function(x, subtype = "GLO") {

return(x.regional)
} else {
stop("Not a valid subtype! Must be either \"regional\" or \"GLO\"")
stop("Not a valid subtype! Must be either \"region\" or \"global\"")
}
}
16 changes: 6 additions & 10 deletions R/fullVALIDATIONREMIND.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,16 @@ fullVALIDATIONREMIND <- function(rev = 0) {
calcOutput("Historical", round = 5, file = valfile, aggregate = "region+global+missingH12",
append = FALSE, na_warning = FALSE, try = TRUE)

calcOutput(type = "IEA_ETP", aggregate = "GLO", file = valfile,
append = TRUE, na_warning = FALSE, try = TRUE,
filterOutput = NULL, isValidation = TRUE)
calcOutput(type = "IEA_ETP", aggregate = "global", file = valfile,
append = TRUE, na_warning = FALSE, try = TRUE, isValidation = TRUE)

calcOutput(type = "IEA_ETP", aggregate = "region", file = valfile,
append = TRUE, na_warning = FALSE, try = TRUE,
filterOutput = "only_regi_meaningful", isValidation = TRUE)
append = TRUE, na_warning = FALSE, try = TRUE, isValidation = TRUE)

calcOutput(type = "IEA_WEO_2021", aggregate = "GLO", file = valfile,
append = TRUE, na_warning = FALSE, try = TRUE,
subtype = "GLO", isValidation = TRUE)
calcOutput(type = "IEA_WEO_2021", aggregate = "global", file = valfile,
append = TRUE, na_warning = FALSE, try = TRUE, isValidation = TRUE)

calcOutput(type = "IEA_WEO_2021", aggregate = "region", file = valfile,
append = TRUE, na_warning = FALSE, try = TRUE,
subtype = "regional", isValidation = TRUE)
append = TRUE, na_warning = FALSE, try = TRUE, isValidation = TRUE)

}

0 comments on commit d4ff0e3

Please sign in to comment.