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
34 changes: 34 additions & 0 deletions R/calcValidIEA_ETP.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#' Generate IEA ETP data used for validation in historical.mif
#'
#' @md
#' @return A [`magpie`][magclass::magclass] object.
#'
#' @author Falk Benke
#'
#' @param varSet either "all" or "only_regi_meaningful" to filter variables that are too imprecise on regional level
#' @export

calcValidIEA_ETP <- function(varSet) {

if (!varSet %in% c("all", "only_regi_meaningful")) {
stop("Not a valid subtype! Must be either \"all\" or \"only_regi_meaningful\"")
}

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

if (varSet == "only_regi_meaningful") {
data <- data[, , c(
"Production|Industry|Cement (Mt/yr)",
"Production|Industry|Steel (Mt/yr"
), pmatch = T, invert = T]
}

data <- add_dimension(data, dim = 3.1, add = "scenario", nm = "historical")

return(list(
x = data,
weight = NULL,
unit = c("EJ/yr", "Mt CO2/yr", "Mt/yr", "bn pkm/yr", "bn tkm/yr"),
description = "IEA ETP projections as REMIND variables"
))
}
4 changes: 3 additions & 1 deletion R/calcIEA_WEO_2021.R → R/calcValidIEA_WEO_2021.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#' @importFrom rlang sym
#' @export

calcValidIEA_WEO_2021 <- function(subtype = "GLO") {

calcIEA_WEO_2021 <- function(subtype = "GLO") {
if (!subtype %in% c("GLO", "regional")) {
stop("Not a valid subtype! Must be either \"regional\" or \"GLO\"")
}
Expand Down Expand Up @@ -74,6 +74,8 @@ calcIEA_WEO_2021 <- function(subtype = "GLO") {
x <- add_columns(x, "Cap|Electricity|Gas (GW)", dim = 3.2)
x[, , "Cap|Electricity|Gas (GW)"] <- x[, , "Cap|Electricity|Gas|w/o CC (GW)"] + x[, , "Cap|Electricity|Gas|w/ CC (GW)"]
}

x <- add_dimension(x, dim = 3.1, add = "scenario", nm = "historical")

return(list(
x = x,
Expand Down
18 changes: 17 additions & 1 deletion R/fullVALIDATIONREMIND.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@
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 = "ValidIEA_ETP", aggregate = "GLO", file = valfile,
append = TRUE, na_warning = FALSE, try = TRUE, varSet = "all")

calcOutput(type = "ValidIEA_ETP", aggregate = "region", file = valfile,
append = TRUE, na_warning = FALSE, try = TRUE, varSet = "only_regi_meaningful")

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

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

}