R/convertIPCC.R

Defines functions convertIPCC

Documented in convertIPCC

#' Convert subtypes of the IPCC data
#'
#' Convert subtypes on ISO country level.
#'
#'
#' @param x MAgPIE object containing IPCC data on region level
#' @param subtype data subtype. Either "awmsShr", "awmsEfCh4", "awmsParCh4",
#' "nExcrRate"
#' @return IPCC data as MAgPIE object for all subtypes on country level
#' @author Nele Steinmetz
#' @seealso [readSource()]
#' @examples
#' \dontrun{
#' a <- readSource("IPCC", "awmsShr")
#' a <- readSource("IPCC", "awmsEfCh4")
#' a <- readSource("IPCC", "awmsParCh4")
#' a <- readSource("IPCC", "nExcrRate")
#' }
#'
convertIPCC <- function(x, subtype) {
  map <- "regionmappingIPCC_livestock.csv"
  mapNExcrRate <- "regionmappingIPCC_nExcrRate.csv"

  if (subtype == "awmsShr") {
    x <- x / 100
    y <- toolAggregate(x, map, weight = NULL)
  } else if (subtype == "awmsEfCh4") {
    y <- toolAggregate(x, map, weight = NULL)
  } else if (subtype == "awmsParCh4") {
    y <- toolAggregate(x, map, weight = NULL)
  } else if (subtype == "nExcrRate") {
    y <- toolAggregate(x, mapNExcrRate, weight = NULL)
  } else {
    stop("no convert script for this subtype")
  }

  return(y)
}
pik-piam/mrcommons documentation built on Dec. 8, 2024, 7:23 a.m.