R/get.G.R

#' @title Calculate net gas flux of CO2 or O2
#' @description Calculates net flux of CO2 or O2 across the air water
#' interface for one time step.  O2 flux is calculated as the difference between
#' the O2 concentraton at saturation and O2 concentration observed, times the
#' O2-specific reaeration coefficent corrected for water temperature.  CO2 flux is
#' calculated as the difference between the partial pressure of CO2 in air and in
#' water, times the CO2-specific reaeration coefficent corrected for water temperature
#' and Henery's constant.
#' @usage
#' get.G(temperature, O2conc, kstd, depth, gas = 'O2')
#' get.G(temperature, pCO2water, pCO2air, kstd, depth, gas = 'CO2')
#' @param temperature Water termperature in degrees Celsius (C).
#' @param salinity Salinity in parts per thousand (ppt or PSU). Defaults to 0.
#' @param pressure Atmopheric pressure in atmospheres (atm). Defults to 1.
#' @param O2conc Dissolved oxygen concentration at the begining of the time step.
#' Required if gas == "O2". Units of micromoles per liter (umol/L)
#' @param pCO2water Partial pressure of CO2 in water at the begining of the time step.
#' Required if gas == "CO2". Units of microatmospheres (Uatm).
#' @param pCO2air Partial pressure of CO2 in air above the water body. Required
#' if gas == "CO2".  Defaults to 410. Units of microatmospheres (uatm).
#' @param kstd Gas transfer velocity of CO2 at a standardized temperature
#' (indicated by referenceT) in units of meters per second. kstd will be corrected
#' for water temperature and gas (O2) if needed.
#' @param referenceT Standardized water temperature for kstd in degrees Celsius.
#' Defaults to 20.
#' @param depth Depth of the mixed layer or stream depth in meters
#' @param gas Character string indicating the gas for which net flux is desired.
#' Options are "O2" or "CO2".
#' @return Numeric vector of net gas flux.
#' @references
#' Lynch et al. (2010), J. Geophys. Res., 115, G03016
#' Holtgrieve et al. (2010) Limn. Ocean. 55 (3): 1047–1063
#'@author
#'Gordon W. Holtgrieve
#'@examples
#'
#'@export
#'
get.G	<-	function(temperature, salinity=0, pressure=1, O2conc = NA, pCO2water = NA,
                  pCO2air = 410, kstd, referenceT = 20, depth, gas){

  if(gas == "CO2"){
    # pCO2 is passed with units of uatm
    # G = K * K0 * (pCO2air - pCO2water)  #Lynch et al. (2010), J. Geophys. Res., 115, G03016
    # K = reaeration coefficent (1/timestep) for CO2 at water temperature
    # K0 = Henery's constant for given water temperature and pressure, umol/L/uatm

    K0 <- get.K0(temperature=temperature, salinity = salinity, pressure = pressure)  #units of mol/L/atm == umol/L/uatm
    kt <- kstd.to.kt(kstd = kstd, temperature=temperature, referenceT = referenceT, gas=gas)
    K <- kt / depth #convert from m/timestep (velocity) to 1/timestep (reaeration coeff)

    G <- K * K0 * (pCO2air - pCO2water)  # final units are umol/L/timestep

    attributes(G) <- NULL  # Strip the attributes

    return(G)

  } else if(gas == "O2"){
    # O2 is passed with units of umol/L
    # K = reaeration coefficent (1/timestep) for O2 at water temperature
    O2sat <- get.O2Sat(temperature = temperature, salinity = salinity, pressure = pressure)
    kt <- kstd.to.kt(kstd = kstd, temperature=temperature, referenceT = referenceT, gas=gas)
    K <- kt / depth #convert from m/timestep (velocity) to 1/timestep (reaeration coeff)

    G <- K * (O2sat - O2conc)  # final units are umol/L/timestep

    attributes(G) <- NULL  # Strip the attributes

    return(G)
  }
}
gholtgrieve/gassyPants documentation built on May 9, 2019, 5:02 a.m.