development/get.concAtSat.R

#'@title
#'@description

#'@usage

#'@param
#'@param
#'@return
#'@note
#'@references

#'@author
#'Gordon W. Holtgrieve
#'@examples
#'@export
#'
#'
get.concAtSat <-	function(temperature, pressure, altitude=1, salinity=0, gas="O2", units = "umol"){
  #Calculate average atmospheric pressure at elevation of water body
  #Using the 'barometric formula' - see e.g. U.S. Standard Atmosphere 1976 or
  # Jacobs 1999 Atmospheric Chemistry, Eqn 2.9
  #Values of Rstar, g0, M are according to US Standard Atmosphere 1976; could use SI instead

  #Constants
  Pb <- 101325        #static pressure, pascals
  Tb <- 288.15        #standard temp, K
  Lb <- -0.0065       #standard temp lapse rate, K m-1
  h <- altitude           #elevation above sea level, m
  hb <- 0             #elevation at bottom of atmospheric layer 0, m (note layer 0 extends to 11000 masl)
  Rstar <-  8.31432   #universal gas constant, N m mol-1 K-1 (equiv to J K-1 mol-1)  SI: 8.314472
  g0 <- 9.80665       #acceleration of gravity, m s-1
  M <- 0.0289644      #molar mass of Earth's air, kg mol-1

  #Pressure, in Pa (pascals)
  P <- Pb * (Tb/(Tb+Lb*(h-hb)))^(g0*M/(Rstar*Lb))
  # In mmHg
  atmPres <- P*0.00750061683

  A <- matrix (data=
                 c(5.80818, 3.20684, 4.11890, 4.93845, 1.01567, 1.41575,      #O2, umol/kg Garcia and Gordon. 1992. Limnol. Oceanogr. 37(6): 307-1312
                   2.79150, 3.17609, 4.13116, 4.90379, 0, 0,                  #Ar, umol/kg  Hamme & Emerson. 2004. Deep Sea Res. 1. 51(11): 1517-1528
                   6.42931, 2.92704, 4.32531, 4.69149, 0, 0),                 #N2, umol/kg  Hamme & Emerson. 2004. Deep Sea Res. 1. 51(11): 1517-1528
               nrow=6, ncol=3, dimnames=list(c(1:6), c("O2", "Ar", "N2")))
  B <- matrix (data=
                 c(-7.01211e-3, -7.25958e-3, -7.93334e-3, -5.54491e-3, -1.32412e-7,  #O2, umol/kg Garcia and Gordon. 1992. Limnol. Oceanogr. 37(6): 307-1312
                   -6.96233e-3, -7.66670e-3, -1.16888e-2, 0, 0,                      #Ar, umol/kg  Hamme & Emerson. 2004. Deep Sea Res. 1. 51(11): 1517-1528
                   -7.44129e-3, -8.02566e-3, -1.46775e-2, 0, 0),                     #N2, umol/kg  Hamme & Emerson. 2004. Deep Sea Res. 1. 51(11): 1517-1528
               nrow=5, ncol=3, dimnames=list(c(1:5), c("O2", "Ar", "N2")))
  A_ <- A[,gas]
  B_ <- B[,gas]

  #Garcia and Gordon 1992 equation
  Ts <- log((298.15 - temperature) / (273.15 + temperature))
  lnConc <-  A_[1] + A_[2] * Ts + A_[3] * Ts^2 + A_[4] * Ts^3 + A_[5] * Ts^4 + A_[5] * Ts^5
         - salinity * (B_[1] + B_[2] * Ts + B_[3] * Ts^2 + B_[4] * Ts^3) - B_[5] * salinity^2
  conc1 <- exp(lnConc)

# #Correction for local average atmospheric pressure
#  u <- 10^(8.10765 - (1750.286/(235+temperatureC)))
#  concSat2 <- (predConc1 * ((atmPres - u) / (760 - u)))   #ml/L
#  concSat3 <- predConc1 / 1000                      #L/L

#  #Convert from L/L to mg/L using standard temperature and pressure.
#  #Similar to calculating saturation DO at STP in ml/L, converting to mg/L (at STP),
#  #and then doing the above temperature and pressure conversions.
#  R <- 0.082057  #L atm deg-1 mol-1
#  molWt <- HEEL::get.molar.mass(mol = gas)
#  convFactor <- molWt * (1/R) * (1/273.15) * (760/760) #g/L
#  concFinal <- concSat3 * convFactor* 1000                   #mg/L

  if(units = "umol"){
    rho <- seacarb::rho(S = salinity, T = temperature, P = 0) #density in kg/m3
    concFinal <- umol.to.mg(conc1 * rho / 1000, mol=gas) # units of mg/L
  } else {
    concFinal <- conc1
  }

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