R/convert_PAR_to_SW.R

Defines functions convert_SW_to_PAR convert_PAR_to_SW

Documented in convert_PAR_to_SW convert_SW_to_PAR

#' Convert from photosynthetically active to shortwave radiation
#' 
#' Convert photosynthetically active radiation (PAR) to shortwave radiation 
#' (SW). Uses a fixed ratio between PAR and SW, ignoring the minor seasonal
#' changes in this ratio (see Britton and Dodd (1976)).
#' 
#' @param par Vector of photosynthetically active radiation (400-700 nm; 
#'   umol/m^2/sec)
#' @param coef Numerical coefficient to convert PAR (umol/m^2/sec) to SW 
#'   (W/m^2). Defaults to value from Britton and Dodd (1976).
#' @return Numeric vector of shortwave values with units W/m^2
#'   
#' @examples
#' convert_PAR_to_SW(par=400, coef=0.47)
#' convert_PAR_to_SW(unitted::u(1000, "umol m^-2 s^-1"))
#' @importFrom LakeMetabolizer par.to.sw.base
#' @importFrom unitted is.unitted verify_units
#' @export
convert_PAR_to_SW <- function(par, coef=0.473) {
  if(is.unitted(par)) {
    verify_units(par, "umol m^-2 s^-1")
    coef <- u(coef, "W umol^-1 s")
  }
  (LakeMetabolizer::par.to.sw.base(par, coef)) # parentheses to return value as visible
}

#' Convert from shortwave to photosynthetically active radiation
#' 
#' Convert shortwave radiation (SW) to photosynthetically active radiation 
#' (PAR). Uses a fixed ratio between SW and PAR, ignoring the minor seasonal 
#' changes in this ratio (see Britton and Dodd (1976)).
#' 
#' @param sw Vector of shortwave radiation (W/m^2)
#' @param coef Numerical coefficient to convert SW (W/m^2) to PAR 
#'   (umol/m^2/sec). Defaults to value from Britton and Dodd (1976).
#' @return Numeric vector of PAR values in units umol/m^2/sec
#'   
#' @examples
#' convert_SW_to_PAR(sw=800)
#' convert_SW_to_PAR(sw=800, coef=2.1)
#' convert_SW_to_PAR(unitted::u(473, "W m^-2"))
#' @importFrom LakeMetabolizer sw.to.par.base
#' @export
convert_SW_to_PAR <- function(sw, coef=2.114) {
  if(is.unitted(sw)) {
    verify_units(sw, "W m^-2")
    coef <- u(coef, "umol s^-1 W^-1")
  }
  (LakeMetabolizer::sw.to.par.base(sw, coef)) # parentheses to return value as visible
}
USGS-R/streamMetabolizer documentation built on Aug. 15, 2023, 7:50 a.m.