R/convertGlobalCCSinstitute.R

Defines functions convertGlobalCCSinstitute

Documented in convertGlobalCCSinstitute

#' Convert Global CCS Institute Project Database
#'
#' @md
#' @param x A [`magpie`][magclass::magclass] object returned by
#'     [readGlobalCCSinstitute()].
#' @inherit readGlobalCCSinstitute
#'
#' @return A [`magpie`][magclass::magclass] object.
#'
#' @importFrom dplyr %>%
#' @importFrom madrat toolCountry2isocode toolCountryFill
#' @importFrom magclass dimSums getRegions getItems<-
#' @importFrom quitte add_countrycode_ madrat_mule
#'
#' @export
convertGlobalCCSinstitute <- function(x, subtype = '08-09-2017') {
  if ('08-09-2017' == subtype) { # 08-09-2017 ----

    # sum over districts of a country
    y <- dimSums(x, dim = 3)

    # transfer into ISO country names
    getItems(y, dim = 1) <- toolCountry2isocode(getRegions(y))

    # fill all other countries with 0
    y <- toolCountryFill(y, fill = 0, verbosity = 2)

    return(y)
  }
  else if ('2023-11' == subtype) { # 2023-11 ----
    stop('Subtype "2023-11" does not support conversion.')
  }
  else {
    stop('Unsupported version argument.')
  }
}
pik-piam/mrremind documentation built on May 1, 2024, 2:12 a.m.