Skip to content
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

Generate global and regional mif #205

Merged
merged 10 commits into from
Feb 17, 2022
7 changes: 2 additions & 5 deletions R/calcHistorical.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#' Gather reference data from various sources.
#' @importFrom magclass setNames getNames getSets add_columns
#' @importFrom luscale rename_dimnames

Expand Down Expand Up @@ -177,8 +178,6 @@ calcHistorical <- function() {
ARIADNE_ReferenceScenarioPop <- add_dimension(ARIADNE_ReferenceScenarioPop,
dim = 3.1, add = "model", nm = "ARIADNE")

IEA_ETP <- calcOutput("IEA_ETP", aggregate = F)

IEA_EVOutlook <- calcOutput("IEA_EVOutlook", aggregate = F)

# Calculate Emission Reference Values
Expand Down Expand Up @@ -235,8 +234,6 @@ calcHistorical <- function() {
BP <- calcOutput("BP", aggregate = FALSE)
BP <- add_dimension(BP, dim = 3.1, add = "model", nm = "BP")

WEO_2021 <- calcOutput("IEA_WEO_2021", subtype = "regional", aggregate = F)

# Steel Production ----
worldsteel <- readSource('worldsteel', convert = FALSE) %>%
madrat_mule() %>%
Expand Down Expand Up @@ -294,7 +291,7 @@ calcHistorical <- function() {
LU_EDGAR_LU, LU_CEDS, LU_FAO_EmisLUC, LU_FAO_EmisAg, LU_PRIMAPhist, IRENAcap, eurostat, #emiMktES, emiMktETS, emiMktESOthers,
EU_ReferenceScenario, emiEurostat, ARIADNE_ReferenceScenarioGdp, ARIADNE_ReferenceScenarioGdpCorona,
ARIADNE_ReferenceScenarioPop, EEA_GHGSectoral, EEA_GHGTotal, EEA_GHGProjections, Emi_Reference, #, EEA_GHGES
IEA_ETP, IEA_EVOutlook, INNOPATHS, JRC_Industry, JRC_Transport, JRC_ResCom, AGEB_FE, UBA_emi, UNFCCC, BP, worldsteel, WEO_2021)
IEA_EVOutlook, INNOPATHS, JRC_Industry, JRC_Transport, JRC_ResCom, AGEB_FE, UBA_emi, UNFCCC, BP, worldsteel)

y <- Reduce(union,lapply(varlist,getYears))
n <- Reduce(c,lapply(varlist,getNames))
Expand Down
16 changes: 15 additions & 1 deletion R/calcIEA_ETP.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
#'
#' @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
#' @importFrom magclass as.magpie
#' @importFrom rlang sym
#' @importFrom stats aggregate na.pass
#' @export

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

mapping <- toolGetMapping("Mapping_IEA_ETP.csv", type = "reportingVariables") %>%
filter(!is.na(!!sym("REMIND")), !!sym("REMIND") != "") %>%
Expand Down Expand Up @@ -52,6 +54,18 @@ calcIEA_ETP <- function() {

x <- aggregate(value ~ region + year + model + variable, x, sum, na.action = na.pass) %>%
as.magpie()


if (!is.null(filterOutput) && filterOutput == "only_regi_meaningful") {
x <- x[, , c(
"Production|Industry|Cement (Mt/yr)",
"Production|Industry|Steel (Mt/yr"
), pmatch = T, invert = T]
}

if (isValidation) {
x <- add_dimension(x, dim = 3.1, add = "scenario", nm = "historical")
}

return(list(
x = x,
Expand Down
11 changes: 8 additions & 3 deletions R/calcIEA_WEO_2021.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
#'
#' @md
#' @return A [`magpie`][magclass::magclass] object.
#' @param subtype Either "GLO" or "regional"
#' @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
#' @importFrom madrat toolGetMapping
#' @importFrom magclass as.magpie
#' @importFrom rlang sym
#' @export


calcIEA_WEO_2021 <- function(subtype = "GLO") {
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\"")
}
Expand Down Expand Up @@ -75,8 +75,13 @@ calcIEA_WEO_2021 <- function(subtype = "GLO") {
x[, , "Cap|Electricity|Gas (GW)"] <- x[, , "Cap|Electricity|Gas|w/o CC (GW)"] + x[, , "Cap|Electricity|Gas|w/ CC (GW)"]
}

if (isValidation) {
x <- add_dimension(x, dim = 3.1, add = "scenario", nm = "historical")
}

return(list(
x = x,
weight = NULL,
unit = c("GW", "EJ/yr", "Mt CO2/yr"),
description = "IEA WEO 2021 values as REMIND variables"
))
Expand Down
22 changes: 21 additions & 1 deletion R/fullVALIDATIONREMIND.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@
fullVALIDATIONREMIND <- function(rev = 0) {

#-------------- historical data ---------------------------------------------------------------------
calcOutput("Historical", round = 5, file = "historical.mif", aggregate = "region+global+missingH12")

valfile <- "historical.mif"

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 = "region", file = valfile,
append = TRUE, na_warning = FALSE, try = TRUE,
filterOutput = "only_regi_meaningful", 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 = "region", file = valfile,
append = TRUE, na_warning = FALSE, try = TRUE,
subtype = "regional", isValidation = TRUE)

}