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
41 changes: 41 additions & 0 deletions R/calcHistoricalGlobal.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#' Gather global reference data from various sources. Call this function with aggregate = "global".
#' @importFrom magclass setNames getNames getSets add_columns
#' @importFrom luscale rename_dimnames
#' @importFrom madrat getISOlist
#'

calcHistoricalGlobal <- function() {

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

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

# ====== start: blow up to union of years ===================
# find all existing years (y) and variable names (n)

varlist <- list(IEA_ETP, WEO_2021)

y <- Reduce(union, lapply(varlist, getYears))
n <- Reduce(c, lapply(varlist, getNames))
y <- sort(y)

# create empty object with full temporal, regional and data dimensionality
data <- new.magpie(getISOlist(), y, n, fill = NA)

getSets(data)[3] <- "model"
getSets(data)[4] <- "variable"

# transfer data of existing years
for (i in varlist) {
data[, getYears(i), getNames(i)] <- i
}
# ====== end: blow up to union of years ===================

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

# rename dimension "data" into "variable"
getSets(data)[5] <- "variable"

return(list(x = data, weight = NULL, unit = "Various", description = "Historical Data"))
}
47 changes: 47 additions & 0 deletions R/calcHistoricalRegion.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#' Gather global reegional data from various sources. Call this function with aggregate = "region".
#' @importFrom magclass setNames getNames getSets add_columns
#' @importFrom luscale rename_dimnames
#' @importFrom madrat getISOlist
#'

calcHistoricalRegion <- function() {

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

# filter regional cement and steel production data from IEA ETP
IEA_ETP <- IEA_ETP[, , c(
"Production|Industry|Cement (Mt/yr)",
"Production|Industry|Steel (Mt/yr"
), pmatch = T, invert = T]

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

# ====== start: blow up to union of years ===================
# find all existing years (y) and variable names (n)

varlist <- list(IEA_ETP, WEO_2021)

y <- Reduce(union, lapply(varlist, getYears))
n <- Reduce(c, lapply(varlist, getNames))
y <- sort(y)

# create empty object with full temporal, regional and data dimensionality
data <- new.magpie(getISOlist(), y, n, fill = NA)

getSets(data)[3] <- "model"
getSets(data)[4] <- "variable"

# transfer data of existing years
for (i in varlist) {
data[, getYears(i), getNames(i)] <- i
}
# ====== end: blow up to union of years ===================

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

# rename dimension "data" into "variable"
getSets(data)[5] <- "variable"

return(list(x = data, weight = NULL, unit = "Various", description = "Historical Data"))
}
7 changes: 6 additions & 1 deletion R/fullVALIDATIONREMIND.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
fullVALIDATIONREMIND <- function(rev = 0) {

#-------------- historical data ---------------------------------------------------------------------

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

calcOutput("HistoricalGlobal", round = 5, file = "historical_global.mif", aggregate = "global")

calcOutput("HistoricalRegion", round = 5, file = "historical_region.mif", aggregate = "region")

}
}