R/calcAtmosphericRedepositionShare.R

Defines functions calcAtmosphericRedepositionShare

Documented in calcAtmosphericRedepositionShare

#' @title calcAtmosphericRedepositionShare
#' @description Calculates share of volatilised nitrogen emissions that is redeposited on different land types.
#' @param cellular cellular or country level
#' @param maxshare the maximum amount of emissions deposited within the same cell or country.
#' The remainder will be handled as global emission
#' @param scenario scenario
#' @return List of magpie object with results on country level, weight on country level, unit and description.
#' @author Benjamin Leon Bodirsky
#' @examples
#' \dontrun{
#' calcOutput("AtmosphericRedepositionShare")
#' }
#'
calcAtmosphericRedepositionShare <- function(cellular = FALSE, maxshare = 0.8, scenario = "rcp45") {

  dep <- calcOutput("AtmosphericDeposition", datasource = "ACCMIP", scenario = scenario,
                    cellular = cellular, emission = FALSE, aggregate = FALSE)
  emi <- calcOutput("AtmosphericDeposition", datasource = "ACCMIP", scenario = scenario,
                    cellular = cellular, emission = TRUE, aggregate = FALSE)

  # limit deposition to maxshare of emissions
  scaling <- collapseNames(dimSums(dep, dim = 3.1) / emi)
  if (any(scaling < maxshare)) {
    # dont scale emissions below maxshare
    scaling[scaling < maxshare] <- maxshare
  }
  dep <- dep / scaling * maxshare

  share <- collapseNames(dep / emi)
  shareGlo <- dimSums(dep, dim = 1, na.rm = TRUE) / dimSums(emi, dim = 1, na.rm = TRUE)

  missing <- where(is.na(share))$true$regions
  if (length(missing) > 0) {
    share[missing, , ] <- shareGlo
  }
  weight <- collapseNames(emi)

  return(list(
    x = share,
    weight = weight,
    unit = "Mt Nr, NH3N and NO2N",
    isocountries = !cellular,
    description = paste("Share of emitted volatilised nitrogen that is",
                        "redeposited within the same country. Based on the assumption",
                        "that most of the N is redeposited in the same country.")))

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