From 175ca78dda3a7c00fc3426e7cc4ed5c5386e6880 Mon Sep 17 00:00:00 2001 From: Thomas Wutzler Date: Sat, 23 Oct 2021 11:27:42 +0200 Subject: [PATCH 01/13] take savefig from example to setup block in Global radiation section in walkthrough.md --- docs/src/walkthrough.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/src/walkthrough.md b/docs/src/walkthrough.md index 7bebc13..4c07eb6 100644 --- a/docs/src/walkthrough.md +++ b/docs/src/walkthrough.md @@ -152,6 +152,9 @@ doy = 160 datetimes = DateTime(2021) .+Day(doy-1) .+ Hour.(hours) #.- Second(round(long*deg2second)) res3 = @suppress_err @pipe calc_sun_position_hor.(datetimes, lat, long) |> toDataFrame(_) @df res3 scatter(datetimes, cols([:altitude,:azimuth]), legend = :topleft, xlab="Date and Time", ylab = "rad") +``` + +```@setup doc savefig("fig/globrad.svg") ``` From a6d8ed8c8a18ff7b40eb785832dbb7716eb3d2a5 Mon Sep 17 00:00:00 2001 From: Thomas Wutzler Date: Sat, 23 Oct 2021 12:38:18 +0200 Subject: [PATCH 02/13] replace \code{...} in R docu --- inst/fromR/WUE_metrics.jl | 2 +- inst/fromR/aerodynamic_conductance.jl | 94 ++++++++++++------------ inst/fromR/bigleaf_constants.jl | 8 +- inst/fromR/bigleaf_physiology.jl | 78 ++++++++++---------- inst/fromR/boundary_layer_conductance.jl | 68 ++++++++--------- inst/fromR/check_input.jl | 4 +- inst/fromR/datasets_description.jl | 64 ++++++++-------- inst/fromR/decoupling.jl | 18 ++--- inst/fromR/energy_balance.jl | 12 +-- inst/fromR/evapotranspiration.jl | 70 +++++++++--------- inst/fromR/filter_data.jl | 80 ++++++++++---------- inst/fromR/meteorological_variables.jl | 42 +++++------ inst/fromR/potential_radiation.jl | 4 +- inst/fromR/stability_correction.jl | 12 +-- inst/fromR/surface_conditions.jl | 18 ++--- inst/fromR/surface_conductance.jl | 28 +++---- inst/fromR/surface_roughness.jl | 68 ++++++++--------- inst/fromR/unit_conversions.jl | 10 +-- 18 files changed, 340 insertions(+), 340 deletions(-) diff --git a/inst/fromR/WUE_metrics.jl b/inst/fromR/WUE_metrics.jl index 3943b30..c744d04 100755 --- a/inst/fromR/WUE_metrics.jl +++ b/inst/fromR/WUE_metrics.jl @@ -54,7 +54,7 @@ #' Zhou, S., et al., 2014: The effect of vapor pressure deficit on water #' use efficiency at the sub-daily time scale. Geophysical Research Letters 41. #' -#' @seealso \code{\link{stomatal_slope}} for a measure of intrinsic WUE +#' @seealso `\link{stomatal_slope`} for a measure of intrinsic WUE #' #' ```@example; output = false #' ``` diff --git a/inst/fromR/aerodynamic_conductance.jl b/inst/fromR/aerodynamic_conductance.jl index cb9cebb..2b3a59f 100755 --- a/inst/fromR/aerodynamic_conductance.jl +++ b/inst/fromR/aerodynamic_conductance.jl @@ -16,27 +16,27 @@ #' - zr Instrument (reference) height (m) #' - zh Canopy height (m) #' - d Zero-plane displacement height (m) -#' - z0m Roughness length for momentum (m), optional; if not provided, it is estimated from \code{roughness_parameters} -#' (method="wind_profile"). Only used if \code{wind_profile = TRUE} and/or \code{Rb_model} = \code{"Su_2001"} or -#' \code{"Choudhury_1988"}. -#' - Dl Characteristic leaf dimension (m) (if \code{Rb_model} = \code{"Su_2001"}) -#' or leaf width (if \code{Rb_model} = \code{"Choudhury_1988"}); ignored otherwise. -#' - N Number of leaf sides participating in heat exchange (1 or 2); only used if \code{Rb_model = "Su_2001"}. +#' - z0m Roughness length for momentum (m), optional; if not provided, it is estimated from `roughness_parameters` +#' (method="wind_profile"). Only used if `wind_profile = TRUE` and/or `Rb_model` = `"Su_2001"` or +#' `"Choudhury_1988"`. +#' - Dl Characteristic leaf dimension (m) (if `Rb_model` = `"Su_2001"`) +#' or leaf width (if `Rb_model` = `"Choudhury_1988"`); ignored otherwise. +#' - N Number of leaf sides participating in heat exchange (1 or 2); only used if `Rb_model = "Su_2001"`. #' Defaults to 2. -#' - fc Fractional vegetation cover (-); only used if \code{Rb_model = "Su_2001"}. See Details. -#' - LAI One-sided leaf area index (m2 m-2); only used if \code{Rb_model} = \code{"Choudhury_1988"} or \code{"Su_2001"}. -#' - Cd Foliage drag coefficient (-); only used if \code{Rb_model = "Su_2001"}. -#' - hs Roughness length of bare soil (m); only used if \code{Rb_model = "Su_2001"}. +#' - fc Fractional vegetation cover (-); only used if `Rb_model = "Su_2001"`. See Details. +#' - LAI One-sided leaf area index (m2 m-2); only used if `Rb_model` = `"Choudhury_1988"` or `"Su_2001"`. +#' - Cd Foliage drag coefficient (-); only used if `Rb_model = "Su_2001"`. +#' - hs Roughness length of bare soil (m); only used if `Rb_model = "Su_2001"`. #' - wind_profile Should Ga for momentum be calculated based on the logarithmic wind profile equation? -#' Defaults to \code{FALSE}. -#' - stab_correction Should stability correction be applied? Defaults to \code{TRUE}. Ignored if \code{wind_profile = FALSE}. -#' - stab_formulation Stability correction function. Either \code{"Dyer_1970"} (default) or -#' \code{"Businger_1971"}. Ignored if \code{wind_profile = FALSE} or if \code{stab_correction = FALSE}. -#' - Rb_model Boundary layer resistance formulation. One of \code{"Thom_1972","Choudhury_1988","Su_2001","constant_kB-1"}. -#' - kB_h kB-1 value for heat transfer; only used if \code{Rb_model = "constant_kB-1"} +#' Defaults to `FALSE`. +#' - stab_correction Should stability correction be applied? Defaults to `TRUE`. Ignored if `wind_profile = FALSE`. +#' - stab_formulation Stability correction function. Either `"Dyer_1970"` (default) or +#' `"Businger_1971"`. Ignored if `wind_profile = FALSE` or if `stab_correction = FALSE`. +#' - Rb_model Boundary layer resistance formulation. One of `"Thom_1972","Choudhury_1988","Su_2001","constant_kB-1"`. +#' - kB_h kB-1 value for heat transfer; only used if `Rb_model = "constant_kB-1"` #' - Sc Optional: Schmidt number of additional quantities to be calculated #' - Sc_name Optional: Name of the additonal quantities, has to be of same length than -#' \code{Sc_name} +#' `Sc_name` #' - constants k - von Karman constant \cr #' cp - specific heat of air for constant pressure (J K-1 kg-1) \cr #' Kelvin - conversion degree Celsius to Kelvin \cr @@ -44,7 +44,7 @@ #' pressure0 - reference atmospheric pressure at sea level (Pa) \cr #' Tair0 - reference air temperature (K) \cr #' Sc_CO2 - Schmidt number for CO2 \cr -#' Pr - Prandtl number (if \code{Sc} is provided) +#' Pr - Prandtl number (if `Sc` is provided) #' #' # Details @@ -64,44 +64,44 @@ #' additional stability correction function. #' #' An alternative method to calculate Ra_m is provided -#' (calculated if \code{wind_profile = TRUE}): +#' (calculated if `wind_profile = TRUE`): #' #' \deqn{Ra_m = (ln((zr - d)/z0m) - psi_h) / (k ustar)} #' #' If the roughness parameters z0m and d are unknown, they can be estimated using -#' \code{\link{roughness_parameters}}. The argument \code{stab_formulation} determines the stability correction function used +#' `\link{roughness_parameters`}. The argument `stab_formulation` determines the stability correction function used #' to account for the effect of atmospheric stability on Ra_m (Ra_m is lower for unstable #' and higher for stable stratification). Stratification is based on a stability parameter zeta (z-d/L), #' where z = reference height, d the zero-plane displacement height, and L the Monin-Obukhov length, -#' calculated with \code{\link{Monin_Obukhov_length}} -#' The stability correction function is chosen by the argument \code{stab_formulation}. Options are -#' \code{"Dyer_1970"} and \code{"Businger_1971"}. +#' calculated with `\link{Monin_Obukhov_length`} +#' The stability correction function is chosen by the argument `stab_formulation`. Options are +#' `"Dyer_1970"` and `"Businger_1971"`. #' #' The model used to determine the canopy boundary layer resistance for heat (Rb_h) is specified by -#' the argument \code{Rb_model}. The following options are implemented: -#' \code{"Thom_1972"} is an empirical formulation based on the friction velocity (ustar) (Thom 1972): +#' the argument `Rb_model`. The following options are implemented: +#' `"Thom_1972"` is an empirical formulation based on the friction velocity (ustar) (Thom 1972): #' #' \deqn{Rb_h = 6.2ustar^-0.667} #' -#' The model by Choudhury & Monteith 1988 (\code{Rb_model = "Choudhury_1988"}), -#' calculates Rb_h based on leaf width, LAI and ustar (Note that function argument \code{Dl} +#' The model by Choudhury & Monteith 1988 (`Rb_model = "Choudhury_1988"`), +#' calculates Rb_h based on leaf width, LAI and ustar (Note that function argument `Dl` #' represents leaf width (w) and not characteristic leaf dimension (Dl) -#' if \code{Rb_model} = \code{"Choudhury_1988"}): +#' if `Rb_model` = `"Choudhury_1988"`): #' #' \deqn{Gb_h = LAI((0.02/\alpha)*sqrt(u(zh)/w)*(1-exp(-\alpha/2)))} #' #' where \eqn{\alpha} is a canopy attenuation coefficient modeled in dependence on LAI, -#' u(zh) is wind speed at canopy height (calculated from \code{\link{wind_profile}}), -#' and w is leaf width (m). See \code{\link{Gb_Choudhury}} for further details. +#' u(zh) is wind speed at canopy height (calculated from `\link{wind_profile`}), +#' and w is leaf width (m). See `\link{Gb_Choudhury`} for further details. #' -#' The option \code{Rb_model = "Su_2001"} calculates Rb_h based on the physically-based Rb model by Su et al. 2001, +#' The option `Rb_model = "Su_2001"` calculates Rb_h based on the physically-based Rb model by Su et al. 2001, #' a simplification of the model developed by Massman 1999: #' #' \deqn{kB-1 = (k Cd fc^2) / (4Ct ustar/u(zh)) + kBs-1(1 - fc)^2} #' #' where Cd is a foliage drag coefficient (defaults to 0.2), fc is fractional #' vegetation cover, Bs-1 is the inverse Stanton number for bare soil surface, -#' and Ct is a heat transfer coefficient. See \code{\link{Gb_Su}} for +#' and Ct is a heat transfer coefficient. See `\link{Gb_Su`} for #' details on the model. #' #' @@ -125,15 +125,15 @@ #' \item{Gb_h}{Canopy boundary layer conductance for heat transfer (m s-1)} #' \item{Rb_h}{Canopy boundary layer resistance for heat transfer (s m-1)} #' \item{kB_h}{kB-1 parameter for heat transfer} -#' \item{zeta}{Stability parameter 'zeta' (NA if \code{wind_profile = FALSE})} -#' \item{psi_h}{Integrated stability correction function (NA if \code{wind_profile = FALSE})} +#' \item{zeta}{Stability parameter 'zeta' (NA if `wind_profile = FALSE`)} +#' \item{psi_h}{Integrated stability correction function (NA if `wind_profile = FALSE`)} #' \item{Ra_CO2}{Aerodynamic resistance for CO2 transfer (s m-1)} #' \item{Ga_CO2}{Aerodynamic conductance for CO2 transfer (m s-1)} #' \item{Gb_CO2}{Canopy boundary layer conductance for CO2 transfer (m s-1)} -#' \item{Ga_Sc_name}{Aerodynamic conductance for \code{Sc_name} (m s-1). Only added if \code{Sc_name} and -#' the respective \code{Sc} are provided} -#' \item{Gb_Sc_name}{Boundary layer conductance for \code{Sc_name} (m s-1). Only added if \code{Sc_name} and -#' the respective \code{Sc} are provided} +#' \item{Ga_Sc_name}{Aerodynamic conductance for `Sc_name` (m s-1). Only added if `Sc_name` and +#' the respective `Sc` are provided} +#' \item{Gb_Sc_name}{Boundary layer conductance for `Sc_name` (m s-1). Only added if `Sc_name` and +#' the respective `Sc` are provided} #' #' @note The roughness length for water and heat (z0h) is not returned by this function, but #' it can be calculated from the following relationship (e.g. Verma 1989): @@ -144,20 +144,20 @@ #' #' \deqn{z0h = z0m / exp(kB-1)} #' -#' \code{kB-1} is an output of this function. +#' `kB-1` is an output of this function. #' #' Input variables such as LAI, Dl, or zh can be either constants, or -#' vary with time (i.e. vectors of the same length as \code{data}). +#' vary with time (i.e. vectors of the same length as `data`). #' #' Note that boundary layer conductance to water vapor transfer (Gb_w) is often #' assumed to equal Gb_h. This assumption is also made in this R package, for -#' example in the function \code{\link{surface_conductance}}. +#' example in the function `\link{surface_conductance`}. #' -#' If the roughness length for momentum (\code{z0m}) is not provided as input, it is estimated -#' from the function \code{roughness_parameters} within \code{wind_profile} if \code{wind_profile = TRUE} -#' and/or \code{Rb_model} = \code{"Su_2001"} or \code{"Choudhury_1988"} The \code{roughness_parameters} -#' function estimates a single \code{z0m} value for the entire time period! If a varying \code{z0m} value -#' (e.g. across seasons or years) is required, \code{z0m} should be provided as input argument. +#' If the roughness length for momentum (`z0m`) is not provided as input, it is estimated +#' from the function `roughness_parameters` within `wind_profile` if `wind_profile = TRUE` +#' and/or `Rb_model` = `"Su_2001"` or `"Choudhury_1988"` The `roughness_parameters` +#' function estimates a single `z0m` value for the entire time period! If a varying `z0m` value +#' (e.g. across seasons or years) is required, `z0m` should be provided as input argument. #' #' #' @references Verma, S., 1989: Aerodynamic resistances to transfers of heat, mass and momentum. @@ -173,7 +173,7 @@ #' Monteith, J_L., Unsworth, M_H., 2008: Principles of environmental physics. #' Third Edition. Elsevier Academic Press, Burlington, USA. #' -#' @seealso \code{\link{Gb_Thom}}, \code{\link{Gb_Choudhury}}, \code{\link{Gb_Su}} for calculations of Rb / Gb only +#' @seealso `\link{Gb_Thom`}, `\link{Gb_Choudhury`}, `\link{Gb_Su`} for calculations of Rb / Gb only #' #' ```@example; output = false #' ``` diff --git a/inst/fromR/bigleaf_constants.jl b/inst/fromR/bigleaf_constants.jl index 8ce30cc..787bfd8 100755 --- a/inst/fromR/bigleaf_constants.jl +++ b/inst/fromR/bigleaf_constants.jl @@ -44,17 +44,17 @@ #' easily altered. E_g. the following command will change the value of #' the von Karman constant from 0.41 to 0.4: #' -#' \code{bigleaf_constants(k=0.4)} +#' `bigleaf_constants(k=0.4)` #' #' the value of a constant can be returned by calling: #' -#' \code{bigleaf_constants()$*name_of_constant*} +#' `bigleaf_constants()$*name_of_constant*` #' #' To permanently change the constants contained within this function (which #' makes sense for some of them, e.g. for the von Karman constant), -#' the command \code{\link[utils]{fixInNamespace}} can be used. E_g. +#' the command `\link[utils]{fixInNamespace`} can be used. E_g. #' -#' \code{fixInNamespace(bigleaf_constants,ns="bigleaf")} +#' `fixInNamespace(bigleaf_constants,ns="bigleaf")` #' #' Note that this has to be repeated every time the package is newly installed/loaded. #' diff --git a/inst/fromR/bigleaf_physiology.jl b/inst/fromR/bigleaf_physiology.jl index ab32abd..fa4b922 100755 --- a/inst/fromR/bigleaf_physiology.jl +++ b/inst/fromR/bigleaf_physiology.jl @@ -13,8 +13,8 @@ #' - GPP Gross primary productivity (umol CO2 m-2 s-1) #' - Gs Surface conductance to water vapor (mol m-2 s-1) #' - Rleaf Ecosystem respiration stemming from leaves (umol CO2 m-2 s-1); defaults to 0 -#' - missing_Rleaf_as_NA if Rleaf is provided, should missing values be treated as \code{NA} (\code{TRUE}) -#' or set to 0 (\code{FALSE}, the default)? +#' - missing_Rleaf_as_NA if Rleaf is provided, should missing values be treated as `NA` (`TRUE`) +#' or set to 0 (`FALSE`, the default)? #' - constants DwDc - Ratio of the molecular diffusivities for water vapor and CO2 (-) #' #' # Details @@ -26,7 +26,7 @@ #' Note that Gs is required in mol m-2 s-1 for water vapor. Gs is converted to #' its value for CO2 internally. #' Ca can either be atmospheric CO2 concentration (as measured), or surface -#' CO2 concentration as calculated from \code{\link{surface_CO2}}. +#' CO2 concentration as calculated from `\link{surface_CO2`}. #' #' @note The equation is based on Fick's law of diffusion and is equivalent to the #' often used equation at leaf level (ci = ca - An/gs). @@ -87,7 +87,7 @@ end #' CO2 concentration using the Farquhar et al. 1980 model for C3 photosynthesis. #' #' - data Data_Frame or matrix with all required columns -#' - C3 C3 vegetation (\code{TRUE}, the default) or C4 vegetation (\code{FALSE})? +#' - C3 C3 vegetation (`TRUE`, the default) or C4 vegetation (`FALSE`)? #' - Temp Surface (or air) temperature (degC) #' - GPP Gross primary productivity (umol m-2 s-1) #' - Ci Bulk canopy intercellular CO2 concentration (umol mol-1) @@ -113,11 +113,11 @@ end #' - Jmax_dS Entropy term for Jmax (kJ mol-1 K-1) #' - Theta Curvature term in the light response function of J (-) #' - alpha_canopy Canopy absorptance (-) -#' - missing_Rleaf_as_NA if Rleaf is provided, should missing values be treated as \code{NA} (\code{TRUE}) -#' or set to 0 (\code{FALSE}, the default)? +#' - missing_Rleaf_as_NA if Rleaf is provided, should missing values be treated as `NA` (`TRUE`) +#' or set to 0 (`FALSE`, the default)? #' - Ci_C4 intercellular CO2 concentration below which photosynthesis #' is considered to be CO2-limited (umol mol-1), ignored -#' if \code{C3 = TRUE}. +#' if `C3 = TRUE`. #' - constants Kelvin - conversion degree Celsius to Kelvin \cr #' Rgas - universal gas constant (J mol-1 K-1) \cr #' kJ2J - conversion kilojoule (kJ) to joule (J) \cr @@ -129,7 +129,7 @@ end #' transport rate at 25degC (Jmax25), which characterize photosynthetic capacity, #' are calculated as at leaf level. #' The required variables Gs and Ci can be calculated from -#' \code{\link{surface_conductance}} and \code{\link{intercellular_CO2}}, respectively. +#' `\link{surface_conductance`} and `\link{intercellular_CO2`}, respectively. #' #' Gas exchange parameters are taken from Bernacchi et al. 2001 (apparent values, which #' assume an infinite mesophyll conductance). Negative and very low Ci values @@ -151,8 +151,8 @@ end #' #' In this function, bulk canopy photosynthesis is assumed to be Rubisco/RuBP-regeneration #' limited, if incoming PPFD is above/below a specified threshold or range. These ranges -#' are determined by the parameters \code{PPFD_j} and \code{PPFD_c}. If, for example, -#' \code{PPFD_j = c(100,400)}, all conditions with a PPFD between 100 and 400 are assumed +#' are determined by the parameters `PPFD_j` and `PPFD_c`. If, for example, +#' `PPFD_j = c(100,400)`, all conditions with a PPFD between 100 and 400 are assumed #' to be in the RuBP-regeneration (i.e. light-limited) photosynthesis domain. The electron #' transport rate J is then only calculated for periods that meet this criterion. #' @@ -193,7 +193,7 @@ end #' #' \deqn{Vcmax = GPP} #' -#' Note that in addition to the range \code{PPFD_c}, the range \code{Ci_C4} +#' Note that in addition to the range `PPFD_c`, the range `Ci_C4` #' discards all periods with low Ci, in which photosynthesis is likely to #' be CO2-limited (see von Caemmerer 2000 for details). #' @@ -206,11 +206,11 @@ end #' #' @note The critical assumption is that bulk canopy photosynthesis is limited by #' one of the two limitation states. Incoming PPFD is assumed to determine -#' the limitation states. Note however that the ranges (\code{PPFD_j} and \code{PPFD_c}) +#' the limitation states. Note however that the ranges (`PPFD_j` and `PPFD_c`) #' are likely ecosystem-specific. E_g. dense canopies presumably require higher -#' \code{PPFD_c} thresholds than open canopies. A threshold of 500 umol m-2 s-1 PPFD +#' `PPFD_c` thresholds than open canopies. A threshold of 500 umol m-2 s-1 PPFD #' for Rubisco-limited photosynthesis was assumed a reasonable working assumption (see Kosugi et al. 2013). -#' Here, \code{PPFD_c} defaults to 1000 umol m-2 s-1. Note that even under very high/low irradiances, +#' Here, `PPFD_c` defaults to 1000 umol m-2 s-1. Note that even under very high/low irradiances, #' not all photosynthetically active plant material of an ecosystem will be in the same #' limitation state. Note that parameters describing bulk canopy photosynthetic capacity are not directly #' comparable to their leaf-level counterparts, as the former integrate over the entire canopy @@ -248,7 +248,7 @@ end #' von Caemmerer, 2000: Biochemical models of leaf photosynthesis. Techniques #' in plant sciences No. 2. CSIRO Publishing, Collingwood VIC, Australia. #' -#' @seealso \code{\link{intercellular_CO2}}, \code{\link{Arrhenius_temp_response}} +#' @seealso `\link{intercellular_CO2`}, `\link{Arrhenius_temp_response`} #' #' ```@example; output = false #' ``` @@ -482,21 +482,21 @@ end #' - VPD Vapor pressure deficit (kPa) #' - Ca Atmospheric CO2 concentration (air or surface) (umol mol-1) #' - Rleaf Ecosystem respiration stemming from leaves (umol CO2 m-2 s-1); defaults to 0 -#' - model Stomatal model used. One of \code{"USO","Ball&Berry","Leuning"}. -#' - robust_nls Use robust nonlinear regression (\code{\link[robustbase]{nlrob}})? Default is \code{FALSE}. +#' - model Stomatal model used. One of `"USO","Ball&Berry","Leuning"`. +#' - robust_nls Use robust nonlinear regression (`\link[robustbase]{nlrob`})? Default is `FALSE`. #' - nmin Minimum number of data required to perform the fit; defaults to 40. #' - fitg0 Should g0 and g1 be fitted simultaneously? -#' - g0 Minimum stomatal conductance (mol m-2 s-1); ignored if \code{fitg0 = TRUE}. -#' - fitD0 Should D0 be fitted along with g1 (and g0 if \code{fitg0 = TRUE})?; only used if \code{model = "Leuning"}. -#' - D0 Stomatal sensitivity parameter to VPD; only used if \code{model = "Leuning"} and \code{fitD0 = FALSE}. -#' - Gamma Canopy CO2 compensation point (umol mol-1); only used if \code{model = "Leuning"}. +#' - g0 Minimum stomatal conductance (mol m-2 s-1); ignored if `fitg0 = TRUE`. +#' - fitD0 Should D0 be fitted along with g1 (and g0 if `fitg0 = TRUE`)?; only used if `model = "Leuning"`. +#' - D0 Stomatal sensitivity parameter to VPD; only used if `model = "Leuning"` and `fitD0 = FALSE`. +#' - Gamma Canopy CO2 compensation point (umol mol-1); only used if `model = "Leuning"`. #' Can be a constant or a variable. Defaults to 50 umol mol-1. #' - constants Kelvin - conversion degree Celsius to Kelvin \cr #' Rgas - universal gas constant (J mol-1 K-1) \cr #' DwDc - Ratio of the molecular diffusivities for water vapor and CO2 -#' - missing_Rleaf_as_NA if Rleaf is provided, should missing values be treated as \code{NA} (\code{TRUE}) -#' or set to 0 (\code{FALSE}, the default)? -#' - ... Additional arguments to \code{\link[stats]{nls}} or \code{\link[robustbase]{nlrob}} if \code{robust_nls = TRUE}. +#' - missing_Rleaf_as_NA if Rleaf is provided, should missing values be treated as `NA` (`TRUE`) +#' or set to 0 (`FALSE`, the default)? +#' - ... Additional arguments to `\link[stats]{nls`} or `\link[robustbase]{nlrob`} if `robust_nls = TRUE`. #' #' # Details All stomatal models were developed at leaf-level, but its parameters @@ -518,16 +518,16 @@ end #' plant species. #' The equations above are valid at leaf-level. At ecosystem level, An is replaced by GPP (or GPP - Rleaf, #' where Rleaf is leaf respiration), and gs (stomatal conductance) by Gs (surface conductance). -#' The parameters in the models are estimated using nonlinear regression (\code{\link[stats]{nls}}) if -#' \code{robust_nls = FALSE} and weighted nonlinear regression if \code{robust_nls = TRUE}. -#' The weights are calculated from \code{\link[robustbase]{nlrob}}, and \code{\link[stats]{nls}} +#' The parameters in the models are estimated using nonlinear regression (`\link[stats]{nls`}) if +#' `robust_nls = FALSE` and weighted nonlinear regression if `robust_nls = TRUE`. +#' The weights are calculated from `\link[robustbase]{nlrob`}, and `\link[stats]{nls`} #' is used for the actual fitting. #' Alternatively to measured VPD and Ca (i.e. conditions at instrument height), conditions at -#' the big-leaf surface can be provided. Those can be calculated using \code{\link{surface_conditions}}. +#' the big-leaf surface can be provided. Those can be calculated using `\link{surface_conditions`}. #' #' #' # Value - A \code{nls} model object, containing information on the fitted parameters, their uncertainty range, + A `nls` model object, containing information on the fitted parameters, their uncertainty range, #' model fit, etc. #' #' @references Medlyn B_E., et al., 2011: Reconciling the optimal and empirical approaches to @@ -544,7 +544,7 @@ end #' Knauer, J. et al., 2018: Towards physiologically meaningful water-use efficiency estimates #' from eddy covariance data. Global Change Biology 24, 694-710. #' -#' @seealso \code{\link{surface_conductance}} +#' @seealso `\link{surface_conductance`} #' #' ```@example; output = false #' ``` @@ -749,7 +749,7 @@ end #' - PPFD Photosynthetic photon flux density (umol m-2 s-1) #' - PPFD_ref Reference PPFD (umol m-2 s-1) for which GPP_ref is estimated. #' Default is 2000 umol m-2 s-1. -#' - ... Additional arguments to \code{\link[stats]{nls}} +#' - ... Additional arguments to `\link[stats]{nls`} #' #' # Details A rectangular light response curve is fitted to NEE data. The curve @@ -767,14 +767,14 @@ end #' curve is that GPP_ref at PPFD_ref is more readily interpretable #' as it constitutes a value observed in the ecosystem, in contrast to #' GPP_ref (mostly named 'beta') in the standard model that occurs at infinite light. -#' \code{PPFD_ref} defaults to 2000 umol m-2 s-1, but other values can be used. For +#' `PPFD_ref` defaults to 2000 umol m-2 s-1, but other values can be used. For #' further details refer to Falge et al. 2001. #' #' @note Note the sign convention. Negative NEE indicates that carbon is taken up #' by the ecosystem. Reco has to be 0 or larger. #' #' # Value - A \code{nls} model object containing estimates (+/- SE) for alpha and GPP_ref. + A `nls` model object containing estimates (+/- SE) for alpha and GPP_ref. #' #' @references Falge E., et al. 2001: Gap filling strategies for defensible annual #' sums of net ecosystem exchange. Agricultural and Forest Meteorology 107, @@ -827,7 +827,7 @@ end #' # Value \item{LUE -}{Light use efficiency (-)} #' -#' @seealso \code{\link{energy_use_efficiency}} +#' @seealso `\link{energy_use_efficiency`} #' #' ```@example; output = false #' ``` @@ -853,7 +853,7 @@ end #' - data Data_frame or matrix containing all required columns #' - Gs Surface conductance to water vapor (mol m-2 s-1) #' - VPD Vapor pressure deficit (kPa) -#' - ... Additional arguments to \code{\link[stats]{nls}} +#' - ... Additional arguments to `\link[stats]{nls`} #' #' # Details The function fits the following equation (Oren et al. 1999): @@ -862,12 +862,12 @@ end #' #' where b is the reference surface conductance (Gs) at VPD=1kPa (in mol m-2 s-1), #' and m is the sensitivity parameter of Gs to VPD (in mol m-2 s-1 log(kPa)-1). -#' The two parameters b and m are fitted using \code{\link[stats]{nls}}. +#' The two parameters b and m are fitted using `\link[stats]{nls`}. #' VPD can be the one directly measured at instrument height, or the -#' one at the surface, as returned by \code{\link{surface_conditions}}. +#' one at the surface, as returned by `\link{surface_conditions`}. #' #' # Value - A \code{nls} model object containing (amongst others) estimates for the mean + A `nls` model object containing (amongst others) estimates for the mean #' and standard errors of the parameters m and b. #' #' @references Oren R., et al. 1999: Survey and synthesis of intra- and interspecific @@ -877,7 +877,7 @@ end #' Novick K_A., et al. 2016: The increasing importance of atmospheric demand #' for ecosystem water and carbon fluxes. Nature Climate Change 6, 1023 - 1027. #' -#' @seealso \code{\link{surface_conductance}} +#' @seealso `\link{surface_conductance`} #' #' ```@example; output = false #' ``` diff --git a/inst/fromR/boundary_layer_conductance.jl b/inst/fromR/boundary_layer_conductance.jl index 32bb20b..38bce8f 100755 --- a/inst/fromR/boundary_layer_conductance.jl +++ b/inst/fromR/boundary_layer_conductance.jl @@ -10,10 +10,10 @@ #' - ustar Friction velocity (m s-1) #' - Sc Optional: Schmidt number of additional quantities to be calculated #' - Sc_name Optional: Name of the additional quantities, has to be of same length than -#' \code{Sc_name} +#' `Sc_name` #' - constants k - von-Karman constant \cr #' Sc_CO2 - Schmidt number for CO2 \cr -#' Pr - Prandtl number (if \code{Sc} is provided) +#' Pr - Prandtl number (if `Sc` is provided) #' #' #' # Details @@ -33,8 +33,8 @@ #' \item{Gb_h}{Boundary layer conductance for heat transfer (m s-1)} #' \item{Rb_h}{Boundary layer resistance for heat transfer (s m-1)} #' \item{kB_h}{kB-1 parameter for heat transfer} -#' \item{Gb_Sc_name}{Boundary layer conductance for \code{Sc_name} (m s-1). Only added if \code{Sc_name} and -#' \code{Sc_name} are provided} +#' \item{Gb_Sc_name}{Boundary layer conductance for `Sc_name` (m s-1). Only added if `Sc_name` and +#' `Sc_name` are provided} #' #' @references Thom, A., 1972: Momentum, mass and heat exchange of vegetation. #' Quarterly Journal of the Royal Meteorological Society 98, 124-134. @@ -43,7 +43,7 @@ #' A preliminary multiple resistance routine for deriving dry deposition velocities #' from measured quantities. Water, Air, and Soil Pollution 36, 311-330. #' -#' @seealso \code{\link{Gb_Choudhury}}, \code{\link{Gb_Su}}, \code{\link{aerodynamic_conductance}} +#' @seealso `\link{Gb_Choudhury`}, `\link{Gb_Su`}, `\link{aerodynamic_conductance`} #' #' ```@example; output = false #' ``` @@ -96,25 +96,25 @@ end #' - LAI One-sided leaf area index #' - zh Canopy height (m) #' - zr Instrument (reference) height (m) -#' - d Zero-plane displacement height (-), can be calculated using \code{roughness_parameters} -#' - z0m Roughness length for momentum (m). If not provided, calculated from \code{roughness_parameters} -#' within \code{wind_profile} -#' - stab_formulation Stability correction function used (If \code{stab_correction = TRUE}). -#' Either \code{"Dyer_1970"} or \code{"Businger_1971"}. +#' - d Zero-plane displacement height (-), can be calculated using `roughness_parameters` +#' - z0m Roughness length for momentum (m). If not provided, calculated from `roughness_parameters` +#' within `wind_profile` +#' - stab_formulation Stability correction function used (If `stab_correction = TRUE`). +#' Either `"Dyer_1970"` or `"Businger_1971"`. #' - Sc Optional: Schmidt number of additional quantities to be calculated #' - Sc_name Optional: Name of the additonal quantities, has to be of same length than -#' \code{Sc_name} +#' `Sc_name` #' - constants k - von-Karman constant \cr #' Sc_CO2 - Schmidt number for CO2 \cr -#' Pr - Prandtl number (if \code{Sc} is provided) +#' Pr - Prandtl number (if `Sc` is provided) #' #' # Value A data frame with the following columns: #' \item{Gb_h}{Boundary layer conductance for heat transfer (m s-1)} #' \item{Rb_h}{Boundary layer resistance for heat transfer (s m-1)} #' \item{kB_h}{kB-1 parameter for heat transfer} -#' \item{Gb_Sc_name}{Boundary layer conductance for \code{Sc_name} (m s-1). Only added if \code{Sc_name} and -#' \code{Sc_name} are provided} +#' \item{Gb_Sc_name}{Boundary layer conductance for `Sc_name` (m s-1). Only added if `Sc_name` and +#' `Sc_name` are provided} #' #' # Details Boundary layer conductance according to Choudhury & Monteith 1988 is @@ -138,10 +138,10 @@ end #' #' where Sc_x is the Schmidt number of quantity x, and Pr is the Prandtl number (0.71). #' -#' @note If the roughness length for momentum (\code{z0m}) is not provided as input, it is estimated -#' from the function \code{roughness_parameters} within \code{wind_profile}. This function -#' estimates a single \code{z0m} value for the entire time period! If a varying \code{z0m} value -#' (e.g. across seasons or years) is required, \code{z0m} should be provided as input argument. +#' @note If the roughness length for momentum (`z0m`) is not provided as input, it is estimated +#' from the function `roughness_parameters` within `wind_profile`. This function +#' estimates a single `z0m` value for the entire time period! If a varying `z0m` value +#' (e.g. across seasons or years) is required, `z0m` should be provided as input argument. #' #' @references Choudhury, B. J., Monteith J_L., 1988: A four-layer model for the heat #' budget of homogeneous land surfaces. Q. J. R. Meteorol. Soc. 114, 373-398. @@ -154,7 +154,7 @@ end #' A preliminary multiple resistance routine for deriving dry deposition velocities #' from measured quantities. Water, Air, and Soil Pollution 36, 311-330. #' -#' @seealso \code{\link{Gb_Thom}}, \code{\link{Gb_Su}}, \code{\link{aerodynamic_conductance}} +#' @seealso `\link{Gb_Thom`}, `\link{Gb_Su`}, `\link{aerodynamic_conductance`} #' #' ```@example; output = false #' ``` @@ -230,33 +230,33 @@ end #' - H Sensible heat flux (W m-2) #' - zh Canopy height (m) #' - zr Reference height (m) -#' - d Zero-plane displacement height (-), can be calculated using \code{roughness_parameters} -#' - z0m Roughness length for momentum (m). If not provided, calculated from \code{roughness_parameters} -#' within \code{wind_profile} +#' - d Zero-plane displacement height (-), can be calculated using `roughness_parameters` +#' - z0m Roughness length for momentum (m). If not provided, calculated from `roughness_parameters` +#' within `wind_profile` #' - Dl Leaf characteristic dimension (m) #' - fc Fractional vegetation cover [0-1] (if not provided, calculated from LAI) #' - LAI One-sided leaf area index (-) #' - N Number of leaf sides participating in heat exchange (defaults to 2) #' - Cd Foliage drag coefficient (-) #' - hs Roughness height of the soil (m) -#' - stab_formulation Stability correction function used (If \code{stab_correction = TRUE}). -#' Either \code{"Dyer_1970"} or \code{"Businger_1971"}. +#' - stab_formulation Stability correction function used (If `stab_correction = TRUE`). +#' Either `"Dyer_1970"` or `"Businger_1971"`. #' - Sc Optional: Schmidt number of additional quantities to be calculated #' - Sc_name Optional: Name of the additional quantities, has to be of same length than -#' \code{Sc_name} +#' `Sc_name` #' - constants Kelvin - conversion degree Celsius to Kelvin \cr #' pressure0 - reference atmospheric pressure at sea level (Pa) \cr #' Tair0 - reference air temperature (K) \cr #' Sc_CO2 - Schmidt number for CO2 \cr -#' Pr - Prandtl number (if \code{Sc} is provided) +#' Pr - Prandtl number (if `Sc` is provided) #' #' # Value A DataFrame with the following columns: #' \item{Gb_h}{Boundary layer conductance for heat transfer (m s-1)} #' \item{Rb_h}{Boundary layer resistance for heat transfer (s m-1)} #' \item{kB_h}{kB-1 parameter for heat transfer} -#' \item{Gb_Sc_name}{Boundary layer conductance for \code{Sc_name} (m s-1). Only added if \code{Sc_name} and -#' \code{Sc_name} are provided} +#' \item{Gb_Sc_name}{Boundary layer conductance for `Sc_name` (m s-1). Only added if `Sc_name` and +#' `Sc_name` are provided} #' #' # Details The formulation is based on the kB-1 model developed by Massman 1999. @@ -269,7 +269,7 @@ end #' \deqn{fc = 1 - exp(-LAI/2)} #' #' The wind speed at the top of the canopy is calculated using function -#' \code{\link{wind_profile}}. +#' `\link{wind_profile`}. #' #' Ct is the heat transfer coefficient of the leaf (Massman 1999): #' @@ -291,10 +291,10 @@ end #' #' where Sc_x is the Schmidt number of quantity x, and Pr is the Prandtl number (0.71). #' -#' @note If the roughness length for momentum (\code{z0m}) is not provided as input, it is estimated -#' from the function \code{roughness_parameters} within \code{wind_profile}. This function -#' estimates a single \code{z0m} value for the entire time period! If a varying \code{z0m} value -#' (e.g. across seasons or years) is required, \code{z0m} should be provided as input argument. +#' @note If the roughness length for momentum (`z0m`) is not provided as input, it is estimated +#' from the function `roughness_parameters` within `wind_profile`. This function +#' estimates a single `z0m` value for the entire time period! If a varying `z0m` value +#' (e.g. across seasons or years) is required, `z0m` should be provided as input argument. #' #' #' @references Su, Z., Schmugge, T., Kustas, W. & Massman, W., 2001: An evaluation of @@ -308,7 +308,7 @@ end #' A preliminary multiple resistance routine for deriving dry deposition velocities #' from measured quantities. Water, Air, and Soil Pollution 36, 311-330. #' -#' @seealso \code{\link{Gb_Thom}}, \code{\link{Gb_Choudhury}}, \code{\link{aerodynamic_conductance}} +#' @seealso `\link{Gb_Thom`}, `\link{Gb_Choudhury`}, `\link{aerodynamic_conductance`} #' #' ```@example; output = false #' ``` diff --git a/inst/fromR/check_input.jl b/inst/fromR/check_input.jl index 21dd940..913f081 100755 --- a/inst/fromR/check_input.jl +++ b/inst/fromR/check_input.jl @@ -12,8 +12,8 @@ #' @note This function can be run for named variables (in which case the return #' value will be named according to the given name), or for placeholder #' variables that are assigned and named according to e.g. entries of a character -#' vector. In the latter case, the input variable has to be named as \code{"var"} or -#' \code{"var_qc"}. +#' vector. In the latter case, the input variable has to be named as `"var"` or +#' `"var_qc"`. #' #' @keywords internal function check_input(data,...) diff --git a/inst/fromR/datasets_description.jl b/inst/fromR/datasets_description.jl index 014f517..6daaabe 100755 --- a/inst/fromR/datasets_description.jl +++ b/inst/fromR/datasets_description.jl @@ -12,31 +12,31 @@ #' \item{doy}{day of year} #' \item{hour}{hour (0 - 23.5)} #' \item{Tair}{Air temperature (degC) [TA_F]} -#' \item{Tair_qc}{Quality control of \code{Tair} [TA_F_QC]} +#' \item{Tair_qc}{Quality control of `Tair` [TA_F_QC]} #' \item{PPFD}{Photosynthetic photon flux density (umol m-2 s-1) [PPFD_IN]} -#' \item{PPFD_qc}{Quality control of \code{PPFD} [PPFD_IN_QC]} +#' \item{PPFD_qc}{Quality control of `PPFD` [PPFD_IN_QC]} #' \item{VPD}{Vapor pressure deficit (kPa) [VPD_F]} -#' \item{VPD_qc}{Quality control of \code{VPD} [VPD_F_QC]} +#' \item{VPD_qc}{Quality control of `VPD` [VPD_F_QC]} #' \item{pressure}{Atmospheric pressure (kPa) [PA_F]} #' \item{precip}{precipitation (mm) [P_F]} -#' \item{precip_qc}{Quality control of \code{precip} [P_F_QC]} +#' \item{precip_qc}{Quality control of `precip` [P_F_QC]} #' \item{ustar}{friction velocity (m s-1) [USTAR]} #' \item{wind}{horizontal wind velocity (m s-1) [WS_F]} -#' \item{wind_qc}{Quality control of \code{wind} [WS_F_QC]} +#' \item{wind_qc}{Quality control of `wind` [WS_F_QC]} #' \item{Ca}{CO2 concentration (ppm) [CO2_F_MDS]} -#' \item{Ca_qc}{Quality control of \code{Ca} [CO2_F_MDS_QC]} +#' \item{Ca_qc}{Quality control of `Ca` [CO2_F_MDS_QC]} #' \item{LW_up}{upward longwave radiation (W m-2) [LW_OUT]} #' \item{Rn}{Net radiation (W m-2) [NETRAD]} #' \item{LE}{Latent heat flux (W m-2) [LE_F_MDS]} -#' \item{LE_qc}{Quality control of \code{LE} [LE_F_MDS_QC]} +#' \item{LE_qc}{Quality control of `LE` [LE_F_MDS_QC]} #' \item{H}{Sensible heat flux (W m-2) [H_F_MDS]} -#' \item{H_qc}{Quality control of \code{H} [H_F_MDS_QC]} +#' \item{H_qc}{Quality control of `H` [H_F_MDS_QC]} #' \item{G}{Ground heat flux (W m-2) [G_F_MDS]} -#' \item{G_qc}{Quality control of \code{G} [G_F_MDS_QC]} +#' \item{G_qc}{Quality control of `G` [G_F_MDS_QC]} #' \item{NEE}{Net ecosystem exchange (umol m-2 s-1) [NEE_VUT_USTAR50]} -#' \item{NEE_qc}{Quality control of \code{NEE} [NEE_VUT_USTAR50_QC]} +#' \item{NEE_qc}{Quality control of `NEE` [NEE_VUT_USTAR50_QC]} #' \item{GPP}{Gross primary productivity from nighttime partitioning (umol m-2 s-1) [GPP_NT_VUT_USTAR50]} -#' \item{GPP_qc}{Quality control of \code{GPP} [NEE_VUT_USTAR50_QC]} +#' \item{GPP_qc}{Quality control of `GPP` [NEE_VUT_USTAR50_QC]} #' \item{Reco}{Ecosystem respiration from nighttime partitioning (umol m-2 s-1) [RECO_NT_VUT_USTAR50]} #' } #' @@ -64,32 +64,32 @@ #' \item{doy}{day of year} #' \item{hour}{hour (0 - 23.5)} #' \item{Tair}{Air temperature (degC) [TA_F]} -#' \item{Tair_qc}{Quality control of \code{Tair} [TA_F_QC]} +#' \item{Tair_qc}{Quality control of `Tair` [TA_F_QC]} #' \item{PPFD}{Photosynthetic photon flux density (umol m-2 s-1) [PPFD_IN]} -#' \item{PPFD_qc}{Quality control of \code{PPFD} [PPFD_IN_QC]} +#' \item{PPFD_qc}{Quality control of `PPFD` [PPFD_IN_QC]} #' \item{VPD}{Vapor pressure deficit (kPa) [VPD_F]} -#' \item{VPD_qc}{Quality control of \code{VPD} [VPD_F_QC]} +#' \item{VPD_qc}{Quality control of `VPD` [VPD_F_QC]} #' \item{pressure}{Atmospheric pressure (kPa) [PA_F]} #' \item{precip}{precipitation (mm) [P_F]} -#' \item{precip_qc}{Quality control of \code{precip} [P_F_QC]} +#' \item{precip_qc}{Quality control of `precip` [P_F_QC]} #' \item{ustar}{friction velocity (m s-1) [USTAR]} #' \item{wind}{horizontal wind velocity (m s-1) [WS_F]} -#' \item{wind_qc}{Quality control of \code{wind} [WS_F_QC]} +#' \item{wind_qc}{Quality control of `wind` [WS_F_QC]} #' \item{Ca}{CO2 concentration (ppm) [CO2_F_MDS]} -#' \item{Ca_qc}{Quality control of \code{Ca} [CO2_F_MDS_QC]} +#' \item{Ca_qc}{Quality control of `Ca` [CO2_F_MDS_QC]} #' \item{LW_up}{upward longwave radiation (W m-2) [LW_OUT]} #' \item{LW_down}{downward longwave radiation (W m-2) [LW_IN_F]} #' \item{Rn}{Net radiation (W m-2) [NETRAD]} #' \item{LE}{Latent heat flux (W m-2) [LE_F_MDS]} -#' \item{LE_qc}{Quality control of \code{LE} [LE_F_MDS_QC]} +#' \item{LE_qc}{Quality control of `LE` [LE_F_MDS_QC]} #' \item{H}{Sensible heat flux (W m-2) [H_F_MDS]} -#' \item{H_qc}{Quality control of \code{H} [H_F_MDS_QC]} +#' \item{H_qc}{Quality control of `H` [H_F_MDS_QC]} #' \item{G}{Ground heat flux (W m-2) [G_F_MDS]} -#' \item{G_qc}{Quality control of \code{G} [G_F_MDS_QC]} +#' \item{G_qc}{Quality control of `G` [G_F_MDS_QC]} #' \item{NEE}{Net ecosystem exchange (umol m-2 s-1) [NEE_VUT_USTAR50]} -#' \item{NEE_qc}{Quality control of \code{NEE} [NEE_VUT_USTAR50_QC]} +#' \item{NEE_qc}{Quality control of `NEE` [NEE_VUT_USTAR50_QC]} #' \item{GPP}{Gross primary productivity from nighttime partitioning (umol m-2 s-1) [GPP_NT_VUT_USTAR50]} -#' \item{GPP_qc}{Quality control of \code{GPP} [NEE_VUT_USTAR50_QC]} +#' \item{GPP_qc}{Quality control of `GPP` [NEE_VUT_USTAR50_QC]} #' \item{Reco}{Ecosystem respiration from nighttime partitioning (umol m-2 s-1) [RECO_NT_VUT_USTAR50]} #' } #' @@ -117,29 +117,29 @@ #' \item{doy}{day of year} #' \item{hour}{hour (0 - 23.5)} #' \item{Tair}{Air temperature (degC) [TA_F]} -#' \item{Tair_qc}{Quality control of \code{Tair} [TA_F_QC]} +#' \item{Tair_qc}{Quality control of `Tair` [TA_F_QC]} #' \item{PPFD}{Photosynthetic photon flux density (umol m-2 s-1) [PPFD_IN]} -#' \item{PPFD_qc}{Quality control of \code{PPFD} [PPFD_IN_QC]} +#' \item{PPFD_qc}{Quality control of `PPFD` [PPFD_IN_QC]} #' \item{VPD}{Vapor pressure deficit (kPa) [VPD_F]} -#' \item{VPD_qc}{Quality control of \code{VPD} [VPD_F_QC]} +#' \item{VPD_qc}{Quality control of `VPD` [VPD_F_QC]} #' \item{pressure}{Atmospheric pressure (kPa) [PA_F]} #' \item{precip}{precipitation (mm) [P_F]} -#' \item{precip_qc}{Quality control of \code{precip} [P_F_QC]} +#' \item{precip_qc}{Quality control of `precip` [P_F_QC]} #' \item{ustar}{friction velocity (m s-1) [USTAR]} #' \item{wind}{horizontal wind velocity (m s-1) [WS_F]} -#' \item{wind_qc}{Quality control of \code{wind} [WS_F_QC]} +#' \item{wind_qc}{Quality control of `wind` [WS_F_QC]} #' \item{Ca}{CO2 concentration (ppm) [CO2_F_MDS]} -#' \item{Ca_qc}{Quality control of \code{Ca} [CO2_F_MDS_QC]} +#' \item{Ca_qc}{Quality control of `Ca` [CO2_F_MDS_QC]} #' \item{LW_up}{upward longwave radiation (W m-2) [LW_OUT]} #' \item{Rn}{Net radiation (W m-2) [NETRAD]} #' \item{LE}{Latent heat flux (W m-2) [LE_F_MDS]} -#' \item{LE_qc}{Quality control of \code{LE} [LE_F_MDS_QC]} +#' \item{LE_qc}{Quality control of `LE` [LE_F_MDS_QC]} #' \item{H}{Sensible heat flux (W m-2) [H_F_MDS]} -#' \item{H_qc}{Quality control of \code{H} [H_F_MDS_QC]} +#' \item{H_qc}{Quality control of `H` [H_F_MDS_QC]} #' \item{NEE}{Net ecosystem exchange (umol m-2 s-1) [NEE_VUT_USTAR50]} -#' \item{NEE_qc}{Quality control of \code{NEE} [NEE_VUT_USTAR50_QC]} +#' \item{NEE_qc}{Quality control of `NEE` [NEE_VUT_USTAR50_QC]} #' \item{GPP}{Gross primary productivity from nighttime partitioning (umol m-2 s-1) [GPP_NT_VUT_USTAR50]} -#' \item{GPP_qc}{Quality control of \code{GPP} [NEE_VUT_USTAR50_QC]} +#' \item{GPP_qc}{Quality control of `GPP` [NEE_VUT_USTAR50_QC]} #' \item{Reco}{Ecosystem respiration from nighttime partitioning (umol m-2 s-1) [RECO_NT_VUT_USTAR50]} #' } #' diff --git a/inst/fromR/decoupling.jl b/inst/fromR/decoupling.jl index 07aac90..fc60c52 100755 --- a/inst/fromR/decoupling.jl +++ b/inst/fromR/decoupling.jl @@ -11,12 +11,12 @@ #' - pressure Atmospheric pressure (kPa) #' - Ga Aerodynamic conductance to heat/water vapor (m s-1) #' - Gs Surface conductance (m s-1) -#' - approach Approach used to calculate omega. Either \code{"Jarvis&McNaughton_1986"} (default) -#' or \code{"Martin_1989"}. -#' - LAI Leaf area index (m2 m-2), only used if \code{approach = "Martin_1989"}. +#' - approach Approach used to calculate omega. Either `"Jarvis&McNaughton_1986"` (default) +#' or `"Martin_1989"`. +#' - LAI Leaf area index (m2 m-2), only used if `approach = "Martin_1989"`. #' - Esat_formula Optional: formula to be used for the calculation of esat and the slope of esat. -#' One of \code{"Sonntag_1990"} (Default), \code{"Alduchov_1996"}, or \code{"Allen_1998"}. -#' See \code{\link{Esat_slope}}. +#' One of `"Sonntag_1990"` (Default), `"Alduchov_1996"`, or `"Allen_1998"`. +#' See `\link{Esat_slope`}. #' - constants Kelvin - conversion degree Celsius to Kelvin \cr #' cp - specific heat of air for constant pressure (J K-1 kg-1) \cr #' eps - ratio of the molecular weight of water vapor to dry air (-) \cr @@ -31,7 +31,7 @@ #' and similar conditions at the canopy surface compared to the atmosphere above #' the canopy. Values close to 1 indicate the opposite, i.e. decoupled conditions and #' a low stomatal control on transpiration (Jarvis & McNaughton 1986). \cr -#' The \code{"Jarvis&McNaughton_1986"} approach (default option) is the original +#' The `"Jarvis&McNaughton_1986"` approach (default option) is the original #' formulation for the decoupling coefficient, given by (for an amphistomatous #' canopy): #' @@ -42,7 +42,7 @@ #' with s being the slope of the saturation vapor pressure curve (Pa K-1), and \eqn{\gamma} the #' psychrometric constant (Pa K-1). #' -#' The approach \code{"Martin_1989"} by Martin 1989 additionally takes radiative coupling +#' The approach `"Martin_1989"` by Martin 1989 additionally takes radiative coupling #' into account: #' #' \deqn{\Omega = \frac{\epsilon + 1 + \frac{Gr}{Ga}}{\epsilon + (1 + \frac{Ga}{Gs}) (1 + \frac{Gr}{Ga})}}{% @@ -57,8 +57,8 @@ #' Martin P., 1989: The significance of radiative coupling between #' vegetation and the atmosphere. Agricultural and Forest Meteorology 49, 45-53. #' -#' @seealso \code{\link{aerodynamic_conductance}}, \code{\link{surface_conductance}}, -#' \code{\link{equilibrium_imposed_ET}} +#' @seealso `\link{aerodynamic_conductance`}, `\link{surface_conductance`}, +#' `\link{equilibrium_imposed_ET`} #' #' ```@example; output = false #' ``` diff --git a/inst/fromR/energy_balance.jl b/inst/fromR/energy_balance.jl index 6de5dc7..0348dc6 100755 --- a/inst/fromR/energy_balance.jl +++ b/inst/fromR/energy_balance.jl @@ -64,7 +64,7 @@ end #' # Value \item{EUE -}{Energy use efficiency (-)} #' -#' @seealso \code{\link{light_use_efficiency}} +#' @seealso `\link{light_use_efficiency`} #' #' ```@example; output = false #' ``` @@ -101,10 +101,10 @@ end #' - LE Latent heat flux (W m-2) #' - H Sensible heat flux (W m-2) #' - instantaneous should the energy balance be calculated at the time step -#' of the observations (\code{TRUE}), or over the entire time period -#' provided as input (\code{FALSE}) -#' - missing_G_as_NA if \code{TRUE}, missing G are treated as \code{NA}s ,otherwise set to 0. -#' - missing_S_as_NA if \code{TRUE}, missing S are treated as \code{NA}s, otherwise set to 0. +#' of the observations (`TRUE`), or over the entire time period +#' provided as input (`FALSE`) +#' - missing_G_as_NA if `TRUE`, missing G are treated as `NA`s ,otherwise set to 0. +#' - missing_S_as_NA if `TRUE`, missing S are treated as `NA`s, otherwise set to 0. #' #' #' # Details @@ -123,7 +123,7 @@ end #' \item{r_squared}{r^2 of the OLS regression} #' \item{EBR}{energy balance ratio} #' -#' if \code{instantaneous = TRUE}, only \code{EBR} is returned. +#' if `instantaneous = TRUE`, only `EBR` is returned. #' #' @references Wilson K., et al. 2002: Energy balance closure at FLUXNET sites. #' Agricultural and Forest Meteorology 113, 223-243. diff --git a/inst/fromR/evapotranspiration.jl b/inst/fromR/evapotranspiration.jl index d57f774..369bb5c 100755 --- a/inst/fromR/evapotranspiration.jl +++ b/inst/fromR/evapotranspiration.jl @@ -13,41 +13,41 @@ #' - Rn Net radiation (W m-2) #' - G Ground heat flux (W m-2); optional #' - S Sum of all storage fluxes (W m-2); optional -#' - VPD Vapor pressure deficit (kPa); only used if \code{approach = "Penman-Monteith"}. -#' - Ga Aerodynamic conductance to heat/water vapor (m s-1); only used if \code{approach = "Penman-Monteith"}. -#' - approach Approach used. Either \code{"Priestley-Taylor"} (default), or \code{"Penman-Monteith"}. -#' - alpha Priestley-Taylor coefficient; only used if \code{approach = "Priestley-Taylor"}. +#' - VPD Vapor pressure deficit (kPa); only used if `approach = "Penman-Monteith"`. +#' - Ga Aerodynamic conductance to heat/water vapor (m s-1); only used if `approach = "Penman-Monteith"`. +#' - approach Approach used. Either `"Priestley-Taylor"` (default), or `"Penman-Monteith"`. +#' - alpha Priestley-Taylor coefficient; only used if `approach = "Priestley-Taylor"`. #' - Gs_pot Potential/maximum surface conductance (mol m-2 s-1); defaults to 0.6 mol m-2 s-1; -#' only used if \code{approach = "Penman-Monteith"}. -#' - missing_G_as_NA if \code{TRUE}, missing G are treated as \code{NA}s, otherwise set to 0. -#' - missing_S_as_NA if \code{TRUE}, missing S are treated as \code{NA}s, otherwise set to 0. +#' only used if `approach = "Penman-Monteith"`. +#' - missing_G_as_NA if `TRUE`, missing G are treated as `NA`s, otherwise set to 0. +#' - missing_S_as_NA if `TRUE`, missing S are treated as `NA`s, otherwise set to 0. #' - Esat_formula Optional: formula to be used for the calculation of esat and the slope of esat. -#' One of \code{"Sonntag_1990"} (Default), \code{"Alduchov_1996"}, or \code{"Allen_1998"}. -#' See \code{\link{Esat_slope}}. +#' One of `"Sonntag_1990"` (Default), `"Alduchov_1996"`, or `"Allen_1998"`. +#' See `\link{Esat_slope`}. #' - constants cp - specific heat of air for constant pressure (J K-1 kg-1) \cr #' eps - ratio of the molecular weight of water vapor to dry air \cr #' Pa2kPa - conversion pascal (Pa) to kilopascal (kPa) \cr -#' Rd - gas constant of dry air (J kg-1 K-1) (only used if \code{approach = "Penman-Monteith"}) \cr -#' Rgas - universal gas constant (J mol-1 K-1) (only used if \code{approach = "Penman-Monteith"}) \cr -#' Kelvin - conversion degree Celsius to Kelvin (only used if \code{approach = "Penman-Monteith"}) \cr +#' Rd - gas constant of dry air (J kg-1 K-1) (only used if `approach = "Penman-Monteith"`) \cr +#' Rgas - universal gas constant (J mol-1 K-1) (only used if `approach = "Penman-Monteith"`) \cr +#' Kelvin - conversion degree Celsius to Kelvin (only used if `approach = "Penman-Monteith"`) \cr #' #' # Details Potential evapotranspiration is calculated according to Priestley & Taylor, 1972 -#' if \code{approach = "Priestley-Taylor"} (the default): +#' if `approach = "Priestley-Taylor"` (the default): #' #' \deqn{LE_pot,PT = (\alpha * \Delta * (Rn - G - S)) / (\Delta + \gamma)} #' #' \eqn{\alpha} is the Priestley-Taylor coefficient, \eqn{\Delta} is the slope #' of the saturation vapor pressure curve (kPa K-1), and \eqn{\gamma} is the #' psychrometric constant (kPa K-1). -#' if \code{approach = "Penman-Monteith"}, potential evapotranspiration is calculated according +#' if `approach = "Penman-Monteith"`, potential evapotranspiration is calculated according #' to the Penman-Monteith equation: #' #' \deqn{LE_pot,PM = (\Delta * (Rn - G - S) + \rho * cp * VPD * Ga) / (\Delta + \gamma * (1 + Ga/Gs_pot)} #' #' where \eqn{\Delta} is the slope of the saturation vapor pressure curve (kPa K-1), #' \eqn{\rho} is the air density (kg m-3), and \eqn{\gamma} is the psychrometric constant (kPa K-1). -#' The value of \code{Gs_pot} is typically a maximum value of Gs observed at the site, e.g. the 90th +#' The value of `Gs_pot` is typically a maximum value of Gs observed at the site, e.g. the 90th #' percentile of Gs within the growing season. #' #' # Value @@ -55,10 +55,10 @@ #' \item{ET_pot}{Potential evapotranspiration (kg m-2 s-1)} #' \item{LE_pot}{Potential latent heat flux (W m-2)} #' -#' @note If the first argument \code{data} is provided (either a matrix or a DataFrame), +#' @note If the first argument `data` is provided (either a matrix or a DataFrame), #' the following variables can be provided as character (in which case they are interpreted as -#' the column name of \code{data}) or as numeric vectors, in which case they are taken -#' directly for the calculations. If \code{data} is not provided, all input variables have to be +#' the column name of `data`) or as numeric vectors, in which case they are taken +#' directly for the calculations. If `data` is not provided, all input variables have to be #' numeric vectors. #' #' @references Priestley, C_H_B., Taylor, R_J., 1972: On the assessment of surface heat flux @@ -71,7 +71,7 @@ #' Novick, K_A., et al. 2016: The increasing importance of atmospheric demand #' for ecosystem water and carbon fluxes. Nature Climate Change 6, 1023 - 1027. #' -#' @seealso \code{\link{surface_conductance}} +#' @seealso `\link{surface_conductance`} #' #' ```@example; output = false #' ``` @@ -160,16 +160,16 @@ end #' - Rn Net radiation (W m-2) #' - G Ground heat flux (W m-2); optional #' - S Sum of all storage fluxes (W m-2); optional -#' - missing_G_as_NA if \code{TRUE}, missing G are treated as \code{NA}s, otherwise set to 0. -#' - missing_S_as_NA if \code{TRUE}, missing S are treated as \code{NA}s, otherwise set to 0. +#' - missing_G_as_NA if `TRUE`, missing G are treated as `NA`s, otherwise set to 0. +#' - missing_S_as_NA if `TRUE`, missing S are treated as `NA`s, otherwise set to 0. #' - Esat_formula Optional: formula to be used for the calculation of esat and the slope of esat. -#' One of \code{"Sonntag_1990"} (Default), \code{"Alduchov_1996"}, or \code{"Allen_1998"}. -#' See \code{\link{Esat_slope}}. +#' One of `"Sonntag_1990"` (Default), `"Alduchov_1996"`, or `"Allen_1998"`. +#' See `\link{Esat_slope`}. #' - constants cp - specific heat of air for constant pressure (J K-1 kg-1) \cr #' eps - ratio of the molecular weight of water vapor to dry air \cr -#' Rd - gas constant of dry air (J kg-1 K-1) (only if \code{approach = "Penman-Monteith"}) \cr -#' Rgas - universal gas constant (J mol-1 K-1) (only if \code{approach = "Penman-Monteith"}) \cr -#' Kelvin - conversion degree Celsius to Kelvin (only if \code{approach = "Penman-Monteith"}) \cr +#' Rd - gas constant of dry air (J kg-1 K-1) (only if `approach = "Penman-Monteith"`) \cr +#' Rgas - universal gas constant (J mol-1 K-1) (only if `approach = "Penman-Monteith"`) \cr +#' Kelvin - conversion degree Celsius to Kelvin (only if `approach = "Penman-Monteith"`) \cr #' #' @export function reference_ET(data,Gs_ref=0.0143,Tair="Tair",pressure="pressure",VPD="VPD",Rn="Rn",Ga="Ga_h", @@ -197,11 +197,11 @@ end #' - Rn Net radiation (W m-2) #' - G Ground heat flux (W m-2); optional #' - S Sum of all storage fluxes (W m-2); optional -#' - missing_G_as_NA if \code{TRUE}, missing G are treated as \code{NA}s, otherwise set to 0. -#' - missing_S_as_NA if \code{TRUE}, missing S are treated as \code{NA}s, otherwise set to 0. +#' - missing_G_as_NA if `TRUE`, missing G are treated as `NA`s, otherwise set to 0. +#' - missing_S_as_NA if `TRUE`, missing S are treated as `NA`s, otherwise set to 0. #' - Esat_formula Optional: formula to be used for the calculation of esat and the slope of esat. -#' One of \code{"Sonntag_1990"} (Default), \code{"Alduchov_1996"}, or \code{"Allen_1998"}. -#' See \code{\link{Esat_slope}}. +#' One of `"Sonntag_1990"` (Default), `"Alduchov_1996"`, or `"Allen_1998"`. +#' See `\link{Esat_slope`}. #' - constants cp - specific heat of air for constant pressure (J K-1 kg-1) \cr #' eps - ratio of the molecular weight of water vapor to dry air (-) \cr #' Pa2kPa - conversion pascal (Pa) to kilopascal (kPa) @@ -212,7 +212,7 @@ end #' \deqn{ET = \Omega ET_eq + (1 - \Omega)ET_imp} #' #' where \eqn{\Omega} is the decoupling coefficient as calculated from -#' \code{\link{decoupling}}. \code{ET_eq} is the equilibrium evapotranspiration rate, +#' `\link{decoupling`}. `ET_eq` is the equilibrium evapotranspiration rate, #' the ET rate that would occur under uncoupled conditions, where the heat budget #' is dominated by radiation (when Ga -> 0): #' @@ -221,15 +221,15 @@ end #' where \eqn{\Delta} is the slope of the saturation vapor pressure curve (kPa K-1), #' \eqn{\lambda} is the latent heat of vaporization (J kg-1), and \eqn{\gamma} #' is the psychrometric constant (kPa K-1). -#' \code{ET_imp} is the imposed evapotranspiration rate, the ET rate +#' `ET_imp` is the imposed evapotranspiration rate, the ET rate #' that would occur under fully coupled conditions (when Ga -> inf): #' #' \deqn{ET_imp = (\rho * cp * VPD * Gs * \lambda) / \gamma} #' #' where \eqn{\rho} is the air density (kg m-3). #' -#' @note Surface conductance (Gs) can be calculated with \code{\link{surface_conductance}}. -#' Aerodynamic conductance (Ga) can be calculated using \code{\link{aerodynamic_conductance}}. +#' @note Surface conductance (Gs) can be calculated with `\link{surface_conductance`}. +#' Aerodynamic conductance (Ga) can be calculated using `\link{aerodynamic_conductance`}. #' #' # Value A DataFrame with the following columns: @@ -244,7 +244,7 @@ end #' Monteith, J_L., Unsworth, M_H., 2008: Principles of Environmental Physics. #' 3rd edition. Academic Press, London. #' -#' @seealso \code{\link{decoupling}} +#' @seealso `\link{decoupling`} #' #' ```@example; output = false #' ``` diff --git a/inst/fromR/filter_data.jl b/inst/fromR/filter_data.jl index 38eaaaa..8351ae9 100755 --- a/inst/fromR/filter_data.jl +++ b/inst/fromR/filter_data.jl @@ -9,43 +9,43 @@ #' #' - data Data_frame or matrix containing all required input variables in #' half-hourly or hourly resolution. Including year, month, day information -#' - quality_control Should quality control be applied? Defaults to \code{TRUE}. -#' - filter_growseas Should data be filtered for growing season? Defaults to \code{FALSE}. -#' - filter_precip Should precipitation filtering be applied? Defaults to \code{FALSE}. +#' - quality_control Should quality control be applied? Defaults to `TRUE`. +#' - filter_growseas Should data be filtered for growing season? Defaults to `FALSE`. +#' - filter_precip Should precipitation filtering be applied? Defaults to `FALSE`. #' - filter_vars Additional variables to be filtered. Vector of type character. #' - filter_vals_min Minimum values of the variables to be filtered. Numeric vector of -#' the same length than \code{filter_vars}. Set to \code{NA} to be ignored. +#' the same length than `filter_vars`. Set to `NA` to be ignored. #' - filter_vals_max Maximum values of the variables to be filtered. Numeric vector of -#' the same length than \code{filter_vars}. Set to \code{NA} to be ignored. -#' - NA_as_invalid If \code{TRUE} (the default) missing data are filtered out (applies to all variables). +#' the same length than `filter_vars`. Set to `NA` to be ignored. +#' - NA_as_invalid If `TRUE` (the default) missing data are filtered out (applies to all variables). #' - vars_qc Character vector indicating the variables for which quality filter should -#' be applied. Ignored if \code{quality_control = FALSE}. +#' be applied. Ignored if `quality_control = FALSE`. #' - quality_ext The extension to the variables' names that marks them as -#' quality control variables. Ignored if \code{quality_control = FALSE}. +#' quality control variables. Ignored if `quality_control = FALSE`. #' - good_quality Which values indicate good quality (i.e. not to be filtered) -#' in the quality control (qc) variables? Ignored if \code{quality_control = FALSE}. -#' - missing_qc_as_bad If quality control variable is \code{NA}, should the corresponding data point be -#' treated as bad quality? Defaults to \code{TRUE}. Ignored if \code{quality_control = FALSE}. +#' in the quality control (qc) variables? Ignored if `quality_control = FALSE`. +#' - missing_qc_as_bad If quality control variable is `NA`, should the corresponding data point be +#' treated as bad quality? Defaults to `TRUE`. Ignored if `quality_control = FALSE`. #' - precip Precipitation (mm time-1) -#' - GPP Gross primary productivity (umol m-2 s-1); Ignored if \code{filter_growseas = FALSE}. -#' - doy Day of year; Ignored if \code{filter_growseas = FALSE}. -#' - year Year; Ignored if \code{filter_growseas = FALSE}. +#' - GPP Gross primary productivity (umol m-2 s-1); Ignored if `filter_growseas = FALSE`. +#' - doy Day of year; Ignored if `filter_growseas = FALSE`. +#' - year Year; Ignored if `filter_growseas = FALSE`. #' - tGPP GPP threshold (fraction of 95th percentile of the GPP time series). -#' Must be between 0 and 1. Ignored if \code{filter_growseas} is \code{FALSE}. +#' Must be between 0 and 1. Ignored if `filter_growseas` is `FALSE`. #' - ws Window size used for GPP time series smoothing. -#' Ignored if \code{filter_growseas = FALSE}. +#' Ignored if `filter_growseas = FALSE`. #' - min_int Minimum time interval in days for a given state of growing season. -#' Ignored if \code{filter_growseas = FALSE}. +#' Ignored if `filter_growseas = FALSE`. #' - tprecip Precipitation threshold used to identify a precipitation event (mm). -#' Ignored if \code{filter_precip = FALSE}. +#' Ignored if `filter_precip = FALSE`. #' - precip_hours Number of hours removed following a precipitation event (h). -#' Ignored if \code{filter_precip = FALSE}. +#' Ignored if `filter_precip = FALSE`. #' - records_per_hour Number of observations per hour. I_e. 2 for half-hourly data. -#' - filtered_data_to_NA Logical. If \code{TRUE} (the default), all variables in the input -#' DataFrame/matrix are set to \code{NA} for the time step where ANY of the -#' \code{filter_vars} were beyond their acceptable range (as -#' determined by \code{filter_vals_min} and \code{filter_vals_max}). -#' If \code{FALSE}, values are not filtered, and an additional column 'valid' +#' - filtered_data_to_NA Logical. If `TRUE` (the default), all variables in the input +#' DataFrame/matrix are set to `NA` for the time step where ANY of the +#' `filter_vars` were beyond their acceptable range (as +#' determined by `filter_vals_min` and `filter_vals_max`). +#' If `FALSE`, values are not filtered, and an additional column 'valid' #' is added to the DataFrame/matrix, indicating if any value of a row #' did (1) or did not fulfill the filter criteria (0). #' - constants frac2percent - conversion between fraction and percent @@ -53,37 +53,37 @@ #' # Details This routine consists of two parts: #' -#' 1) Quality control: All variables included in \code{vars_qc} are filtered for +#' 1) Quality control: All variables included in `vars_qc` are filtered for #' good quality data. For these variables a corresponding quality variable with -#' the same name as the variable plus the extension as specified in \code{quality_ext} +#' the same name as the variable plus the extension as specified in `quality_ext` #' must be provided. For time steps where the value of the quality indicator is not included -#' in the argument \code{good_quality}, i.e. the quality is not considered as 'good', -#' its value is set to \code{NA}. +#' in the argument `good_quality`, i.e. the quality is not considered as 'good', +#' its value is set to `NA`. #' #' 2) Meteorological filtering. Under certain conditions (e.g. low ustar), the assumptions #' of the EC method are not fulfilled. Further, some data analysis require certain meteorological #' conditions, such as periods without rainfall, or active vegetation (growing season, daytime). #' The filter applied in this second step serves to exclude time periods that do not fulfill the criteria #' specified in the arguments. More specifically, time periods where one of the variables is higher -#' or lower than the specified thresholds (\code{filter_vals_min} and \code{filter_vals_max}) -#' are set to \code{NA} for all variables. If a threshold is set to \code{NA}, it will be ignored. +#' or lower than the specified thresholds (`filter_vals_min` and `filter_vals_max`) +#' are set to `NA` for all variables. If a threshold is set to `NA`, it will be ignored. #' #' # Value - If \code{filtered_data_to_NA = TRUE} (default), the input DataFrame/matrix with -#' observations which did not fulfill the filter criteria set to \code{NA}. -#' If \code{filtered_data_to_NA = FALSE}, the input DataFrame/matrix with an additional + If `filtered_data_to_NA = TRUE` (default), the input DataFrame/matrix with +#' observations which did not fulfill the filter criteria set to `NA`. +#' If `filtered_data_to_NA = FALSE`, the input DataFrame/matrix with an additional #' column "valid", which indicates whether all the data of a time step fulfill the #' filtering criteria (1) or not (0). #' -#' @note The thresholds set with \code{filter_vals_min} and \code{filter_vals_max} filter all data +#' @note The thresholds set with `filter_vals_min` and `filter_vals_max` filter all data #' that are smaller than ("<"), or greater than (">") the specified thresholds. That means #' if a variable has exactly the same value as the threshold, it will not be filtered. Likewise, -#' \code{tprecip} filters all data that are greater than \code{tprecip}. +#' `tprecip` filters all data that are greater than `tprecip`. #' #' Variables considered of bad quality (as specified by the corresponding quality control variables) -#' will be set to \code{NA} by this routine. Data that do not fulfill the filtering criteria are set to -#' \code{NA} if \code{filtered_data_to_NA = TRUE}. Note that with this option *all* variables of the same -#' time step are set to \code{NA}. Alternatively, if \code{filtered_data_to_NA = FALSE} data are not set to \code{NA}, +#' will be set to `NA` by this routine. Data that do not fulfill the filtering criteria are set to +#' `NA` if `filtered_data_to_NA = TRUE`. Note that with this option *all* variables of the same +#' time step are set to `NA`. Alternatively, if `filtered_data_to_NA = FALSE` data are not set to `NA`, #' and a new column "valid" is added to the DataFrame/matrix, indicating if any value of a row #' did (1) or did not fulfill the filter criteria (0). #' @@ -302,9 +302,9 @@ end #' in the delineation of the growing season. The window size defaults to 15 #' days, but depending on the ecosystem, other values can be appropriate. #' -#' The argument \code{min_int} serves to avoid short fluctuations in the +#' The argument `min_int` serves to avoid short fluctuations in the #' status growing season vs. no growing season by defining a minimum length -#' of the status. If a time interval shorter than \code{min_int} is labeled +#' of the status. If a time interval shorter than `min_int` is labeled #' as growing season or non-growing season, it is changed to the status of #' the neighboring values. #' diff --git a/inst/fromR/meteorological_variables.jl b/inst/fromR/meteorological_variables.jl index 0867df8..c071f7f 100755 --- a/inst/fromR/meteorological_variables.jl +++ b/inst/fromR/meteorological_variables.jl @@ -108,8 +108,8 @@ end #' corresponding slope of the saturation vapor pressure curve. #' #' - Tair Air temperature (deg C) -#' - formula Formula to be used. Either \code{"Sonntag_1990"} (Default), -#' \code{"Alduchov_1996"}, or \code{"Allen_1998"}. +#' - formula Formula to be used. Either `"Sonntag_1990"` (Default), +#' `"Alduchov_1996"`, or `"Allen_1998"`. #' - constants Pa2kPa - conversion pascal (Pa) to kilopascal (kPa) #' #' # Details @@ -126,7 +126,7 @@ end #' #' \deqn{\Delta = dEsat / dTair} #' -#' which is solved using \code{\link[stats]{D}}. +#' which is solved using `\link[stats]{D`}. #' #' # Value A dataframe with the following columns: @@ -203,7 +203,7 @@ end #' \deqn{\gamma = cp * pressure / (eps * \lambda)} #' #' where \eqn{\lambda} is the latent heat of vaporization (J kg-1), -#' as calculated from \code{\link{latent_heat_vaporization}}. +#' as calculated from `\link{latent_heat_vaporization`}. #' #' # Value \item{\eqn{\gamma} -}{the psychrometric constant (kPa K-1)} @@ -275,11 +275,11 @@ end #' - gamma Psychrometric constant (kPa K-1) #' - accuracy Accuracy of the result (degC) #' - Esat_formula Optional: formula to be used for the calculation of esat and the slope of esat. -#' One of \code{"Sonntag_1990"} (Default), \code{"Alduchov_1996"}, or \code{"Allen_1998"}. -#' See \code{\link{Esat_slope}}. +#' One of `"Sonntag_1990"` (Default), `"Alduchov_1996"`, or `"Allen_1998"`. +#' See `\link{Esat_slope`}. #' - constants Pa2kPa - conversion pascal (Pa) to kilopascal (kPa) #' -#' @note Arguments \code{accuracy} and \code{Esat_formula} are passed to this function by wetbulb_temp(). +#' @note Arguments `accuracy` and `Esat_formula` are passed to this function by wetbulb_temp(). #' #' @importFrom stats optimize #' @@ -302,8 +302,8 @@ end #' - VPD Vapor pressure deficit (kPa) #' - accuracy Accuracy of the result (deg C) #' - Esat_formula Optional: formula to be used for the calculation of esat and the slope of esat. -#' One of \code{"Sonntag_1990"} (Default), \code{"Alduchov_1996"}, or \code{"Allen_1998"}. -#' See \code{\link{Esat_slope}}. +#' One of `"Sonntag_1990"` (Default), `"Alduchov_1996"`, or `"Allen_1998"`. +#' See `\link{Esat_slope`}. #' - constants cp - specific heat of air for constant pressure (J K-1 kg-1) \cr #' eps - ratio of the molecular weight of water vapor to dry air (-) \cr #' Pa2kPa - conversion pascal (Pa) to kilopascal (kPa) @@ -313,9 +313,9 @@ end #' #' \deqn{e = Esat(Tw) - gamma* (Tair - Tw)} #' -#' The equation is solved for Tw using \code{\link[stats]{optimize}}. -#' Actual vapor pressure e (kPa) is calculated from VPD using the function \code{\link{VPD_to_e}}. -#' The psychrometric constant gamma (kPa K-1) is calculated from \code{\link{psychrometric_constant}}. +#' The equation is solved for Tw using `\link[stats]{optimize`}. +#' Actual vapor pressure e (kPa) is calculated from VPD using the function `\link{VPD_to_e`}. +#' The psychrometric constant gamma (kPa K-1) is calculated from `\link{psychrometric_constant`}. #' #' # Value \item{Tw -}{wet-bulb temperature (degC)} @@ -374,11 +374,11 @@ end #' - ea Air vapor pressure (kPa) #' - accuracy Accuracy of the result (degC) #' - Esat_formula Optional: formula to be used for the calculation of esat and the slope of esat. -#' One of \code{"Sonntag_1990"} (Default), \code{"Alduchov_1996"}, or \code{"Allen_1998"}. -#' See \code{\link{Esat_slope}}. +#' One of `"Sonntag_1990"` (Default), `"Alduchov_1996"`, or `"Allen_1998"`. +#' See `\link{Esat_slope`}. #' - constants Pa2kPa - conversion pascal (Pa) to kilopascal (kPa) #' -#' @note Arguments \code{accuracy} and \code{Esat_formula} are passed to this function by dew_point(). +#' @note Arguments `accuracy` and `Esat_formula` are passed to this function by dew_point(). #' #' @importFrom stats optimize #' @@ -401,8 +401,8 @@ end #' - VPD Vapor pressure deficit (kPa) #' - accuracy Accuracy of the result (deg C) #' - Esat_formula Optional: formula to be used for the calculation of esat and the slope of esat. -#' One of \code{"Sonntag_1990"} (Default), \code{"Alduchov_1996"}, or \code{"Allen_1998"}. -#' See \code{\link{Esat_slope}}. +#' One of `"Sonntag_1990"` (Default), `"Alduchov_1996"`, or `"Allen_1998"`. +#' See `\link{Esat_slope`}. #' - constants Pa2kPa - conversion pascal (Pa) to kilopascal (kPa) #' #' # Details @@ -411,7 +411,7 @@ end #' \deqn{e = Esat(Td)} #' #' where e is vapor pressure of the air and Esat is the vapor pressure deficit. -#' This equation is solved for Td using \code{\link[stats]{optimize}}. +#' This equation is solved for Td using `\link[stats]{optimize`}. #' #' # Value \item{Td -}{dew point temperature (degC)} @@ -463,8 +463,8 @@ end #' - pressure Atmospheric pressure (kPa) #' - VPD Vapor pressure deficit (kPa) #' - Esat_formula Optional: formula to be used for the calculation of esat and the slope of esat. -#' One of \code{"Sonntag_1990"} (Default), \code{"Alduchov_1996"}, or \code{"Allen_1998"}. -#' See \code{\link{Esat_slope}}. +#' One of `"Sonntag_1990"` (Default), `"Alduchov_1996"`, or `"Allen_1998"`. +#' See `\link{Esat_slope`}. #' - constants Kelvin - conversion degree Celsius to Kelvin \cr #' eps - ratio of the molecular weight of water vapor to dry air (-) #' @@ -474,7 +474,7 @@ end #' \deqn{Tv = Tair / (1 - (1 - eps) e/pressure)} #' #' where Tair is in Kelvin (converted internally). Likewise, VPD is converted -#' to actual vapor pressure (e in kPa) with \code{\link{VPD_to_e}} internally. +#' to actual vapor pressure (e in kPa) with `\link{VPD_to_e`} internally. #' #' # Value \item{Tv -}{virtual temperature (deg C)} diff --git a/inst/fromR/potential_radiation.jl b/inst/fromR/potential_radiation.jl index 675bca7..7086916 100755 --- a/inst/fromR/potential_radiation.jl +++ b/inst/fromR/potential_radiation.jl @@ -42,14 +42,14 @@ end #' #' Compute potential radiation for given geolocation and day of year. #' -#' - doy Integer vector with day of year (start at 1), same length as \code{hour} or length 1. +#' - doy Integer vector with day of year (start at 1), same length as `hour` or length 1. #' - hour Numeric vector with daytime as decimal hour of local time zone #' - latDeg Latitude (decimal degrees) #' - longDeg Longitude (decimal degrees) #' - timezone Time zone (hours) #' - useSolartime by default corrects hour (given in local winter time) #' for latitude to solar time (where noon is exactly at 12:00). -#' Set this to \code{FALSE} to directly use local winter time. +#' Set this to `FALSE` to directly use local winter time. #' #' # Value vector of potential radiation (W m-2) diff --git a/inst/fromR/stability_correction.jl b/inst/fromR/stability_correction.jl index 93012c3..84e6f62 100755 --- a/inst/fromR/stability_correction.jl +++ b/inst/fromR/stability_correction.jl @@ -32,7 +32,7 @@ #' #' @references Foken, T, 2008: Micrometeorology. Springer, Berlin, Germany. #' -#' @seealso \code{\link{stability_parameter}} +#' @seealso `\link{stability_parameter`} #' #' ```@example; output = false #' ``` @@ -77,8 +77,8 @@ end #' \deqn{\zeta = (zr - d) / L} #' #' where L is the Monin-Obukhov length (m), calculated from the function -#' \code{\link{Monin_Obukhov_length}}. The displacement height d can -#' be estimated from the function \code{\link{roughness_parameters}}. +#' `\link{Monin_Obukhov_length`}. The displacement height d can +#' be estimated from the function `\link{roughness_parameters`}. #' #' # Value \item{\eqn{\zeta} - }{stability parameter (-)} @@ -109,13 +109,13 @@ end #' from the exponential wind profile under non-neutral conditions. #' #' - zeta Stability parameter zeta (-) -#' - formulation Formulation for the stability function. Either \code{"Dyer_1970"}, -#' or \code{"Businger_1971"} +#' - formulation Formulation for the stability function. Either `"Dyer_1970"`, +#' or `"Businger_1971"` #' #' # Details The functions give the integrated form of the universal functions. They #' depend on the value of the stability parameter \eqn{\zeta}, -#' which can be calculated from the function \code{\link{stability_parameter}}. +#' which can be calculated from the function `\link{stability_parameter`}. #' The integration of the universal functions is: #' #' \deqn{\psi = -x * zeta} diff --git a/inst/fromR/surface_conditions.jl b/inst/fromR/surface_conditions.jl index 486f576..02eff8c 100755 --- a/inst/fromR/surface_conditions.jl +++ b/inst/fromR/surface_conditions.jl @@ -15,13 +15,13 @@ #' - LE Latent heat flux (W m-2) #' - VPD Vapor pressure deficit (kPa) #' - Ga Aerodynamic conductance for heat/water vapor (m s-1) -#' - calc_surface_CO2 Calculate surface CO2 concentration? Defaults to \code{FALSE}. -#' - Ca Atmospheric CO2 concentration (mol mol-1). Required if \code{calc_surface_CO2 = TRUE}. -#' - NEE Net ecosystem exchange (umol m-2 s-1). Required if \code{calc_surface_CO2 = TRUE}. -#' - Ga_CO2 Aerodynamic conductance for CO2 (m s-1). Required if \code{calc_surface_CO2 = TRUE}. +#' - calc_surface_CO2 Calculate surface CO2 concentration? Defaults to `FALSE`. +#' - Ca Atmospheric CO2 concentration (mol mol-1). Required if `calc_surface_CO2 = TRUE`. +#' - NEE Net ecosystem exchange (umol m-2 s-1). Required if `calc_surface_CO2 = TRUE`. +#' - Ga_CO2 Aerodynamic conductance for CO2 (m s-1). Required if `calc_surface_CO2 = TRUE`. #' - Esat_formula Optional: formula to be used for the calculation of esat and the slope of esat. -#' One of \code{"Sonntag_1990"} (Default), \code{"Alduchov_1996"}, or \code{"Allen_1998"}. -#' See \code{\link{Esat_slope}}. +#' One of `"Sonntag_1990"` (Default), `"Alduchov_1996"`, or `"Allen_1998"`. +#' See `\link{Esat_slope`}. #' - constants cp - specific heat of air for constant pressure (J K-1 kg-1) \cr #' eps - ratio of the molecular weight of water vapor to dry air (-) \cr #' Pa2kPa - conversion pascal (Pa) to kilopascal (kPa) @@ -51,14 +51,14 @@ #' Note that Ga is assumed to be equal for water vapor and sensible heat. #' Ga is further assumed to be the inverse of the sum of the turbulent part #' and the canopy boundary layer conductance (1/Ga = 1/Ga_m + 1/Gb; -#' see \code{\link{aerodynamic_conductance}}). Ga_CO2, the aerodynamic conductance -#' for CO2 is also calculated by \code{\link{aerodynamic_conductance}}. +#' see `\link{aerodynamic_conductance`}). Ga_CO2, the aerodynamic conductance +#' for CO2 is also calculated by `\link{aerodynamic_conductance`}. #' If Ga is replaced by Ga_m (i.e. only the turbulent conductance part), #' the results of the functions represent conditions outside the canopy #' boundary layer, i.e. in the canopy airspace. #' #' @note The following sign convention for NEE is employed (relevant if -#' \code{calc_surface_CO2 = TRUE}): +#' `calc_surface_CO2 = TRUE`): #' negative values of NEE denote net CO2 uptake by the ecosystem. #' #' # Value diff --git a/inst/fromR/surface_conductance.jl b/inst/fromR/surface_conductance.jl index 99cbe54..953ba83 100755 --- a/inst/fromR/surface_conductance.jl +++ b/inst/fromR/surface_conductance.jl @@ -16,16 +16,16 @@ #' - LE Latent heat flux (W m-2) #' - VPD Vapor pressure deficit (kPa) #' - Ga Aerodynamic conductance to heat/water vapor (m s-1) -#' - missing_G_as_NA if \code{TRUE}, missing G are treated as \code{NA}s, otherwise they are set to 0. -#' Only used if \code{formulation = "Penman-Monteith"}. -#' - missing_S_as_NA if \code{TRUE}, missing S are treated as \code{NA}s, otherwise they are set to 0. -#' Only used if \code{formulation = "Penman-Monteith"}. -#' - formulation Formulation used. Either \code{"Penman-Monteith"} (the default) -#' using the inverted Penman-Monteith equation, or \code{"Flux-Gradient"}, +#' - missing_G_as_NA if `TRUE`, missing G are treated as `NA`s, otherwise they are set to 0. +#' Only used if `formulation = "Penman-Monteith"`. +#' - missing_S_as_NA if `TRUE`, missing S are treated as `NA`s, otherwise they are set to 0. +#' Only used if `formulation = "Penman-Monteith"`. +#' - formulation Formulation used. Either `"Penman-Monteith"` (the default) +#' using the inverted Penman-Monteith equation, or `"Flux-Gradient"`, #' for a simple flux-gradient approach requiring ET, pressure, and VPD only. #' - Esat_formula Optional: formula to be used for the calculation of esat and the slope of esat. -#' One of \code{"Sonntag_1990"} (Default), \code{"Alduchov_1996"}, or \code{"Allen_1998"}. -#' Only used if \code{formulation = "Penman-Monteith"}. See \code{\link{Esat_slope}}. +#' One of `"Sonntag_1990"` (Default), `"Alduchov_1996"`, or `"Allen_1998"`. +#' Only used if `formulation = "Penman-Monteith"`. See `\link{Esat_slope`}. #' - constants cp - specific heat of air for constant pressure (J K-1 kg-1) \cr #' eps - ratio of the molecular weight of water vapor to dry air (-) \cr #' Rd - gas constant of dry air (J kg-1 K-1) \cr @@ -36,7 +36,7 @@ #' #' #' # Details - If \code{formulation = "Penman-Monteith"} (the default), surface conductance (Gs) in m s-1 + If `formulation = "Penman-Monteith"` (the default), surface conductance (Gs) in m s-1 #' is calculated from the inverted Penman-Monteith equation: #' #' \deqn{Gs = ( LE * Ga * \gamma ) / ( \Delta * A + \rho * cp * Ga * VPD - LE * ( \Delta + \gamma ) )} @@ -45,10 +45,10 @@ #' saturation vapor pressure curve (kPa K-1), and \eqn{\rho} is air density (kg m-3). #' Available energy (A) is defined as A = Rn - G - S. If G and/or S are not provided, A = Rn. #' -#' By default, any missing data in G and S are set to 0. If \code{missing_S_as_NA = TRUE} -#' or \code{missing_S_as_NA = TRUE}, Gs will give \code{NA} for these timesteps. +#' By default, any missing data in G and S are set to 0. If `missing_S_as_NA = TRUE` +#' or `missing_S_as_NA = TRUE`, Gs will give `NA` for these timesteps. #' -#' If \code{formulation="Flux-Gradient"}, Gs (in mol m-2 s-1) is calculated from VPD and ET only: +#' If `formulation="Flux-Gradient"`, Gs (in mol m-2 s-1) is calculated from VPD and ET only: #' #' \deqn{Gs = ET/pressure * VPD} #' @@ -60,8 +60,8 @@ #' which gives Gs in m s-1. Note that Gs > Gc (canopy conductance) under conditions #' when a significant fraction of ET comes from interception or soil evaporation. #' -#' If \code{pressure} is not available, it can be approximated by elevation using the -#' function \code{\link{pressure_from_elevation}} +#' If `pressure` is not available, it can be approximated by elevation using the +#' function `\link{pressure_from_elevation`} #' #' # Value a dataframe with the following columns: diff --git a/inst/fromR/surface_roughness.jl b/inst/fromR/surface_roughness.jl index cd241e9..5129959 100755 --- a/inst/fromR/surface_roughness.jl +++ b/inst/fromR/surface_roughness.jl @@ -19,7 +19,7 @@ #' #' \deqn{Re = z0m * ustar / v} #' -#' where \code{v} is the kinematic viscosity (m2 s-1). +#' where `v` is the kinematic viscosity (m2 s-1). #' #' # Value \item{Re -}{Roughness Reynolds Number (-)} @@ -48,19 +48,19 @@ end #' A simple approximation of the two roughness parameters displacement height (d) #' and roughness length for momentum (z0m). #' -#' - method Method to use, one of \code{"canopy_height","canopy_height&LAI","wind_profile"} \cr -#' NOTE: if \code{method = "canopy_height"}, only the following three arguments -#' are used. If \code{method = "canopy_height&LAI"}, only \code{zh, LAI, cd}, -#' and \code{hs} are required. +#' - method Method to use, one of `"canopy_height","canopy_height&LAI","wind_profile"` \cr +#' NOTE: if `method = "canopy_height"`, only the following three arguments +#' are used. If `method = "canopy_height&LAI"`, only `zh, LAI, cd`, +#' and `hs` are required. #' - zh Vegetation height (m) #' - frac_d Fraction of displacement height on canopy height (-) #' - frac_z0m Fraction of roughness length on canopy height (-) #' - LAI Leaf area index (-) #' - zr Instrument (reference) height (m) #' - cd Mean drag coefficient for individual leaves. Defaults to 0.2. -#' Only needed if \code{method = "canopy_height&LAI"}. -#' - hs roughness length of the soil surface (m). Only needed if \code{method = "canopy_height&LAI"} -#' The following arguments are only needed if \code{method = "wind_profile"}! +#' Only needed if `method = "canopy_height&LAI"`. +#' - hs roughness length of the soil surface (m). Only needed if `method = "canopy_height&LAI"` +#' The following arguments are only needed if `method = "wind_profile"`! #' - data Data_frame or matrix containing all required variables #' - Tair Air temperature (deg C) #' - pressure Atmospheric pressure (kPa) @@ -69,9 +69,9 @@ end #' - H Sensible heat flux (W m-2) #' - d Zero-plane displacement height (m); optional #' - z0m Roughness length for momentum (m); optional -#' - stab_roughness Should stability correction be considered? Default is \code{TRUE}. -#' - stab_formulation Stability correction function used (If \code{stab_correction = TRUE}). -#' Either \code{"Dyer_1970"} or \code{"Businger_1971"}. +#' - stab_roughness Should stability correction be considered? Default is `TRUE`. +#' - stab_formulation Stability correction function used (If `stab_correction = TRUE`). +#' Either `"Dyer_1970"` or `"Businger_1971"`. #' - constants k - von-Karman constant (-) \cr #' Kelvin - conversion degree Celsius to Kelvin \cr #' cp - specific heat of air for constant pressure (J K-1 kg-1) \cr @@ -82,7 +82,7 @@ end #' # Details The two main roughness parameters, the displacement height (d) #' and the roughness length for momentum (z0m) can be estimated from simple -#' empirical relationships with canopy height (zh). If \code{method = "canopy_height"}, +#' empirical relationships with canopy height (zh). If `method = "canopy_height"`, #' the following formulas are used: #' #' \deqn{d = frac_d * zh} @@ -92,7 +92,7 @@ end #' where frac_d defaults to 0.7 and frac_z0m to 0.1. #' #' Alternatively, d and z0m can be estimated from both canopy height and LAI -#' (If \code{method = "canopy_height&LAI"}). +#' (If `method = "canopy_height&LAI"`). #' Based on data from Shaw & Pereira 1982, Choudhury & Monteith 1988 proposed #' the following semi-empirical relations: #' @@ -104,19 +104,19 @@ end #' #' \deqn{z0m = hs * zh * (1 - d/zh) for 0.2 < X} #' -#' If \code{method = "wind_profile"}, z0m is estimated by solving +#' If `method = "wind_profile"`, z0m is estimated by solving #' the wind speed profile for z0m: #' #' \deqn{z0m = median((zr - d) * exp(-k*wind / ustar - psi_m)} #' #' By default, d in this equation is fixed to 0.7*zh, but can be set to any -#' other value. psi_m is 0 if \code{stab_roughness = FALSE}. +#' other value. psi_m is 0 if `stab_roughness = FALSE`. #' #' # Value a DataFrame with the following columns: #' \item{d}{Zero-plane displacement height (m)} #' \item{z0m}{Roughness length for momentum (m)} -#' \item{z0m_se}{Only if \code{method = wind_profile}: Standard Error of the median for z0m (m)} +#' \item{z0m_se}{Only if `method = wind_profile`: Standard Error of the median for z0m (m)} #' #' @references Choudhury, B. J., Monteith J_L., 1988: A four-layer model for the heat #' budget of homogeneous land surfaces. Q. J. R. Meteorol. Soc. 114, 373-398. @@ -124,7 +124,7 @@ end #' Shaw, R. H., Pereira, A., 1982: Aerodynamic roughness of a plant canopy: #' a numerical experiment. Agricultural Meteorology, 26, 51-65. #' -#' @seealso \code{\link{wind_profile}} +#' @seealso `\link{wind_profile`} #' #' ```@example; output = false #' ``` @@ -210,26 +210,26 @@ end #' #' - data Data_frame or matrix containing all required variables #' - z Heights above ground for which wind speed is calculated. -#' Needs to be of same length as \code{data} or of length 1 +#' Needs to be of same length as `data` or of length 1 #' - Tair Air temperature (deg C) #' - pressure Atmospheric pressure (kPa) #' - ustar Friction velocity (m s-1) #' - H Sensible heat flux (W m-2) -#' - wind Wind speed at height zr (m s-1); only used if \code{stab_correction = TRUE} +#' - wind Wind speed at height zr (m s-1); only used if `stab_correction = TRUE` #' - zr Instrument (reference) height (m) #' - zh Canopy height (m) #' - d Zero-plane displacement height (-) #' - frac_d Fraction of displacement height on canopy height (-); -#' only used if \code{d} is not available -#' - z0m Roughness length (m), optional; only used if \code{stab_correction = FALSE} (default=0.1) -#' - frac_z0m Fraction of roughness length on canopy height (-), optional; only used if \code{z0m} is not provided. +#' only used if `d` is not available +#' - z0m Roughness length (m), optional; only used if `stab_correction = FALSE` (default=0.1) +#' - frac_z0m Fraction of roughness length on canopy height (-), optional; only used if `z0m` is not provided. #' Default is 0.1. -#' - estimate_z0m Should \code{z0m} be estimated from the logarithmic wind profile? If \code{TRUE} (the default), -#' arguments \code{z0m} and \code{frac_z0m} are ignored. -#' See \code{\link{roughness_parameters}} for details. -#' - stab_correction Should stability correction be applied? Defaults to \code{TRUE} -#' - stab_formulation Stability correction function used (If \code{stab_correction = TRUE}). -#' Either \code{"Dyer_1970"} or \code{"Businger_1971"}. +#' - estimate_z0m Should `z0m` be estimated from the logarithmic wind profile? If `TRUE` (the default), +#' arguments `z0m` and `frac_z0m` are ignored. +#' See `\link{roughness_parameters`} for details. +#' - stab_correction Should stability correction be applied? Defaults to `TRUE` +#' - stab_formulation Stability correction function used (If `stab_correction = TRUE`). +#' Either `"Dyer_1970"` or `"Businger_1971"`. #' - constants k - von-Karman constant (-) \cr #' Kelvin - conversion degree Celsius to Kelvin \cr #' cp - specific heat of air for constant pressure (J K-1 kg-1) \cr @@ -244,17 +244,17 @@ end #' \deqn{u(z) = (ustar/k) * (ln((z - d) / z0m) - \psi{m}} #' #' The roughness parameters zero-plane displacement height (d) and roughness length (z0m) -#' can be approximated from \code{\link{roughness_parameters}}. \eqn{\psi{m}} is omitted -#' if \code{stab_correction = FALSE} (not recommended). If \code{estimate_z0m = TRUE}, +#' can be approximated from `\link{roughness_parameters`}. \eqn{\psi{m}} is omitted +#' if `stab_correction = FALSE` (not recommended). If `estimate_z0m = TRUE`, #' z0m is first estimated from the wind profile equation and then used in the equation -#' above for the calculation of \code{u(z)} (see e.g. Newman & Klein 2014). +#' above for the calculation of `u(z)` (see e.g. Newman & Klein 2014). #' #' @note Note that this equation is only valid for z >= d + z0m, and it is not -#' meaningful to calculate values closely above d + z0m. All values in \code{heights} +#' meaningful to calculate values closely above d + z0m. All values in `heights` #' smaller than d + z0m will return 0. #' #' # Value - A vector of wind speed at heights \code{z}. + A vector of wind speed at heights `z`. #' #' @references Monteith, J_L., Unsworth, M_H., 2008: Principles of Environmental Physics. #' 3rd edition. Academic Press, London. @@ -262,7 +262,7 @@ end #' Newman, J_F., Klein, P_M., 2014: The impacts of atmospheric stability on #' the accuracy of wind speed extrapolation methods. Resources 3, 81-105. #' -#' @seealso \code{\link{roughness_parameters}} +#' @seealso `\link{roughness_parameters`} #' #' ```@example; output = false #' ``` diff --git a/inst/fromR/unit_conversions.jl b/inst/fromR/unit_conversions.jl index 7f68aaa..a1754a6 100755 --- a/inst/fromR/unit_conversions.jl +++ b/inst/fromR/unit_conversions.jl @@ -22,7 +22,7 @@ #' \deqn{LE = \lambda ET} #' #' where \eqn{\lambda} is the latent heat of vaporization (J kg-1) as calculated by -#' \code{\link{latent_heat_vaporization}}. +#' `\link{latent_heat_vaporization`}. #' #' ```@example; output = false #' ``` @@ -125,8 +125,8 @@ end #' - VPD Vapor pressure deficit (kPa) #' - rH Relative humidity (-) #' - Esat_formula Optional: formula to be used for the calculation of esat and the slope of esat. -#' One of \code{"Sonntag_1990"} (Default), \code{"Alduchov_1996"}, or \code{"Allen_1998"}. -#' See \code{\link{Esat_slope}}. +#' One of `"Sonntag_1990"` (Default), `"Alduchov_1996"`, or `"Allen_1998"`. +#' See `\link{Esat_slope`}. #' - constants eps - ratio of the molecular weight of water vapor to dry air (-) \cr #' Pa2kPa - conversion pascal (Pa) to kilopascal (kPa) #' @@ -273,7 +273,7 @@ end #' #' \deqn{PPFD = Rg * frac_PAR * J_to_mol} #' -#' by default, the combined conversion factor (\code{frac_PAR * J_to_mol}) is 2.3 +#' by default, the combined conversion factor (`frac_PAR * J_to_mol`) is 2.3 #' #' ```@example; output = false #' ``` @@ -308,7 +308,7 @@ end #' #' - mass Numeric vector of mass in kg #' - molarMass Numeric vector of molar mass of the substance (kg mol-1) -#' e.g. as provided by \code{\link{bigleaf_constants}}()$H2Omol +#' e.g. as provided by `\link{bigleaf_constants`}()$H2Omol #' Default is molar mass of Water. #' #' # Value From b9d535c5dcad5e5541ca5116569f2f6809746f45 Mon Sep 17 00:00:00 2001 From: Thomas Wutzler Date: Sat, 23 Oct 2021 13:06:37 +0200 Subject: [PATCH 03/13] replacing constant$key from R files --- inst/fromR/WUE_metrics.jl | 4 +- inst/fromR/aerodynamic_conductance.jl | 10 ++--- inst/fromR/bigleaf_physiology.jl | 52 ++++++++++++------------ inst/fromR/boundary_layer_conductance.jl | 22 +++++----- inst/fromR/decoupling.jl | 4 +- inst/fromR/energy_balance.jl | 6 +-- inst/fromR/evapotranspiration.jl | 4 +- inst/fromR/filter_data.jl | 10 ++--- inst/fromR/meteorological_variables.jl | 38 ++++++++--------- inst/fromR/potential_radiation.jl | 2 +- inst/fromR/stability_correction.jl | 4 +- inst/fromR/surface_conditions.jl | 8 ++-- inst/fromR/surface_conductance.jl | 4 +- inst/fromR/surface_roughness.jl | 10 ++--- inst/fromR/unit_conversions.jl | 20 ++++----- 15 files changed, 99 insertions(+), 99 deletions(-) diff --git a/inst/fromR/WUE_metrics.jl b/inst/fromR/WUE_metrics.jl index c744d04..ef5463a 100755 --- a/inst/fromR/WUE_metrics.jl +++ b/inst/fromR/WUE_metrics.jl @@ -82,8 +82,8 @@ function WUE_metrics(data,GPP="GPP",NEE="NEE",LE="LE",VPD="VPD",Tair="Tair", check_input(data,list(GPP,NEE,LE,VPD,Tair)) ET = LE_to_ET(LE,Tair) # kg H2O m-2 s-1 - GPP = (GPP * constants$umol2mol * constants$Cmol) * constants$kg2g # gC m-2 s-1 - NEE = (NEE * constants$umol2mol * constants$Cmol) * constants$kg2g # gC m-2 s-1 + GPP = (GPP * constants[:umol2mol] * constants[:Cmol]) * constants[:kg2g] # gC m-2 s-1 + NEE = (NEE * constants[:umol2mol] * constants[:Cmol]) * constants[:kg2g] # gC m-2 s-1 WUE = median(GPP/ET,na_rm=TRUE) WUE_NEE = median(abs(NEE)/ET,na_rm=TRUE) diff --git a/inst/fromR/aerodynamic_conductance.jl b/inst/fromR/aerodynamic_conductance.jl index 2b3a59f..d258bfc 100755 --- a/inst/fromR/aerodynamic_conductance.jl +++ b/inst/fromR/aerodynamic_conductance.jl @@ -236,7 +236,7 @@ else if (Rb_model == "constant_kB-1") if(is_null(kB_h)) stop("value of kB-1 has to be specified if Rb_model is set to 'constant_kB-1'!") else - Rb_h = kB_h/(constants$k * ustar) + Rb_h = kB_h/(constants[:k] * ustar) Gb_h = 1/Rb_h if (!is_null(Sc) | !is_null(Sc_name)) @@ -248,8 +248,8 @@ end end end - Sc = c(constants$Sc_CO2,Sc) - Gb_x = DataFrame(lapply(Sc,function(x) Gb_h / (x/constants$Pr)^0.67)) + Sc = c(constants[:Sc_CO2],Sc) + Gb_x = DataFrame(lapply(Sc,function(x) Gb_h / (x/constants[:Pr])^0.67)) colnames(Gb_x) = paste0("Gb_",c("CO2",Sc_name)) end @@ -283,11 +283,11 @@ else Choose 'stab_correction = FALSE' if no stability correction should be applied.") end - Ra_m = pmax((log((zr - d)/z0m) - psi_h),0) / (constants$k*ustar) + Ra_m = pmax((log((zr - d)/z0m) - psi_h),0) / (constants[:k]*ustar) else - Ra_m = pmax((log((zr - d)/z0m)),0) / (constants$k*ustar) + Ra_m = pmax((log((zr - d)/z0m)),0) / (constants[:k]*ustar) zeta = psi_h = rep(NA_integer_,length=length(Ra_m)) end diff --git a/inst/fromR/bigleaf_physiology.jl b/inst/fromR/bigleaf_physiology.jl index fa4b922..314e9c1 100755 --- a/inst/fromR/bigleaf_physiology.jl +++ b/inst/fromR/bigleaf_physiology.jl @@ -72,7 +72,7 @@ else Rleaf = 0 end - Ci = Ca - (GPP - Rleaf)/(Gs/constants$DwDc) + Ci = Ca - (GPP - Rleaf)/(Gs/constants[:DwDc]) return(Ci) @@ -289,19 +289,19 @@ function photosynthetic_capacity(data,C3=TRUE,Temp,GPP="GPP",Ci,PPFD="PPFD",PPFD check_input(data,list(Temp,GPP,Ci,PPFD)) - Temp = Temp + constants$Kelvin - Tref = 25.0 + constants$Kelvin + Temp = Temp + constants[:Kelvin] + Tref = 25.0 + constants[:Kelvin] if (C3){ # C3 vegetation - Kc_Ha = Kc_Ha * constants$kJ2J - Ko_Ha = Ko_Ha * constants$kJ2J - Gam_Ha = Gam_Ha * constants$kJ2J + Kc_Ha = Kc_Ha * constants[:kJ2J] + Ko_Ha = Ko_Ha * constants[:kJ2J] + Gam_Ha = Gam_Ha * constants[:kJ2J] # Temperature dependencies of photosynthetic parameters - Kc = Kc25 * exp(Kc_Ha * (Temp - Tref) / (Tref*constants$Rgas*Temp)) - Ko = Ko25 * exp(Ko_Ha * (Temp - Tref) / (Tref*constants$Rgas*Temp)) - Gam = Gam25 * exp(Gam_Ha * (Temp - Tref) / (Tref*constants$Rgas*Temp)) - Ko = Ko * constants$J2kJ + Kc = Kc25 * exp(Kc_Ha * (Temp - Tref) / (Tref*constants[:Rgas]*Temp)) + Ko = Ko25 * exp(Ko_Ha * (Temp - Tref) / (Tref*constants[:Rgas]*Temp)) + Gam = Gam25 * exp(Gam_Ha * (Temp - Tref) / (Tref*constants[:Rgas]*Temp)) + Ko = Ko * constants[:J2kJ] # basic filtering on Ci Ci[Ci < 80 | is_na(Ci)] = NA @@ -355,18 +355,18 @@ else end # calculate Vcmax25 and Jmax25 - Vcmax25 = Arrhenius_temp_response(Vcmax,Temp-constants$Kelvin,Ha=Vcmax_Ha, + Vcmax25 = Arrhenius_temp_response(Vcmax,Temp-constants[:Kelvin],Ha=Vcmax_Ha, Hd=Vcmax_Hd,dS=Vcmax_dS,constants=constants) - Jmax25 = Arrhenius_temp_response(Jmax,Temp[calcJmax]-constants$Kelvin,Ha=Jmax_Ha, + Jmax25 = Arrhenius_temp_response(Jmax,Temp[calcJmax]-constants[:Kelvin],Ha=Jmax_Ha, Hd=Jmax_Hd,dS=Jmax_dS,constants=constants) # calculate medians and standard errors of the median Vcmax25_Median = median(Vcmax25,na_rm=TRUE) - Vcmax25_SE = constants$se_median * sd(Vcmax25,na_rm=TRUE)/sqrt((sum(!is_na(Vcmax25)))) + Vcmax25_SE = constants[:se_median] * sd(Vcmax25,na_rm=TRUE)/sqrt((sum(!is_na(Vcmax25)))) Jmax25_Median = median(Jmax25,na_rm=TRUE) - Jmax25_SE = constants$se_median * sd(Jmax25,na_rm=TRUE)/sqrt((sum(!is_na(Jmax25)))) + Jmax25_SE = constants[:se_median] * sd(Jmax25,na_rm=TRUE)/sqrt((sum(!is_na(Jmax25)))) return(c("Vcmax25"=round(Vcmax25_Median,2),"Vcmax25_SE"=round(Vcmax25_SE,2), "Jmax25"=round(Jmax25_Median,2),"Jmax25_SE"=round(Jmax25_SE,2))) @@ -428,12 +428,12 @@ end #' @export function Arrhenius_temp_response(param,Temp,Ha,Hd,dS,constants=bigleaf_constants()) - Temp = Temp + constants$Kelvin - Tref = 25.0 + constants$Kelvin + Temp = Temp + constants[:Kelvin] + Tref = 25.0 + constants[:Kelvin] - Ha = ifelse(missing(Ha),NA,Ha*constants$kJ2J) - Hd = ifelse(missing(Hd),NA,Hd*constants$kJ2J) - dS = ifelse(missing(dS),NA,dS*constants$kJ2J) + Ha = ifelse(missing(Ha),NA,Ha*constants[:kJ2J]) + Hd = ifelse(missing(Hd),NA,Hd*constants[:kJ2J]) + dS = ifelse(missing(dS),NA,dS*constants[:kJ2J]) if (is_na(Ha)) @@ -443,14 +443,14 @@ end if (is_na(Hd) & is_na(dS)) - param25 = param / exp(Ha * (Temp - Tref) / (Tref*constants$Rgas*Temp)) + param25 = param / exp(Ha * (Temp - Tref) / (Tref*constants[:Rgas]*Temp)) else if (!is_na(Hd) & !is_na(dS)) param25 = param / - ( exp(Ha * (Temp - Tref) / (Tref*constants$Rgas*Temp)) * - (1 + exp((Tref*dS - Hd) / (Tref * constants$Rgas))) / - (1 + exp((Temp*dS - Hd) / (Temp * constants$Rgas))) + ( exp(Ha * (Temp - Tref) / (Tref*constants[:Rgas]*Temp)) * + (1 + exp((Tref*dS - Hd) / (Tref * constants[:Rgas]))) / + (1 + exp((Temp*dS - Hd) / (Temp * constants[:Rgas]))) ) else if ((!is_na(Hd) & is_na(dS)) | (is_na(Hd) & !is_na(dS)) ) @@ -459,7 +459,7 @@ else if ((!is_na(Hd) & is_na(dS)) | (is_na(Hd) & !is_na(dS)) ) that considers a temperature optimum and a deactivation term! Continue considering activation energy (Ha) only...") - param25 = param / exp(Ha * (Temp - Tref) / (Tref*constants$Rgas*Temp)) + param25 = param / exp(Ha * (Temp - Tref) / (Tref*constants[:Rgas]*Temp)) end @@ -599,7 +599,7 @@ function stomatal_slope(data,Tair="Tair",pressure="pressure",GPP="GPP",Gs="Gs_mo check_input(data,list(Tair,pressure,GPP,Gs,VPD,Ca)) df = DataFrame(Tair,pressure,GPP,Gs,VPD,Ca) - DwDc = constants$DwDc # ...to work within nls() + DwDc = constants[:DwDc] # ...to work within nls() if (model == "Leuning") @@ -644,7 +644,7 @@ end else if (robust_nls) df$g0 = rep(g0,nrow(df)) # g0 as constant does not work in the nlrob function... - df$DwDc = rep(DwDc,nrow(df)) # same with constants$DwDc + df$DwDc = rep(DwDc,nrow(df)) # same with constants[:DwDc] mod_weights = nlrob(Gs ~ g0 + DwDc*(1.0 + g1/sqrt(VPD))*GPP/Ca,data=df,start=list(g1=3), na_action=na_exclude,...)$w mod = nls(Gs ~ g0 + DwDc*(1.0 + g1/sqrt(VPD))*GPP/Ca,start=list(g1=3),weights=mod_weights,...) diff --git a/inst/fromR/boundary_layer_conductance.jl b/inst/fromR/boundary_layer_conductance.jl index 38bce8f..d83ab9e 100755 --- a/inst/fromR/boundary_layer_conductance.jl +++ b/inst/fromR/boundary_layer_conductance.jl @@ -60,7 +60,7 @@ function Gb_Thom(ustar,Sc=NULL,Sc_name=NULL,constants=bigleaf_constants()) Rb_h = 6.2*ustar^-0.667 Gb_h = 1/Rb_h - kB_h = Rb_h*constants$k*ustar + kB_h = Rb_h*constants[:k]*ustar if (!is_null(Sc) | !is_null(Sc_name)) if (length(Sc) != length(Sc_name)) @@ -71,8 +71,8 @@ end end end - Sc = c(constants$Sc_CO2,Sc) - Gb_x = DataFrame(lapply(Sc,function(x) Gb_h / (x/constants$Pr)^0.67)) + Sc = c(constants[:Sc_CO2],Sc) + Gb_x = DataFrame(lapply(Sc,function(x) Gb_h / (x/constants[:Pr])^0.67)) colnames(Gb_x) = paste0("Gb_",c("CO2",Sc_name)) return(DataFrame(Gb_h,Rb_h,kB_h,Gb_x)) @@ -202,10 +202,10 @@ end Gb_h = LAI*((0.02/alpha)*sqrt(wind_zh/leafwidth)*(1-exp(-alpha/2))) Rb_h = 1/Gb_h - kB_h = Rb_h*constants$k*ustar + kB_h = Rb_h*constants[:k]*ustar - Sc = c(constants$Sc_CO2,Sc) - Gb_x = DataFrame(lapply(Sc,function(x) Gb_h / (x/constants$Pr)^0.67)) + Sc = c(constants[:Sc_CO2],Sc) + Gb_x = DataFrame(lapply(Sc,function(x) Gb_h / (x/constants[:Pr])^0.67)) colnames(Gb_x) = paste0("Gb_",c("CO2",Sc_name)) @@ -357,10 +357,10 @@ end Re = Reynolds_Number(Tair,pressure,ustar,hs,constants) kBs = 2.46 * (Re)^0.25 - log(7.4) Reh = Dl * wind_zh / v - Ct = 1*constants$Pr^-0.6667*Reh^-0.5*N + Ct = 1*constants[:Pr]^-0.6667*Reh^-0.5*N - kB_h = (constants$k*Cd)/(4*Ct*ustar/wind_zh)*fc^2 + kBs*(1 - fc)^2 - Rb_h = kB_h/(constants$k*ustar) + kB_h = (constants[:k]*Cd)/(4*Ct*ustar/wind_zh)*fc^2 + kBs*(1 - fc)^2 + Rb_h = kB_h/(constants[:k]*ustar) Gb_h = 1/Rb_h if (!is_null(Sc) | !is_null(Sc_name)) @@ -372,8 +372,8 @@ end end end - Sc = c(constants$Sc_CO2,Sc) - Gb_x = DataFrame(lapply(Sc,function(x) Gb_h / (x/constants$Pr)^0.67)) + Sc = c(constants[:Sc_CO2],Sc) + Gb_x = DataFrame(lapply(Sc,function(x) Gb_h / (x/constants[:Pr])^0.67)) colnames(Gb_x) = paste0("Gb_",c("CO2",Sc_name)) return(DataFrame(Gb_h,Rb_h,kB_h,Gb_x)) diff --git a/inst/fromR/decoupling.jl b/inst/fromR/decoupling.jl index fc60c52..44d6348 100755 --- a/inst/fromR/decoupling.jl +++ b/inst/fromR/decoupling.jl @@ -136,9 +136,9 @@ end #' @export function longwave_conductance(Tair,LAI,constants=bigleaf_constants()) - Tair = Tair + constants$Kelvin + Tair = Tair + constants[:Kelvin] - Gr = 4 * constants$sigma * Tair^3 * LAI / constants$cp + Gr = 4 * constants[:sigma] * Tair^3 * LAI / constants[:cp] return(Gr) end diff --git a/inst/fromR/energy_balance.jl b/inst/fromR/energy_balance.jl index 0348dc6..d435f82 100755 --- a/inst/fromR/energy_balance.jl +++ b/inst/fromR/energy_balance.jl @@ -222,10 +222,10 @@ function isothermal_Rn(data,Rn="Rn",Tair="Tair",Tsurf="Tsurf",emissivity, check_input(data,list(Rn,Tair,Tsurf)) - Tair = Tair + constants$Kelvin - Tsurf = Tsurf + constants$Kelvin + Tair = Tair + constants[:Kelvin] + Tsurf = Tsurf + constants[:Kelvin] - Rni = Rn + emissivity * constants$sigma * (Tsurf^4 - Tair^4) + Rni = Rn + emissivity * constants[:sigma] * (Tsurf^4 - Tair^4) return(Rni) diff --git a/inst/fromR/evapotranspiration.jl b/inst/fromR/evapotranspiration.jl index 369bb5c..5a192bd 100755 --- a/inst/fromR/evapotranspiration.jl +++ b/inst/fromR/evapotranspiration.jl @@ -133,7 +133,7 @@ else if (approach == "Penman-Monteith") Gs_pot = mol_to_ms(Gs_pot,Tair=Tair,pressure=pressure,constants=constants) rho = air_density(Tair,pressure,constants) - LE_pot = (Delta * (Rn - G - S) + rho * constants$cp * VPD * Ga) / + LE_pot = (Delta * (Rn - G - S) + rho * constants[:cp] * VPD * Ga) / (Delta + gamma * (1 + Ga / Gs_pot)) ET_pot = LE_to_ET(LE_pot,Tair) end @@ -280,7 +280,7 @@ end Delta = Esat_slope(Tair,Esat_formula,constants)[,"Delta"] LE_eq = (Delta * (Rn - G - S)) / (gamma + Delta) - LE_imp = (rho * constants$cp * Gs * VPD) / gamma + LE_imp = (rho * constants[:cp] * Gs * VPD) / gamma ET_imp = LE_to_ET(LE_imp,Tair) ET_eq = LE_to_ET(LE_eq,Tair) diff --git a/inst/fromR/filter_data.jl b/inst/fromR/filter_data.jl index 8351ae9..a729ac9 100755 --- a/inst/fromR/filter_data.jl +++ b/inst/fromR/filter_data.jl @@ -173,7 +173,7 @@ else { # same, but consider missing quality flag variables as good qc_invalid = sum(get(paste0(var,quality_ext)) > max(good_quality) & !is_na(get(paste0(var,quality_ext)))) end - qc_invalid_perc = round((qc_invalid/nrow(data))*constants$frac2percent,2) + qc_invalid_perc = round((qc_invalid/nrow(data))*constants[:frac2percent],2) cat(var,": ",qc_invalid," data points (",qc_invalid_perc,"%) set to NA",fill=TRUE,sep="") end @@ -222,12 +222,12 @@ end end # 4) calculate number and percentage of filtered values - invalids_perc = sapply(invalids, function(x) round((length(x)/nrow(data))*constants$frac2percent,2)) + invalids_perc = sapply(invalids, function(x) round((length(x)/nrow(data))*constants[:frac2percent],2)) additional_invalids = sapply(2:length(invalids), function(x) length(setdiff(invalids[[x]],unique(unlist(invalids[1:(x-1)]))))) - additional_invalids_perc = round(additional_invalids/nrow(data)*constants$frac2percent,2) + additional_invalids_perc = round(additional_invalids/nrow(data)*constants[:frac2percent],2) # 5) write to output @@ -252,10 +252,10 @@ end invalid = unique(unlist(invalids)) valid[invalid] = 0 - excl_perc = round((length(invalid)/nrow(data))*constants$frac2percent,2) + excl_perc = round((length(invalid)/nrow(data))*constants[:frac2percent],2) cat(length(invalid)," data points (",excl_perc,"%) excluded in total",fill=TRUE,sep="") - cat(nrow(data) - length(invalid)," valid data points (",constants$frac2percent-excl_perc,"%) remaining.",fill=TRUE,sep="") + cat(nrow(data) - length(invalid)," valid data points (",constants[:frac2percent]-excl_perc,"%) remaining.",fill=TRUE,sep="") # 6) return input data frame with filtered time steps set to NA or an additional 'valid' column diff --git a/inst/fromR/meteorological_variables.jl b/inst/fromR/meteorological_variables.jl index c071f7f..c98679b 100755 --- a/inst/fromR/meteorological_variables.jl +++ b/inst/fromR/meteorological_variables.jl @@ -31,10 +31,10 @@ """ function air_density(Tair,pressure,constants=bigleaf_constants()) - Tair = Tair + constants$Kelvin - pressure = pressure * constants$kPa2Pa + Tair = Tair + constants[:Kelvin] + pressure = pressure * constants[:kPa2Pa] - rho = pressure / (constants$Rd * Tair) + rho = pressure / (constants[:Rd] * Tair) return(rho) end @@ -80,22 +80,22 @@ end #' @export function pressure_from_elevation(elev,Tair,VPD=NULL,constants=bigleaf_constants()) - Tair = Tair + constants$Kelvin + Tair = Tair + constants[:Kelvin] if(is_null(VPD)) - pressure = constants$pressure0 / exp(constants$g * elev / (constants$Rd*Tair)) + pressure = constants[:pressure0] / exp(constants[:g] * elev / (constants[:Rd]*Tair)) else - pressure1 = constants$pressure0 / exp(constants$g * elev / (constants$Rd*Tair)) - Tv = virtual_temp(Tair - constants$Kelvin,pressure1 * constants$Pa2kPa, - VPD,Esat_formula="Sonntag_1990",constants) + constants$Kelvin + pressure1 = constants[:pressure0] / exp(constants[:g] * elev / (constants[:Rd]*Tair)) + Tv = virtual_temp(Tair - constants[:Kelvin],pressure1 * constants[:Pa2kPa], + VPD,Esat_formula="Sonntag_1990",constants) + constants[:Kelvin] - pressure = constants$pressure0 / exp(constants$g * elev / (constants$Rd*Tv)) + pressure = constants[:pressure0] / exp(constants[:g] * elev / (constants[:Rd]*Tv)) end - pressure = pressure * constants$Pa2kPa + pressure = pressure * constants[:Pa2kPa] return(pressure) end @@ -177,11 +177,11 @@ end # saturation vapor pressure Esat = a * exp((b * Tair) / (c + Tair)) - Esat = Esat * constants$Pa2kPa + Esat = Esat * constants[:Pa2kPa] # slope of the saturation vapor pressure curve Delta = eval(D(expression(a * exp((b * Tair) / (c + Tair))),name="Tair")) - Delta = Delta * constants$Pa2kPa + Delta = Delta * constants[:Pa2kPa] return(DataFrame(Esat,Delta)) end @@ -220,7 +220,7 @@ end function psychrometric_constant(Tair,pressure,constants=bigleaf_constants()) lambda = latent_heat_vaporization(Tair) - gamma = (constants$cp * pressure) / (constants$eps * lambda) + gamma = (constants[:cp] * pressure) / (constants[:eps] * lambda) return(gamma) end @@ -492,10 +492,10 @@ function virtual_temp(Tair,pressure,VPD,Esat_formula=c("Sonntag_1990","Alduchov_ constants=bigleaf_constants()) e = VPD_to_e(VPD,Tair,Esat_formula) - Tair = Tair + constants$Kelvin + Tair = Tair + constants[:Kelvin] - Tv = Tair / (1 - (1 - constants$eps) * e/pressure) - Tv = Tv - constants$Kelvin + Tv = Tair / (1 - (1 - constants[:eps]) * e/pressure) + Tv = Tv - constants[:Kelvin] return(Tv) end @@ -533,9 +533,9 @@ end #' @export function kinematic_viscosity(Tair,pressure,constants=bigleaf_constants()) - Tair = Tair + constants$Kelvin - pressure = pressure * constants$kPa2Pa + Tair = Tair + constants[:Kelvin] + pressure = pressure * constants[:kPa2Pa] - v = 1.327e-05*(constants$pressure0/pressure)*(Tair/constants$Tair0)^1.81 + v = 1.327e-05*(constants[:pressure0]/pressure)*(Tair/constants[:Tair0])^1.81 return(v) end diff --git a/inst/fromR/potential_radiation.jl b/inst/fromR/potential_radiation.jl index 7086916..7d6243f 100755 --- a/inst/fromR/potential_radiation.jl +++ b/inst/fromR/potential_radiation.jl @@ -27,7 +27,7 @@ function extraterrestrial_radiation(doy,constants = bigleaf_constants()) FracYearRad = 2 * pi * (doy - 1) / 365.24 #Eccentricity correction - ExtRadiation = constants$solar_constant * ( + ExtRadiation = constants[:solar_constant] * ( 1.00011 + 0.034221 * cos(FracYearRad) + 0.00128 * sin(FracYearRad) + 0.000719 * cos(2 * FracYearRad) + 0.000077 * sin(2 * FracYearRad) ) diff --git a/inst/fromR/stability_correction.jl b/inst/fromR/stability_correction.jl index 84e6f62..6475c0f 100755 --- a/inst/fromR/stability_correction.jl +++ b/inst/fromR/stability_correction.jl @@ -46,8 +46,8 @@ function Monin_Obukhov_length(data,Tair="Tair",pressure="pressure",ustar="ustar" check_input(data,list(Tair,pressure,ustar,H)) rho = air_density(Tair,pressure,constants) - Tair = Tair + constants$Kelvin - MOL = (-rho*constants$cp*ustar^3*Tair) / (constants$k*constants$g*H) + Tair = Tair + constants[:Kelvin] + MOL = (-rho*constants[:cp]*ustar^3*Tair) / (constants[:k]*constants[:g]*H) return(MOL) end diff --git a/inst/fromR/surface_conditions.jl b/inst/fromR/surface_conditions.jl index 02eff8c..e3289ea 100755 --- a/inst/fromR/surface_conditions.jl +++ b/inst/fromR/surface_conditions.jl @@ -103,13 +103,13 @@ function surface_conditions(data,Tair="Tair",pressure="pressure",LE="LE",H="H", gamma = psychrometric_constant(Tair,pressure,constants) # 1) Temperature - Tsurf = Tair + H / (rho * constants$cp * Ga) + Tsurf = Tair + H / (rho * constants[:cp] * Ga) # 2) Humidity esat = Esat_slope(Tair,Esat_formula,constants)[,"Esat"] e = esat - VPD esat_surf = Esat_slope(Tsurf,Esat_formula,constants)[,"Esat"] - esurf = e + (LE * gamma)/(Ga * rho * constants$cp) + esurf = e + (LE * gamma)/(Ga * rho * constants[:cp]) VPD_surf = pmax(esat_surf - esurf,0) qsurf = VPD_to_q(VPD_surf,Tsurf,pressure,Esat_formula,constants) rH_surf = VPD_to_rH(VPD_surf,Tsurf,Esat_formula) @@ -213,8 +213,8 @@ function radiometric_surface_temp(data,LW_up="LW_up",LW_down="LW_down", check_input(data,list(LW_up,LW_down)) - Trad_K = ((LW_up - (1 - emissivity)*LW_down) / (constants$sigma * emissivity))^(1/4) - Trad_degC = Trad_K - constants$Kelvin + Trad_K = ((LW_up - (1 - emissivity)*LW_down) / (constants[:sigma] * emissivity))^(1/4) + Trad_degC = Trad_K - constants[:Kelvin] return(DataFrame(Trad_K,Trad_degC)) end diff --git a/inst/fromR/surface_conductance.jl b/inst/fromR/surface_conductance.jl index 953ba83..783fc3a 100755 --- a/inst/fromR/surface_conductance.jl +++ b/inst/fromR/surface_conductance.jl @@ -129,7 +129,7 @@ function surface_conductance(data,Tair="Tair",pressure="pressure",Rn="Rn",G=NULL check_input(data,list(Tair,pressure,VPD,LE)) - Gs_mol = (LE_to_ET(LE,Tair)/constants$Mw) * pressure / VPD + Gs_mol = (LE_to_ET(LE,Tair)/constants[:Mw]) * pressure / VPD Gs_ms = mol_to_ms(Gs_mol,Tair,pressure) else if (formulation == "Penman-Monteith") @@ -154,7 +154,7 @@ end gamma = psychrometric_constant(Tair,pressure,constants) rho = air_density(Tair,pressure,constants) - Gs_ms = ( LE * Ga * gamma ) / ( Delta * (Rn-G-S) + rho * constants$cp * Ga * VPD - LE * ( Delta + gamma ) ) + Gs_ms = ( LE * Ga * gamma ) / ( Delta * (Rn-G-S) + rho * constants[:cp] * Ga * VPD - LE * ( Delta + gamma ) ) Gs_mol = ms_to_mol(Gs_ms,Tair,pressure) end diff --git a/inst/fromR/surface_roughness.jl b/inst/fromR/surface_roughness.jl index 5129959..030ffe5 100755 --- a/inst/fromR/surface_roughness.jl +++ b/inst/fromR/surface_roughness.jl @@ -183,18 +183,18 @@ end zeta = stability_parameter(data=data,Tair=Tair,pressure=pressure,ustar=ustar,H=H, zr=zr,d=d,constants=constants) psi_m = stability_correction(zeta,formulation=stab_formulation)[,"psi_m"] - z0m_all = (zr - d) * exp(-constants$k*wind / ustar - psi_m) + z0m_all = (zr - d) * exp(-constants[:k]*wind / ustar - psi_m) else - z0m_all = (zr - d) * exp(-constants$k*wind / ustar) + z0m_all = (zr - d) * exp(-constants[:k]*wind / ustar) end z0m_all[z0m_all > zh] = NA z0m = median(z0m_all,na_rm=TRUE) - z0m_se = constants$se_median * (sd(z0m_all,na_rm=TRUE) / sqrt(length(z0m_all[complete_cases(z0m_all)]))) + z0m_se = constants[:se_median] * (sd(z0m_all,na_rm=TRUE) / sqrt(length(z0m_all[complete_cases(z0m_all)]))) end @@ -325,11 +325,11 @@ end zeta = stability_parameter(data=data,Tair=Tair,pressure=pressure,ustar=ustar,H=H, zr=z,d=d,constants=constants) psi_m = stability_correction(zeta,formulation=stab_formulation)[,"psi_m"] - wind_heights = pmax(0,(ustar / constants$k) * (log(pmax(0,(z - d)) / z0m) - psi_m)) + wind_heights = pmax(0,(ustar / constants[:k]) * (log(pmax(0,(z - d)) / z0m) - psi_m)) else - wind_heights = pmax(0,(ustar / constants$k) * (log(pmax(0,(z - d)) / z0m))) + wind_heights = pmax(0,(ustar / constants[:k]) * (log(pmax(0,(z - d)) / z0m))) end diff --git a/inst/fromR/unit_conversions.jl b/inst/fromR/unit_conversions.jl index a1754a6..66d1273 100755 --- a/inst/fromR/unit_conversions.jl +++ b/inst/fromR/unit_conversions.jl @@ -89,10 +89,10 @@ end """ function ms_to_mol(G_ms,Tair,pressure,constants=bigleaf_constants()) - Tair = Tair + constants$Kelvin - pressure = pressure * constants$kPa2Pa + Tair = Tair + constants[:Kelvin] + pressure = pressure * constants[:kPa2Pa] - G_mol = G_ms * pressure / (constants$Rgas * Tair) + G_mol = G_ms * pressure / (constants[:Rgas] * Tair) return(G_mol) end @@ -103,10 +103,10 @@ end """ function mol_to_ms(G_mol,Tair,pressure,constants=bigleaf_constants()) - Tair = Tair + constants$Kelvin - pressure = pressure * constants$kPa2Pa + Tair = Tair + constants[:Kelvin] + pressure = pressure * constants[:kPa2Pa] - G_ms = G_mol * (constants$Rgas * Tair) / (pressure) + G_ms = G_mol * (constants[:Rgas] * Tair) / (pressure) return(G_ms) end @@ -211,7 +211,7 @@ end """ """ function e_to_q(e,pressure,constants=bigleaf_constants()) - q = constants$eps * e / (pressure - (1-constants$eps) * e) + q = constants[:eps] * e / (pressure - (1-constants[:eps]) * e) return(q) end @@ -221,7 +221,7 @@ end """ """ function q_to_e(q,pressure,constants=bigleaf_constants()) - e = q * pressure / ((1-constants$eps) * q + constants$eps) + e = q * pressure / ((1-constants[:eps]) * q + constants[:eps]) return(e) end @@ -347,7 +347,7 @@ end """ function umolCO2_to_gC(CO2_flux,constants=bigleaf_constants()) - C_flux = CO2_flux * constants$umol2mol * constants$Cmol * constants$kg2g * constants$days2seconds + C_flux = CO2_flux * constants[:umol2mol] * constants[:Cmol] * constants[:kg2g] * constants[:days2seconds] return(C_flux) end @@ -360,7 +360,7 @@ end """ function gC_to_umolCO2(C_flux,constants=bigleaf_constants()) - CO2_flux = (C_flux * constants$g2kg / constants$days2seconds) / constants$Cmol * constants$mol2umol + CO2_flux = (C_flux * constants[:g2kg] / constants[:days2seconds]) / constants[:Cmol] * constants[:mol2umol] return(CO2_flux) end \ No newline at end of file From d1f81946e601420b14344b3428042bb167b71267 Mon Sep 17 00:00:00 2001 From: Thomas Wutzler Date: Sat, 23 Oct 2021 18:22:56 +0200 Subject: [PATCH 04/13] implement global ratiation tests and help --- .github/workflows/CI.yml | 3 +- Project.toml | 5 +- docs/src/global_radiation.md | 4 +- docs/src/walkthrough.md | 15 ++--- src/Bigleaf.jl | 10 ++- src/potential_radiation.jl | 114 +++++++++++++++++++++++++++++++++++ src/sun_position.jl | 16 +++-- src/util.jl | 23 +++++++ test/potential_radiation.jl | 27 +++++++++ test/sun_position.jl | 3 +- 10 files changed, 201 insertions(+), 19 deletions(-) create mode 100755 src/potential_radiation.jl create mode 100644 test/potential_radiation.jl diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 5129220..1f4174e 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -3,6 +3,7 @@ on: push: branches: - main + - ci tags: '*' pull_request: jobs: @@ -14,7 +15,7 @@ jobs: matrix: version: - '1' - - '1.6' + - '^1.7.0-0' os: - ubuntu-latest arch: diff --git a/Project.toml b/Project.toml index fa23732..e9fa14e 100644 --- a/Project.toml +++ b/Project.toml @@ -9,17 +9,20 @@ DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" LabelledArrays = "2ee39098-c373-598a-b85f-a56591580800" Optim = "429524aa-4258-5aef-a3af-852621145aeb" +Pipe = "b98c9c47-44ae-5843-9183-064241ee97a0" RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" +Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb" +TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53" [compat] -julia = "1" AstroLib = "0.4" DataFrames = "1" LabelledArrays = "1" Optim = "1" RecursiveArrayTools = "2" StaticArrays = "1" +julia = "1" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/docs/src/global_radiation.md b/docs/src/global_radiation.md index 9e45a2c..bb57c13 100644 --- a/docs/src/global_radiation.md +++ b/docs/src/global_radiation.md @@ -4,6 +4,8 @@ Pages = ["global_radiation.md",] ``` ```@docs +potential_radiation +extraterrestrial_radiation calc_sun_position_hor calc_sun_position_MOD -``` \ No newline at end of file +``` diff --git a/docs/src/walkthrough.md b/docs/src/walkthrough.md index 4c07eb6..2d75d85 100644 --- a/docs/src/walkthrough.md +++ b/docs/src/walkthrough.md @@ -142,7 +142,14 @@ The following figure compares them at absole scale and as difference to the ## Global radiation -Computing solar position in horizontal coordinates +Potential radiation for given time and latitude: +```@example doc +doy, hour = 160, 10.5 +lat, long = 51.0, 11.5 +potrad = potential_radiation(doy, hour, lat, long) +``` + +Calculation is based on sun's altitude, one of the horizontal coordinates of its position. ```@example doc using Plots, StatsPlots, DataFrames, Dates, Pipe, Suppressor hours = 0:24 @@ -154,12 +161,6 @@ res3 = @suppress_err @pipe calc_sun_position_hor.(datetimes, lat, long) |> toDat @df res3 scatter(datetimes, cols([:altitude,:azimuth]), legend = :topleft, xlab="Date and Time", ylab = "rad") ``` -```@setup doc -savefig("fig/globrad.svg") -``` - -![](fig/globrad.svg) - The hour-angle at noon represents the difference to local time. In the following example solar time is about 55min ahead of local winter time. diff --git a/src/Bigleaf.jl b/src/Bigleaf.jl index 1b7d0b0..4387caa 100644 --- a/src/Bigleaf.jl +++ b/src/Bigleaf.jl @@ -4,10 +4,14 @@ module Bigleaf using Optim using StaticArrays, LabelledArrays, RecursiveArrayTools using DataFrames -using Dates +using Dates, TimeZones +using Pipe using AstroLib +using Suppressor -export toDataFrame + + +export toDataFrame, frac_hour export bigleaf_constants export Esat_slope, Esat_from_Tair, Esat_from_Tair_deriv, LE_to_ET, ET_to_LE, ms_to_mol, mol_to_ms, VPD_to_rH, rH_to_VPD, @@ -18,11 +22,13 @@ export air_density, pressure_from_elevation, psychrometric_constant, dew_point_from_e, dew_point, wetbulb_temp_from_e_Tair_gamma, wetbulb_temp export calc_sun_position_MOD, calc_sun_position_hor +export potential_radiation, extraterrestrial_radiation, get_datetime_for_doy_hour include("util.jl") include("bigleaf_constants.jl") include("unit_conversions.jl") include("meteorological_variables.jl") include("sun_position.jl") +include("potential_radiation.jl") end diff --git a/src/potential_radiation.jl b/src/potential_radiation.jl new file mode 100755 index 0000000..ddd3ed9 --- /dev/null +++ b/src/potential_radiation.jl @@ -0,0 +1,114 @@ +""" + extraterrestrial_radiation(doy::Number; ...) + extraterrestrial_radiation(datetime::TimeType; ...) + +Compute the extraterrestrial solar radiation with the +eccentricity correction. Computation follows Lanini, 2010 (Master thesis, Bern University). + + +# Arguments +- doy: integer vector with day of year (DoY) +optional +- `constants=`[`bigleaf_constants`](@ref)`()`: Dictionary with entries + - solar_constant +- `year`=2030: year to create timestamps. Due to precession results slightly + change across decades. + +# Value +numeric vector of extraterrestrial radiation (W_m-2) + +# Examples +```jldoctest; output = false +ex_rad = extraterrestrial_radiation(1) +≈(ex_rad, 1414, atol = 1) +# output +true +``` +""" +function extraterrestrial_radiation(doy::Number;constants = bigleaf_constants(), year = 2030) + FracYearRad = 2 * π * (doy - 1) / 365.24 + #Eccentricity correction + ExtRadiation = constants[:solar_constant] * ( + 1.00011 + 0.034221 * cos(FracYearRad) + 0.00128 * sin(FracYearRad) + + 0.000719 * cos(2 * FracYearRad) + 0.000077 * sin(2 * FracYearRad) + ) +end, +function extraterrestrial_radiation(datetime::TimeType; constants = bigleaf_constants()) + # Fractional year in radians + doy = Dates.dayofyear(datetime) + extraterrestrial_radiation(doy; constants) +end + +""" + potential_radiation(datetime, lat, long) + potential_radiation(doy, hour, lat, long; timezone,year) + +Compute potential radiation for given geolocation and time. + +Because potential radiation does not change across years +(for a given location and daytime and day of year), time +can be specified alternatively by doy and hour. + +# Arguments +- datetime: UTC timestamp. +- lat: Latitude (decimal degrees) +- long: Longitude (decimal degrees) +- doy: day of year (integer starting from 1) +- hour: hour within the day (0.0 .. 24.0 float) +optional +- timezone: Timezone for doy and hour, defaults to "GMT+x" + nearest to given longitude. +- year: specific year for doy and hour + +# Value +vector of potential radiation (W m-2) + +# Examples +```@example +# assume hours in the GMT+x that is closest to given longitude +potrad = potential_radiation(160, 10.5, 51.0, 11.5) +``` +""" +function potential_radiation(doy, hour, lat, long; timezone = FixedTimeZone("UTC+"*string(round(Int32, long/15))), year = 2030) + # the following doctest does not suppress warnings and fails + # ```jldoctest; output = false + # # assume hours in the GMT+x that is closest to given longitude + # potrad = potential_radiation(160, 10.5, 51.0, 11.5) + # ≈(potrad, 1093, atol=1) + # # output + # true + # ``` + @pipe get_datetime_for_doy_hour(doy,hour; year) |> + ZonedDateTime(_, timezone) |> + potential_radiation(_, lat, long) +end, +function potential_radiation(datetime::TimeType, lat, long) + # Calculate potential radiation from solar elevation and extraterrestrial solar radiation + solElevRad = calc_sun_position_hor(datetime, lat, long).altitude + extRadiation = extraterrestrial_radiation(datetime) + potRad = extRadiation * sin(solElevRad) +end + +""" + get_datetime_for_doy_hour(doy, hour=12; year = 2030) + +Create DateTime for given day_of_year and hour. Hour defaults +to noon and year to 2030, a near future where earth axis +precession does not differ too much from year where the function +is called. Fractional hours can be provided. + +# Examples +```jldoctest output = false +get_datetime_for_doy_hour(2; year = 2021) +# output +2021-01-02T12:00:00 +``` +""" +get_datetime_for_doy_hour(doy, hour::Integer=12; year = 2030) = DateTime(year) + Day(doy-1) + Hour(hour) + +get_datetime_for_doy_hour(doy, hour; year = 2030) = DateTime(year) + Day(doy-1) + frac_hour(Dates.Millisecond, hour) + + + + + diff --git a/src/sun_position.jl b/src/sun_position.jl index 090a3ac..6980c78 100644 --- a/src/sun_position.jl +++ b/src/sun_position.jl @@ -1,10 +1,10 @@ """ - calc_sun_position_hor(datetime::DateTime, lat, long) + calc_sun_position_hor(datetime, lat, long) Compute the Sun position at given time and observer coordinates in horizontal coordinates. # Arguments: -- `datetime`: time given in UTC. +- `datetime`: time: Either a `ZonedDateTime`, or `DateTime` assumed in UTC - `lat`, `long`: latitude and longitude in degree # Value @@ -15,13 +15,17 @@ Compute the Sun position at given time and observer coordinates in horizontal co Seems to represent time [day/2pi] after solar noon. Value at local timezone noon provdes (local time - solar time). """ +function calc_sun_position_hor(datetime::ZonedDateTime, lat, long) + datetimeUTC = DateTime(datetime,UTC) + calc_sun_position_hor(datetimeUTC, lat, long) +end, function calc_sun_position_hor(datetime::DateTime, lat, long) deg2rad = π/180 jd = datetime2julian(datetime) pos_eq = calc_sun_position_MOD(jd) # precession is already account for in MOD pos_hor = eq2hor(pos_eq.α/deg2rad, pos_eq.δ/deg2rad, jd, lat, long; precession = false) .* deg2rad - SLVector(altitude = pos_hor[1], azimuth = pos_hor[2], hourangle = pos_hor[3]) + @suppress_err SLVector(altitude = pos_hor[1], azimuth = pos_hor[2], hourangle = pos_hor[3]) end @@ -57,8 +61,8 @@ end Compute the Sun position at the Julian Day `JD`. Results are represented in the Mean Equinox of Date (MOD), -i.e. accounting for precision but not for nutation and smaller pertubation -of the x axes, in Spherical coordinates. +i.e. accounting for precession but not for nutation and smaller pertubation +of the polar axes, in spherical ecliptic and equatorial coordinates. The algorithm was adapted from [Vallado 2013, p. 277-279]. # Arguments: @@ -128,7 +132,7 @@ function calc_sun_position_MOD(JD::Number) # declination δ = asin(sinϵ * sinλ_e) - S_MOD_rad = SLVector( + @suppress_err S_MOD_rad = SLVector( λ = λ_e, β = 0.0, r = r, α = α, δ = δ, ϵ = ϵ diff --git a/src/util.jl b/src/util.jl index bdc3a84..0e3c412 100644 --- a/src/util.jl +++ b/src/util.jl @@ -18,3 +18,26 @@ end # DataFrame(collect(map(idx -> getindex.(data, idx), eachindex(collect(first(data))))), collect(names)) # end +""" + frac_hour(float::AbstractFloat) + frac_hour(period::Type{<:Period}, float::AbstractFloat) + +Create a period in given type (defaults to `Nanosecond`) from +fractional hours. + +```jldoctest; output = false +using Dates +frac_hour(1+1/60) == Hour(1) + Minute(1) +# output +true +``` +""" +function frac_hour(period::Type{<:Period}, float::AbstractFloat) + #adapted from https://stackoverflow.com/a/51448499 + full_hour, Δ = divrem(float, 1) + partial = period(round(Dates.value(period(Hour(1))) * Δ)) + Hour(full_hour) + partial +end +frac_hour(float::AbstractFloat) = frac_hour(Nanosecond, float) + + diff --git a/test/potential_radiation.jl b/test/potential_radiation.jl new file mode 100644 index 0000000..840c4e7 --- /dev/null +++ b/test/potential_radiation.jl @@ -0,0 +1,27 @@ +@testset "frac_hour" begin + p = frac_hour(1+1/60) + @test p == Hour(1) + Minute(1) +end + +@testset "get_datetime_for_doy_hour summer" begin + hours = [0,π,24] + dts = get_datetime_for_doy_hour.(1, hours; year = 2021) + @test dts[1] == DateTime(2021,1,1) + @test dts[3] == DateTime(2021,1,2) + @test dts[1] < dts[2] < dts[3] +end + +@testset "Dresden summer" begin + hours = 8:16 + potRadSolar = potential_radiation.(160, hours, 39.94, -5.77; timezone = tz"UTC+1") + expSolar = [ + 484.152670743821, 717.876981534078, 925.130678985721, + 1091.78976612035, 1206.4967015669, 1261.43439723686, 1252.85893995917, + 1181.35473297567, 1051.79466982602] + @test all(.≈(potRadSolar, expSolar, rtol = 0.02)) +end + + + + + diff --git a/test/sun_position.jl b/test/sun_position.jl index 297a2a5..ac27605 100644 --- a/test/sun_position.jl +++ b/test/sun_position.jl @@ -54,5 +54,6 @@ end # azimuth increasing (aside edge cases) @test all(diff(res3.azimuth[2:(end-1)]) .> 0) end - + + From 48cfcfbb759c00f1d55c4d681d6319e174a356fe Mon Sep 17 00:00:00 2001 From: Thomas Wutzler Date: Sat, 23 Oct 2021 19:49:03 +0200 Subject: [PATCH 05/13] reformatting evapotranspiration.jl --- Project.toml | 1 + inst/fromR/WUE_metrics.jl | 33 ++-- inst/fromR/aerodynamic_conductance.jl | 93 +++++----- inst/fromR/bigleaf_physiology.jl | 145 ++++++++------- inst/fromR/boundary_layer_conductance.jl | 94 +++++----- inst/fromR/check_input.jl | 30 +-- inst/fromR/datasets_description.jl | 193 ++++++++++---------- inst/fromR/decoupling.jl | 45 ++--- inst/fromR/energy_balance.jl | 46 ++--- inst/fromR/evapotranspiration.jl | 128 ++++++------- inst/fromR/filter_data.jl | 55 +++--- inst/fromR/meteorological_variables.jl | 128 +++++++------ inst/fromR/potential_radiation.jl | 4 +- inst/fromR/stability_correction.jl | 56 +++--- inst/fromR/surface_conditions.jl | 64 ++++--- inst/fromR/surface_conductance.jl | 55 +++--- inst/fromR/surface_roughness.jl | 76 ++++---- inst/fromR/unit_conversions.jl | 40 ++-- inst/walkthrough_todo.jmd | 12 +- src/Bigleaf.jl | 4 +- src/evapotranspiration.jl | 223 +++++++++++++++++++++++ 21 files changed, 913 insertions(+), 612 deletions(-) create mode 100755 src/evapotranspiration.jl diff --git a/Project.toml b/Project.toml index e9fa14e..2c4176b 100644 --- a/Project.toml +++ b/Project.toml @@ -8,6 +8,7 @@ AstroLib = "c7932e45-9af1-51e7-9da9-f004cd3a462b" DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" LabelledArrays = "2ee39098-c373-598a-b85f-a56591580800" +Missings = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" Optim = "429524aa-4258-5aef-a3af-852621145aeb" Pipe = "b98c9c47-44ae-5843-9183-064241ee97a0" RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" diff --git a/inst/fromR/WUE_metrics.jl b/inst/fromR/WUE_metrics.jl index ef5463a..227f4be 100755 --- a/inst/fromR/WUE_metrics.jl +++ b/inst/fromR/WUE_metrics.jl @@ -12,8 +12,8 @@ #' - LE Latent heat flux (W m-2) #' - VPD Vapor pressure deficit (kPa) #' - Tair Air temperature (deg C) -#' - constants Cmol - molar mass of carbon (kg mol-1) \cr -#' umol2mol - conversion micromole (umol) to mole (mol) \cr +#' - constants Cmol - molar mass of carbon (kg mol-1) +#' umol2mol - conversion micromole (umol) to mole (mol) #' kg2g - conversion kilogram (kg) to gram (g) #' #' # Details @@ -21,47 +21,50 @@ #' #' Water-use efficiency (WUE): #' -#' \deqn{WUE = GPP / ET} +#' ``WUE = GPP / ET`` #' #' Water-use efficiency based on NEE (WUE_NEE): #' -#' \deqn{WUE_NEE = NEE / ET} +#' ``WUE_NEE = NEE / ET`` #' #' Inherent water-use efficiency (IWUE; Beer et al. 2009): #' -#' \deqn{IWUE = (GPP * VPD) / ET} +#' ``IWUE = (GPP * VPD) / ET`` #' #' Underlying water-use efficiency (uWUE; Zhou et al. 2014): #' -#' \deqn{uWUE= (GPP * sqrt(VPD)) / ET} +#' ``uWUE= (GPP * sqrt(VPD)) / ET`` #' #' All metrics are calculated based on the median of all values. E_g. #' WUE = median(GPP/ET,na_rm=TRUE) #' #' # Value a named vector with the following elements: -#' \item{WUE}{Water-use efficiency (gC (kg H20)-1)} -#' \item{WUE_NEE}{Water-use efficiency based on NEE (gC (kg H20)-1)} -#' \item{IWUE}{Inherent water-use efficiency (gC kPa (kg H20)-1)} -#' \item{uWUE}{Underlying water-use efficiency (gC kPa^0.5 (kg H20)-1)} +#' - WUE: Water-use efficiency (gC (kg H20)-1) +#' - WUE_NEE: Water-use efficiency based on NEE (gC (kg H20)-1) +#' - IWUE: Inherent water-use efficiency (gC kPa (kg H20)-1) +#' - uWUE: Underlying water-use efficiency (gC kPa^0.5 (kg H20)-1) #' -#' @note Units for VPD can also be hPa. Units change accordingly. +#' #Note +#' Units for VPD can also be hPa. Units change accordingly. #' WUE_NEE is calculated based on the absolute value of NEE (the sign convention does not matter here). #' -#' @references Beer, C., et al., 2009: Temporal and among-site variability of inherent +#' #References +#' Beer, C., et al., 2009: Temporal and among-site variability of inherent #' water use efficiency at the ecosystem level. Global Biogeochemical Cycles 23, GB2018. #' #' Zhou, S., et al., 2014: The effect of vapor pressure deficit on water #' use efficiency at the sub-daily time scale. Geophysical Research Letters 41. #' -#' @seealso `\link{stomatal_slope`} for a measure of intrinsic WUE +#' #See also +#' [`stomatal_slope`](@ref) for a measure of intrinsic WUE #' #' ```@example; output = false #' ``` #' ## filter data for dry periods and daytime at DE-Tha in June 2014 -#' DE_Tha_Jun_2014_2 = filter_data(DE_Tha_Jun_2014,quality_control=FALSE, +#' DE_Tha_Jun_2014_2 = filter_data(DE_Tha_Jun_2014,quality_control=false, #' vars_qc=c("Tair","precip","VPD","H","LE"), -#' filter_growseas=FALSE,filter_precip=TRUE, +#' filter_growseas=false,filter_precip=TRUE, #' filter_vars=c("Tair","PPFD","ustar"), #' filter_vals_min=c(5,200,0.2), #' filter_vals_max=c(NA,NA,NA),NA_as_invalid=TRUE, diff --git a/inst/fromR/aerodynamic_conductance.jl b/inst/fromR/aerodynamic_conductance.jl index d258bfc..bd6a739 100755 --- a/inst/fromR/aerodynamic_conductance.jl +++ b/inst/fromR/aerodynamic_conductance.jl @@ -28,22 +28,22 @@ #' - Cd Foliage drag coefficient (-); only used if `Rb_model = "Su_2001"`. #' - hs Roughness length of bare soil (m); only used if `Rb_model = "Su_2001"`. #' - wind_profile Should Ga for momentum be calculated based on the logarithmic wind profile equation? -#' Defaults to `FALSE`. -#' - stab_correction Should stability correction be applied? Defaults to `TRUE`. Ignored if `wind_profile = FALSE`. +#' Defaults to `false`. +#' - stab_correction Should stability correction be applied? Defaults to `TRUE`. Ignored if `wind_profile = false`. #' - stab_formulation Stability correction function. Either `"Dyer_1970"` (default) or -#' `"Businger_1971"`. Ignored if `wind_profile = FALSE` or if `stab_correction = FALSE`. +#' `"Businger_1971"`. Ignored if `wind_profile = false` or if `stab_correction = false`. #' - Rb_model Boundary layer resistance formulation. One of `"Thom_1972","Choudhury_1988","Su_2001","constant_kB-1"`. #' - kB_h kB-1 value for heat transfer; only used if `Rb_model = "constant_kB-1"` #' - Sc Optional: Schmidt number of additional quantities to be calculated #' - Sc_name Optional: Name of the additonal quantities, has to be of same length than #' `Sc_name` -#' - constants k - von Karman constant \cr -#' cp - specific heat of air for constant pressure (J K-1 kg-1) \cr -#' Kelvin - conversion degree Celsius to Kelvin \cr -#' g - gravitational acceleration (m s-2) \cr -#' pressure0 - reference atmospheric pressure at sea level (Pa) \cr -#' Tair0 - reference air temperature (K) \cr -#' Sc_CO2 - Schmidt number for CO2 \cr +#' - constants k - von Karman constant +#' cp - specific heat of air for constant pressure (J K-1 kg-1) +#' Kelvin - conversion degree Celsius to Kelvin +#' g - gravitational acceleration (m s-2) +#' pressure0 - reference atmospheric pressure at sea level (Pa) +#' Tair0 - reference air temperature (K) +#' Sc_CO2 - Schmidt number for CO2 #' Pr - Prandtl number (if `Sc` is provided) #' #' # Details @@ -51,14 +51,14 @@ #' #' Aerodynamic conductance for heat (Ga_h) is calculated as: #' -#' \deqn{Ga_h = 1 / (Ra_m + Rb_h)} +#' ``Ga_h = 1 / (Ra_m + Rb_h)`` #' #' where Ra_m is the aerodynamic resistance for momentum and Rb the (quasi-laminar) canopy boundary #' layer resistance ('excess resistance'). #' #' The aerodynamic resistance for momentum Ra_m is given by: #' -#' \deqn{Ra_m = u/ustar^2} +#' ``Ra_m = u/ustar^2`` #' #' Note that this formulation accounts for changes in atmospheric stability, and does not require an #' additional stability correction function. @@ -66,14 +66,14 @@ #' An alternative method to calculate Ra_m is provided #' (calculated if `wind_profile = TRUE`): #' -#' \deqn{Ra_m = (ln((zr - d)/z0m) - psi_h) / (k ustar)} +#' ``Ra_m = (ln((zr - d)/z0m) - psi_h) / (k ustar)`` #' #' If the roughness parameters z0m and d are unknown, they can be estimated using -#' `\link{roughness_parameters`}. The argument `stab_formulation` determines the stability correction function used +#' [`roughness_parameters`](@ref). The argument `stab_formulation` determines the stability correction function used #' to account for the effect of atmospheric stability on Ra_m (Ra_m is lower for unstable #' and higher for stable stratification). Stratification is based on a stability parameter zeta (z-d/L), #' where z = reference height, d the zero-plane displacement height, and L the Monin-Obukhov length, -#' calculated with `\link{Monin_Obukhov_length`} +#' calculated with [`Monin_Obukhov_length`](@ref) #' The stability correction function is chosen by the argument `stab_formulation`. Options are #' `"Dyer_1970"` and `"Businger_1971"`. #' @@ -81,68 +81,69 @@ #' the argument `Rb_model`. The following options are implemented: #' `"Thom_1972"` is an empirical formulation based on the friction velocity (ustar) (Thom 1972): #' -#' \deqn{Rb_h = 6.2ustar^-0.667} +#' ``Rb_h = 6.2ustar^-0.667`` #' #' The model by Choudhury & Monteith 1988 (`Rb_model = "Choudhury_1988"`), #' calculates Rb_h based on leaf width, LAI and ustar (Note that function argument `Dl` #' represents leaf width (w) and not characteristic leaf dimension (Dl) #' if `Rb_model` = `"Choudhury_1988"`): #' -#' \deqn{Gb_h = LAI((0.02/\alpha)*sqrt(u(zh)/w)*(1-exp(-\alpha/2)))} +#' ``Gb_h = LAI((0.02/\\alpha)*sqrt(u(zh)/w)*(1-exp(-\\alpha/2)))`` #' -#' where \eqn{\alpha} is a canopy attenuation coefficient modeled in dependence on LAI, -#' u(zh) is wind speed at canopy height (calculated from `\link{wind_profile`}), -#' and w is leaf width (m). See `\link{Gb_Choudhury`} for further details. +#' where ``\\alpha`` is a canopy attenuation coefficient modeled in dependence on LAI, +#' u(zh) is wind speed at canopy height (calculated from [`wind_profile`](@ref)), +#' and w is leaf width (m). See [`Gb_Choudhury`](@ref) for further details. #' #' The option `Rb_model = "Su_2001"` calculates Rb_h based on the physically-based Rb model by Su et al. 2001, #' a simplification of the model developed by Massman 1999: #' -#' \deqn{kB-1 = (k Cd fc^2) / (4Ct ustar/u(zh)) + kBs-1(1 - fc)^2} +#' ``kB-1 = (k Cd fc^2) / (4Ct ustar/u(zh)) + kBs-1(1 - fc)^2`` #' #' where Cd is a foliage drag coefficient (defaults to 0.2), fc is fractional #' vegetation cover, Bs-1 is the inverse Stanton number for bare soil surface, -#' and Ct is a heat transfer coefficient. See `\link{Gb_Su`} for +#' and Ct is a heat transfer coefficient. See [`Gb_Su`](@ref) for #' details on the model. #' #' #' The models calculate the parameter kB-1, which is related to Rb_h: #' -#' \deqn{kB-1 = Rb_h * (k * ustar)} +#' ``kB-1 = Rb_h * (k * ustar)`` #' #' Rb (and Gb) for water vapor and heat are assumed to be equal in this package. #' Gb for other quantities x is calculated as (Hicks et al. 1987): #' -#' \deqn{Gb_x = Gb / (Sc_x / Pr)^0.67} +#' ``Gb_x = Gb / (Sc_x / Pr)^0.67`` #' #' where Sc_x is the Schmidt number of quantity x, and Pr is the Prandtl number (0.71). #' #' # Value a dataframe with the following columns: -#' \item{Ga_m}{Aerodynamic conductance for momentum transfer (m s-1)} -#' \item{Ra_m}{Aerodynamic resistance for momentum transfer (s m-1)} -#' \item{Ga_h}{Aerodynamic conductance for heat transfer (m s-1)} -#' \item{Ra_h}{Aerodynamic resistance for heat transfer (s m-1)} -#' \item{Gb_h}{Canopy boundary layer conductance for heat transfer (m s-1)} -#' \item{Rb_h}{Canopy boundary layer resistance for heat transfer (s m-1)} -#' \item{kB_h}{kB-1 parameter for heat transfer} -#' \item{zeta}{Stability parameter 'zeta' (NA if `wind_profile = FALSE`)} -#' \item{psi_h}{Integrated stability correction function (NA if `wind_profile = FALSE`)} -#' \item{Ra_CO2}{Aerodynamic resistance for CO2 transfer (s m-1)} -#' \item{Ga_CO2}{Aerodynamic conductance for CO2 transfer (m s-1)} -#' \item{Gb_CO2}{Canopy boundary layer conductance for CO2 transfer (m s-1)} +#' - Ga_m: Aerodynamic conductance for momentum transfer (m s-1) +#' - Ra_m: Aerodynamic resistance for momentum transfer (s m-1) +#' - Ga_h: Aerodynamic conductance for heat transfer (m s-1) +#' - Ra_h: Aerodynamic resistance for heat transfer (s m-1) +#' - Gb_h: Canopy boundary layer conductance for heat transfer (m s-1) +#' - Rb_h: Canopy boundary layer resistance for heat transfer (s m-1) +#' - kB_h: kB-1 parameter for heat transfer +#' - zeta: Stability parameter 'zeta' (NA if `wind_profile = false`) +#' - psi_h: Integrated stability correction function (NA if `wind_profile = false`) +#' - Ra_CO2: Aerodynamic resistance for CO2 transfer (s m-1) +#' - Ga_CO2: Aerodynamic conductance for CO2 transfer (m s-1) +#' - Gb_CO2: Canopy boundary layer conductance for CO2 transfer (m s-1) #' \item{Ga_Sc_name}{Aerodynamic conductance for `Sc_name` (m s-1). Only added if `Sc_name` and #' the respective `Sc` are provided} #' \item{Gb_Sc_name}{Boundary layer conductance for `Sc_name` (m s-1). Only added if `Sc_name` and #' the respective `Sc` are provided} #' -#' @note The roughness length for water and heat (z0h) is not returned by this function, but +#' #Note +#' The roughness length for water and heat (z0h) is not returned by this function, but #' it can be calculated from the following relationship (e.g. Verma 1989): #' -#' \deqn{kB-1 = ln(z0m/z0h)} +#' ``kB-1 = ln(z0m/z0h)`` #' #' it follows: #' -#' \deqn{z0h = z0m / exp(kB-1)} +#' ``z0h = z0m / exp(kB-1)`` #' #' `kB-1` is an output of this function. #' @@ -151,7 +152,7 @@ #' #' Note that boundary layer conductance to water vapor transfer (Gb_w) is often #' assumed to equal Gb_h. This assumption is also made in this R package, for -#' example in the function `\link{surface_conductance`}. +#' example in the function [`surface_conductance`](@ref). #' #' If the roughness length for momentum (`z0m`) is not provided as input, it is estimated #' from the function `roughness_parameters` within `wind_profile` if `wind_profile = TRUE` @@ -160,7 +161,8 @@ #' (e.g. across seasons or years) is required, `z0m` should be provided as input argument. #' #' -#' @references Verma, S., 1989: Aerodynamic resistances to transfers of heat, mass and momentum. +#' #References +#' Verma, S., 1989: Aerodynamic resistances to transfers of heat, mass and momentum. #' In: Estimation of areal evapotranspiration, IAHS Pub, 177, 13-20. #' #' Verhoef, A., De Bruin, H., Van Den Hurk, B., 1997: Some practical notes on the parameter kB-1 @@ -173,7 +175,8 @@ #' Monteith, J_L., Unsworth, M_H., 2008: Principles of environmental physics. #' Third Edition. Elsevier Academic Press, Burlington, USA. #' -#' @seealso `\link{Gb_Thom`}, `\link{Gb_Choudhury`}, `\link{Gb_Su`} for calculations of Rb / Gb only +#' #See also +#' [`Gb_Thom`](@ref), [`Gb_Choudhury`](@ref), [`Gb_Su`](@ref) for calculations of Rb / Gb only #' #' ```@example; output = false #' ``` @@ -191,7 +194,7 @@ """ """ function aerodynamic_conductance(data,Tair="Tair",pressure="pressure",wind="wind",ustar="ustar",H="H", - zr,zh,d,z0m=NULL,Dl,N=2,fc=NULL,LAI,Cd=0.2,hs=0.01,wind_profile=FALSE, + zr,zh,d,z0m=NULL,Dl,N=2,fc=NULL,LAI,Cd=0.2,hs=0.01,wind_profile=false, stab_correction=TRUE,stab_formulation=c("Dyer_1970","Businger_1971"), Rb_model=c("Thom_1972","Choudhury_1988","Su_2001","constant_kB-1"), kB_h=NULL,Sc=NULL,Sc_name=NULL,constants=bigleaf_constants()) @@ -280,7 +283,7 @@ end else stop("'stab_formulation' has to be one of 'Dyer_1970' or 'Businger_1971'. - Choose 'stab_correction = FALSE' if no stability correction should be applied.") + Choose 'stab_correction = false' if no stability correction should be applied.") end Ra_m = pmax((log((zr - d)/z0m) - psi_h),0) / (constants[:k]*ustar) @@ -295,7 +298,7 @@ end else if ((!missing(zr) | !missing(d) | !missing(z0m)) & Rb_model %in% c("constant_kB-1","Thom_1972")) - warning("Provided roughness length parameters (zr,d,z0m) are not used if 'wind_profile = FALSE' (the default). Ra_m is calculated as wind / ustar^2") + warning("Provided roughness length parameters (zr,d,z0m) are not used if 'wind_profile = false' (the default). Ra_m is calculated as wind / ustar^2") end Ra_m = wind / ustar^2 diff --git a/inst/fromR/bigleaf_physiology.jl b/inst/fromR/bigleaf_physiology.jl index 314e9c1..b583b34 100755 --- a/inst/fromR/bigleaf_physiology.jl +++ b/inst/fromR/bigleaf_physiology.jl @@ -14,21 +14,22 @@ #' - Gs Surface conductance to water vapor (mol m-2 s-1) #' - Rleaf Ecosystem respiration stemming from leaves (umol CO2 m-2 s-1); defaults to 0 #' - missing_Rleaf_as_NA if Rleaf is provided, should missing values be treated as `NA` (`TRUE`) -#' or set to 0 (`FALSE`, the default)? +#' or set to 0 (`false`, the default)? #' - constants DwDc - Ratio of the molecular diffusivities for water vapor and CO2 (-) #' #' # Details Bulk intercellular CO2 concentration (Ci) is given by: #' -#' \deqn{Ci = Ca - (GPP - Rleaf)/(Gs/1.6)} +#' ``Ci = Ca - (GPP - Rleaf)/(Gs/1.6)`` #' #' where Gs/1.6 (mol m-2 s-1) represents the surface conductance to CO2. #' Note that Gs is required in mol m-2 s-1 for water vapor. Gs is converted to #' its value for CO2 internally. #' Ca can either be atmospheric CO2 concentration (as measured), or surface -#' CO2 concentration as calculated from `\link{surface_CO2`}. +#' CO2 concentration as calculated from [`surface_CO2`](@ref). #' -#' @note The equation is based on Fick's law of diffusion and is equivalent to the +#' #Note +#' The equation is based on Fick's law of diffusion and is equivalent to the #' often used equation at leaf level (ci = ca - An/gs). #' Note that GPP and Gs have a different interpretation than An and gs. #' Gs comprises non-physiological contributions (i.e. physical evaporation) @@ -41,9 +42,10 @@ #' readily comparable to its leaf-level analogue and/or physiological meaningful. #' #' # Value - \item{Ci -}{Bulk canopy intercellular CO2 concentration (umol mol-1)} + - Ci -: Bulk canopy intercellular CO2 concentration (umol mol-1) #' -#' @references Kosugi Y. et al., 2013: Determination of the gas exchange phenology in an +#' #References +#' Kosugi Y. et al., 2013: Determination of the gas exchange phenology in an #' evergreen coniferous forest from 7 years of eddy covariance flux data using #' an extended big-leaf analysis. Ecol Res 28, 373-385. #' @@ -61,7 +63,7 @@ """ """ function intercellular_CO2(data,Ca="Ca",GPP="GPP",Gs="Gs_mol",Rleaf=NULL, - missing_Rleaf_as_NA=FALSE,constants=bigleaf_constants()) + missing_Rleaf_as_NA=false,constants=bigleaf_constants()) check_input(data,list(Ca,GPP,Gs)) @@ -87,7 +89,7 @@ end #' CO2 concentration using the Farquhar et al. 1980 model for C3 photosynthesis. #' #' - data Data_Frame or matrix with all required columns -#' - C3 C3 vegetation (`TRUE`, the default) or C4 vegetation (`FALSE`)? +#' - C3 C3 vegetation (`TRUE`, the default) or C4 vegetation (`false`)? #' - Temp Surface (or air) temperature (degC) #' - GPP Gross primary productivity (umol m-2 s-1) #' - Ci Bulk canopy intercellular CO2 concentration (umol mol-1) @@ -114,14 +116,14 @@ end #' - Theta Curvature term in the light response function of J (-) #' - alpha_canopy Canopy absorptance (-) #' - missing_Rleaf_as_NA if Rleaf is provided, should missing values be treated as `NA` (`TRUE`) -#' or set to 0 (`FALSE`, the default)? +#' or set to 0 (`false`, the default)? #' - Ci_C4 intercellular CO2 concentration below which photosynthesis #' is considered to be CO2-limited (umol mol-1), ignored #' if `C3 = TRUE`. -#' - constants Kelvin - conversion degree Celsius to Kelvin \cr -#' Rgas - universal gas constant (J mol-1 K-1) \cr -#' kJ2J - conversion kilojoule (kJ) to joule (J) \cr -#' J2kJ - conversion joule (J) to kilojoule (kJ) \cr +#' - constants Kelvin - conversion degree Celsius to Kelvin +#' Rgas - universal gas constant (J mol-1 K-1) +#' kJ2J - conversion kilojoule (kJ) to joule (J) +#' J2kJ - conversion joule (J) to kilojoule (kJ) #' se_median - conversion standard error (SE) of the mean to SE of the median #' #' # Details @@ -129,7 +131,7 @@ end #' transport rate at 25degC (Jmax25), which characterize photosynthetic capacity, #' are calculated as at leaf level. #' The required variables Gs and Ci can be calculated from -#' `\link{surface_conductance`} and `\link{intercellular_CO2`}, respectively. +#' [`surface_conductance`](@ref) and [`intercellular_CO2`](@ref), respectively. #' #' Gas exchange parameters are taken from Bernacchi et al. 2001 (apparent values, which #' assume an infinite mesophyll conductance). Negative and very low Ci values @@ -139,7 +141,7 @@ end #' If net photosynthesis is Rubisco-limited (RuBP-saturated carboxylation #' rate, i.e. light has to be (near-)saturating): #' -#' \deqn{Vcmax = (GPP * (Ci + Kc*(1.0 + Oi/Ko))) / (Ci - Gam)} +#' ``Vcmax = (GPP * (Ci + Kc*(1.0 + Oi/Ko))) / (Ci - Gam)`` #' #' where Kc and Ko are the Michaelis-Menten constants for CO2 and O2 (mmol mol-1), #' respectively, Oi is the O2 concentration, and Gam is the photorespiratory CO2 @@ -147,7 +149,7 @@ end #' Under low-light conditions, the electron transport rate J is calculated from #' the RuBP regeneration-limited photosynthesis rate: #' -#' \deqn{J = (GPP * (4.0 * Ci + 8.0 * Gam) / (Ci - Gam)} +#' ``J = (GPP * (4.0 * Ci + 8.0 * Gam) / (Ci - Gam)`` #' #' In this function, bulk canopy photosynthesis is assumed to be Rubisco/RuBP-regeneration #' limited, if incoming PPFD is above/below a specified threshold or range. These ranges @@ -165,7 +167,7 @@ end #' where APPFD_PSII is the absorbed PPFD by photosystem II (PS II), #' and Theta is a curvature parameter. APPFD_PSII is calculated as #' -#' \deqn{PPFD * alpha_canopy * 0.85 * beta} +#' ``PPFD * alpha_canopy * 0.85 * beta`` #' #' where alpha_canopy is canopy-scale absorptance, 0.85 is a correction factor, #' and beta is the fraction of photons absorbed by PS II (assumed 0.5). @@ -191,7 +193,7 @@ end #' For C4 photosynthesis, the simplified model by von Caemmerer 2000 is used. #' For light-saturated photosynthesis, Vcmax is given by: #' -#' \deqn{Vcmax = GPP} +#' ``Vcmax = GPP`` #' #' Note that in addition to the range `PPFD_c`, the range `Ci_C4` #' discards all periods with low Ci, in which photosynthesis is likely to @@ -199,12 +201,13 @@ end #' #' In the light-limited case, J is calculated as: #' -#' \deqn{J = 3 * GPPj / (1 - 0.5) } +#' ``J = 3 * GPPj / (1 - 0.5) `` #' #' The calculation of Jmax25 and Vcmax25 is identical to C3 photosynthesis #' as described above. #' -#' @note The critical assumption is that bulk canopy photosynthesis is limited by +#' #Note +#' The critical assumption is that bulk canopy photosynthesis is limited by #' one of the two limitation states. Incoming PPFD is assumed to determine #' the limitation states. Note however that the ranges (`PPFD_j` and `PPFD_c`) #' are likely ecosystem-specific. E_g. dense canopies presumably require higher @@ -219,10 +222,11 @@ end #' #' # Value a DataFrame with the following columns: -#' \item{Vcmax25}{maximum bulk canopy carboxylation rate at 25degC (umol m-2 (ground) s-1)} -#' \item{Jmax25}{maximum bulk canopy electron transport rate at 25degC (umol m-2 (ground) s-1)} +#' - Vcmax25: maximum bulk canopy carboxylation rate at 25degC (umol m-2 (ground) s-1) +#' - Jmax25: maximum bulk canopy electron transport rate at 25degC (umol m-2 (ground) s-1) #' -#' @references Lloyd J. et al., 1995: A simple calibrated model of Amazon rainforest productivity +#' #References +#' Lloyd J. et al., 1995: A simple calibrated model of Amazon rainforest productivity #' based on leaf biochemical properties. Plant, Cell and Environment 18, 1129-1145. #' #' Rayment M_B., Loustau D., Jarvis P_G., 2002: Photosynthesis and respiration @@ -248,13 +252,14 @@ end #' von Caemmerer, 2000: Biochemical models of leaf photosynthesis. Techniques #' in plant sciences No. 2. CSIRO Publishing, Collingwood VIC, Australia. #' -#' @seealso `\link{intercellular_CO2`}, `\link{Arrhenius_temp_response`} +#' #See also +#' [`intercellular_CO2`](@ref), [`Arrhenius_temp_response`](@ref) #' #' ```@example; output = false #' ``` -#' DE_Tha_Jun_2014_2 = filter_data(DE_Tha_Jun_2014,quality_control=FALSE, +#' DE_Tha_Jun_2014_2 = filter_data(DE_Tha_Jun_2014,quality_control=false, #' vars_qc=c("Tair","precip","VPD","H","LE"), -#' filter_growseas=FALSE,filter_precip=TRUE, +#' filter_growseas=false,filter_precip=TRUE, #' filter_vars=c("Tair","PPFD","ustar","LE"), #' filter_vals_min=c(5,200,0.2,0), #' filter_vals_max=c(NA,NA,NA,NA),NA_as_invalid=TRUE, @@ -269,7 +274,7 @@ end #' # calculate Gs from the the inverted PM equation #' Gs_PM = surface_conductance(DE_Tha_Jun_2014_2,Tair="Tair",pressure="pressure", #' Rn="Rn",G="G",S=NULL,VPD="VPD",Ga=Ga, -#' formulation="Penman-Monteith")[,"Gs_mol"] +#' formulation=Val(:Penman-Monteith))[,"Gs_mol"] #' #' # calculate Ci #' Ci = intercellular_CO2(DE_Tha_Jun_2014_2,Ca="Ca",GPP="GPP",Gs=Gs_PM) @@ -284,7 +289,7 @@ function photosynthetic_capacity(data,C3=TRUE,Temp,GPP="GPP",Ci,PPFD="PPFD",PPFD Rleaf=NULL,Oi=0.21,Kc25=404.9,Ko25=278.4,Gam25=42.75, Kc_Ha=79.43,Ko_Ha=36.38,Gam_Ha=37.83,Vcmax_Ha=65.33,Vcmax_Hd=200, Vcmax_dS=0.635,Jmax_Ha=43.9,Jmax_Hd=200,Jmax_dS=0.640, - Theta=0.7,alpha_canopy=0.8,missing_Rleaf_as_NA=FALSE,Ci_C4=100, + Theta=0.7,alpha_canopy=0.8,missing_Rleaf_as_NA=false,Ci_C4=100, constants=bigleaf_constants()) check_input(data,list(Temp,GPP,Ci,PPFD)) @@ -386,8 +391,8 @@ end #' - Ha Activation energy for param (kJ mol-1) #' - Hd Deactivation energy for param (kJ mol-1) #' - dS Entropy term for param (kJ mol-1 K-1) -#' - constants Kelvin - conversion degree Celsius to Kelvin \cr -#' Rgas - universal gas constant (J mol-1 K-1) \cr +#' - constants Kelvin - conversion degree Celsius to Kelvin +#' Rgas - universal gas constant (J mol-1 K-1) #' kJ2J - conversion kilojoule (kJ) to joule (J) #' #' # Details @@ -416,7 +421,8 @@ end #' # Value param25 - value of the input parameter at the reference temperature of 25degC (umol m-2 s-1) #' -#' @references Johnson F_H., Eyring H., Williams R_W. 1942: +#' #References +#' Johnson F_H., Eyring H., Williams R_W. 1942: #' The nature of enzyme inhibitions in bacterial luminescence: sulfanilamide, #' urethane, temperature and pressure. Journal of cellular and comparative #' physiology 20, 247-268. @@ -483,19 +489,19 @@ end #' - Ca Atmospheric CO2 concentration (air or surface) (umol mol-1) #' - Rleaf Ecosystem respiration stemming from leaves (umol CO2 m-2 s-1); defaults to 0 #' - model Stomatal model used. One of `"USO","Ball&Berry","Leuning"`. -#' - robust_nls Use robust nonlinear regression (`\link[robustbase]{nlrob`})? Default is `FALSE`. +#' - robust_nls Use robust nonlinear regression (`\link[robustbase]{nlrob`})? Default is `false`. #' - nmin Minimum number of data required to perform the fit; defaults to 40. #' - fitg0 Should g0 and g1 be fitted simultaneously? #' - g0 Minimum stomatal conductance (mol m-2 s-1); ignored if `fitg0 = TRUE`. #' - fitD0 Should D0 be fitted along with g1 (and g0 if `fitg0 = TRUE`)?; only used if `model = "Leuning"`. -#' - D0 Stomatal sensitivity parameter to VPD; only used if `model = "Leuning"` and `fitD0 = FALSE`. +#' - D0 Stomatal sensitivity parameter to VPD; only used if `model = "Leuning"` and `fitD0 = false`. #' - Gamma Canopy CO2 compensation point (umol mol-1); only used if `model = "Leuning"`. #' Can be a constant or a variable. Defaults to 50 umol mol-1. -#' - constants Kelvin - conversion degree Celsius to Kelvin \cr -#' Rgas - universal gas constant (J mol-1 K-1) \cr +#' - constants Kelvin - conversion degree Celsius to Kelvin +#' Rgas - universal gas constant (J mol-1 K-1) #' DwDc - Ratio of the molecular diffusivities for water vapor and CO2 #' - missing_Rleaf_as_NA if Rleaf is provided, should missing values be treated as `NA` (`TRUE`) -#' or set to 0 (`FALSE`, the default)? +#' or set to 0 (`false`, the default)? #' - ... Additional arguments to `\link[stats]{nls`} or `\link[robustbase]{nlrob`} if `robust_nls = TRUE`. #' #' # Details @@ -504,33 +510,34 @@ end #' #' The unified stomatal optimization (USO) model is given by (Medlyn et al. 2011): #' -#' \deqn{gs = g0 + 1.6*(1.0 + g1/sqrt(VPD)) * An/ca} +#' ``gs = g0 + 1.6*(1.0 + g1/sqrt(VPD)) * An/ca`` #' #' The semi-empirical model by Ball et al. 1987 is defined as: #' -#' \deqn{gs = g0 + g1* ((An * rH) / ca)} +#' ``gs = g0 + g1* ((An * rH) / ca)`` #' #' Leuning 1995 suggested a revised version of the Ball&Berry model: #' -#' \deqn{gs = g0 + g1*An / ((ca - \Gamma) * (1 + VPD/D0))} +#' ``gs = g0 + g1*An / ((ca - \\gamma) * (1 + VPD/D0))`` #' -#' where \eqn{\Gamma} is by default assumed to be constant, but likely varies with temperature and among +#' where ``\\gamma`` is by default assumed to be constant, but likely varies with temperature and among #' plant species. #' The equations above are valid at leaf-level. At ecosystem level, An is replaced by GPP (or GPP - Rleaf, #' where Rleaf is leaf respiration), and gs (stomatal conductance) by Gs (surface conductance). #' The parameters in the models are estimated using nonlinear regression (`\link[stats]{nls`}) if -#' `robust_nls = FALSE` and weighted nonlinear regression if `robust_nls = TRUE`. +#' `robust_nls = false` and weighted nonlinear regression if `robust_nls = TRUE`. #' The weights are calculated from `\link[robustbase]{nlrob`}, and `\link[stats]{nls`} #' is used for the actual fitting. #' Alternatively to measured VPD and Ca (i.e. conditions at instrument height), conditions at -#' the big-leaf surface can be provided. Those can be calculated using `\link{surface_conditions`}. +#' the big-leaf surface can be provided. Those can be calculated using [`surface_conditions`](@ref). #' #' #' # Value A `nls` model object, containing information on the fitted parameters, their uncertainty range, #' model fit, etc. #' -#' @references Medlyn B_E., et al., 2011: Reconciling the optimal and empirical approaches to +#' #References +#' Medlyn B_E., et al., 2011: Reconciling the optimal and empirical approaches to #' modelling stomatal conductance. Global Change Biology 17, 2134-2144. #' #' Ball T_J., Woodrow I_E., Berry J_A. 1987: A model predicting stomatal conductance @@ -544,14 +551,15 @@ end #' Knauer, J. et al., 2018: Towards physiologically meaningful water-use efficiency estimates #' from eddy covariance data. Global Change Biology 24, 694-710. #' -#' @seealso `\link{surface_conductance`} +#' #See also +#' [`surface_conductance`](@ref) #' #' ```@example; output = false #' ``` #' ## filter data to ensure that Gs is a meaningful proxy to canopy conductance (Gc) -#' DE_Tha_Jun_2014_2 = filter_data(DE_Tha_Jun_2014,quality_control=FALSE, +#' DE_Tha_Jun_2014_2 = filter_data(DE_Tha_Jun_2014,quality_control=false, #' vars_qc=c("Tair","precip","VPD","H","LE"), -#' filter_growseas=FALSE,filter_precip=TRUE, +#' filter_growseas=false,filter_precip=TRUE, #' filter_vars=c("Tair","PPFD","ustar","LE"), #' filter_vals_min=c(5,200,0.2,0), #' filter_vals_max=c(NA,NA,NA,NA),NA_as_invalid=TRUE, @@ -566,23 +574,23 @@ end #' # if G and/or S are available, don't forget to indicate (they are ignored by default). #' Gs_PM = surface_conductance(DE_Tha_Jun_2014_2,Tair="Tair",pressure="pressure", #' Rn="Rn",G="G",S=NULL,VPD="VPD",Ga=Ga, -#' formulation="Penman-Monteith")[,"Gs_mol"] +#' formulation=Val(:Penman-Monteith))[,"Gs_mol"] #' #' ### Estimate the stomatal slope parameter g1 using the USO model #' mod_USO = stomatal_slope(DE_Tha_Jun_2014_2,model="USO",GPP="GPP",Gs=Gs_PM, -#' robust_nls=FALSE,nmin=40,fitg0=FALSE) +#' robust_nls=false,nmin=40,fitg0=false) #' #' ### Use robust regression to minimize influence of outliers in Gs #' mod_USO = stomatal_slope(DE_Tha_Jun_2014_2,model="USO",GPP="GPP",Gs=Gs_PM, -#' robust_nls=TRUE,nmin=40,fitg0=FALSE) +#' robust_nls=TRUE,nmin=40,fitg0=false) #' #' ### Estimate the same parameter from the Ball&Berry model and prescribe g0 #' mod_BB = stomatal_slope(DE_Tha_Jun_2014_2,model="Ball&Berry",GPP="GPP", -#' robust_nls=FALSE,Gs=Gs_PM,g0=0.01,nmin=40,fitg0=FALSE) +#' robust_nls=false,Gs=Gs_PM,g0=0.01,nmin=40,fitg0=false) #' #' ## same for the Leuning model, but this time estimate both g1 and g0 (but fix D0) #' mod_Leu = stomatal_slope(DE_Tha_Jun_2014_2,model="Leuning",GPP="GPP",Gs=Gs_PM, -#' robust_nls=FALSE,nmin=40,fitg0=FALSE,D0=1.5,fitD0=FALSE) +#' robust_nls=false,nmin=40,fitg0=false,D0=1.5,fitD0=false) #' #' @importFrom stats nls na_exclude #' @importFrom robustbase nlrob @@ -590,8 +598,8 @@ end #' @export function stomatal_slope(data,Tair="Tair",pressure="pressure",GPP="GPP",Gs="Gs_mol", VPD="VPD",Ca="Ca",Rleaf=NULL,model=c("USO","Ball&Berry","Leuning"), - robust_nls=FALSE,nmin=40,fitg0=FALSE,g0=0,fitD0=FALSE, - D0=1.5,Gamma=50,missing_Rleaf_as_NA=FALSE, + robust_nls=false,nmin=40,fitg0=false,g0=0,fitD0=false, + D0=1.5,Gamma=50,missing_Rleaf_as_NA=false, constants=bigleaf_constants(),...) model = match_arg(model) @@ -755,11 +763,11 @@ end A rectangular light response curve is fitted to NEE data. The curve #' takes the form as described in Falge et al. 2001: #' -#' \deqn{-NEE = \alpha PPFD / (1 - (PPFD / PPFD_ref) + \alpha +#' \deqn{-NEE = \\alpha PPFD / (1 - (PPFD / PPFD_ref) + \\alpha #' PPFD / GPP_ref) - Reco} #' -#' where \eqn{\alpha} is the ecosystem quantum yield (umol CO2 m-2 s-1) (umol quanta m-2 s-1)-1, -#' and GPP_ref is the GPP at the reference PPFD (usually at saturating light). \eqn{\alpha} +#' where ``\\alpha`` is the ecosystem quantum yield (umol CO2 m-2 s-1) (umol quanta m-2 s-1)-1, +#' and GPP_ref is the GPP at the reference PPFD (usually at saturating light). ``\\alpha`` #' represents the slope of the light response curve, and is a measure for the light use #' efficiency of the canopy. #' @@ -770,13 +778,15 @@ end #' `PPFD_ref` defaults to 2000 umol m-2 s-1, but other values can be used. For #' further details refer to Falge et al. 2001. #' -#' @note Note the sign convention. Negative NEE indicates that carbon is taken up +#' #Note +#' Note the sign convention. Negative NEE indicates that carbon is taken up #' by the ecosystem. Reco has to be 0 or larger. #' #' # Value A `nls` model object containing estimates (+/- SE) for alpha and GPP_ref. #' -#' @references Falge E., et al. 2001: Gap filling strategies for defensible annual +#' #References +#' Falge E., et al. 2001: Gap filling strategies for defensible annual #' sums of net ecosystem exchange. Agricultural and Forest Meteorology 107, #' 43-69. #' @@ -818,16 +828,17 @@ end #' # Details Light use efficiency is calculated as #' -#' \deqn{LUE = sum(GPP)/sum(PPFD)} +#' ``LUE = sum(GPP)/sum(PPFD)`` #' #' where both GPP and PPFD are in umol m-2 s-1. A more meaningful #' (as directly comparable across ecosystems) approach is to take #' absorbed PPFD rather than incoming PPFD as used here. #' #' # Value - \item{LUE -}{Light use efficiency (-)} + - LUE -: Light use efficiency (-) #' -#' @seealso `\link{energy_use_efficiency`} +#' #See also +#' [`energy_use_efficiency`](@ref) #' #' ```@example; output = false #' ``` @@ -858,26 +869,28 @@ end #' # Details The function fits the following equation (Oren et al. 1999): #' -#' \deqn{Gs = -m ln(VPD) + b} +#' ``Gs = -m ln(VPD) + b`` #' #' where b is the reference surface conductance (Gs) at VPD=1kPa (in mol m-2 s-1), #' and m is the sensitivity parameter of Gs to VPD (in mol m-2 s-1 log(kPa)-1). #' The two parameters b and m are fitted using `\link[stats]{nls`}. #' VPD can be the one directly measured at instrument height, or the -#' one at the surface, as returned by `\link{surface_conditions`}. +#' one at the surface, as returned by [`surface_conditions`](@ref). #' #' # Value A `nls` model object containing (amongst others) estimates for the mean #' and standard errors of the parameters m and b. #' -#' @references Oren R., et al. 1999: Survey and synthesis of intra- and interspecific +#' #References +#' Oren R., et al. 1999: Survey and synthesis of intra- and interspecific #' variation in stomatal sensitivity to vapour pressure deficit. Plant, #' Cell & Environment 22, 1515-1526. #' #' Novick K_A., et al. 2016: The increasing importance of atmospheric demand #' for ecosystem water and carbon fluxes. Nature Climate Change 6, 1023 - 1027. #' -#' @seealso `\link{surface_conductance`} +#' #See also +#' [`surface_conductance`](@ref) #' #' ```@example; output = false #' ``` @@ -885,7 +898,7 @@ end #' ## May 2012. Data are filtered for daytime, sufficiently high ustar, etc. #' FR_Pue_May_2012_2 = filter_data(FR_Pue_May_2012,quality_control=TRUE, #' vars_qc=c("Tair","precip","H","LE"), -#' filter_growseas=FALSE,filter_precip=TRUE, +#' filter_growseas=false,filter_precip=TRUE, #' filter_vars=c("Tair","PPFD","ustar","VPD"), #' filter_vals_min=c(5,200,0.2,0.3), #' filter_vals_max=c(NA,NA,NA,NA), diff --git a/inst/fromR/boundary_layer_conductance.jl b/inst/fromR/boundary_layer_conductance.jl index d83ab9e..29d62fb 100755 --- a/inst/fromR/boundary_layer_conductance.jl +++ b/inst/fromR/boundary_layer_conductance.jl @@ -11,39 +11,41 @@ #' - Sc Optional: Schmidt number of additional quantities to be calculated #' - Sc_name Optional: Name of the additional quantities, has to be of same length than #' `Sc_name` -#' - constants k - von-Karman constant \cr -#' Sc_CO2 - Schmidt number for CO2 \cr +#' - constants k - von-Karman constant +#' Sc_CO2 - Schmidt number for CO2 #' Pr - Prandtl number (if `Sc` is provided) #' #' #' # Details The empirical equation for Rb suggested by Thom 1972 is: #' -#' \deqn{Rb = 6.2ustar^-0.67} +#' ``Rb = 6.2ustar^-0.67`` #' #' Gb (=1/Rb) for water vapor and heat are assumed to be equal in this package. #' Gb for other quantities x is calculated as (Hicks et al. 1987): #' -#' \deqn{Gb_x = Gb / (Sc_x / Pr)^0.67} +#' ``Gb_x = Gb / (Sc_x / Pr)^0.67`` #' #' where Sc_x is the Schmidt number of quantity x, and Pr is the Prandtl number (0.71). #' #' # Value a DataFrame with the following columns: -#' \item{Gb_h}{Boundary layer conductance for heat transfer (m s-1)} -#' \item{Rb_h}{Boundary layer resistance for heat transfer (s m-1)} -#' \item{kB_h}{kB-1 parameter for heat transfer} +#' - Gb_h: Boundary layer conductance for heat transfer (m s-1) +#' - Rb_h: Boundary layer resistance for heat transfer (s m-1) +#' - kB_h: kB-1 parameter for heat transfer #' \item{Gb_Sc_name}{Boundary layer conductance for `Sc_name` (m s-1). Only added if `Sc_name` and #' `Sc_name` are provided} #' -#' @references Thom, A., 1972: Momentum, mass and heat exchange of vegetation. +#' #References +#' Thom, A., 1972: Momentum, mass and heat exchange of vegetation. #' Quarterly Journal of the Royal Meteorological Society 98, 124-134. #' #' Hicks, B_B., Baldocchi, D_D., Meyers, T_P., Hosker, J_R., Matt, D_R., 1987: #' A preliminary multiple resistance routine for deriving dry deposition velocities #' from measured quantities. Water, Air, and Soil Pollution 36, 311-330. #' -#' @seealso `\link{Gb_Choudhury`}, `\link{Gb_Su`}, `\link{aerodynamic_conductance`} +#' #See also +#' [`Gb_Choudhury`](@ref), [`Gb_Su`](@ref), [`aerodynamic_conductance`](@ref) #' #' ```@example; output = false #' ``` @@ -104,15 +106,15 @@ end #' - Sc Optional: Schmidt number of additional quantities to be calculated #' - Sc_name Optional: Name of the additonal quantities, has to be of same length than #' `Sc_name` -#' - constants k - von-Karman constant \cr -#' Sc_CO2 - Schmidt number for CO2 \cr +#' - constants k - von-Karman constant +#' Sc_CO2 - Schmidt number for CO2 #' Pr - Prandtl number (if `Sc` is provided) #' #' # Value A data frame with the following columns: -#' \item{Gb_h}{Boundary layer conductance for heat transfer (m s-1)} -#' \item{Rb_h}{Boundary layer resistance for heat transfer (s m-1)} -#' \item{kB_h}{kB-1 parameter for heat transfer} +#' - Gb_h: Boundary layer conductance for heat transfer (m s-1) +#' - Rb_h: Boundary layer resistance for heat transfer (s m-1) +#' - kB_h: kB-1 parameter for heat transfer #' \item{Gb_Sc_name}{Boundary layer conductance for `Sc_name` (m s-1). Only added if `Sc_name` and #' `Sc_name` are provided} #' @@ -120,30 +122,32 @@ end Boundary layer conductance according to Choudhury & Monteith 1988 is #' given by: #' -#' \deqn{Gb_h = LAI((2a/\alpha)*sqrt(u(h)/w)*(1-exp(-\alpha/2)))} +#' ``Gb_h = LAI((2a/\\alpha)*sqrt(u(h)/w)*(1-exp(-\\alpha/2)))`` #' #' where u(zh) is the wind speed at the canopy surface, approximated from -#' measured wind speed at sensor height zr and a wind extinction coefficient \eqn{\alpha}: +#' measured wind speed at sensor height zr and a wind extinction coefficient ``\\alpha``: #' -#' \deqn{u(zh) = u(zr) / (exp(\alpha(zr/zh -1)))}. +#' ``u(zh) = u(zr) / (exp(\\alpha(zr/zh -1)))``. #' -#' \eqn{\alpha} is modeled as an empirical relation to LAI (McNaughton & van den Hurk 1995): +#' ``\\alpha`` is modeled as an empirical relation to LAI (McNaughton & van den Hurk 1995): #' -#' \deqn{\alpha = 4.39 - 3.97*exp(-0.258*LAI)} +#' ``\\alpha = 4.39 - 3.97*exp(-0.258*LAI)`` #' #' Gb (=1/Rb) for water vapor and heat are assumed to be equal in this package. #' Gb for other quantities x is calculated as (Hicks et al. 1987): #' -#' \deqn{Gb_x = Gb / (Sc_x / Pr)^0.67} +#' ``Gb_x = Gb / (Sc_x / Pr)^0.67`` #' #' where Sc_x is the Schmidt number of quantity x, and Pr is the Prandtl number (0.71). #' -#' @note If the roughness length for momentum (`z0m`) is not provided as input, it is estimated +#' #Note +#' If the roughness length for momentum (`z0m`) is not provided as input, it is estimated #' from the function `roughness_parameters` within `wind_profile`. This function #' estimates a single `z0m` value for the entire time period! If a varying `z0m` value #' (e.g. across seasons or years) is required, `z0m` should be provided as input argument. #' -#' @references Choudhury, B. J., Monteith J_L., 1988: A four-layer model for the heat +#' #References +#' Choudhury, B. J., Monteith J_L., 1988: A four-layer model for the heat #' budget of homogeneous land surfaces. Q. J. R. Meteorol. Soc. 114, 373-398. #' #' McNaughton, K. G., Van den Hurk, B_J_J_M., 1995: A 'Lagrangian' revision of @@ -154,7 +158,8 @@ end #' A preliminary multiple resistance routine for deriving dry deposition velocities #' from measured quantities. Water, Air, and Soil Pollution 36, 311-330. #' -#' @seealso `\link{Gb_Thom`}, `\link{Gb_Su`}, `\link{aerodynamic_conductance`} +#' #See also +#' [`Gb_Thom`](@ref), [`Gb_Su`](@ref), [`aerodynamic_conductance`](@ref) #' #' ```@example; output = false #' ``` @@ -181,7 +186,7 @@ function Gb_Choudhury(data,Tair="Tair",pressure="pressure",wind="wind",ustar="us estimate_z0m = TRUE z0m = NULL else - estimate_z0m = FALSE + estimate_z0m = false end wind_zh = wind_profile(data=data,z=zh,Tair=Tair,pressure=pressure,ustar=ustar,H=H, @@ -244,17 +249,17 @@ end #' - Sc Optional: Schmidt number of additional quantities to be calculated #' - Sc_name Optional: Name of the additional quantities, has to be of same length than #' `Sc_name` -#' - constants Kelvin - conversion degree Celsius to Kelvin \cr -#' pressure0 - reference atmospheric pressure at sea level (Pa) \cr -#' Tair0 - reference air temperature (K) \cr -#' Sc_CO2 - Schmidt number for CO2 \cr +#' - constants Kelvin - conversion degree Celsius to Kelvin +#' pressure0 - reference atmospheric pressure at sea level (Pa) +#' Tair0 - reference air temperature (K) +#' Sc_CO2 - Schmidt number for CO2 #' Pr - Prandtl number (if `Sc` is provided) #' #' # Value A DataFrame with the following columns: -#' \item{Gb_h}{Boundary layer conductance for heat transfer (m s-1)} -#' \item{Rb_h}{Boundary layer resistance for heat transfer (s m-1)} -#' \item{kB_h}{kB-1 parameter for heat transfer} +#' - Gb_h: Boundary layer conductance for heat transfer (m s-1) +#' - Rb_h: Boundary layer resistance for heat transfer (s m-1) +#' - kB_h: kB-1 parameter for heat transfer #' \item{Gb_Sc_name}{Boundary layer conductance for `Sc_name` (m s-1). Only added if `Sc_name` and #' `Sc_name` are provided} #' @@ -262,42 +267,44 @@ end The formulation is based on the kB-1 model developed by Massman 1999. #' Su et al. 2001 derived the following approximation: #' -#' \deqn{kB-1 = (k Cd fc^2) / (4Ct ustar/u(zh)) + kBs-1(1 - fc)^2} +#' ``kB-1 = (k Cd fc^2) / (4Ct ustar/u(zh)) + kBs-1(1 - fc)^2`` #' #' If fc (fractional vegetation cover) is missing, it is estimated from LAI: #' -#' \deqn{fc = 1 - exp(-LAI/2)} +#' ``fc = 1 - exp(-LAI/2)`` #' #' The wind speed at the top of the canopy is calculated using function -#' `\link{wind_profile`}. +#' [`wind_profile`](@ref). #' #' Ct is the heat transfer coefficient of the leaf (Massman 1999): #' -#' \deqn{Ct = Pr^-2/3 Reh^-1/2 N} +#' ``Ct = Pr^-2/3 Reh^-1/2 N`` #' #' where Pr is the Prandtl number (set to 0.71), and Reh is the Reynolds number for leaves: #' -#' \deqn{Reh = Dl wind(zh) / v} +#' ``Reh = Dl wind(zh) / v`` #' #' kBs-1, the kB-1 value for bare soil surface, is calculated according #' to Su et al. 2001: #' -#' \deqn{kBs^-1 = 2.46(Re)^0.25 - ln(7.4)} +#' ``kBs^-1 = 2.46(Re)^0.25 - ln(7.4)`` #' #' Gb (=1/Rb) for water vapor and heat are assumed to be equal in this package. #' Gb for other quantities x is calculated as (Hicks et al. 1987): #' -#' \deqn{Gb_x = Gb / (Sc_x / Pr)^0.67} +#' ``Gb_x = Gb / (Sc_x / Pr)^0.67`` #' #' where Sc_x is the Schmidt number of quantity x, and Pr is the Prandtl number (0.71). #' -#' @note If the roughness length for momentum (`z0m`) is not provided as input, it is estimated +#' #Note +#' If the roughness length for momentum (`z0m`) is not provided as input, it is estimated #' from the function `roughness_parameters` within `wind_profile`. This function #' estimates a single `z0m` value for the entire time period! If a varying `z0m` value #' (e.g. across seasons or years) is required, `z0m` should be provided as input argument. #' #' -#' @references Su, Z., Schmugge, T., Kustas, W. & Massman, W., 2001: An evaluation of +#' #References +#' Su, Z., Schmugge, T., Kustas, W. & Massman, W., 2001: An evaluation of #' two models for estimation of the roughness height for heat transfer between #' the land surface and the atmosphere. Journal of Applied Meteorology 40, 1933-1951. #' @@ -308,7 +315,8 @@ end #' A preliminary multiple resistance routine for deriving dry deposition velocities #' from measured quantities. Water, Air, and Soil Pollution 36, 311-330. #' -#' @seealso `\link{Gb_Thom`}, `\link{Gb_Choudhury`}, `\link{aerodynamic_conductance`} +#' #See also +#' [`Gb_Thom`](@ref), [`Gb_Choudhury`](@ref), [`aerodynamic_conductance`](@ref) #' #' ```@example; output = false #' ``` @@ -336,7 +344,7 @@ function Gb_Su(data,Tair="Tair",pressure="pressure",ustar="ustar",wind="wind", if (is_null(fc)) if (is_null(LAI)) - stop("one of 'fc' or 'LAI' must be provided",call.=FALSE) + stop("one of 'fc' or 'LAI' must be provided",call.=false) else fc = (1-exp(-LAI/2)) end @@ -346,7 +354,7 @@ end estimate_z0m = TRUE z0m = NULL else - estimate_z0m = FALSE + estimate_z0m = false end wind_zh = wind_profile(data=data,z=zh,Tair=Tair,pressure=pressure,ustar=ustar,H=H, diff --git a/inst/fromR/check_input.jl b/inst/fromR/check_input.jl index 913f081..36242ae 100755 --- a/inst/fromR/check_input.jl +++ b/inst/fromR/check_input.jl @@ -9,7 +9,8 @@ #' - data Input DataFrame or matrix #' - ... Input variables. Either a list or individual vectors #' -#' @note This function can be run for named variables (in which case the return +#' #Note +#' This function can be run for named variables (in which case the return #' value will be named according to the given name), or for placeholder #' variables that are assigned and named according to e.g. entries of a character #' vector. In the latter case, the input variable has to be named as `"var"` or @@ -41,23 +42,23 @@ end if (is_numeric(var)) assign(varname,var,pos=sys_frame(-1)) else - stop("column representing '",varname,"' in the input matrix/DataFrame must be numeric",call.=FALSE) + stop("column representing '",varname,"' in the input matrix/DataFrame must be numeric",call.=false) end else - stop ("there is no column named '",var,"' in the input matrix/DataFrame. Indicate the name of the column representing variable '",varname,"', or alternatively, provide a numeric vector of the same length as the input matrix/DataFrame or of length 1.",call.=FALSE) + stop ("there is no column named '",var,"' in the input matrix/DataFrame. Indicate the name of the column representing variable '",varname,"', or alternatively, provide a numeric vector of the same length as the input matrix/DataFrame or of length 1.",call.=false) end else - stop("name of variable '",varname,"' must have length 1",call.=FALSE) + stop("name of variable '",varname,"' must have length 1",call.=false) end else if ("data" %in% names(formals(sys_function(which=-1)))) if (var %in% as_character(unlist(match_call(definition=sys_function(-1),call=sys_call(-1))[-1]))) - stop("variable '",var,"' is of type character and interpreted as a column name, but no input matrix/DataFrame is provided. Provide '",var,"' as a numeric vector, or an input matrix/DataFrame with a column named '",var,"'",call.=FALSE) + stop("variable '",var,"' is of type character and interpreted as a column name, but no input matrix/DataFrame is provided. Provide '",var,"' as a numeric vector, or an input matrix/DataFrame with a column named '",var,"'",call.=false) else - stop("variable '",var,"' is not provided",call.=FALSE) + stop("variable '",var,"' is not provided",call.=false) end else - stop("variable '",var,"' must be numeric",call.=FALSE) + stop("variable '",var,"' must be numeric",call.=false) end end else @@ -78,16 +79,16 @@ else if (is_numeric(var) & length(var) != nrow(data)) var = rep(var,length=nrow(data)) assign(varname,var,envir=sys_frame(-1)) else - stop("variable '",varname,"' must have the same length as the input matrix/DataFrame or length 1. Do NOT provide an input matrix/DataFrame if none of its variables are used!",call.=FALSE) + stop("variable '",varname,"' must have the same length as the input matrix/DataFrame or length 1. Do NOT provide an input matrix/DataFrame if none of its variables are used!",call.=false) end else if (!is_numeric(var)) - stop("variable '",varname,"' must be numeric",call.=FALSE) + stop("variable '",varname,"' must be numeric",call.=false) end else if (is_numeric(var)) assign(varname,var,envir=sys_frame(-1)) else - stop("variable '",varname,"' must be numeric",call.=FALSE) + stop("variable '",varname,"' must be numeric",call.=false) end end end @@ -100,15 +101,16 @@ end #' #' - varlist List of variables for which the length has to be compared #' -#' @note This function only plays a role if no input DataFrame or matrix are +#' #Note +#' This function only plays a role if no input DataFrame or matrix are #' provided. In this case it ensures that provided vectors have the same #' length to avoid trouble later up the function call. #' #' @keywords internal function check_length(varlist) - if (is_list(unlist(varlist,recursive=FALSE))) - varlist = unlist(varlist,recursive=FALSE) + if (is_list(unlist(varlist,recursive=false))) + varlist = unlist(varlist,recursive=false) end length_vars = sapply(varlist,length) @@ -116,7 +118,7 @@ end if (length(unique(length_vars)) >= 2) if (sort(unique(length_vars))[1] != 1 | length(unique(length_vars)) > 2) - stop("All input variables must have the same length or a length of 1!",call.=FALSE) + stop("All input variables must have the same length or a length of 1!",call.=false) end end return(varlist) diff --git a/inst/fromR/datasets_description.jl b/inst/fromR/datasets_description.jl index 6daaabe..5e627d4 100755 --- a/inst/fromR/datasets_description.jl +++ b/inst/fromR/datasets_description.jl @@ -7,40 +7,41 @@ #' #' @format A data frame with 1488 observations and 31 columns: #' \describe -#' \item{year}{year of measurement} -#' \item{month}{month of measurement} -#' \item{doy}{day of year} -#' \item{hour}{hour (0 - 23.5)} -#' \item{Tair}{Air temperature (degC) [TA_F]} -#' \item{Tair_qc}{Quality control of `Tair` [TA_F_QC]} -#' \item{PPFD}{Photosynthetic photon flux density (umol m-2 s-1) [PPFD_IN]} -#' \item{PPFD_qc}{Quality control of `PPFD` [PPFD_IN_QC]} -#' \item{VPD}{Vapor pressure deficit (kPa) [VPD_F]} -#' \item{VPD_qc}{Quality control of `VPD` [VPD_F_QC]} -#' \item{pressure}{Atmospheric pressure (kPa) [PA_F]} -#' \item{precip}{precipitation (mm) [P_F]} -#' \item{precip_qc}{Quality control of `precip` [P_F_QC]} -#' \item{ustar}{friction velocity (m s-1) [USTAR]} -#' \item{wind}{horizontal wind velocity (m s-1) [WS_F]} -#' \item{wind_qc}{Quality control of `wind` [WS_F_QC]} -#' \item{Ca}{CO2 concentration (ppm) [CO2_F_MDS]} -#' \item{Ca_qc}{Quality control of `Ca` [CO2_F_MDS_QC]} -#' \item{LW_up}{upward longwave radiation (W m-2) [LW_OUT]} -#' \item{Rn}{Net radiation (W m-2) [NETRAD]} -#' \item{LE}{Latent heat flux (W m-2) [LE_F_MDS]} -#' \item{LE_qc}{Quality control of `LE` [LE_F_MDS_QC]} -#' \item{H}{Sensible heat flux (W m-2) [H_F_MDS]} -#' \item{H_qc}{Quality control of `H` [H_F_MDS_QC]} -#' \item{G}{Ground heat flux (W m-2) [G_F_MDS]} -#' \item{G_qc}{Quality control of `G` [G_F_MDS_QC]} -#' \item{NEE}{Net ecosystem exchange (umol m-2 s-1) [NEE_VUT_USTAR50]} -#' \item{NEE_qc}{Quality control of `NEE` [NEE_VUT_USTAR50_QC]} -#' \item{GPP}{Gross primary productivity from nighttime partitioning (umol m-2 s-1) [GPP_NT_VUT_USTAR50]} -#' \item{GPP_qc}{Quality control of `GPP` [NEE_VUT_USTAR50_QC]} -#' \item{Reco}{Ecosystem respiration from nighttime partitioning (umol m-2 s-1) [RECO_NT_VUT_USTAR50]} +#' - year: year of measurement +#' - month: month of measurement +#' - doy: day of year +#' - hour: hour (0 - 23.5) +#' - Tair: Air temperature (degC) [TA_F] +#' - Tair_qc: Quality control of `Tair` [TA_F_QC] +#' - PPFD: Photosynthetic photon flux density (umol m-2 s-1) [PPFD_IN] +#' - PPFD_qc: Quality control of `PPFD` [PPFD_IN_QC] +#' - VPD: Vapor pressure deficit (kPa) [VPD_F] +#' - VPD_qc: Quality control of `VPD` [VPD_F_QC] +#' - pressure: Atmospheric pressure (kPa) [PA_F] +#' - precip: precipitation (mm) [P_F] +#' - precip_qc: Quality control of `precip` [P_F_QC] +#' - ustar: friction velocity (m s-1) [USTAR] +#' - wind: horizontal wind velocity (m s-1) [WS_F] +#' - wind_qc: Quality control of `wind` [WS_F_QC] +#' - Ca: CO2 concentration (ppm) [CO2_F_MDS] +#' - Ca_qc: Quality control of `Ca` [CO2_F_MDS_QC] +#' - LW_up: upward longwave radiation (W m-2) [LW_OUT] +#' - Rn: Net radiation (W m-2) [NETRAD] +#' - LE: Latent heat flux (W m-2) [LE_F_MDS] +#' - LE_qc: Quality control of `LE` [LE_F_MDS_QC] +#' - H: Sensible heat flux (W m-2) [H_F_MDS] +#' - H_qc: Quality control of `H` [H_F_MDS_QC] +#' - G: Ground heat flux (W m-2) [G_F_MDS] +#' - G_qc: Quality control of `G` [G_F_MDS_QC] +#' - NEE: Net ecosystem exchange (umol m-2 s-1) [NEE_VUT_USTAR50] +#' - NEE_qc: Quality control of `NEE` [NEE_VUT_USTAR50_QC] +#' - GPP: Gross primary productivity from nighttime partitioning (umol m-2 s-1) [GPP_NT_VUT_USTAR50] +#' - GPP_qc: Quality control of `GPP` [NEE_VUT_USTAR50_QC] +#' - Reco: Ecosystem respiration from nighttime partitioning (umol m-2 s-1) [RECO_NT_VUT_USTAR50] #' } #' -#' @note The original variable names as provided by the FLUXNET2015 dataset are +#' #Note +#' The original variable names as provided by the FLUXNET2015 dataset are #' given in squared brackets. Note that variable units have been converted #' in some cases (e.g. VPD from hPa to kPa). #' @@ -59,41 +60,42 @@ #' #' @format A data frame with 1440 observations and 32 columns: #' \describe -#' \item{year}{year of measurement} -#' \item{month}{month of measurement} -#' \item{doy}{day of year} -#' \item{hour}{hour (0 - 23.5)} -#' \item{Tair}{Air temperature (degC) [TA_F]} -#' \item{Tair_qc}{Quality control of `Tair` [TA_F_QC]} -#' \item{PPFD}{Photosynthetic photon flux density (umol m-2 s-1) [PPFD_IN]} -#' \item{PPFD_qc}{Quality control of `PPFD` [PPFD_IN_QC]} -#' \item{VPD}{Vapor pressure deficit (kPa) [VPD_F]} -#' \item{VPD_qc}{Quality control of `VPD` [VPD_F_QC]} -#' \item{pressure}{Atmospheric pressure (kPa) [PA_F]} -#' \item{precip}{precipitation (mm) [P_F]} -#' \item{precip_qc}{Quality control of `precip` [P_F_QC]} -#' \item{ustar}{friction velocity (m s-1) [USTAR]} -#' \item{wind}{horizontal wind velocity (m s-1) [WS_F]} -#' \item{wind_qc}{Quality control of `wind` [WS_F_QC]} -#' \item{Ca}{CO2 concentration (ppm) [CO2_F_MDS]} -#' \item{Ca_qc}{Quality control of `Ca` [CO2_F_MDS_QC]} -#' \item{LW_up}{upward longwave radiation (W m-2) [LW_OUT]} -#' \item{LW_down}{downward longwave radiation (W m-2) [LW_IN_F]} -#' \item{Rn}{Net radiation (W m-2) [NETRAD]} -#' \item{LE}{Latent heat flux (W m-2) [LE_F_MDS]} -#' \item{LE_qc}{Quality control of `LE` [LE_F_MDS_QC]} -#' \item{H}{Sensible heat flux (W m-2) [H_F_MDS]} -#' \item{H_qc}{Quality control of `H` [H_F_MDS_QC]} -#' \item{G}{Ground heat flux (W m-2) [G_F_MDS]} -#' \item{G_qc}{Quality control of `G` [G_F_MDS_QC]} -#' \item{NEE}{Net ecosystem exchange (umol m-2 s-1) [NEE_VUT_USTAR50]} -#' \item{NEE_qc}{Quality control of `NEE` [NEE_VUT_USTAR50_QC]} -#' \item{GPP}{Gross primary productivity from nighttime partitioning (umol m-2 s-1) [GPP_NT_VUT_USTAR50]} -#' \item{GPP_qc}{Quality control of `GPP` [NEE_VUT_USTAR50_QC]} -#' \item{Reco}{Ecosystem respiration from nighttime partitioning (umol m-2 s-1) [RECO_NT_VUT_USTAR50]} +#' - year: year of measurement +#' - month: month of measurement +#' - doy: day of year +#' - hour: hour (0 - 23.5) +#' - Tair: Air temperature (degC) [TA_F] +#' - Tair_qc: Quality control of `Tair` [TA_F_QC] +#' - PPFD: Photosynthetic photon flux density (umol m-2 s-1) [PPFD_IN] +#' - PPFD_qc: Quality control of `PPFD` [PPFD_IN_QC] +#' - VPD: Vapor pressure deficit (kPa) [VPD_F] +#' - VPD_qc: Quality control of `VPD` [VPD_F_QC] +#' - pressure: Atmospheric pressure (kPa) [PA_F] +#' - precip: precipitation (mm) [P_F] +#' - precip_qc: Quality control of `precip` [P_F_QC] +#' - ustar: friction velocity (m s-1) [USTAR] +#' - wind: horizontal wind velocity (m s-1) [WS_F] +#' - wind_qc: Quality control of `wind` [WS_F_QC] +#' - Ca: CO2 concentration (ppm) [CO2_F_MDS] +#' - Ca_qc: Quality control of `Ca` [CO2_F_MDS_QC] +#' - LW_up: upward longwave radiation (W m-2) [LW_OUT] +#' - LW_down: downward longwave radiation (W m-2) [LW_IN_F] +#' - Rn: Net radiation (W m-2) [NETRAD] +#' - LE: Latent heat flux (W m-2) [LE_F_MDS] +#' - LE_qc: Quality control of `LE` [LE_F_MDS_QC] +#' - H: Sensible heat flux (W m-2) [H_F_MDS] +#' - H_qc: Quality control of `H` [H_F_MDS_QC] +#' - G: Ground heat flux (W m-2) [G_F_MDS] +#' - G_qc: Quality control of `G` [G_F_MDS_QC] +#' - NEE: Net ecosystem exchange (umol m-2 s-1) [NEE_VUT_USTAR50] +#' - NEE_qc: Quality control of `NEE` [NEE_VUT_USTAR50_QC] +#' - GPP: Gross primary productivity from nighttime partitioning (umol m-2 s-1) [GPP_NT_VUT_USTAR50] +#' - GPP_qc: Quality control of `GPP` [NEE_VUT_USTAR50_QC] +#' - Reco: Ecosystem respiration from nighttime partitioning (umol m-2 s-1) [RECO_NT_VUT_USTAR50] #' } #' -#' @note The original variable names as provided by the FLUXNET2015 dataset are +#' #Note +#' The original variable names as provided by the FLUXNET2015 dataset are #' given in squared brackets. Note that variable units have been converted #' in some cases (e.g. VPD from hPa to kPa). #' @@ -112,38 +114,39 @@ #' #' @format A data frame with 1488 observations and 29 columns: #' \describe -#' \item{year}{year of measurement} -#' \item{month}{month of measurement} -#' \item{doy}{day of year} -#' \item{hour}{hour (0 - 23.5)} -#' \item{Tair}{Air temperature (degC) [TA_F]} -#' \item{Tair_qc}{Quality control of `Tair` [TA_F_QC]} -#' \item{PPFD}{Photosynthetic photon flux density (umol m-2 s-1) [PPFD_IN]} -#' \item{PPFD_qc}{Quality control of `PPFD` [PPFD_IN_QC]} -#' \item{VPD}{Vapor pressure deficit (kPa) [VPD_F]} -#' \item{VPD_qc}{Quality control of `VPD` [VPD_F_QC]} -#' \item{pressure}{Atmospheric pressure (kPa) [PA_F]} -#' \item{precip}{precipitation (mm) [P_F]} -#' \item{precip_qc}{Quality control of `precip` [P_F_QC]} -#' \item{ustar}{friction velocity (m s-1) [USTAR]} -#' \item{wind}{horizontal wind velocity (m s-1) [WS_F]} -#' \item{wind_qc}{Quality control of `wind` [WS_F_QC]} -#' \item{Ca}{CO2 concentration (ppm) [CO2_F_MDS]} -#' \item{Ca_qc}{Quality control of `Ca` [CO2_F_MDS_QC]} -#' \item{LW_up}{upward longwave radiation (W m-2) [LW_OUT]} -#' \item{Rn}{Net radiation (W m-2) [NETRAD]} -#' \item{LE}{Latent heat flux (W m-2) [LE_F_MDS]} -#' \item{LE_qc}{Quality control of `LE` [LE_F_MDS_QC]} -#' \item{H}{Sensible heat flux (W m-2) [H_F_MDS]} -#' \item{H_qc}{Quality control of `H` [H_F_MDS_QC]} -#' \item{NEE}{Net ecosystem exchange (umol m-2 s-1) [NEE_VUT_USTAR50]} -#' \item{NEE_qc}{Quality control of `NEE` [NEE_VUT_USTAR50_QC]} -#' \item{GPP}{Gross primary productivity from nighttime partitioning (umol m-2 s-1) [GPP_NT_VUT_USTAR50]} -#' \item{GPP_qc}{Quality control of `GPP` [NEE_VUT_USTAR50_QC]} -#' \item{Reco}{Ecosystem respiration from nighttime partitioning (umol m-2 s-1) [RECO_NT_VUT_USTAR50]} +#' - year: year of measurement +#' - month: month of measurement +#' - doy: day of year +#' - hour: hour (0 - 23.5) +#' - Tair: Air temperature (degC) [TA_F] +#' - Tair_qc: Quality control of `Tair` [TA_F_QC] +#' - PPFD: Photosynthetic photon flux density (umol m-2 s-1) [PPFD_IN] +#' - PPFD_qc: Quality control of `PPFD` [PPFD_IN_QC] +#' - VPD: Vapor pressure deficit (kPa) [VPD_F] +#' - VPD_qc: Quality control of `VPD` [VPD_F_QC] +#' - pressure: Atmospheric pressure (kPa) [PA_F] +#' - precip: precipitation (mm) [P_F] +#' - precip_qc: Quality control of `precip` [P_F_QC] +#' - ustar: friction velocity (m s-1) [USTAR] +#' - wind: horizontal wind velocity (m s-1) [WS_F] +#' - wind_qc: Quality control of `wind` [WS_F_QC] +#' - Ca: CO2 concentration (ppm) [CO2_F_MDS] +#' - Ca_qc: Quality control of `Ca` [CO2_F_MDS_QC] +#' - LW_up: upward longwave radiation (W m-2) [LW_OUT] +#' - Rn: Net radiation (W m-2) [NETRAD] +#' - LE: Latent heat flux (W m-2) [LE_F_MDS] +#' - LE_qc: Quality control of `LE` [LE_F_MDS_QC] +#' - H: Sensible heat flux (W m-2) [H_F_MDS] +#' - H_qc: Quality control of `H` [H_F_MDS_QC] +#' - NEE: Net ecosystem exchange (umol m-2 s-1) [NEE_VUT_USTAR50] +#' - NEE_qc: Quality control of `NEE` [NEE_VUT_USTAR50_QC] +#' - GPP: Gross primary productivity from nighttime partitioning (umol m-2 s-1) [GPP_NT_VUT_USTAR50] +#' - GPP_qc: Quality control of `GPP` [NEE_VUT_USTAR50_QC] +#' - Reco: Ecosystem respiration from nighttime partitioning (umol m-2 s-1) [RECO_NT_VUT_USTAR50] #' } #' -#' @note The original variable names as provided by the FLUXNET2015 dataset are +#' #Note +#' The original variable names as provided by the FLUXNET2015 dataset are #' given in squared brackets. Note that variable units have been converted #' in some cases (e.g. VPD from hPa to kPa). #' diff --git a/inst/fromR/decoupling.jl b/inst/fromR/decoupling.jl index 44d6348..5d50b4e 100755 --- a/inst/fromR/decoupling.jl +++ b/inst/fromR/decoupling.jl @@ -16,11 +16,11 @@ #' - LAI Leaf area index (m2 m-2), only used if `approach = "Martin_1989"`. #' - Esat_formula Optional: formula to be used for the calculation of esat and the slope of esat. #' One of `"Sonntag_1990"` (Default), `"Alduchov_1996"`, or `"Allen_1998"`. -#' See `\link{Esat_slope`}. -#' - constants Kelvin - conversion degree Celsius to Kelvin \cr -#' cp - specific heat of air for constant pressure (J K-1 kg-1) \cr -#' eps - ratio of the molecular weight of water vapor to dry air (-) \cr -#' sigma - Stefan-Boltzmann constant (W m-2 K-4) \cr +#' See [`Esat_slope`](@ref). +#' - constants Kelvin - conversion degree Celsius to Kelvin +#' cp - specific heat of air for constant pressure (J K-1 kg-1) +#' eps - ratio of the molecular weight of water vapor to dry air (-) +#' sigma - Stefan-Boltzmann constant (W m-2 K-4) #' Pa2kPa - conversion pascal (Pa) to kilopascal (kPa) #' #' # Details @@ -30,35 +30,37 @@ #' characterized by high physiological (i.e. stomatal) control on transpiration #' and similar conditions at the canopy surface compared to the atmosphere above #' the canopy. Values close to 1 indicate the opposite, i.e. decoupled conditions and -#' a low stomatal control on transpiration (Jarvis & McNaughton 1986). \cr +#' a low stomatal control on transpiration (Jarvis & McNaughton 1986). #' The `"Jarvis&McNaughton_1986"` approach (default option) is the original #' formulation for the decoupling coefficient, given by (for an amphistomatous #' canopy): #' -#' \deqn{\Omega = \frac{\epsilon + 1}{\epsilon + 1 + \frac{Ga}{Gc}}}{% -#' \Omega = (\epsilon + 1) / ( \epsilon + 1 + Ga/Gc)} +#' ``\\Omega = \frac{\epsilon + 1``{\epsilon + 1 + \frac{Ga}{Gc}}}{% +#' \\Omega = (\epsilon + 1) / ( \epsilon + 1 + Ga/Gc)} #' -#' where \eqn{\epsilon = \frac{s}{\gamma}}{\epsilon = s/\gamma} is a dimensionless coefficient -#' with s being the slope of the saturation vapor pressure curve (Pa K-1), and \eqn{\gamma} the +#' where ``\epsilon = \frac{s``{\\gamma}}{\epsilon = s/\\gamma} is a dimensionless coefficient +#' with s being the slope of the saturation vapor pressure curve (Pa K-1), and ``\\gamma`` the #' psychrometric constant (Pa K-1). #' #' The approach `"Martin_1989"` by Martin 1989 additionally takes radiative coupling #' into account: #' -#' \deqn{\Omega = \frac{\epsilon + 1 + \frac{Gr}{Ga}}{\epsilon + (1 + \frac{Ga}{Gs}) (1 + \frac{Gr}{Ga})}}{% -#' \Omega = (\epsilon + 1 + Gr/Ga) / (\epsilon + (1 + Ga/Gs) (1 + Gr/Ga))} +#' ``\\Omega = \frac{\epsilon + 1 + \frac{Gr``{Ga}}{\epsilon + (1 + \frac{Ga}{Gs}) (1 + \frac{Gr}{Ga})}}{% +#' \\Omega = (\epsilon + 1 + Gr/Ga) / (\epsilon + (1 + Ga/Gs) (1 + Gr/Ga))} #' #' # Value - \item{\eqn{\Omega} -}{the decoupling coefficient Omega (-)} + - ``\\Omega`` -: the decoupling coefficient Omega (-) #' -#' @references Jarvis P_G., McNaughton K_G., 1986: Stomatal control of transpiration: +#' #References +#' Jarvis P_G., McNaughton K_G., 1986: Stomatal control of transpiration: #' scaling up from leaf to region. Advances in Ecological Research 15, 1-49. #' #' Martin P., 1989: The significance of radiative coupling between #' vegetation and the atmosphere. Agricultural and Forest Meteorology 49, 45-53. #' -#' @seealso `\link{aerodynamic_conductance`}, `\link{surface_conductance`}, -#' `\link{equilibrium_imposed_ET`} +#' #See also +#' [`aerodynamic_conductance`](@ref), [`surface_conductance`](@ref), +#' [`equilibrium_imposed_ET`](@ref) #' #' ```@example; output = false #' ``` @@ -114,19 +116,20 @@ end #' #' - Tair Air temperature (deg C) #' - LAI Leaf area index (m2 m-2) -#' - constants Kelvin - conversion degree Celsius to Kelvin \cr -#' sigma - Stefan-Boltzmann constant (W m-2 K-4) \cr +#' - constants Kelvin - conversion degree Celsius to Kelvin +#' sigma - Stefan-Boltzmann constant (W m-2 K-4) #' cp - specific heat of air for constant pressure (J K-1 kg-1) #' #' # Details the following formula is used (Martin, 1989): #' -#' \deqn{Gr = 4 \sigma Tair^3 LAI / cp} +#' ``Gr = 4 \sigma Tair^3 LAI / cp`` #' #' # Value - \item{Gr -}{longwave radiative transfer conductance of the canopy (m s-1)} + - Gr -: longwave radiative transfer conductance of the canopy (m s-1) #' -#' @references Martin P., 1989: The significance of radiative coupling between +#' #References +#' Martin P., 1989: The significance of radiative coupling between #' vegetation and the atmosphere. Agricultural and Forest Meteorology 49, 45-53. #' #' ```@example; output = false diff --git a/inst/fromR/energy_balance.jl b/inst/fromR/energy_balance.jl index d435f82..472f516 100755 --- a/inst/fromR/energy_balance.jl +++ b/inst/fromR/energy_balance.jl @@ -18,9 +18,10 @@ #' have been used (e.g. Blanken et al., 1997) #' #' # Value - \item{Sp -}{biochemical energy (W m-2)} + - Sp -: biochemical energy (W m-2) #' -#' @references Meyers, T_P., Hollinger, S_E. 2004: An assessment of storage terms in the surface energy +#' #References +#' Meyers, T_P., Hollinger, S_E. 2004: An assessment of storage terms in the surface energy #' balance of maize and soybean. Agricultural and Forest Meteorology 125, 105-115. #' #' Nobel, P_S., 1974: Introduction to Biophysical Plant Physiology. @@ -56,15 +57,16 @@ end #' # Details Energy use efficiency is calculated as: #' -#' \deqn{EUE = sum(GPP)/sum(Rn)} +#' ``EUE = sum(GPP)/sum(Rn)`` #' #' where the sums are calculated for complete cases of GPP and Rn over #' the entire time period. #' #' # Value - \item{EUE -}{Energy use efficiency (-)} + - EUE -: Energy use efficiency (-) #' -#' @seealso `\link{light_use_efficiency`} +#' #See also +#' [`light_use_efficiency`](@ref) #' #' ```@example; output = false #' ``` @@ -102,7 +104,7 @@ end #' - H Sensible heat flux (W m-2) #' - instantaneous should the energy balance be calculated at the time step #' of the observations (`TRUE`), or over the entire time period -#' provided as input (`FALSE`) +#' provided as input (`false`) #' - missing_G_as_NA if `TRUE`, missing G are treated as `NA`s ,otherwise set to 0. #' - missing_S_as_NA if `TRUE`, missing S are treated as `NA`s, otherwise set to 0. #' @@ -110,28 +112,29 @@ end #' # Details The energy balance ratio (EBR) is calculated as: #' -#' \deqn{EBR = sum(LE + H)/sum(Rn - G - S)} +#' ``EBR = sum(LE + H)/sum(Rn - G - S)`` #' #' the sum is taken for all time steps with complete observations (i.e. where #' all energy balance terms are available). #' #' # Value a named vector containing: -#' \item{n}{number of complete (all energy balance terms available) observations} -#' \item{intercept}{intercept of the OLS regression} -#' \item{slope}{slope of the OLS regression} -#' \item{r_squared}{r^2 of the OLS regression} -#' \item{EBR}{energy balance ratio} +#' - n: number of complete (all energy balance terms available) observations +#' - intercept: intercept of the OLS regression +#' - slope: slope of the OLS regression +#' - r_squared: r^2 of the OLS regression +#' - EBR: energy balance ratio #' #' if `instantaneous = TRUE`, only `EBR` is returned. #' -#' @references Wilson K., et al. 2002: Energy balance closure at FLUXNET sites. +#' #References +#' Wilson K., et al. 2002: Energy balance closure at FLUXNET sites. #' Agricultural and Forest Meteorology 113, 223-243. #' #' ```@example; output = false #' ``` #' ## characterize energy balance closure for DE-Tha in June 2014 -#' energy_closure(DE_Tha_Jun_2014,instantaneous=FALSE) +#' energy_closure(DE_Tha_Jun_2014,instantaneous=false) #' #' ## look at half-hourly closure #' EBR_inst = energy_closure(DE_Tha_Jun_2014,instantaneous=TRUE) @@ -140,8 +143,8 @@ end #' @importFrom stats complete_cases lm """ """ -function energy_closure(data,Rn="Rn",G=NULL,S=NULL,LE="LE",H="H",instantaneous=FALSE, - missing_G_as_NA=FALSE,missing_S_as_NA=FALSE) +function energy_closure(data,Rn="Rn",G=NULL,S=NULL,LE="LE",H="H",instantaneous=false, + missing_G_as_NA=false,missing_S_as_NA=false) check_input(data,list(Rn,LE,H,G,S)) @@ -193,21 +196,22 @@ end #' - Tair Air temperature (degC) #' - Tsurf Surface temperature (degC) #' - emissivity Emissivity of the surface (-) -#' - constants sigma - Stefan-Boltzmann constant (W m-2 K-4) \cr +#' - constants sigma - Stefan-Boltzmann constant (W m-2 K-4) #' Kelvin - conversion degree Celsius to Kelvin #' #' # Details The isothermal net radiation (Rni) is given by: #' -#' \deqn{Rni = Rn + \epsilon * \sigma * (Tsurf^4 - Tair^4)} +#' ``Rni = Rn + \epsilon * \sigma * (Tsurf^4 - Tair^4)`` #' -#' where \eqn{\epsilon} is the emissivity of the surface. Tsurf and Tair +#' where ``\epsilon`` is the emissivity of the surface. Tsurf and Tair #' are in Kelvin. #' #' # Value - \item{Rni -}{isothermal net radiation (W m-2)} + - Rni -: isothermal net radiation (W m-2) #' -#' @references Jones, H. 2014: Plants and Microclimate. 3rd edition, Cambridge +#' #References +#' Jones, H. 2014: Plants and Microclimate. 3rd edition, Cambridge #' University Press. #' #' ```@example; output = false diff --git a/inst/fromR/evapotranspiration.jl b/inst/fromR/evapotranspiration.jl index 5a192bd..9c5beed 100755 --- a/inst/fromR/evapotranspiration.jl +++ b/inst/fromR/evapotranspiration.jl @@ -13,55 +13,57 @@ #' - Rn Net radiation (W m-2) #' - G Ground heat flux (W m-2); optional #' - S Sum of all storage fluxes (W m-2); optional -#' - VPD Vapor pressure deficit (kPa); only used if `approach = "Penman-Monteith"`. -#' - Ga Aerodynamic conductance to heat/water vapor (m s-1); only used if `approach = "Penman-Monteith"`. -#' - approach Approach used. Either `"Priestley-Taylor"` (default), or `"Penman-Monteith"`. -#' - alpha Priestley-Taylor coefficient; only used if `approach = "Priestley-Taylor"`. +#' - VPD Vapor pressure deficit (kPa); only used if `approach = Val(:Penman-Monteith)`. +#' - Ga Aerodynamic conductance to heat/water vapor (m s-1); only used if `approach = Val(:Penman-Monteith)`. +#' - approach Approach used. Either `Val(:Priestley-Taylor)` (default), or `Val(:Penman-Monteith)`. +#' - alpha Priestley-Taylor coefficient; only used if `approach = Val(:Priestley-Taylor)`. #' - Gs_pot Potential/maximum surface conductance (mol m-2 s-1); defaults to 0.6 mol m-2 s-1; -#' only used if `approach = "Penman-Monteith"`. +#' only used if `approach = Val(:Penman-Monteith)`. #' - missing_G_as_NA if `TRUE`, missing G are treated as `NA`s, otherwise set to 0. #' - missing_S_as_NA if `TRUE`, missing S are treated as `NA`s, otherwise set to 0. #' - Esat_formula Optional: formula to be used for the calculation of esat and the slope of esat. #' One of `"Sonntag_1990"` (Default), `"Alduchov_1996"`, or `"Allen_1998"`. -#' See `\link{Esat_slope`}. -#' - constants cp - specific heat of air for constant pressure (J K-1 kg-1) \cr -#' eps - ratio of the molecular weight of water vapor to dry air \cr -#' Pa2kPa - conversion pascal (Pa) to kilopascal (kPa) \cr -#' Rd - gas constant of dry air (J kg-1 K-1) (only used if `approach = "Penman-Monteith"`) \cr -#' Rgas - universal gas constant (J mol-1 K-1) (only used if `approach = "Penman-Monteith"`) \cr -#' Kelvin - conversion degree Celsius to Kelvin (only used if `approach = "Penman-Monteith"`) \cr +#' See [`Esat_slope`](@ref). +#' - constants cp - specific heat of air for constant pressure (J K-1 kg-1) +#' eps - ratio of the molecular weight of water vapor to dry air +#' Pa2kPa - conversion pascal (Pa) to kilopascal (kPa) +#' Rd - gas constant of dry air (J kg-1 K-1) (only used if `approach = Val(:Penman-Monteith)`) +#' Rgas - universal gas constant (J mol-1 K-1) (only used if `approach = Val(:Penman-Monteith)`) +#' Kelvin - conversion degree Celsius to Kelvin (only used if `approach = Val(:Penman-Monteith)`) #' #' # Details - Potential evapotranspiration is calculated according to Priestley & Taylor, 1972 -#' if `approach = "Priestley-Taylor"` (the default): +#' Potential evapotranspiration is calculated according to Priestley & Taylor, 1972 +#' if `approach = Val(:Priestley-Taylor)` (the default): #' -#' \deqn{LE_pot,PT = (\alpha * \Delta * (Rn - G - S)) / (\Delta + \gamma)} +#' ``LE_pot,PT = (\\alpha * \\Delta * (Rn - G - S)) / (\\Delta + \\gamma)`` #' -#' \eqn{\alpha} is the Priestley-Taylor coefficient, \eqn{\Delta} is the slope -#' of the saturation vapor pressure curve (kPa K-1), and \eqn{\gamma} is the +#' ``\\alpha`` is the Priestley-Taylor coefficient, ``\\Delta`` is the slope +#' of the saturation vapor pressure curve (kPa K-1), and ``\\gamma`` is the #' psychrometric constant (kPa K-1). -#' if `approach = "Penman-Monteith"`, potential evapotranspiration is calculated according +#' if `approach = Val(:Penman-Monteith)`, potential evapotranspiration is calculated according #' to the Penman-Monteith equation: #' -#' \deqn{LE_pot,PM = (\Delta * (Rn - G - S) + \rho * cp * VPD * Ga) / (\Delta + \gamma * (1 + Ga/Gs_pot)} +#' ``LE_pot,PM = (\\Delta * (Rn - G - S) + \\rho * cp * VPD * Ga) / (\\Delta + \\gamma * (1 + Ga/Gs_pot)`` #' -#' where \eqn{\Delta} is the slope of the saturation vapor pressure curve (kPa K-1), -#' \eqn{\rho} is the air density (kg m-3), and \eqn{\gamma} is the psychrometric constant (kPa K-1). +#' where ``\\Delta`` is the slope of the saturation vapor pressure curve (kPa K-1), +#' ``\\rho`` is the air density (kg m-3), and ``\\gamma`` is the psychrometric constant (kPa K-1). #' The value of `Gs_pot` is typically a maximum value of Gs observed at the site, e.g. the 90th #' percentile of Gs within the growing season. #' #' # Value - a DataFrame with the following columns: -#' \item{ET_pot}{Potential evapotranspiration (kg m-2 s-1)} -#' \item{LE_pot}{Potential latent heat flux (W m-2)} +#' a DataFrame with the following columns: +#' - ET_pot: Potential evapotranspiration (kg m-2 s-1) +#' - LE_pot: Potential latent heat flux (W m-2) #' -#' @note If the first argument `data` is provided (either a matrix or a DataFrame), +#' #Note +#' If the first argument `data` is provided (either a matrix or a DataFrame), #' the following variables can be provided as character (in which case they are interpreted as #' the column name of `data`) or as numeric vectors, in which case they are taken #' directly for the calculations. If `data` is not provided, all input variables have to be #' numeric vectors. #' -#' @references Priestley, C_H_B., Taylor, R_J., 1972: On the assessment of surface heat flux +#' #References +#' Priestley, C_H_B., Taylor, R_J., 1972: On the assessment of surface heat flux #' and evaporation using large-scale parameters. Monthly Weather Review 100, 81-92. #' #' Allen, R_G., Pereira L_S., Raes D., Smith M., 1998: Crop evapotranspiration - @@ -71,18 +73,19 @@ #' Novick, K_A., et al. 2016: The increasing importance of atmospheric demand #' for ecosystem water and carbon fluxes. Nature Climate Change 6, 1023 - 1027. #' -#' @seealso `\link{surface_conductance`} +#' #See also +#' [`surface_conductance`](@ref) #' #' ```@example; output = false #' ``` #' # Calculate potential ET of a surface that receives a net radiation of 500 Wm-2 #' # using Priestley-Taylor: -#' potential_ET(Tair=30,pressure=100,Rn=500,alpha=1.26,approach="Priestley-Taylor") +#' potential_ET(Tair=30,pressure=100,Rn=500,alpha=1.26,approach=Val(:Priestley-Taylor)) #' #' # Calculate potential ET for a surface with known Gs (0.5 mol m-2 s-1) and Ga (0.1 m s-1) #' # using Penman-Monteith: #' LE_pot_PM = potential_ET(Gs_pot=0.5,Tair=20,pressure=100,VPD=2,Ga=0.1,Rn=400, -#' approach="Penman-Monteith")[,"LE_pot"] +#' approach=Val(:Penman-Monteith))[,"LE_pot"] #' LE_pot_PM #' #' # now cross-check with the inverted equation @@ -90,8 +93,8 @@ """ """ function potential_ET(data,Tair="Tair",pressure="pressure",Rn="Rn",G=NULL,S=NULL, - VPD="VPD",Ga="Ga_h",approach=c("Priestley-Taylor","Penman-Monteith"), - alpha=1.26,Gs_pot=0.6,missing_G_as_NA=FALSE,missing_S_as_NA=FALSE, + VPD="VPD",Ga="Ga_h",approach=c(Val(:Priestley-Taylor),Val(:Penman-Monteith)), + alpha=1.26,Gs_pot=0.6,missing_G_as_NA=false,missing_S_as_NA=false, Esat_formula=c("Sonntag_1990","Alduchov_1996","Allen_1998"), constants=bigleaf_constants()) @@ -121,12 +124,12 @@ end Delta = Esat_slope(Tair,Esat_formula,constants)[,"Delta"] - if (approach == "Priestley-Taylor") + if (approach == Val(:Priestley-Taylor)) LE_pot = (alpha * Delta * (Rn - G - S)) / (Delta + gamma) ET_pot = LE_to_ET(LE_pot,Tair) -else if (approach == "Penman-Monteith") +else if (approach == Val(:Penman-Monteith)) check_input(data,list(Gs_pot,VPD,Ga)) @@ -149,7 +152,7 @@ end #' #' Reference evapotranspiration calculated from the Penman-Monteith #' equation with a prescribed surface conductance. -#' This function is deprecated. Use potential_ET(...,approach="Penman-Monteith") instead. +#' This function is deprecated. Use potential_ET(...,approach=Val(:Penman-Monteith)) instead. #' #' - data Data_frame or matrix containing all required variables; optional #' - Gs_ref Reference surface conductance (m s-1); defaults to 0.0143 m s-1. @@ -164,16 +167,16 @@ end #' - missing_S_as_NA if `TRUE`, missing S are treated as `NA`s, otherwise set to 0. #' - Esat_formula Optional: formula to be used for the calculation of esat and the slope of esat. #' One of `"Sonntag_1990"` (Default), `"Alduchov_1996"`, or `"Allen_1998"`. -#' See `\link{Esat_slope`}. -#' - constants cp - specific heat of air for constant pressure (J K-1 kg-1) \cr -#' eps - ratio of the molecular weight of water vapor to dry air \cr -#' Rd - gas constant of dry air (J kg-1 K-1) (only if `approach = "Penman-Monteith"`) \cr -#' Rgas - universal gas constant (J mol-1 K-1) (only if `approach = "Penman-Monteith"`) \cr -#' Kelvin - conversion degree Celsius to Kelvin (only if `approach = "Penman-Monteith"`) \cr +#' See [`Esat_slope`](@ref). +#' - constants cp - specific heat of air for constant pressure (J K-1 kg-1) +#' eps - ratio of the molecular weight of water vapor to dry air +#' Rd - gas constant of dry air (J kg-1 K-1) (only if `approach = Val(:Penman-Monteith)`) +#' Rgas - universal gas constant (J mol-1 K-1) (only if `approach = Val(:Penman-Monteith)`) +#' Kelvin - conversion degree Celsius to Kelvin (only if `approach = Val(:Penman-Monteith)`) #' #' @export function reference_ET(data,Gs_ref=0.0143,Tair="Tair",pressure="pressure",VPD="VPD",Rn="Rn",Ga="Ga_h", - G=NULL,S=NULL,missing_G_as_NA=FALSE,missing_S_as_NA=FALSE, + G=NULL,S=NULL,missing_G_as_NA=false,missing_S_as_NA=false, Esat_formula=c("Sonntag_1990","Alduchov_1996","Allen_1998"), constants=bigleaf_constants()) @@ -201,50 +204,53 @@ end #' - missing_S_as_NA if `TRUE`, missing S are treated as `NA`s, otherwise set to 0. #' - Esat_formula Optional: formula to be used for the calculation of esat and the slope of esat. #' One of `"Sonntag_1990"` (Default), `"Alduchov_1996"`, or `"Allen_1998"`. -#' See `\link{Esat_slope`}. -#' - constants cp - specific heat of air for constant pressure (J K-1 kg-1) \cr -#' eps - ratio of the molecular weight of water vapor to dry air (-) \cr +#' See [`Esat_slope`](@ref). +#' - constants cp - specific heat of air for constant pressure (J K-1 kg-1) +#' eps - ratio of the molecular weight of water vapor to dry air (-) #' Pa2kPa - conversion pascal (Pa) to kilopascal (kPa) #' #' # Details Total evapotranspiration can be written in the form (Jarvis & McNaughton 1986): #' -#' \deqn{ET = \Omega ET_eq + (1 - \Omega)ET_imp} +#' ``ET = \\Omega ET_eq + (1 - \\Omega)ET_imp`` #' -#' where \eqn{\Omega} is the decoupling coefficient as calculated from -#' `\link{decoupling`}. `ET_eq` is the equilibrium evapotranspiration rate, +#' where ``\\Omega`` is the decoupling coefficient as calculated from +#' [`decoupling`](@ref). `ET_eq` is the equilibrium evapotranspiration rate, #' the ET rate that would occur under uncoupled conditions, where the heat budget #' is dominated by radiation (when Ga -> 0): #' -#' \deqn{ET_eq = (\Delta * (Rn - G - S) * \lambda) / (\Delta + \gamma)} +#' ``ET_eq = (\\Delta * (Rn - G - S) * \\lambda) / (\\Delta + \\gamma)`` #' -#' where \eqn{\Delta} is the slope of the saturation vapor pressure curve (kPa K-1), -#' \eqn{\lambda} is the latent heat of vaporization (J kg-1), and \eqn{\gamma} +#' where ``\\Delta`` is the slope of the saturation vapor pressure curve (kPa K-1), +#' ``\\lambda`` is the latent heat of vaporization (J kg-1), and ``\\gamma`` #' is the psychrometric constant (kPa K-1). #' `ET_imp` is the imposed evapotranspiration rate, the ET rate #' that would occur under fully coupled conditions (when Ga -> inf): #' -#' \deqn{ET_imp = (\rho * cp * VPD * Gs * \lambda) / \gamma} +#' ``ET_imp = (\\rho * cp * VPD * Gs * \\lambda) / \\gamma`` #' -#' where \eqn{\rho} is the air density (kg m-3). +#' where ``\\rho`` is the air density (kg m-3). #' -#' @note Surface conductance (Gs) can be calculated with `\link{surface_conductance`}. -#' Aerodynamic conductance (Ga) can be calculated using `\link{aerodynamic_conductance`}. +#' #Note +#' Surface conductance (Gs) can be calculated with [`surface_conductance`](@ref). +#' Aerodynamic conductance (Ga) can be calculated using [`aerodynamic_conductance`](@ref). #' #' # Value A DataFrame with the following columns: -#' \item{ET_eq}{Equilibrium ET (kg m-2 s-1)} -#' \item{ET_imp}{Imposed ET (kg m-2 s-1)} -#' \item{LE_eq}{Equilibrium LE (W m-2)} -#' \item{LE_imp}{Imposed LE (W m-2)} +#' - ET_eq: Equilibrium ET (kg m-2 s-1) +#' - ET_imp: Imposed ET (kg m-2 s-1) +#' - LE_eq: Equilibrium LE (W m-2) +#' - LE_imp: Imposed LE (W m-2) #' -#' @references Jarvis, P_G., McNaughton, K_G., 1986: Stomatal control of transpiration: +#' #References +#' Jarvis, P_G., McNaughton, K_G., 1986: Stomatal control of transpiration: #' scaling up from leaf to region. Advances in Ecological Research 15, 1-49. #' #' Monteith, J_L., Unsworth, M_H., 2008: Principles of Environmental Physics. #' 3rd edition. Academic Press, London. #' -#' @seealso `\link{decoupling`} +#' #See also +#' [`decoupling`](@ref) #' #' ```@example; output = false #' ``` @@ -255,7 +261,7 @@ end """ """ function equilibrium_imposed_ET(data,Tair="Tair",pressure="pressure",VPD="VPD",Gs="Gs_ms", - Rn="Rn",G=NULL,S=NULL,missing_G_as_NA=FALSE,missing_S_as_NA=FALSE, + Rn="Rn",G=NULL,S=NULL,missing_G_as_NA=false,missing_S_as_NA=false, Esat_formula=c("Sonntag_1990","Alduchov_1996","Allen_1998"), constants=bigleaf_constants()) diff --git a/inst/fromR/filter_data.jl b/inst/fromR/filter_data.jl index a729ac9..bba40e9 100755 --- a/inst/fromR/filter_data.jl +++ b/inst/fromR/filter_data.jl @@ -10,8 +10,8 @@ #' - data Data_frame or matrix containing all required input variables in #' half-hourly or hourly resolution. Including year, month, day information #' - quality_control Should quality control be applied? Defaults to `TRUE`. -#' - filter_growseas Should data be filtered for growing season? Defaults to `FALSE`. -#' - filter_precip Should precipitation filtering be applied? Defaults to `FALSE`. +#' - filter_growseas Should data be filtered for growing season? Defaults to `false`. +#' - filter_precip Should precipitation filtering be applied? Defaults to `false`. #' - filter_vars Additional variables to be filtered. Vector of type character. #' - filter_vals_min Minimum values of the variables to be filtered. Numeric vector of #' the same length than `filter_vars`. Set to `NA` to be ignored. @@ -19,33 +19,33 @@ #' the same length than `filter_vars`. Set to `NA` to be ignored. #' - NA_as_invalid If `TRUE` (the default) missing data are filtered out (applies to all variables). #' - vars_qc Character vector indicating the variables for which quality filter should -#' be applied. Ignored if `quality_control = FALSE`. +#' be applied. Ignored if `quality_control = false`. #' - quality_ext The extension to the variables' names that marks them as -#' quality control variables. Ignored if `quality_control = FALSE`. +#' quality control variables. Ignored if `quality_control = false`. #' - good_quality Which values indicate good quality (i.e. not to be filtered) -#' in the quality control (qc) variables? Ignored if `quality_control = FALSE`. +#' in the quality control (qc) variables? Ignored if `quality_control = false`. #' - missing_qc_as_bad If quality control variable is `NA`, should the corresponding data point be -#' treated as bad quality? Defaults to `TRUE`. Ignored if `quality_control = FALSE`. +#' treated as bad quality? Defaults to `TRUE`. Ignored if `quality_control = false`. #' - precip Precipitation (mm time-1) -#' - GPP Gross primary productivity (umol m-2 s-1); Ignored if `filter_growseas = FALSE`. -#' - doy Day of year; Ignored if `filter_growseas = FALSE`. -#' - year Year; Ignored if `filter_growseas = FALSE`. +#' - GPP Gross primary productivity (umol m-2 s-1); Ignored if `filter_growseas = false`. +#' - doy Day of year; Ignored if `filter_growseas = false`. +#' - year Year; Ignored if `filter_growseas = false`. #' - tGPP GPP threshold (fraction of 95th percentile of the GPP time series). -#' Must be between 0 and 1. Ignored if `filter_growseas` is `FALSE`. +#' Must be between 0 and 1. Ignored if `filter_growseas` is `false`. #' - ws Window size used for GPP time series smoothing. -#' Ignored if `filter_growseas = FALSE`. +#' Ignored if `filter_growseas = false`. #' - min_int Minimum time interval in days for a given state of growing season. -#' Ignored if `filter_growseas = FALSE`. +#' Ignored if `filter_growseas = false`. #' - tprecip Precipitation threshold used to identify a precipitation event (mm). -#' Ignored if `filter_precip = FALSE`. +#' Ignored if `filter_precip = false`. #' - precip_hours Number of hours removed following a precipitation event (h). -#' Ignored if `filter_precip = FALSE`. +#' Ignored if `filter_precip = false`. #' - records_per_hour Number of observations per hour. I_e. 2 for half-hourly data. #' - filtered_data_to_NA Logical. If `TRUE` (the default), all variables in the input #' DataFrame/matrix are set to `NA` for the time step where ANY of the #' `filter_vars` were beyond their acceptable range (as #' determined by `filter_vals_min` and `filter_vals_max`). -#' If `FALSE`, values are not filtered, and an additional column 'valid' +#' If `false`, values are not filtered, and an additional column 'valid' #' is added to the DataFrame/matrix, indicating if any value of a row #' did (1) or did not fulfill the filter criteria (0). #' - constants frac2percent - conversion between fraction and percent @@ -71,11 +71,12 @@ #' # Value If `filtered_data_to_NA = TRUE` (default), the input DataFrame/matrix with #' observations which did not fulfill the filter criteria set to `NA`. -#' If `filtered_data_to_NA = FALSE`, the input DataFrame/matrix with an additional +#' If `filtered_data_to_NA = false`, the input DataFrame/matrix with an additional #' column "valid", which indicates whether all the data of a time step fulfill the #' filtering criteria (1) or not (0). #' -#' @note The thresholds set with `filter_vals_min` and `filter_vals_max` filter all data +#' #Note +#' The thresholds set with `filter_vals_min` and `filter_vals_max` filter all data #' that are smaller than ("<"), or greater than (">") the specified thresholds. That means #' if a variable has exactly the same value as the threshold, it will not be filtered. Likewise, #' `tprecip` filters all data that are greater than `tprecip`. @@ -83,7 +84,7 @@ #' Variables considered of bad quality (as specified by the corresponding quality control variables) #' will be set to `NA` by this routine. Data that do not fulfill the filtering criteria are set to #' `NA` if `filtered_data_to_NA = TRUE`. Note that with this option *all* variables of the same -#' time step are set to `NA`. Alternatively, if `filtered_data_to_NA = FALSE` data are not set to `NA`, +#' time step are set to `NA`. Alternatively, if `filtered_data_to_NA = false` data are not set to `NA`, #' and a new column "valid" is added to the DataFrame/matrix, indicating if any value of a row #' did (1) or did not fulfill the filter criteria (0). #' @@ -94,9 +95,9 @@ #' # hence growing season is not filtered. #' # If filtered_data_to_NA=TRUE, all values of a row are set to NA if one filter #' # variable is beyond its bounds. -#' DE_Tha_Jun_2014_2 = filter_data(DE_Tha_Jun_2014,quality_control=FALSE, +#' DE_Tha_Jun_2014_2 = filter_data(DE_Tha_Jun_2014,quality_control=false, #' vars_qc=c("Tair","precip","H","LE"), -#' filter_growseas=FALSE,filter_precip=TRUE, +#' filter_growseas=false,filter_precip=TRUE, #' filter_vars=c("Tair","PPFD","ustar"), #' filter_vals_min=c(5,200,0.2), #' filter_vals_max=c(NA,NA,NA),NA_as_invalid=TRUE, @@ -106,10 +107,10 @@ #' tprecip=0.1,precip_hours=24,records_per_hour=2, #' filtered_data_to_NA=TRUE) #' -#' ## same, but with filtered_data_to_NA=FALSE -#' DE_Tha_Jun_2014_3 = filter_data(DE_Tha_Jun_2014,quality_control=FALSE, +#' ## same, but with filtered_data_to_NA=false +#' DE_Tha_Jun_2014_3 = filter_data(DE_Tha_Jun_2014,quality_control=false, #' vars_qc=c("Tair","precip","H","LE"), -#' filter_growseas=FALSE,filter_precip=TRUE, +#' filter_growseas=false,filter_precip=TRUE, #' filter_vars=c("Tair","PPFD","ustar"), #' filter_vals_min=c(5,200,0.2), #' filter_vals_max=c(NA,NA,NA),NA_as_invalid=TRUE, @@ -117,7 +118,7 @@ #' missing_qc_as_bad=TRUE,GPP="GPP",doy="doy", #' year="year",tGPP=0.5,ws=15,min_int=5,precip="precip", #' tprecip=0.1,precip_hours=24,records_per_hour=2, -#' filtered_data_to_NA=FALSE) +#' filtered_data_to_NA=false) #' #' # note the additional column 'valid' in DE_Tha_Jun_2014_3. #' # To remove time steps marked as filtered out (i.e. 0 values in column 'valid'): @@ -126,8 +127,8 @@ #' #' @importFrom stats aggregate #' @export -function filter_data(data,quality_control=TRUE,filter_growseas=FALSE, - filter_precip=FALSE,filter_vars=NULL, +function filter_data(data,quality_control=TRUE,filter_growseas=false, + filter_precip=false,filter_vars=NULL, filter_vals_min,filter_vals_max,NA_as_invalid=TRUE, vars_qc=NULL,quality_ext="_qc",good_quality=c(0,1), missing_qc_as_bad=TRUE,GPP="GPP",doy="doy", @@ -296,7 +297,7 @@ end #' observed in the year. #' The GPP-threshold is calculated as: #' -#' \deqn{GPP_threshold = quantile(GPPd,0.95)*tGPP} +#' ``GPP_threshold = quantile(GPPd,0.95)*tGPP`` #' #' GPPd time series are smoothed with a moving average to avoid fluctuations #' in the delineation of the growing season. The window size defaults to 15 diff --git a/inst/fromR/meteorological_variables.jl b/inst/fromR/meteorological_variables.jl index c98679b..ef9d59e 100755 --- a/inst/fromR/meteorological_variables.jl +++ b/inst/fromR/meteorological_variables.jl @@ -8,24 +8,25 @@ #' #' - Tair Air temperature (deg C) #' - pressure Atmospheric pressure (kPa) -#' - constants Kelvin - conversion degC to Kelvin \cr -#' Rd - gas constant of dry air (J kg-1 K-1) \cr +#' - constants Kelvin - conversion degC to Kelvin +#' Rd - gas constant of dry air (J kg-1 K-1) #' kPa2Pa - conversion kilopascal (kPa) to pascal (Pa) #' #' # Details - Air density (\eqn{\rho}) is calculated as: + Air density (``\\rho``) is calculated as: #' -#' \deqn{\rho = pressure / (Rd * Tair)} +#' ``\\rho = pressure / (Rd * Tair)`` #' #' # Value - \item{\eqn{\rho}}{air density (kg m-3)} + - ``\\rho``: air density (kg m-3) #' #' ```@example; output = false #' ``` #' # air density at 25degC and standard pressure (101.325kPa) #' air_density(25,101.325) #' -#' @references Foken, T, 2008: Micrometeorology. Springer, Berlin, Germany. +#' #References +#' Foken, T, 2008: Micrometeorology. Springer, Berlin, Germany. #' """ """ @@ -49,27 +50,29 @@ end #' - elev Elevation a_s_l. (m) #' - Tair Air temperature (deg C) #' - VPD Vapor pressure deficit (kPa); optional -#' - constants Kelvin- conversion degC to Kelvin \cr -#' pressure0 - reference atmospheric pressure at sea level (Pa) \cr -#' Rd - gas constant of dry air (J kg-1 K-1) \cr -#' g - gravitational acceleration (m s-2) \cr +#' - constants Kelvin- conversion degC to Kelvin +#' pressure0 - reference atmospheric pressure at sea level (Pa) +#' Rd - gas constant of dry air (J kg-1 K-1) +#' g - gravitational acceleration (m s-2) #' Pa2kPa - conversion pascal (Pa) to kilopascal (kPa) #' #' # Details Atmospheric pressure is approximated by the hypsometric equation: #' -#' \deqn{pressure = pressure_0 / (exp(g * elevation / (Rd Temp)))} +#' ``pressure = pressure_0 / (exp(g * elevation / (Rd Temp)))`` #' -#' @note The hypsometric equation gives an estimate of the standard pressure +#' #Note +#' The hypsometric equation gives an estimate of the standard pressure #' at a given altitude. #' If VPD is provided, humidity correction is applied and the #' virtual temperature instead of air temperature is used. VPD is #' internally converted to specific humidity. #' #' # Value - \item{pressure -}{Atmospheric pressure (kPa)} + - pressure -: Atmospheric pressure (kPa) #' -#' @references Stull B., 1988: An Introduction to Boundary Layer Meteorology. +#' #References +#' Stull B., 1988: An Introduction to Boundary Layer Meteorology. #' Kluwer Academic Publishers, Dordrecht, Netherlands. #' #' ```@example; output = false @@ -115,25 +118,26 @@ end #' # Details Esat (kPa) is calculated using the Magnus equation: #' -#' \deqn{Esat = a * exp((b * Tair) / (c + Tair)) / 1000} +#' ``Esat = a * exp((b * Tair) / (c + Tair)) / 1000`` #' #' where the coefficients a, b, c take different values depending on the formula used. #' The default values are from Sonntag 1990 (a=611.2, b=17.62, c=243.12). This version #' of the Magnus equation is recommended by the WMO (WMO 2008; p1.4-29). Alternatively, #' parameter values determined by Alduchov & Eskridge 1996 or Allen et al. 1998 can be #' used (see references). -#' The slope of the Esat curve (\eqn{\Delta}) is calculated as the first derivative of the function: +#' The slope of the Esat curve (``\\Delta``) is calculated as the first derivative of the function: #' -#' \deqn{\Delta = dEsat / dTair} +#' ``\\Delta = dEsat / dTair`` #' #' which is solved using `\link[stats]{D`}. #' #' # Value A dataframe with the following columns: -#' \item{Esat}{Saturation vapor pressure (kPa)} -#' \item{Delta}{Slope of the saturation vapor pressure curve (kPa K-1)} +#' - Esat: Saturation vapor pressure (kPa) +#' - Delta: Slope of the saturation vapor pressure curve (kPa K-1) #' -#' @references Sonntag D. 1990: Important new values of the physical constants of 1986, vapor +#' #References +#' Sonntag D. 1990: Important new values of the physical constants of 1986, vapor #' pressure formulations based on the ITS-90 and psychrometric formulae. #' Zeitschrift fuer Meteorologie 70, 340-344. #' @@ -194,21 +198,22 @@ end #' #' - Tair Air temperature (deg C) #' - pressure Atmospheric pressure (kPa) -#' - constants cp - specific heat of air for constant pressure (J K-1 kg-1) \cr +#' - constants cp - specific heat of air for constant pressure (J K-1 kg-1) #' eps - ratio of the molecular weight of water vapor to dry air (-) #' #' # Details - The psychrometric constant (\eqn{\gamma}) is given as: + The psychrometric constant (``\\gamma``) is given as: #' -#' \deqn{\gamma = cp * pressure / (eps * \lambda)} +#' ``\\gamma = cp * pressure / (eps * \\lambda)`` #' -#' where \eqn{\lambda} is the latent heat of vaporization (J kg-1), -#' as calculated from `\link{latent_heat_vaporization`}. +#' where ``\\lambda`` is the latent heat of vaporization (J kg-1), +#' as calculated from [`latent_heat_vaporization`](@ref). #' #' # Value - \item{\eqn{\gamma} -}{the psychrometric constant (kPa K-1)} + - ``\\gamma`` -: the psychrometric constant (kPa K-1) #' -#' @references Monteith J_L., Unsworth M_H., 2008: Principles of Environmental Physics. +#' #References +#' Monteith J_L., Unsworth M_H., 2008: Principles of Environmental Physics. #' 3rd Edition. Academic Press, London. #' #' ```@example; output = false @@ -236,12 +241,13 @@ end #' # Details The following formula is used: #' -#' \deqn{\lambda = (2.501 - 0.00237*Tair)10^6} +#' ``\\lambda = (2.501 - 0.00237*Tair)10^6`` #' #' # Value - \item{\eqn{\lambda} -}{Latent heat of vaporization (J kg-1)} + - ``\\lambda`` -: Latent heat of vaporization (J kg-1) #' -#' @references Stull, B., 1988: An Introduction to Boundary Layer Meteorology (p.641) +#' #References +#' Stull, B., 1988: An Introduction to Boundary Layer Meteorology (p.641) #' Kluwer Academic Publishers, Dordrecht, Netherlands #' #' Foken, T, 2008: Micrometeorology. Springer, Berlin, Germany. @@ -276,10 +282,11 @@ end #' - accuracy Accuracy of the result (degC) #' - Esat_formula Optional: formula to be used for the calculation of esat and the slope of esat. #' One of `"Sonntag_1990"` (Default), `"Alduchov_1996"`, or `"Allen_1998"`. -#' See `\link{Esat_slope`}. +#' See [`Esat_slope`](@ref). #' - constants Pa2kPa - conversion pascal (Pa) to kilopascal (kPa) #' -#' @note Arguments `accuracy` and `Esat_formula` are passed to this function by wetbulb_temp(). +#' #Note +#' Arguments `accuracy` and `Esat_formula` are passed to this function by wetbulb_temp(). #' #' @importFrom stats optimize #' @@ -303,24 +310,25 @@ end #' - accuracy Accuracy of the result (deg C) #' - Esat_formula Optional: formula to be used for the calculation of esat and the slope of esat. #' One of `"Sonntag_1990"` (Default), `"Alduchov_1996"`, or `"Allen_1998"`. -#' See `\link{Esat_slope`}. -#' - constants cp - specific heat of air for constant pressure (J K-1 kg-1) \cr -#' eps - ratio of the molecular weight of water vapor to dry air (-) \cr +#' See [`Esat_slope`](@ref). +#' - constants cp - specific heat of air for constant pressure (J K-1 kg-1) +#' eps - ratio of the molecular weight of water vapor to dry air (-) #' Pa2kPa - conversion pascal (Pa) to kilopascal (kPa) #' #' # Details Wet-bulb temperature (Tw) is calculated from the following expression: #' -#' \deqn{e = Esat(Tw) - gamma* (Tair - Tw)} +#' ``e = Esat(Tw) - gamma* (Tair - Tw)`` #' #' The equation is solved for Tw using `\link[stats]{optimize`}. -#' Actual vapor pressure e (kPa) is calculated from VPD using the function `\link{VPD_to_e`}. -#' The psychrometric constant gamma (kPa K-1) is calculated from `\link{psychrometric_constant`}. +#' Actual vapor pressure e (kPa) is calculated from VPD using the function [`VPD_to_e`](@ref). +#' The psychrometric constant gamma (kPa K-1) is calculated from [`psychrometric_constant`](@ref). #' #' # Value - \item{Tw -}{wet-bulb temperature (degC)} + - Tw -: wet-bulb temperature (degC) #' -#' @references Monteith J_L., Unsworth M_H., 2008: Principles of Environmental Physics. +#' #References +#' Monteith J_L., Unsworth M_H., 2008: Principles of Environmental Physics. #' 3rd edition. Academic Press, London. #' #' ```@example; output = false @@ -375,10 +383,11 @@ end #' - accuracy Accuracy of the result (degC) #' - Esat_formula Optional: formula to be used for the calculation of esat and the slope of esat. #' One of `"Sonntag_1990"` (Default), `"Alduchov_1996"`, or `"Allen_1998"`. -#' See `\link{Esat_slope`}. +#' See [`Esat_slope`](@ref). #' - constants Pa2kPa - conversion pascal (Pa) to kilopascal (kPa) #' -#' @note Arguments `accuracy` and `Esat_formula` are passed to this function by dew_point(). +#' #Note +#' Arguments `accuracy` and `Esat_formula` are passed to this function by dew_point(). #' #' @importFrom stats optimize #' @@ -402,21 +411,22 @@ end #' - accuracy Accuracy of the result (deg C) #' - Esat_formula Optional: formula to be used for the calculation of esat and the slope of esat. #' One of `"Sonntag_1990"` (Default), `"Alduchov_1996"`, or `"Allen_1998"`. -#' See `\link{Esat_slope`}. +#' See [`Esat_slope`](@ref). #' - constants Pa2kPa - conversion pascal (Pa) to kilopascal (kPa) #' #' # Details Dew point temperature (Td) is defined by: #' -#' \deqn{e = Esat(Td)} +#' ``e = Esat(Td)`` #' #' where e is vapor pressure of the air and Esat is the vapor pressure deficit. #' This equation is solved for Td using `\link[stats]{optimize`}. #' #' # Value - \item{Td -}{dew point temperature (degC)} + - Td -: dew point temperature (degC) #' -#' @references Monteith J_L., Unsworth M_H., 2008: Principles of Environmental Physics. +#' #References +#' Monteith J_L., Unsworth M_H., 2008: Principles of Environmental Physics. #' 3rd edition. Academic Press, London. #' #' ```@example; output = false @@ -464,22 +474,23 @@ end #' - VPD Vapor pressure deficit (kPa) #' - Esat_formula Optional: formula to be used for the calculation of esat and the slope of esat. #' One of `"Sonntag_1990"` (Default), `"Alduchov_1996"`, or `"Allen_1998"`. -#' See `\link{Esat_slope`}. -#' - constants Kelvin - conversion degree Celsius to Kelvin \cr +#' See [`Esat_slope`](@ref). +#' - constants Kelvin - conversion degree Celsius to Kelvin #' eps - ratio of the molecular weight of water vapor to dry air (-) #' #' # Details the virtual temperature is given by: #' -#' \deqn{Tv = Tair / (1 - (1 - eps) e/pressure)} +#' ``Tv = Tair / (1 - (1 - eps) e/pressure)`` #' #' where Tair is in Kelvin (converted internally). Likewise, VPD is converted -#' to actual vapor pressure (e in kPa) with `\link{VPD_to_e`} internally. +#' to actual vapor pressure (e in kPa) with [`VPD_to_e`](@ref) internally. #' #' # Value - \item{Tv -}{virtual temperature (deg C)} + - Tv -: virtual temperature (deg C) #' -#' @references Monteith J_L., Unsworth M_H., 2008: Principles of Environmental Physics. +#' #References +#' Monteith J_L., Unsworth M_H., 2008: Principles of Environmental Physics. #' 3rd edition. Academic Press, London. #' #' ```@example; output = false @@ -508,21 +519,22 @@ end #' #' - Tair Air temperature (deg C) #' - pressure Atmospheric pressure (kPa) -#' - constants Kelvin - conversion degree Celsius to Kelvin \cr -#' pressure0 - reference atmospheric pressure at sea level (Pa) \cr -#' Tair0 - reference air temperature (K) \cr +#' - constants Kelvin - conversion degree Celsius to Kelvin +#' pressure0 - reference atmospheric pressure at sea level (Pa) +#' Tair0 - reference air temperature (K) #' kPa2Pa - conversion kilopascal (kPa) to pascal (Pa) #' #' # Details where v is the kinematic viscosity of the air (m2 s-1), #' given by (Massman 1999b): #' -#' \deqn{v = 1.327 * 10^-5(pressure0/pressure)(Tair/Tair0)^1.81} +#' ``v = 1.327 * 10^-5(pressure0/pressure)(Tair/Tair0)^1.81`` #' #' # Value - \item{v -}{kinematic viscosity of air (m2 s-1)} + - v -: kinematic viscosity of air (m2 s-1) #' -#' @references Massman, W_J., 1999b: Molecular diffusivities of Hg vapor in air, +#' #References +#' Massman, W_J., 1999b: Molecular diffusivities of Hg vapor in air, #' O2 and N2 near STP and the kinematic viscosity and thermal diffusivity #' of air near STP. Atmospheric Environment 33, 453-457. #' diff --git a/inst/fromR/potential_radiation.jl b/inst/fromR/potential_radiation.jl index 7d6243f..d5e59ff 100755 --- a/inst/fromR/potential_radiation.jl +++ b/inst/fromR/potential_radiation.jl @@ -49,7 +49,7 @@ end #' - timezone Time zone (hours) #' - useSolartime by default corrects hour (given in local winter time) #' for latitude to solar time (where noon is exactly at 12:00). -#' Set this to `FALSE` to directly use local winter time. +#' Set this to `false` to directly use local winter time. #' #' # Value vector of potential radiation (W m-2) @@ -60,7 +60,7 @@ end #' potRadApparentLocal = potential_radiation( #' 160, hour, 39.94, -5.77, timezone = +1) #' potRadTimezone = potential_radiation( -#' 160, hour, 39.94, -5.77, timezone = +1, useSolartime = FALSE) +#' 160, hour, 39.94, -5.77, timezone = +1, useSolartime = false) #' plot(potRadApparentLocal ~ hour, type = 'l' #' , ylab = 'potential radiation (W m-2)') #' lines(potRadTimezone ~ hour, col = "blue") diff --git a/inst/fromR/stability_correction.jl b/inst/fromR/stability_correction.jl index 6475c0f..0a68405 100755 --- a/inst/fromR/stability_correction.jl +++ b/inst/fromR/stability_correction.jl @@ -11,28 +11,31 @@ #' - pressure Atmospheric pressure (kPa) #' - ustar Friction velocity (m s-1) #' - H Sensible heat flux (W m-2) -#' - constants Kelvin - conversion degree Celsius to Kelvin \cr -#' cp - specific heat of air for constant pressure (J K-1 kg-1) \cr -#' k - von Karman constant (-) \cr +#' - constants Kelvin - conversion degree Celsius to Kelvin +#' cp - specific heat of air for constant pressure (J K-1 kg-1) +#' k - von Karman constant (-) #' g - gravitational acceleration (m s-2) #' #' # Details The Monin-Obukhov length (L) is given by: #' -#' \deqn{L = - (\rho * cp * ustar^3 * Tair) / (k * g * H)} +#' ``L = - (\\rho * cp * ustar^3 * Tair) / (k * g * H)`` #' -#' where \eqn{rho} is air density (kg m-3). +#' where ``rho`` is air density (kg m-3). #' #' # Value - \item{L -}{Monin-Obukhov length (m)} + - L -: Monin-Obukhov length (m) #' -#' @note Note that L gets very small for very low ustar values with implications +#' #Note +#' Note that L gets very small for very low ustar values with implications #' for subsequent functions using L as input. It is recommended to filter #' data and exclude low ustar values (ustar < ~0.2) beforehand. #' -#' @references Foken, T, 2008: Micrometeorology. Springer, Berlin, Germany. +#' #References +#' Foken, T, 2008: Micrometeorology. Springer, Berlin, Germany. #' -#' @seealso `\link{stability_parameter`} +#' #See also +#' [`stability_parameter`](@ref) #' #' ```@example; output = false #' ``` @@ -66,22 +69,22 @@ end #' - H Sensible heat flux (W m-2) #' - zr Instrument (reference) height (m) #' - d Zero-plane displacement height (m) -#' - constants Kelvin - conversion degree Celsius to Kelvin \cr -#' cp - specific heat of air for constant pressure (J K-1 kg-1) \cr -#' k - von Karman constant (-) \cr +#' - constants Kelvin - conversion degree Celsius to Kelvin +#' cp - specific heat of air for constant pressure (J K-1 kg-1) +#' k - von Karman constant (-) #' g - gravitational acceleration (m s-2) #' #' # Details - The stability parameter \eqn{\zeta} is given by: + The stability parameter ``\zeta`` is given by: #' -#' \deqn{\zeta = (zr - d) / L} +#' ``\zeta = (zr - d) / L`` #' #' where L is the Monin-Obukhov length (m), calculated from the function -#' `\link{Monin_Obukhov_length`}. The displacement height d can -#' be estimated from the function `\link{roughness_parameters`}. +#' [`Monin_Obukhov_length`](@ref). The displacement height d can +#' be estimated from the function [`roughness_parameters`](@ref). #' #' # Value - \item{\eqn{\zeta} - }{stability parameter (-)} + - ``\zeta`` - : stability parameter (-) #' #' ```@example; output = false #' ``` @@ -114,26 +117,27 @@ end #' #' # Details The functions give the integrated form of the universal functions. They -#' depend on the value of the stability parameter \eqn{\zeta}, -#' which can be calculated from the function `\link{stability_parameter`}. +#' depend on the value of the stability parameter ``\zeta``, +#' which can be calculated from the function [`stability_parameter`](@ref). #' The integration of the universal functions is: #' -#' \deqn{\psi = -x * zeta} +#' ``\psi = -x * zeta`` #' -#' for stable atmospheric conditions (\eqn{\zeta} >= 0), and +#' for stable atmospheric conditions (``\zeta`` >= 0), and #' -#' \deqn{\psi = 2 * log( (1 + y) / 2) } +#' ``\psi = 2 * log( (1 + y) / 2) `` #' -#' for unstable atmospheric conditions (\eqn{\zeta} < 0). +#' for unstable atmospheric conditions (``\zeta`` < 0). #' #' The different formulations differ in their value of x and y. #' #' # Value a DataFrame with the following columns: -#' \item{psi_h}{the value of the stability function for heat and water vapor (-)} -#' \item{psi_m}{the value of the stability function for momentum (-)} +#' - psi_h: the value of the stability function for heat and water vapor (-) +#' - psi_m: the value of the stability function for momentum (-) #' -#' @references Dyer, A_J., 1974: A review of flux-profile relationships. +#' #References +#' Dyer, A_J., 1974: A review of flux-profile relationships. #' Boundary-Layer Meteorology 7, 363-372. #' #' Dyer, A. J., Hicks, B_B., 1970: Flux-Gradient relationships in the diff --git a/inst/fromR/surface_conditions.jl b/inst/fromR/surface_conditions.jl index e3289ea..853c281 100755 --- a/inst/fromR/surface_conditions.jl +++ b/inst/fromR/surface_conditions.jl @@ -15,15 +15,15 @@ #' - LE Latent heat flux (W m-2) #' - VPD Vapor pressure deficit (kPa) #' - Ga Aerodynamic conductance for heat/water vapor (m s-1) -#' - calc_surface_CO2 Calculate surface CO2 concentration? Defaults to `FALSE`. +#' - calc_surface_CO2 Calculate surface CO2 concentration? Defaults to `false`. #' - Ca Atmospheric CO2 concentration (mol mol-1). Required if `calc_surface_CO2 = TRUE`. #' - NEE Net ecosystem exchange (umol m-2 s-1). Required if `calc_surface_CO2 = TRUE`. #' - Ga_CO2 Aerodynamic conductance for CO2 (m s-1). Required if `calc_surface_CO2 = TRUE`. #' - Esat_formula Optional: formula to be used for the calculation of esat and the slope of esat. #' One of `"Sonntag_1990"` (Default), `"Alduchov_1996"`, or `"Allen_1998"`. -#' See `\link{Esat_slope`}. -#' - constants cp - specific heat of air for constant pressure (J K-1 kg-1) \cr -#' eps - ratio of the molecular weight of water vapor to dry air (-) \cr +#' See [`Esat_slope`](@ref). +#' - constants cp - specific heat of air for constant pressure (J K-1 kg-1) +#' eps - ratio of the molecular weight of water vapor to dry air (-) #' Pa2kPa - conversion pascal (Pa) to kilopascal (kPa) #' #' # Details @@ -32,44 +32,45 @@ #' the surface of the big-leaf (i.e. at height d + z0h; the apparent sink of sensible heat and water vapor). #' Aerodynamic canopy surface temperature is given by: #' -#' \deqn{Tsurf = Tair + H / (\rho * cp * Ga)} +#' ``Tsurf = Tair + H / (\\rho * cp * Ga)`` #' -#' where \eqn{\rho} is air density (kg m-3). +#' where ``\\rho`` is air density (kg m-3). #' Vapor pressure at the canopy surface is: #' -#' \deqn{esurf = e + (LE * \gamma)/(Ga * \rho * cp)} +#' ``esurf = e + (LE * \\gamma)/(Ga * \\rho * cp)`` #' -#' where \eqn{\gamma} is the psychrometric constant (kPa K-1). +#' where ``\\gamma`` is the psychrometric constant (kPa K-1). #' Vapor pressure deficit (VPD) at the canopy surface is calculated as: #' -#' \deqn{VPD_surf = Esat_surf - esurf} +#' ``VPD_surf = Esat_surf - esurf`` #' #' CO2 concentration at the canopy surface is given by: #' -#' \deqn{Ca_surf = Ca + NEE / Ga_CO2} +#' ``Ca_surf = Ca + NEE / Ga_CO2`` #' #' Note that Ga is assumed to be equal for water vapor and sensible heat. #' Ga is further assumed to be the inverse of the sum of the turbulent part #' and the canopy boundary layer conductance (1/Ga = 1/Ga_m + 1/Gb; -#' see `\link{aerodynamic_conductance`}). Ga_CO2, the aerodynamic conductance -#' for CO2 is also calculated by `\link{aerodynamic_conductance`}. +#' see [`aerodynamic_conductance`](@ref)). Ga_CO2, the aerodynamic conductance +#' for CO2 is also calculated by [`aerodynamic_conductance`](@ref). #' If Ga is replaced by Ga_m (i.e. only the turbulent conductance part), #' the results of the functions represent conditions outside the canopy #' boundary layer, i.e. in the canopy airspace. #' -#' @note The following sign convention for NEE is employed (relevant if +#' #Note +#' The following sign convention for NEE is employed (relevant if #' `calc_surface_CO2 = TRUE`): #' negative values of NEE denote net CO2 uptake by the ecosystem. #' #' # Value a DataFrame with the following columns: -#' \item{Tsurf}{Surface temperature (deg C)} \cr -#' \item{esat_surf}{Saturation vapor pressure at the surface (kPa)} \cr -#' \item{esurf}{vapor pressure at the surface (kPa)} \cr -#' \item{VPD_surf}{vapor pressure deficit at the surface (kPa)} \cr -#' \item{qsurf}{specific humidity at the surface (kg kg-1)} \cr -#' \item{rH_surf}{relative humidity at the surface (-)} \cr -#' \item{Ca_surf}{CO2 concentration at the surface (umol mol-1)} +#' - Tsurf: Surface temperature (deg C) +#' - esat_surf: Saturation vapor pressure at the surface (kPa) +#' - esurf: vapor pressure at the surface (kPa) +#' - VPD_surf: vapor pressure deficit at the surface (kPa) +#' - qsurf: specific humidity at the surface (kg kg-1) +#' - rH_surf: relative humidity at the surface (-) +#' - Ca_surf: CO2 concentration at the surface (umol mol-1) #' #' ```@example; output = false #' ``` @@ -82,7 +83,8 @@ #' surface_conditions(Tair=25,pressure=100,LE=100,H=200,VPD=1.2,Ga=c(0.02,0.05,0.1), #' Ca=400,Ga_CO2=c(0.02,0.05,0.1),NEE=-20,calc_surface_CO2=TRUE) #' -#' @references Knauer, J. et al., 2018: Towards physiologically meaningful water-use efficiency estimates +#' #References +#' Knauer, J. et al., 2018: Towards physiologically meaningful water-use efficiency estimates #' from eddy covariance data. Global Change Biology 24, 694-710. #' #' Blanken, P_D. & Black, T_A., 2004: The canopy conductance of a boreal aspen forest, @@ -93,7 +95,7 @@ #' #' @export function surface_conditions(data,Tair="Tair",pressure="pressure",LE="LE",H="H", - VPD="VPD",Ga="Ga_h",calc_surface_CO2=FALSE,Ca="Ca",Ga_CO2="Ga_CO2", + VPD="VPD",Ga="Ga_h",calc_surface_CO2=false,Ca="Ca",Ga_CO2="Ga_CO2", NEE="NEE",Esat_formula=c("Sonntag_1990","Alduchov_1996","Allen_1998"), constants=bigleaf_constants()) @@ -141,17 +143,18 @@ end #' # Details CO2 concentration at the canopy surface is calculated as: #' -#' \deqn{Ca_surf = Ca + NEE / Ga_CO2} +#' ``Ca_surf = Ca + NEE / Ga_CO2`` #' #' Note that this equation can be used for any gas measured (with NEE #' replaced by the net exchange of the respective gas and Ga_CO2 by the Ga of #' that gas). #' -#' @note the following sign convention is employed: negative values of NEE denote +#' #Note +#' the following sign convention is employed: negative values of NEE denote #' net CO2 uptake by the ecosystem. #' #' # Value - \item{Ca_surf -}{CO2 concentration at the canopy surface (umol mol-1)} + - Ca_surf -: CO2 concentration at the canopy surface (umol mol-1) #' #' ```@example; output = false #' ``` @@ -180,18 +183,18 @@ end #' - LW_up Longwave upward radiation (W m-2) #' - LW_down Longwave downward radiation (W m-2) #' - emissivity Emissivity of the surface (-) -#' - constants sigma - Stefan-Boltzmann constant (W m-2 K-4) \cr +#' - constants sigma - Stefan-Boltzmann constant (W m-2 K-4) #' Kelvin - conversion degree Celsius to Kelvin #' #' # Details Radiometric surface temperature (Trad) is calculated as: #' -#' \deqn{Trad = ((LW_up - (1 - \epsilon)*LW_down) / (\sigma \epsilon))^(1/4)} +#' ``Trad = ((LW_up - (1 - \epsilon)*LW_down) / (\sigma \epsilon))^(1/4)`` #' #' # Value a DataFrame with the following columns: -#' \item{Trad_K}{Radiometric surface temperature (K)} \cr -#' \item{Trad_degC}{Radiometric surface temperature (degC)} +#' - Trad_K: Radiometric surface temperature (K) +#' - Trad_degC: Radiometric surface temperature (degC) #' #' ```@example; output = false #' ``` @@ -202,7 +205,8 @@ end #' Trad = radiometric_surface_temp(DE_Tha_Jun_2014,emissivity=0.98) #' summary(Trad) #' -#' @references Wang, W., Liang, S., Meyers, T. 2008: Validating MODIS land surface +#' #References +#' Wang, W., Liang, S., Meyers, T. 2008: Validating MODIS land surface #' temperature products using long-term nighttime ground measurements. #' Remote Sensing of Environment 112, 623-635. #' diff --git a/inst/fromR/surface_conductance.jl b/inst/fromR/surface_conductance.jl index 783fc3a..180eb77 100755 --- a/inst/fromR/surface_conductance.jl +++ b/inst/fromR/surface_conductance.jl @@ -17,32 +17,32 @@ #' - VPD Vapor pressure deficit (kPa) #' - Ga Aerodynamic conductance to heat/water vapor (m s-1) #' - missing_G_as_NA if `TRUE`, missing G are treated as `NA`s, otherwise they are set to 0. -#' Only used if `formulation = "Penman-Monteith"`. +#' Only used if `formulation = Val(:Penman-Monteith)`. #' - missing_S_as_NA if `TRUE`, missing S are treated as `NA`s, otherwise they are set to 0. -#' Only used if `formulation = "Penman-Monteith"`. -#' - formulation Formulation used. Either `"Penman-Monteith"` (the default) +#' Only used if `formulation = Val(:Penman-Monteith)`. +#' - formulation Formulation used. Either `Val(:Penman-Monteith)` (the default) #' using the inverted Penman-Monteith equation, or `"Flux-Gradient"`, #' for a simple flux-gradient approach requiring ET, pressure, and VPD only. #' - Esat_formula Optional: formula to be used for the calculation of esat and the slope of esat. #' One of `"Sonntag_1990"` (Default), `"Alduchov_1996"`, or `"Allen_1998"`. -#' Only used if `formulation = "Penman-Monteith"`. See `\link{Esat_slope`}. -#' - constants cp - specific heat of air for constant pressure (J K-1 kg-1) \cr -#' eps - ratio of the molecular weight of water vapor to dry air (-) \cr -#' Rd - gas constant of dry air (J kg-1 K-1) \cr -#' Rgas - universal gas constant (J mol-1 K-1) \cr -#' Kelvin - conversion degree Celsius to Kelvin \cr -#' Mw - molar mass of water vapor (kg mol-1) \cr +#' Only used if `formulation = Val(:Penman-Monteith)`. See [`Esat_slope`](@ref). +#' - constants cp - specific heat of air for constant pressure (J K-1 kg-1) +#' eps - ratio of the molecular weight of water vapor to dry air (-) +#' Rd - gas constant of dry air (J kg-1 K-1) +#' Rgas - universal gas constant (J mol-1 K-1) +#' Kelvin - conversion degree Celsius to Kelvin +#' Mw - molar mass of water vapor (kg mol-1) #' Pa2kPa - conversion pascal (Pa) to kilopascal (kPa) #' #' #' # Details - If `formulation = "Penman-Monteith"` (the default), surface conductance (Gs) in m s-1 + If `formulation = Val(:Penman-Monteith)` (the default), surface conductance (Gs) in m s-1 #' is calculated from the inverted Penman-Monteith equation: #' -#' \deqn{Gs = ( LE * Ga * \gamma ) / ( \Delta * A + \rho * cp * Ga * VPD - LE * ( \Delta + \gamma ) )} +#' ``Gs = ( LE * Ga * \\gamma ) / ( \\Delta * A + \\rho * cp * Ga * VPD - LE * ( \\Delta + \\gamma ) )`` #' -#' Where \eqn{\gamma} is the psychrometric constant (kPa K-1), \eqn{\Delta} is the slope of the -#' saturation vapor pressure curve (kPa K-1), and \eqn{\rho} is air density (kg m-3). +#' Where ``\\gamma`` is the psychrometric constant (kPa K-1), ``\\Delta`` is the slope of the +#' saturation vapor pressure curve (kPa K-1), and ``\\rho`` is air density (kg m-3). #' Available energy (A) is defined as A = Rn - G - S. If G and/or S are not provided, A = Rn. #' #' By default, any missing data in G and S are set to 0. If `missing_S_as_NA = TRUE` @@ -50,30 +50,30 @@ #' #' If `formulation="Flux-Gradient"`, Gs (in mol m-2 s-1) is calculated from VPD and ET only: #' -#' \deqn{Gs = ET/pressure * VPD} +#' ``Gs = ET/pressure * VPD`` #' #' where ET is in mol m-2 s-1. Note that this formulation assumes fully coupled conditions (i.e. Ga = inf). #' This formulation is equivalent to the inverted form of Eq.6 in McNaughton & Black 1973: #' -#' \deqn{Gs = LE * \gamma / (\rho * cp * VPD)} +#' ``Gs = LE * \\gamma / (\\rho * cp * VPD)`` #' #' which gives Gs in m s-1. Note that Gs > Gc (canopy conductance) under conditions #' when a significant fraction of ET comes from interception or soil evaporation. #' #' If `pressure` is not available, it can be approximated by elevation using the -#' function `\link{pressure_from_elevation`} +#' function [`pressure_from_elevation`](@ref) #' #' # Value a dataframe with the following columns: -#' \item{Gs_ms}{Surface conductance in m s-1} -#' \item{Gs_mol}{Surface conductance in mol m-2 s-1} +#' - Gs_ms: Surface conductance in m s-1 +#' - Gs_mol: Surface conductance in mol m-2 s-1 #' #' ```@example; output = false #' ``` #' ## filter data to ensure that Gs is a meaningful proxy to canopy conductance (Gc) -#' DE_Tha_Jun_2014_2 = filter_data(DE_Tha_Jun_2014,quality_control=FALSE, +#' DE_Tha_Jun_2014_2 = filter_data(DE_Tha_Jun_2014,quality_control=false, #' vars_qc=c("Tair","precip","VPD","H","LE"), -#' filter_growseas=FALSE,filter_precip=TRUE, +#' filter_growseas=false,filter_precip=TRUE, #' filter_vars=c("Tair","PPFD","ustar","LE"), #' filter_vals_min=c(5,200,0.2,0), #' filter_vals_max=c(NA,NA,NA,NA),NA_as_invalid=TRUE, @@ -95,7 +95,7 @@ #' # Note that Ga is not added to the DataFrame 'DE_Tha_Jun_2014' #' Gs_PM = surface_conductance(DE_Tha_Jun_2014_2,Tair="Tair",pressure="pressure", #' Rn="Rn",G="G",S=NULL,VPD="VPD",Ga=Ga, -#' formulation="Penman-Monteith") +#' formulation=Val(:Penman-Monteith)) #' summary(Gs_PM) #' #' @@ -103,11 +103,12 @@ #' DE_Tha_Jun_2014_2$Ga = Ga #' Gs_PM2 = surface_conductance(DE_Tha_Jun_2014_2,Tair="Tair",pressure="pressure", #' Rn="Rn",G="G",S=NULL,VPD="VPD",Ga="Ga", -#' formulation="Penman-Monteith") +#' formulation=Val(:Penman-Monteith)) #' # note the difference to the previous version (Ga="Ga") #' summary(Gs_PM2) #' -#' @references Monteith, J., 1965: Evaporation and environment. In Fogg, G. E. (Ed.), +#' #References +#' Monteith, J., 1965: Evaporation and environment. In Fogg, G. E. (Ed.), #' The state and movement of water in living organisms (pp.205-234). #' 19th Symp. Soc. Exp. Biol., Cambridge University Press, Cambridge #' @@ -118,8 +119,8 @@ """ """ function surface_conductance(data,Tair="Tair",pressure="pressure",Rn="Rn",G=NULL,S=NULL, - VPD="VPD",LE="LE",Ga="Ga_h",missing_G_as_NA=FALSE,missing_S_as_NA=FALSE, - formulation=c("Penman-Monteith","Flux-Gradient"), + VPD="VPD",LE="LE",Ga="Ga_h",missing_G_as_NA=false,missing_S_as_NA=false, + formulation=c(Val(:Penman-Monteith),"Flux-Gradient"), Esat_formula=c("Sonntag_1990","Alduchov_1996","Allen_1998"), constants=bigleaf_constants()) @@ -132,7 +133,7 @@ function surface_conductance(data,Tair="Tair",pressure="pressure",Rn="Rn",G=NULL Gs_mol = (LE_to_ET(LE,Tair)/constants[:Mw]) * pressure / VPD Gs_ms = mol_to_ms(Gs_mol,Tair,pressure) -else if (formulation == "Penman-Monteith") +else if (formulation == Val(:Penman-Monteith)) check_input(data,list(Tair,pressure,VPD,LE,Rn,Ga,G,S)) diff --git a/inst/fromR/surface_roughness.jl b/inst/fromR/surface_roughness.jl index 030ffe5..c6a2d34 100755 --- a/inst/fromR/surface_roughness.jl +++ b/inst/fromR/surface_roughness.jl @@ -10,21 +10,22 @@ #' - pressure Atmospheric pressure (kPa) #' - ustar Friction velocity (m s-1) #' - z0m Roughness length (m) -#' - constants Kelvin - conversion degree Celsius to Kelvin \cr -#' pressure0 - reference atmospheric pressure at sea level (Pa) \cr +#' - constants Kelvin - conversion degree Celsius to Kelvin +#' pressure0 - reference atmospheric pressure at sea level (Pa) #' Tair0 - reference air temperature (K) #' #' # Details The Roughness Reynolds Number is calculated as in Massman 1999a: #' -#' \deqn{Re = z0m * ustar / v} +#' ``Re = z0m * ustar / v`` #' #' where `v` is the kinematic viscosity (m2 s-1). #' #' # Value - \item{Re -}{Roughness Reynolds Number (-)} + - Re -: Roughness Reynolds Number (-) #' -#' @references Massman, W_J., 1999a: A model study of kB H- 1 for vegetated surfaces using +#' #References +#' Massman, W_J., 1999a: A model study of kB H- 1 for vegetated surfaces using #' 'localized near-field' Lagrangian theory. Journal of Hydrology 223, 27-43. #' #' ```@example; output = false @@ -48,7 +49,7 @@ end #' A simple approximation of the two roughness parameters displacement height (d) #' and roughness length for momentum (z0m). #' -#' - method Method to use, one of `"canopy_height","canopy_height&LAI","wind_profile"` \cr +#' - method Method to use, one of `"canopy_height","canopy_height&LAI","wind_profile"` #' NOTE: if `method = "canopy_height"`, only the following three arguments #' are used. If `method = "canopy_height&LAI"`, only `zh, LAI, cd`, #' and `hs` are required. @@ -72,10 +73,10 @@ end #' - stab_roughness Should stability correction be considered? Default is `TRUE`. #' - stab_formulation Stability correction function used (If `stab_correction = TRUE`). #' Either `"Dyer_1970"` or `"Businger_1971"`. -#' - constants k - von-Karman constant (-) \cr -#' Kelvin - conversion degree Celsius to Kelvin \cr -#' cp - specific heat of air for constant pressure (J K-1 kg-1) \cr -#' g - gravitational acceleration (m s-2) \cr +#' - constants k - von-Karman constant (-) +#' Kelvin - conversion degree Celsius to Kelvin +#' cp - specific heat of air for constant pressure (J K-1 kg-1) +#' g - gravitational acceleration (m s-2) #' se_median - conversion standard error (SE) of the mean to SE of the median #' #' @@ -85,9 +86,9 @@ end #' empirical relationships with canopy height (zh). If `method = "canopy_height"`, #' the following formulas are used: #' -#' \deqn{d = frac_d * zh} +#' ``d = frac_d * zh`` #' -#' \deqn{z0m = frac_z0m * zh} +#' ``z0m = frac_z0m * zh`` #' #' where frac_d defaults to 0.7 and frac_z0m to 0.1. #' @@ -96,35 +97,37 @@ end #' Based on data from Shaw & Pereira 1982, Choudhury & Monteith 1988 proposed #' the following semi-empirical relations: #' -#' \deqn{X = cd * LAI} +#' ``X = cd * LAI`` #' -#' \deqn{d = 1.1 * zh * ln(1 + X^(1/4))} +#' ``d = 1.1 * zh * ln(1 + X^(1/4))`` #' -#' \deqn{z0m = hs + 0.3 * zh * X^(1/2) for 0 <= X <= 0.2} +#' ``z0m = hs + 0.3 * zh * X^(1/2) for 0 <= X <= 0.2`` #' -#' \deqn{z0m = hs * zh * (1 - d/zh) for 0.2 < X} +#' ``z0m = hs * zh * (1 - d/zh) for 0.2 < X`` #' #' If `method = "wind_profile"`, z0m is estimated by solving #' the wind speed profile for z0m: #' -#' \deqn{z0m = median((zr - d) * exp(-k*wind / ustar - psi_m)} +#' ``z0m = median((zr - d) * exp(-k*wind / ustar - psi_m)`` #' #' By default, d in this equation is fixed to 0.7*zh, but can be set to any -#' other value. psi_m is 0 if `stab_roughness = FALSE`. +#' other value. psi_m is 0 if `stab_roughness = false`. #' #' # Value a DataFrame with the following columns: -#' \item{d}{Zero-plane displacement height (m)} -#' \item{z0m}{Roughness length for momentum (m)} -#' \item{z0m_se}{Only if `method = wind_profile`: Standard Error of the median for z0m (m)} +#' - d: Zero-plane displacement height (m) +#' - z0m: Roughness length for momentum (m) +#' - z0m_se: Only if `method = wind_profile`: Standard Error of the median for z0m (m) #' -#' @references Choudhury, B. J., Monteith J_L., 1988: A four-layer model for the heat +#' #References +#' Choudhury, B. J., Monteith J_L., 1988: A four-layer model for the heat #' budget of homogeneous land surfaces. Q. J. R. Meteorol. Soc. 114, 373-398. #' #' Shaw, R. H., Pereira, A., 1982: Aerodynamic roughness of a plant canopy: #' a numerical experiment. Agricultural Meteorology, 26, 51-65. #' -#' @seealso `\link{wind_profile`} +#' #See also +#' [`wind_profile`](@ref) #' #' ```@example; output = false #' ``` @@ -221,18 +224,18 @@ end #' - d Zero-plane displacement height (-) #' - frac_d Fraction of displacement height on canopy height (-); #' only used if `d` is not available -#' - z0m Roughness length (m), optional; only used if `stab_correction = FALSE` (default=0.1) +#' - z0m Roughness length (m), optional; only used if `stab_correction = false` (default=0.1) #' - frac_z0m Fraction of roughness length on canopy height (-), optional; only used if `z0m` is not provided. #' Default is 0.1. #' - estimate_z0m Should `z0m` be estimated from the logarithmic wind profile? If `TRUE` (the default), #' arguments `z0m` and `frac_z0m` are ignored. -#' See `\link{roughness_parameters`} for details. +#' See [`roughness_parameters`](@ref) for details. #' - stab_correction Should stability correction be applied? Defaults to `TRUE` #' - stab_formulation Stability correction function used (If `stab_correction = TRUE`). #' Either `"Dyer_1970"` or `"Businger_1971"`. -#' - constants k - von-Karman constant (-) \cr -#' Kelvin - conversion degree Celsius to Kelvin \cr -#' cp - specific heat of air for constant pressure (J K-1 kg-1) \cr +#' - constants k - von-Karman constant (-) +#' Kelvin - conversion degree Celsius to Kelvin +#' cp - specific heat of air for constant pressure (J K-1 kg-1) #' g - gravitational acceleration (m s-2) #' #' # Details @@ -241,28 +244,31 @@ end #' according to the Monin-Obhukov similarity theory). #' In this case, the wind speed at a given height z is given by: #' -#' \deqn{u(z) = (ustar/k) * (ln((z - d) / z0m) - \psi{m}} +#' ``u(z) = (ustar/k) * (ln((z - d) / z0m) - \psi{m``} #' #' The roughness parameters zero-plane displacement height (d) and roughness length (z0m) -#' can be approximated from `\link{roughness_parameters`}. \eqn{\psi{m}} is omitted -#' if `stab_correction = FALSE` (not recommended). If `estimate_z0m = TRUE`, +#' can be approximated from [`roughness_parameters`](@ref). ``\psi{m``} is omitted +#' if `stab_correction = false` (not recommended). If `estimate_z0m = TRUE`, #' z0m is first estimated from the wind profile equation and then used in the equation #' above for the calculation of `u(z)` (see e.g. Newman & Klein 2014). #' -#' @note Note that this equation is only valid for z >= d + z0m, and it is not +#' #Note +#' Note that this equation is only valid for z >= d + z0m, and it is not #' meaningful to calculate values closely above d + z0m. All values in `heights` #' smaller than d + z0m will return 0. #' #' # Value A vector of wind speed at heights `z`. #' -#' @references Monteith, J_L., Unsworth, M_H., 2008: Principles of Environmental Physics. +#' #References +#' Monteith, J_L., Unsworth, M_H., 2008: Principles of Environmental Physics. #' 3rd edition. Academic Press, London. #' #' Newman, J_F., Klein, P_M., 2014: The impacts of atmospheric stability on #' the accuracy of wind speed extrapolation methods. Resources 3, 81-105. #' -#' @seealso `\link{roughness_parameters`} +#' #See also +#' [`roughness_parameters`](@ref) #' #' ```@example; output = false #' ``` @@ -294,7 +300,7 @@ end if (is_null(z0m) & !estimate_z0m) if (is_null(frac_z0m)) - stop("Either 'z0m' or 'frac_z0m' must be specified if 'estimate_z0m' = FALSE") + stop("Either 'z0m' or 'frac_z0m' must be specified if 'estimate_z0m' = false") end z0m = frac_z0m * zh end diff --git a/inst/fromR/unit_conversions.jl b/inst/fromR/unit_conversions.jl index 66d1273..2349213 100755 --- a/inst/fromR/unit_conversions.jl +++ b/inst/fromR/unit_conversions.jl @@ -17,12 +17,12 @@ #' The conversions are given by: #' -#' \deqn{ET = LE/\lambda} +#' ``ET = LE/\\lambda`` #' -#' \deqn{LE = \lambda ET} +#' ``LE = \\lambda ET`` #' -#' where \eqn{\lambda} is the latent heat of vaporization (J kg-1) as calculated by -#' `\link{latent_heat_vaporization`}. +#' where ``\\lambda`` is the latent heat of vaporization (J kg-1) as calculated by +#' [`latent_heat_vaporization`](@ref). #' #' ```@example; output = false #' ``` @@ -64,21 +64,22 @@ end #' - G_mol Conductance (mol m-2 s-1) #' - Tair Air temperature (deg C) #' - pressure Atmospheric pressure (kPa) -#' - constants Kelvin - conversion degree Celsius to Kelvin \cr -#' Rgas - universal gas constant (J mol-1 K-1) \cr +#' - constants Kelvin - conversion degree Celsius to Kelvin +#' Rgas - universal gas constant (J mol-1 K-1) #' kPa2Pa - conversion kilopascal (kPa) to pascal (Pa) #' #' # Details #' The conversions are given by: #' -#' \deqn{G_mol = G_ms * pressure / (Rgas * Tair)} +#' ``G_mol = G_ms * pressure / (Rgas * Tair)`` #' -#' \deqn{G_ms = G_mol * (Rgas * Tair) / pressure} +#' ``G_ms = G_mol * (Rgas * Tair) / pressure`` #' #' where Tair is in Kelvin and pressure in Pa (converted from kPa internally) #' -#' @references Jones, H_G. 1992. Plants and microclimate: a quantitative approach to environmental plant physiology. +#' #References +#' Jones, H_G. 1992. Plants and microclimate: a quantitative approach to environmental plant physiology. #' 2nd Edition., Cambridge University Press, Cambridge. 428 p #' #' ```@example; output = false @@ -126,13 +127,14 @@ end #' - rH Relative humidity (-) #' - Esat_formula Optional: formula to be used for the calculation of esat and the slope of esat. #' One of `"Sonntag_1990"` (Default), `"Alduchov_1996"`, or `"Allen_1998"`. -#' See `\link{Esat_slope`}. -#' - constants eps - ratio of the molecular weight of water vapor to dry air (-) \cr +#' See [`Esat_slope`](@ref). +#' - constants eps - ratio of the molecular weight of water vapor to dry air (-) #' Pa2kPa - conversion pascal (Pa) to kilopascal (kPa) #' #' @family humidity conversion #' -#' @references Foken, T, 2008: Micrometeorology. Springer, Berlin, Germany. +#' #References +#' Foken, T, 2008: Micrometeorology. Springer, Berlin, Germany. #' """ """ @@ -271,7 +273,7 @@ end #' The conversion is given by: #' -#' \deqn{PPFD = Rg * frac_PAR * J_to_mol} +#' ``PPFD = Rg * frac_PAR * J_to_mol`` #' #' by default, the combined conversion factor (`frac_PAR * J_to_mol`) is 2.3 #' @@ -308,7 +310,7 @@ end #' #' - mass Numeric vector of mass in kg #' - molarMass Numeric vector of molar mass of the substance (kg mol-1) -#' e.g. as provided by `\link{bigleaf_constants`}()$H2Omol +#' e.g. as provided by [`bigleaf_constants`](@ref)()$H2Omol #' Default is molar mass of Water. #' #' # Value @@ -332,11 +334,11 @@ end #' #' - CO2_flux CO2 flux (umol CO2 m-2 s-1) #' - C_flux Carbon (C) flux (gC m-2 d-1) -#' - constants Cmol - molar mass of carbon (kg mol-1) \cr -#' umol2mol - conversion micromole (umol) to mol (mol) \cr -#' mol2umol - conversion mole (mol) to micromole (umol) \cr -#' kg2g - conversion kilogram (kg) to gram (g) \cr -#' g2kg - conversion gram (g) to kilogram (kg) \cr +#' - constants Cmol - molar mass of carbon (kg mol-1) +#' umol2mol - conversion micromole (umol) to mol (mol) +#' mol2umol - conversion mole (mol) to micromole (umol) +#' kg2g - conversion kilogram (kg) to gram (g) +#' g2kg - conversion gram (g) to kilogram (kg) #' days2seconds - seconds per day #' #' ```@example; output = false diff --git a/inst/walkthrough_todo.jmd b/inst/walkthrough_todo.jmd index 0f2c735..85b7d67 100644 --- a/inst/walkthrough_todo.jmd +++ b/inst/walkthrough_todo.jmd @@ -11,7 +11,7 @@ that accept a DataFrame with columnnames corresponding to required arguments. We can demonstrate the usage with a simple example: ```julia -potential_ET(tha,Tair="Tair",pressure="pressure",Rn="Rn",VPD="VPD",approach="Priestley-Taylor") +potential_ET(tha,Tair="Tair",pressure="pressure",Rn="Rn",VPD="VPD",approach=Val(:Priestley-Taylor)) potential_ET(tha) potential_ET(tha,Tair=tha$Tair) potential_ET(tha,Tair=25) @@ -61,7 +61,7 @@ In the function call above, `vars_qc` lists the variables that should be filtere In the next example, we filter for meteorological conditions only, including growing season (`filter_growseas=TRUE`): ```julia -tha_filtered2 = filter_data(tha,quality_control=FALSE,filter_growseas=TRUE, +tha_filtered2 = filter_data(tha,quality_control=false,filter_growseas=TRUE, filter_vars=c("PPFD","ustar","LE","VPD"), filter_vals_min=c(200,0.2,0,0.01), filter_vals_max=c(NA,NA,NA,NA), NA_as_invalid = TRUE, @@ -78,7 +78,7 @@ In this case, it does not really make sense to filter for growing season, since As a last step we will filter for precipitation events. This is often meaningful for ecophysiological studies because data during and shortly after rainfall events do not contain much information on the physiological activity of the vegetation (i.e. they comprise significant fractions of evaporation from the soil and plant surfaces). The purpose of such a filter is mostly to minimize the fraction of soil and interception evaporation on the total water flux. This filter simply excludes periods following a precipitation event. A precipitation event is here defined as any time step with a recorded precipitation higher than `tprecip` (in mm per timestep). The function then filters all time periods following a precipitation event. The number of subsequent time periods excluded is controlled by the argument `precip_hours`. Here, we exclude rainfall events and the following 24 hours. ```julia -tha_filtered3 = filter_data(tha,quality_control=FALSE,filter_growseas=FALSE, +tha_filtered3 = filter_data(tha,quality_control=false,filter_growseas=false, filter_precip=TRUE,precip="precip",tprecip=0.02, records_per_hour=2,precip_hours=24) ``` @@ -267,8 +267,8 @@ Here, the points denote the mean wind speed and the bars denote the standard dev For many hydrological applications, it is relevant to get an estimate on the potential evapotranspiration (PET). At the moment, the `Bigleaf.jl` package contains two formulations for the estimate of PET: the Priestley-Taylor equation, and the Penman-Monteith equation: ```julia -summary(potential_ET(tha_filtered,G="G",approach="Priestley-Taylor")) -summary(potential_ET(tha_filtered,G="G",approach="Penman-Monteith"), +summary(potential_ET(tha_filtered,G="G",approach=Val(:Priestley-Taylor))) +summary(potential_ET(tha_filtered,G="G",approach=Val(:Penman-Monteith)), Gs_pot=quantile(tha_filtered$Gs_mol,0.95,na_rm=TRUE)) ``` @@ -480,7 +480,7 @@ unc_all = mapply(aerodynamic_conductance,Dl=Dl_sample,z0m=z0m_sample,LAI=LAI_sam ) # select "Ga_h" output variable and convert to matrix -unc_Ga_h = matrix(unlist(unc_all["Ga_h",]),ncol=n_pert,byrow=FALSE) +unc_Ga_h = matrix(unlist(unc_all["Ga_h",]),ncol=n_pert,byrow=false) # calculate 2.5th, 50th, and 97.5th quantile of the n_pert calculations for every timestep Ga_low = apply(unc_Ga_h,1,quantile,0.025,na_rm=T) diff --git a/src/Bigleaf.jl b/src/Bigleaf.jl index 4387caa..83b7c99 100644 --- a/src/Bigleaf.jl +++ b/src/Bigleaf.jl @@ -8,7 +8,7 @@ using Dates, TimeZones using Pipe using AstroLib using Suppressor - +using Missings export toDataFrame, frac_hour @@ -23,6 +23,7 @@ export air_density, pressure_from_elevation, psychrometric_constant, wetbulb_temp_from_e_Tair_gamma, wetbulb_temp export calc_sun_position_MOD, calc_sun_position_hor export potential_radiation, extraterrestrial_radiation, get_datetime_for_doy_hour +export potential_ET include("util.jl") include("bigleaf_constants.jl") @@ -30,5 +31,6 @@ include("unit_conversions.jl") include("meteorological_variables.jl") include("sun_position.jl") include("potential_radiation.jl") +include("evapotranspiration.jl") end diff --git a/src/evapotranspiration.jl b/src/evapotranspiration.jl new file mode 100755 index 0000000..9fc7107 --- /dev/null +++ b/src/evapotranspiration.jl @@ -0,0 +1,223 @@ +""" +Potential Evapotranspiration + +Potential evapotranspiration according to Priestley & Taylor 1972 or + the Penman-Monteith equation with a prescribed surface conductance. + +# Arguments +- data: Data_frame or matrix containing all required variables; optional +- Tair: Air temperature (degC) +- pressure: Atmospheric pressure (kPa) +- Rn: Net radiation (W m-2) +- G: Ground heat flux (W m-2); optional +- S: Sum of all storage fluxes (W m-2); optional +- VPD: Vapor pressure deficit (kPa); only used if `approach = Val(:Penman-Monteith)`. +- Ga: Aerodynamic conductance to heat/water vapor (m s-1); only used if `approach = Val(:Penman-Monteith)`. +- approach: Approach used. Either `Val(:Priestley-Taylor)` (default), or `Val(:Penman-Monteith)`. +- alpha: Priestley-Taylor coefficient; only used if `approach = Val(:Priestley-Taylor)`. +- Gs_pot: Potential/maximum surface conductance (mol m-2 s-1); defaults to 0.6 mol m-2 s-1; + only used if `approach = Val(:Penman-Monteith)`. +- missing_G_as_NA: if `TRUE`, missing G are treated as `NA`s, otherwise set to 0. +- missing_S_as_NA: if `TRUE`, missing S are treated as `NA`s, otherwise set to 0. +- Esat_formula: Optional: formula to be used for the calculation of esat and the slope of esat. + One of `"Sonntag_1990"` (Default), `"Alduchov_1996"`, or `"Allen_1998"`. + See [`Esat_slope`](@ref). +- `constants=`[`bigleaf_constants`](@ref)`()`: Dictionary with entries + - cp - specific heat of air for constant pressure (J K-1 kg-1) + - eps - ratio of the molecular weight of water vapor to dry air + - Pa2kPa - conversion pascal (Pa) to kilopascal (kPa) + - Rd - gas constant of dry air (J kg-1 K-1) (only used if `approach = Val(:Penman-Monteith)`) + - Rgas - universal gas constant (J mol-1 K-1) (only used if `approach = Val(:Penman-Monteith)`) + - Kelvin - conversion degree Celsius to Kelvin (only used if `approach = Val(:Penman-Monteith)`) + +# Details +Potential evapotranspiration is calculated according to Priestley & Taylor, 1972 +if `approach = Val(:Priestley-Taylor)` (the defau +``LE_pot,PT = (\\alpha * \\Delta * (Rn - G - S)) / (\\Delta + \\gamma)`` + +``\\alpha`` is the Priestley-Taylor coefficient, ``\\Delta`` is the slope +of the saturation vapor pressure curve (kPa K-1), and ``\\gamma`` is the +psychrometric constant (kPa K-1). +if `approach = Val(:Penman-Monteith)`, potential evapotranspiration is calculated according +to the Penman-Monteith equat + +``LE_pot,PM = (\\Delta * (Rn - G - S) + \\rho * cp * VPD * Ga) / (\\Delta + \\gamma * (1 + Ga/Gs_pot)`` + +where ``\\Delta`` is the slope of the saturation vapor pressure curve (kPa K-1), +``\\rho`` is the air density (kg m-3), and ``\\gamma`` is the psychrometric constant (kPa K-1). +The value of `Gs_pot` is typically a maximum value of Gs observed at the site, e.g. the 90th +percentile of Gs within the growing season. + +# Value +a DataFrame with the following columns: +- ET_pot: Potential evapotranspiration (kg m-2 s-1) +- LE_pot: Potential latent heat flux (W m-2) + +# Note +If the first argument `data` is provided (either a matrix or a DataFrame), +the following variables can be provided as character (in which case they are interpreted as +the column name of `data`) or as numeric vectors, in which case they are taken +directly for the calculations. If `data` is not provided, all input variables have to be +numeric vectors. + +# References +Priestley, C_H_B., Taylor, R_J., 1972: On the assessment of surface heat flux +and evaporation using large-scale parameters. Monthly Weather Review 100, 81-92. + +Allen, R_G., Pereira L_S., Raes D., Smith M., 1998: Crop evapotranspiration - +Guidelines for computing crop water requirements - FAO Irrigation and drainage +paper 56. + +Novick, K_A., et al. 2016: The increasing importance of atmospheric demand +for ecosystem water and carbon fluxes. Nature Climate Change 6, 1023 - 1027. + +# See also +[`surface_conductance`](@ref) + +```@example; output = false +# Calculate potential ET of a surface that receives a net radiation of 500 Wm-2 +# using Priestley-Taylor: +potential_ET(Tair=30,pressure=100,Rn=500,alpha=1.26,approach=Val(:Priestley-Taylor)) + +# Calculate potential ET for a surface with known Gs (0.5 mol m-2 s-1) and Ga (0.1 m s-1) +# using Penman-Monteith: +LE_pot_PM = potential_ET(Gs_pot=0.5,Tair=20,pressure=100,VPD=2,Ga=0.1,Rn=400, + approach=Val(:Penman-Monteith))[,"LE_pot"] +LE_pot_PM + +# now cross-check with the inverted equation +surface_conductance(Tair=20,pressure=100,VPD=2,Ga=0.1,Rn=400,LE=LE_pot_PM) +``` +""" +function potential_ET(Tair,pressure,Rn, VPD,Ga; + G=missing,S=missing, approach=Val(:Priestley-Taylor), + alpha=1.26,Gs_pot=0.6, + missing_G_as_NA=false, missing_S_as_NA=false, + Esat_formula=Val(:Sonntag_1990), + constants=bigleaf_constants()) + + #TODO check_input(data,list(Tair,pressure,Rn,G,S)) + G,S = deal_GS_missings(G,S,missing_G_as_NA, missing_S_as_NA) + gamma = psychrometric_constant(Tair,pressure,constants) + Delta = Esat_from_Tair_deriv(Tair; formula = Esat_formula,constants) + # TODO replace by dispatch + if (approach == Val(:Priestley-Taylor)) + LE_pot = (alpha * Delta * (Rn - G - S)) / (Delta + gamma) + ET_pot = LE_to_ET(LE_pot,Tair) + elseif (approach == Val(:Penman-Monteith)) + #TODO check_input(data,list(Gs_pot,VPD,Ga)) + Gs_pot = mol_to_ms(Gs_pot,Tair,pressure;constants) + rho = air_density(Tair,pressure;constants) + LE_pot = (Delta * (Rn - G - S) + rho * constants[:cp] * VPD * Ga) / + (Delta + gamma * (1 + Ga / Gs_pot)) + ET_pot = LE_to_ET(LE_pot,Tair) + end + @suppress_err SLVector(ET_pot = ET_pot, LE_pot = LE_pot) +end + + +""" + TODO + +Evapotranspiration (ET) split up into imposed ET and equilibrium ET. + +- Tair: Air temperature (deg C) +- pressure: Atmospheric pressure (kPa) +- VPD: Air vapor pressure deficit (kPa) +- Gs: surface conductance to water vapor (m s-1) +- Rn: Net radiation (W m-2) +- G: Ground heat flux (W m-2); optional +- S: Sum of all storage fluxes (W m-2); optional +- missing_G_as_NA: if `TRUE`, missing G are treated as `NA`s, otherwise set 0. +- missing_S_as_NA: if `TRUE`, missing S are treated as `NA`s, otherwise set 0. +- Esat_formula: Optional: formula to be used for the calculation of esat and slope of esat. + One of `"Sonntag_1990"` (Default), `"Alduchov_1996"`, `"Allen_1998"`. + See [`Esat_slope`](@ref). +- `constants=`[`bigleaf_constants`](@ref)`()`: Dictionary with entries + +- constants + - cp - specific heat of air for constant pressure (J K-1 kg-1) + - eps - ratio of the molecular weight of water vapor to dry (-) + - Pa2kPa - conversion pascal (Pa) to kilopascal (kPa) + +# Details +Total evapotranspiration can be written in the form (Jarvis & McNaughton 6): + +``ET = \\Omega ET_eq + (1 - \\Omega)ET_imp`` + +where ``\\Omega`` is the decoupling coefficient as calculated from +[`decoupling`](@ref). `ET_eq` is the equilibrium evapotranspiration e, +the ET rate that would occur under uncoupled conditions, where tbudget +is dominated by radiation (when Ga -> 0): + + ``ET_eq = (\\Delta * (Rn - G - S) * \\lambda) / (\\Del\\gamma) + +where ``\\Delta`` is the slope of the saturation vapor pressur(kPa K-1), +``\\lambda`` is the latent heat of vaporization (J kg-1), and \\gamma`` +is the psychrometric constant (kPa K-1). +`ET_imp` is the imposed evapotranspiration rate, the ET rate +that would occur under fully coupled conditions (when Ga -> inf): + + ``ET_imp = (\\rho * cp * VPD * Gs * \\lambda) / \\gamma`` + +where ``\\rho`` is the air density (kg m-3). + +#Note +Surface conductance (Gs) can be calculated with [`surface_conductance`](@ref) +Aerodynamic conductance (Ga) can be calculated using erodynamic_conductance`](@ref). + +# Value +A DataFrame with the following columns: +- ET_eq: Equilibrium ET (kg m-2 s-1) +- ET_imp: Imposed ET (kg m-2 s-1) +- LE_eq: Equilibrium LE (W m-2) +- LE_imp: Imposed LE (W m-2) + +#References +- Jarvis, P_G., McNaughton, K_G., 1986: Stomatal control of transpiration: +scaling up from leaf to region. Advances in Ecological Rese1-49. +- Monteith, J_L., Unsworth, M_H., 2008: Principles of ironmPhysics. +3rd edition. Academic Press, London. + +#See also +[`decoupling`](@ref) + +```@example; output = false +df = DataFrame(Tair=20,pressure=100,VPD=seq(0.5,4,0.5), + Gs_ms=seq(0.01,0.002,length_out=8),Rn=seq(50,400,50) +equilibrium_imposed_ET(df) +``` +""" +function equilibrium_imposed_ET(Tair,pressure,VPD,Gs, Rn, + G=NULL,S=NULL,missing_G_as_NA=false,missing_S_as_NA=false, + Esat_formula=Val(:Sonntag_1990), + constants=bigleaf_constants()) + # + #check_input(data,list(Tair,pressure,VPD,Rn,Gs,G,S)) + G,S = deal_GS_missings(G,S,missing_G_as_NA, missing_S_as_NA) + rho = air_density(Tair,pressure,constants) + gamma = psychrometric_constant(Tair,pressure,constants) + Delta = Esat_from_Tair_deriv(Tair,Esat_formula,constants) + LE_eq = (Delta * (Rn - G - S)) / (gamma + Delta) + LE_imp = (rho * constants[:cp] * Gs * VPD) / gamma + # + ET_imp = LE_to_ET(LE_imp,Tair) + ET_eq = LE_to_ET(LE_eq,Tair) + @suppress_err SLVector(ET_pot = ET_pot, LE_pot = LE_pot, LE_imp = LE_imp) +end + +function deal_GS_missings(G,S,missing_G_as_NA, missing_S_as_NA) + if ismissing(G) + @info("Ground heat flux G is not provided and set to 0.") + G = 0 + elseif missing_G_as_NA == false + G = coalesce(G, 0) + end + if ismissing(S) + @info("Energy storage fluxes S are not provided and set to 0.") + S = 0 + elseif missing_S_as_NA false + S = coalesce(S, 0) + end + G,S +end From e1de84a45b340b4fef73f8371af13f857c312f67 Mon Sep 17 00:00:00 2001 From: Thomas Wutzler Date: Sun, 24 Oct 2021 20:30:09 +0200 Subject: [PATCH 06/13] return NamedTuple instead of SLVector --- docs/src/walkthrough.md | 2 +- src/evapotranspiration.jl | 4 ++-- src/sun_position.jl | 4 ++-- test/sun_position.jl | 8 ++++---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/src/walkthrough.md b/docs/src/walkthrough.md index 2d75d85..67e5216 100644 --- a/docs/src/walkthrough.md +++ b/docs/src/walkthrough.md @@ -157,7 +157,7 @@ lat,long = 51.0, 13.6 # Dresden Germany #deg2second = 24*3600/360 doy = 160 datetimes = DateTime(2021) .+Day(doy-1) .+ Hour.(hours) #.- Second(round(long*deg2second)) -res3 = @suppress_err @pipe calc_sun_position_hor.(datetimes, lat, long) |> toDataFrame(_) +res3 = @suppress_err @pipe calc_sun_position_hor.(datetimes, lat, long) |> DataFrame(_) @df res3 scatter(datetimes, cols([:altitude,:azimuth]), legend = :topleft, xlab="Date and Time", ylab = "rad") ``` diff --git a/src/evapotranspiration.jl b/src/evapotranspiration.jl index 9fc7107..77e4bd5 100755 --- a/src/evapotranspiration.jl +++ b/src/evapotranspiration.jl @@ -112,7 +112,7 @@ function potential_ET(Tair,pressure,Rn, VPD,Ga; (Delta + gamma * (1 + Ga / Gs_pot)) ET_pot = LE_to_ET(LE_pot,Tair) end - @suppress_err SLVector(ET_pot = ET_pot, LE_pot = LE_pot) + (ET_pot = ET_pot, LE_pot = LE_pot) end @@ -203,7 +203,7 @@ function equilibrium_imposed_ET(Tair,pressure,VPD,Gs, Rn, # ET_imp = LE_to_ET(LE_imp,Tair) ET_eq = LE_to_ET(LE_eq,Tair) - @suppress_err SLVector(ET_pot = ET_pot, LE_pot = LE_pot, LE_imp = LE_imp) + (ET_pot = ET_pot, LE_pot = LE_pot, LE_imp = LE_imp) end function deal_GS_missings(G,S,missing_G_as_NA, missing_S_as_NA) diff --git a/src/sun_position.jl b/src/sun_position.jl index 6980c78..d04cfe2 100644 --- a/src/sun_position.jl +++ b/src/sun_position.jl @@ -25,7 +25,7 @@ function calc_sun_position_hor(datetime::DateTime, lat, long) pos_eq = calc_sun_position_MOD(jd) # precession is already account for in MOD pos_hor = eq2hor(pos_eq.α/deg2rad, pos_eq.δ/deg2rad, jd, lat, long; precession = false) .* deg2rad - @suppress_err SLVector(altitude = pos_hor[1], azimuth = pos_hor[2], hourangle = pos_hor[3]) + (altitude = pos_hor[1], azimuth = pos_hor[2], hourangle = pos_hor[3]) end @@ -132,7 +132,7 @@ function calc_sun_position_MOD(JD::Number) # declination δ = asin(sinϵ * sinλ_e) - @suppress_err S_MOD_rad = SLVector( + S_MOD_rad = ( λ = λ_e, β = 0.0, r = r, α = α, δ = δ, ϵ = ϵ diff --git a/test/sun_position.jl b/test/sun_position.jl index ac27605..2a8b00b 100644 --- a/test/sun_position.jl +++ b/test/sun_position.jl @@ -3,7 +3,7 @@ lat,long = 0.0,0.0 deg2second = 24*3600/360 datetimes = DateTime(2021,3,20) .+ Hour.(hours) .- Second(round(long*deg2second)) - res2 = @pipe calc_sun_position_MOD.(datetime2julian.(datetimes)) |> toDataFrame(_) + res2 = @pipe calc_sun_position_MOD.(datetime2julian.(datetimes)) |> DataFrame(_) # latitude over ecliptic of sun is zero @test all(res2.β .≈ 0.0) au2m = 149597870700.0 @@ -21,14 +21,14 @@ # @df res3 scatter(hours, cols(1:2), legend = :topleft, xlab="hours") # end # - res3 = @pipe calc_sun_position_hor.(datetimes, lat, long) |> toDataFrame(_) + res3 = @pipe calc_sun_position_hor.(datetimes, lat, long) |> DataFrame(_) # altitude (-pi, +pi) @test minimum(res3.altitude) ≈ -π/2 atol = 0.1 @test maximum(res3.altitude) ≈ +π/2 atol = 0.1 # lat,long = 45.0,0.0 datetimes = DateTime(2021,3,20) .+ Hour.(hours) .- Second(round(long*deg2second)) - res3 = @pipe calc_sun_position_hor.(datetimes, lat, long) |> toDataFrame(_) + res3 = @pipe calc_sun_position_hor.(datetimes, lat, long) |> DataFrame(_) # altitude (-pi, +pi) @test minimum(res3.altitude) ≈ -π/4 atol = 0.1 @test maximum(res3.altitude) ≈ +π/4 atol = 0.1 @@ -48,7 +48,7 @@ end # @df res3 scatter(hours, cols(1:2), legend = :topleft, xlab="hours") # end # - res3 = @pipe calc_sun_position_hor.(datetimes, lat, long) |> toDataFrame(_) + res3 = @pipe calc_sun_position_hor.(datetimes, lat, long) |> DataFrame(_) # maximum altitude at noon @test argmax(res3.altitude) == 1 + (length(hours)-1) ÷ 2 # azimuth increasing (aside edge cases) From a8b9982d1a1f67a9ada60acfe82e08f456ab2a7b Mon Sep 17 00:00:00 2001 From: Thomas Wutzler Date: Mon, 25 Oct 2021 22:51:25 +0200 Subject: [PATCH 07/13] implement DataFrame variants of potential_ET --- Project.toml | 1 + docs/make.jl | 2 + docs/src/evapotranspiration.md | 11 + docs/src/index.md | 5 + docs/src/walkthrough.md | 39 ++- inst/fromR/WUE_metrics.jl | 2 +- inst/fromR/aerodynamic_conductance.jl | 2 +- inst/fromR/bigleaf_physiology.jl | 10 +- inst/fromR/boundary_layer_conductance.jl | 4 +- inst/fromR/check_input.jl | 4 +- inst/fromR/datasets_description.jl | 6 +- inst/fromR/evapotranspiration.jl | 42 +-- inst/fromR/filter_data.jl | 2 +- inst/fromR/meteorological_variables.jl | 6 +- inst/fromR/stability_correction.jl | 2 +- inst/fromR/surface_conditions.jl | 4 +- inst/fromR/surface_conductance.jl | 18 +- inst/fromR/surface_roughness.jl | 2 +- inst/walkthrough_todo.jmd | 6 +- src/Bigleaf.jl | 7 +- src/evapotranspiration.jl | 318 +++++++++++++++++------ src/sun_position.jl | 4 +- src/util.jl | 24 +- test/evapotranspiration.jl | 46 ++++ test/runtests.jl | 3 + 25 files changed, 410 insertions(+), 160 deletions(-) create mode 100644 docs/src/evapotranspiration.md create mode 100644 test/evapotranspiration.jl diff --git a/Project.toml b/Project.toml index 2c4176b..468ddf1 100644 --- a/Project.toml +++ b/Project.toml @@ -7,6 +7,7 @@ version = "0.1.0" AstroLib = "c7932e45-9af1-51e7-9da9-f004cd3a462b" DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" +FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b" LabelledArrays = "2ee39098-c373-598a-b85f-a56591580800" Missings = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" Optim = "429524aa-4258-5aef-a3af-852621145aeb" diff --git a/docs/make.jl b/docs/make.jl index 1c5b753..33dcbda 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -13,6 +13,7 @@ makedocs(; authors="Thomas Wutzler . Jürgen Knauer and contributors", repo="https://github.com/bgctw/Bigleaf.jl/blob/{commit}{path}#{line}", sitename="Bigleaf.jl", + doctestfilters=[r".*Info.*"], format=Documenter.HTML(; prettyurls=get(ENV, "CI", "false") == "true", canonical="https://bgctw.github.io/Bigleaf.jl", @@ -24,6 +25,7 @@ makedocs(; #"Unit conversions" => "unit_conversions.md", "Walkthrough" => "walkthrough.md", hide("metorological_variables.md"), + hide("evapotranspiration.md"), hide("global_radiation.md"), hide("unit_conversions.md"), hide("bigleaf_constants.md"), diff --git a/docs/src/evapotranspiration.md b/docs/src/evapotranspiration.md new file mode 100644 index 0000000..fc755c6 --- /dev/null +++ b/docs/src/evapotranspiration.md @@ -0,0 +1,11 @@ +## Evapotranspiration +```@index +Pages = ["evapotranspiration.md",] +``` + +```@docs +potential_ET +equilibrium_imposed_ET +fill_GS_missings! +surface_conductance +``` \ No newline at end of file diff --git a/docs/src/index.md b/docs/src/index.md index 6aaf4a9..2925b20 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -13,6 +13,11 @@ Pages = ["index.md",] Pages = ["metorological_variables.md",] ``` +## Evapotranspiration +```@index +Pages = ["evapotranspiration.md",] +``` + ## Global radiation ```@index Pages = ["global_radiation.md",] diff --git a/docs/src/walkthrough.md b/docs/src/walkthrough.md index 67e5216..e6004f6 100644 --- a/docs/src/walkthrough.md +++ b/docs/src/walkthrough.md @@ -70,9 +70,44 @@ There are a few general guidelines that are important to consider when using the ## Units -It is imperative that variables are provided in the right units, as the plausibility of the input units is not checked in most cases. The required units of the input arguments can be found in the respective help file of the function. The good news is that units do not change across functions. For example, pressure is always required in kPa, and temperature always in °c. +It is imperative that variables are provided in the right units, as the plausibility of +the input units is not checked in most cases. The required units of the input arguments +can be found in the respective help file of the function. The good news is that units +do not change across functions. For example, pressure is always required in kPa, +and temperature always in °c. + +## Function arguments + +Most functions of `Bigleaf.jl` require a DataFrame, from which the required +variables are extracted. This is usually the first argument of a function. +Most functions further provide default values for their arguments, +such that in many cases it is not necessary to provide them explicitly. + +The column names in the DataFrame should correspond to the argument names +of the corresponding method that accespts each input individually. + +We can demonstrate the usage with a simple example: + +```@example doc +# explicit inputs +Tair, pressure, Rn, = 14.81, 97.71, 778.17 +potential_ET(Tair, pressure, Rn, Val(:PriestleyTaylor)) +# DataFrame +potential_ET(tha, Val(:PriestleyTaylor)) +# DataFrame with a few columns overwritten by user values +potential_ET(transform(tha, :Tair => x -> 25.0; renamecols=false), Val(:PriestleyTaylor)) +# varying one input only +Tair_vec = 10.0:1.0:20.0 +DataFrame(potential_ET.(Tair_vec, pressure, Rn, Val(:PriestleyTaylor); infoGS=false)) +nothing # hide +``` + +## Ground heat flux and storage fluxes + +Many functions require the available energy ($A$), which is defined as ($A = R_n - G - S$, all in $\text{W m}^{-2}$), where $R_n$ is the net radiation, $G$ is the ground heat flux, and $S$ is the sum of all storage fluxes of the ecosystem (see e.g. Leuning et al. 2012 for an overview). For some sites, $G$ is not available, and for most sites, only a few components of $S$ are measured. In `Bigleaf.jl` it is not a problem if $G$ and/or $S$ are missing (other than the results might be (slightly) biased), but special options exist for the treatment of missing $S$ and $G$ values. If the options `missing_G_as_NA = TRUE` or `missing_S_as_NA = TRUE`, then the output variable is not calculated for that time period. Otherwise missing $S$ and $G$ values are set to O automatically. Please note that the default is to ignore $S$ and $G$ values. If $G$ and/or $S$ are available, they usually have to be added explicitly to the function call by explicitly using the optional arguments. The positional forms do not check for missing +values. -## TODO ## +# Function walkthrough # ## Meteorological variables diff --git a/inst/fromR/WUE_metrics.jl b/inst/fromR/WUE_metrics.jl index 227f4be..0c521c6 100755 --- a/inst/fromR/WUE_metrics.jl +++ b/inst/fromR/WUE_metrics.jl @@ -45,7 +45,7 @@ #' - IWUE: Inherent water-use efficiency (gC kPa (kg H20)-1) #' - uWUE: Underlying water-use efficiency (gC kPa^0.5 (kg H20)-1) #' -#' #Note +#' # Note #' Units for VPD can also be hPa. Units change accordingly. #' WUE_NEE is calculated based on the absolute value of NEE (the sign convention does not matter here). #' diff --git a/inst/fromR/aerodynamic_conductance.jl b/inst/fromR/aerodynamic_conductance.jl index bd6a739..fdbe33c 100755 --- a/inst/fromR/aerodynamic_conductance.jl +++ b/inst/fromR/aerodynamic_conductance.jl @@ -135,7 +135,7 @@ #' \item{Gb_Sc_name}{Boundary layer conductance for `Sc_name` (m s-1). Only added if `Sc_name` and #' the respective `Sc` are provided} #' -#' #Note +#' # Note #' The roughness length for water and heat (z0h) is not returned by this function, but #' it can be calculated from the following relationship (e.g. Verma 1989): #' diff --git a/inst/fromR/bigleaf_physiology.jl b/inst/fromR/bigleaf_physiology.jl index b583b34..2007954 100755 --- a/inst/fromR/bigleaf_physiology.jl +++ b/inst/fromR/bigleaf_physiology.jl @@ -28,7 +28,7 @@ #' Ca can either be atmospheric CO2 concentration (as measured), or surface #' CO2 concentration as calculated from [`surface_CO2`](@ref). #' -#' #Note +#' # Note #' The equation is based on Fick's law of diffusion and is equivalent to the #' often used equation at leaf level (ci = ca - An/gs). #' Note that GPP and Gs have a different interpretation than An and gs. @@ -206,7 +206,7 @@ end #' The calculation of Jmax25 and Vcmax25 is identical to C3 photosynthesis #' as described above. #' -#' #Note +#' # Note #' The critical assumption is that bulk canopy photosynthesis is limited by #' one of the two limitation states. Incoming PPFD is assumed to determine #' the limitation states. Note however that the ranges (`PPFD_j` and `PPFD_c`) @@ -274,7 +274,7 @@ end #' # calculate Gs from the the inverted PM equation #' Gs_PM = surface_conductance(DE_Tha_Jun_2014_2,Tair="Tair",pressure="pressure", #' Rn="Rn",G="G",S=NULL,VPD="VPD",Ga=Ga, -#' formulation=Val(:Penman-Monteith))[,"Gs_mol"] +#' formulation=Val(:PenmanMonteith))[,"Gs_mol"] #' #' # calculate Ci #' Ci = intercellular_CO2(DE_Tha_Jun_2014_2,Ca="Ca",GPP="GPP",Gs=Gs_PM) @@ -574,7 +574,7 @@ end #' # if G and/or S are available, don't forget to indicate (they are ignored by default). #' Gs_PM = surface_conductance(DE_Tha_Jun_2014_2,Tair="Tair",pressure="pressure", #' Rn="Rn",G="G",S=NULL,VPD="VPD",Ga=Ga, -#' formulation=Val(:Penman-Monteith))[,"Gs_mol"] +#' formulation=Val(:PenmanMonteith))[,"Gs_mol"] #' #' ### Estimate the stomatal slope parameter g1 using the USO model #' mod_USO = stomatal_slope(DE_Tha_Jun_2014_2,model="USO",GPP="GPP",Gs=Gs_PM, @@ -778,7 +778,7 @@ end #' `PPFD_ref` defaults to 2000 umol m-2 s-1, but other values can be used. For #' further details refer to Falge et al. 2001. #' -#' #Note +#' # Note #' Note the sign convention. Negative NEE indicates that carbon is taken up #' by the ecosystem. Reco has to be 0 or larger. #' diff --git a/inst/fromR/boundary_layer_conductance.jl b/inst/fromR/boundary_layer_conductance.jl index 29d62fb..b6ac2d0 100755 --- a/inst/fromR/boundary_layer_conductance.jl +++ b/inst/fromR/boundary_layer_conductance.jl @@ -140,7 +140,7 @@ end #' #' where Sc_x is the Schmidt number of quantity x, and Pr is the Prandtl number (0.71). #' -#' #Note +#' # Note #' If the roughness length for momentum (`z0m`) is not provided as input, it is estimated #' from the function `roughness_parameters` within `wind_profile`. This function #' estimates a single `z0m` value for the entire time period! If a varying `z0m` value @@ -296,7 +296,7 @@ end #' #' where Sc_x is the Schmidt number of quantity x, and Pr is the Prandtl number (0.71). #' -#' #Note +#' # Note #' If the roughness length for momentum (`z0m`) is not provided as input, it is estimated #' from the function `roughness_parameters` within `wind_profile`. This function #' estimates a single `z0m` value for the entire time period! If a varying `z0m` value diff --git a/inst/fromR/check_input.jl b/inst/fromR/check_input.jl index 36242ae..d94461b 100755 --- a/inst/fromR/check_input.jl +++ b/inst/fromR/check_input.jl @@ -9,7 +9,7 @@ #' - data Input DataFrame or matrix #' - ... Input variables. Either a list or individual vectors #' -#' #Note +#' # Note #' This function can be run for named variables (in which case the return #' value will be named according to the given name), or for placeholder #' variables that are assigned and named according to e.g. entries of a character @@ -101,7 +101,7 @@ end #' #' - varlist List of variables for which the length has to be compared #' -#' #Note +#' # Note #' This function only plays a role if no input DataFrame or matrix are #' provided. In this case it ensures that provided vectors have the same #' length to avoid trouble later up the function call. diff --git a/inst/fromR/datasets_description.jl b/inst/fromR/datasets_description.jl index 5e627d4..44f21cd 100755 --- a/inst/fromR/datasets_description.jl +++ b/inst/fromR/datasets_description.jl @@ -40,7 +40,7 @@ #' - Reco: Ecosystem respiration from nighttime partitioning (umol m-2 s-1) [RECO_NT_VUT_USTAR50] #' } #' -#' #Note +#' # Note #' The original variable names as provided by the FLUXNET2015 dataset are #' given in squared brackets. Note that variable units have been converted #' in some cases (e.g. VPD from hPa to kPa). @@ -94,7 +94,7 @@ #' - Reco: Ecosystem respiration from nighttime partitioning (umol m-2 s-1) [RECO_NT_VUT_USTAR50] #' } #' -#' #Note +#' # Note #' The original variable names as provided by the FLUXNET2015 dataset are #' given in squared brackets. Note that variable units have been converted #' in some cases (e.g. VPD from hPa to kPa). @@ -145,7 +145,7 @@ #' - Reco: Ecosystem respiration from nighttime partitioning (umol m-2 s-1) [RECO_NT_VUT_USTAR50] #' } #' -#' #Note +#' # Note #' The original variable names as provided by the FLUXNET2015 dataset are #' given in squared brackets. Note that variable units have been converted #' in some cases (e.g. VPD from hPa to kPa). diff --git a/inst/fromR/evapotranspiration.jl b/inst/fromR/evapotranspiration.jl index 9c5beed..cab37f9 100755 --- a/inst/fromR/evapotranspiration.jl +++ b/inst/fromR/evapotranspiration.jl @@ -13,12 +13,12 @@ #' - Rn Net radiation (W m-2) #' - G Ground heat flux (W m-2); optional #' - S Sum of all storage fluxes (W m-2); optional -#' - VPD Vapor pressure deficit (kPa); only used if `approach = Val(:Penman-Monteith)`. -#' - Ga Aerodynamic conductance to heat/water vapor (m s-1); only used if `approach = Val(:Penman-Monteith)`. -#' - approach Approach used. Either `Val(:Priestley-Taylor)` (default), or `Val(:Penman-Monteith)`. -#' - alpha Priestley-Taylor coefficient; only used if `approach = Val(:Priestley-Taylor)`. +#' - VPD Vapor pressure deficit (kPa); only used if `approach = Val(:PenmanMonteith)`. +#' - Ga Aerodynamic conductance to heat/water vapor (m s-1); only used if `approach = Val(:PenmanMonteith)`. +#' - approach Approach used. Either `Val(:PriestleyTaylor)` (default), or `Val(:PenmanMonteith)`. +#' - alpha Priestley-Taylor coefficient; only used if `approach = Val(:PriestleyTaylor)`. #' - Gs_pot Potential/maximum surface conductance (mol m-2 s-1); defaults to 0.6 mol m-2 s-1; -#' only used if `approach = Val(:Penman-Monteith)`. +#' only used if `approach = Val(:PenmanMonteith)`. #' - missing_G_as_NA if `TRUE`, missing G are treated as `NA`s, otherwise set to 0. #' - missing_S_as_NA if `TRUE`, missing S are treated as `NA`s, otherwise set to 0. #' - Esat_formula Optional: formula to be used for the calculation of esat and the slope of esat. @@ -27,20 +27,20 @@ #' - constants cp - specific heat of air for constant pressure (J K-1 kg-1) #' eps - ratio of the molecular weight of water vapor to dry air #' Pa2kPa - conversion pascal (Pa) to kilopascal (kPa) -#' Rd - gas constant of dry air (J kg-1 K-1) (only used if `approach = Val(:Penman-Monteith)`) -#' Rgas - universal gas constant (J mol-1 K-1) (only used if `approach = Val(:Penman-Monteith)`) -#' Kelvin - conversion degree Celsius to Kelvin (only used if `approach = Val(:Penman-Monteith)`) +#' Rd - gas constant of dry air (J kg-1 K-1) (only used if `approach = Val(:PenmanMonteith)`) +#' Rgas - universal gas constant (J mol-1 K-1) (only used if `approach = Val(:PenmanMonteith)`) +#' Kelvin - conversion degree Celsius to Kelvin (only used if `approach = Val(:PenmanMonteith)`) #' #' # Details #' Potential evapotranspiration is calculated according to Priestley & Taylor, 1972 -#' if `approach = Val(:Priestley-Taylor)` (the default): +#' if `approach = Val(:PriestleyTaylor)` (the default): #' #' ``LE_pot,PT = (\\alpha * \\Delta * (Rn - G - S)) / (\\Delta + \\gamma)`` #' #' ``\\alpha`` is the Priestley-Taylor coefficient, ``\\Delta`` is the slope #' of the saturation vapor pressure curve (kPa K-1), and ``\\gamma`` is the #' psychrometric constant (kPa K-1). -#' if `approach = Val(:Penman-Monteith)`, potential evapotranspiration is calculated according +#' if `approach = Val(:PenmanMonteith)`, potential evapotranspiration is calculated according #' to the Penman-Monteith equation: #' #' ``LE_pot,PM = (\\Delta * (Rn - G - S) + \\rho * cp * VPD * Ga) / (\\Delta + \\gamma * (1 + Ga/Gs_pot)`` @@ -55,7 +55,7 @@ #' - ET_pot: Potential evapotranspiration (kg m-2 s-1) #' - LE_pot: Potential latent heat flux (W m-2) #' -#' #Note +#' # Note #' If the first argument `data` is provided (either a matrix or a DataFrame), #' the following variables can be provided as character (in which case they are interpreted as #' the column name of `data`) or as numeric vectors, in which case they are taken @@ -80,12 +80,12 @@ #' ``` #' # Calculate potential ET of a surface that receives a net radiation of 500 Wm-2 #' # using Priestley-Taylor: -#' potential_ET(Tair=30,pressure=100,Rn=500,alpha=1.26,approach=Val(:Priestley-Taylor)) +#' potential_ET(Tair=30,pressure=100,Rn=500,alpha=1.26,approach=Val(:PriestleyTaylor)) #' #' # Calculate potential ET for a surface with known Gs (0.5 mol m-2 s-1) and Ga (0.1 m s-1) #' # using Penman-Monteith: #' LE_pot_PM = potential_ET(Gs_pot=0.5,Tair=20,pressure=100,VPD=2,Ga=0.1,Rn=400, -#' approach=Val(:Penman-Monteith))[,"LE_pot"] +#' approach=Val(:PenmanMonteith))[,"LE_pot"] #' LE_pot_PM #' #' # now cross-check with the inverted equation @@ -93,7 +93,7 @@ """ """ function potential_ET(data,Tair="Tair",pressure="pressure",Rn="Rn",G=NULL,S=NULL, - VPD="VPD",Ga="Ga_h",approach=c(Val(:Priestley-Taylor),Val(:Penman-Monteith)), + VPD="VPD",Ga="Ga_h",approach=c(Val(:PriestleyTaylor),Val(:PenmanMonteith)), alpha=1.26,Gs_pot=0.6,missing_G_as_NA=false,missing_S_as_NA=false, Esat_formula=c("Sonntag_1990","Alduchov_1996","Allen_1998"), constants=bigleaf_constants()) @@ -124,12 +124,12 @@ end Delta = Esat_slope(Tair,Esat_formula,constants)[,"Delta"] - if (approach == Val(:Priestley-Taylor)) + if (approach == Val(:PriestleyTaylor)) LE_pot = (alpha * Delta * (Rn - G - S)) / (Delta + gamma) ET_pot = LE_to_ET(LE_pot,Tair) -else if (approach == Val(:Penman-Monteith)) +else if (approach == Val(:PenmanMonteith)) check_input(data,list(Gs_pot,VPD,Ga)) @@ -152,7 +152,7 @@ end #' #' Reference evapotranspiration calculated from the Penman-Monteith #' equation with a prescribed surface conductance. -#' This function is deprecated. Use potential_ET(...,approach=Val(:Penman-Monteith)) instead. +#' This function is deprecated. Use potential_ET(...,approach=Val(:PenmanMonteith)) instead. #' #' - data Data_frame or matrix containing all required variables; optional #' - Gs_ref Reference surface conductance (m s-1); defaults to 0.0143 m s-1. @@ -170,9 +170,9 @@ end #' See [`Esat_slope`](@ref). #' - constants cp - specific heat of air for constant pressure (J K-1 kg-1) #' eps - ratio of the molecular weight of water vapor to dry air -#' Rd - gas constant of dry air (J kg-1 K-1) (only if `approach = Val(:Penman-Monteith)`) -#' Rgas - universal gas constant (J mol-1 K-1) (only if `approach = Val(:Penman-Monteith)`) -#' Kelvin - conversion degree Celsius to Kelvin (only if `approach = Val(:Penman-Monteith)`) +#' Rd - gas constant of dry air (J kg-1 K-1) (only if `approach = Val(:PenmanMonteith)`) +#' Rgas - universal gas constant (J mol-1 K-1) (only if `approach = Val(:PenmanMonteith)`) +#' Kelvin - conversion degree Celsius to Kelvin (only if `approach = Val(:PenmanMonteith)`) #' #' @export function reference_ET(data,Gs_ref=0.0143,Tair="Tair",pressure="pressure",VPD="VPD",Rn="Rn",Ga="Ga_h", @@ -231,7 +231,7 @@ end #' #' where ``\\rho`` is the air density (kg m-3). #' -#' #Note +#' # Note #' Surface conductance (Gs) can be calculated with [`surface_conductance`](@ref). #' Aerodynamic conductance (Ga) can be calculated using [`aerodynamic_conductance`](@ref). #' diff --git a/inst/fromR/filter_data.jl b/inst/fromR/filter_data.jl index bba40e9..00b5566 100755 --- a/inst/fromR/filter_data.jl +++ b/inst/fromR/filter_data.jl @@ -75,7 +75,7 @@ #' column "valid", which indicates whether all the data of a time step fulfill the #' filtering criteria (1) or not (0). #' -#' #Note +#' # Note #' The thresholds set with `filter_vals_min` and `filter_vals_max` filter all data #' that are smaller than ("<"), or greater than (">") the specified thresholds. That means #' if a variable has exactly the same value as the threshold, it will not be filtered. Likewise, diff --git a/inst/fromR/meteorological_variables.jl b/inst/fromR/meteorological_variables.jl index ef9d59e..b5d1a17 100755 --- a/inst/fromR/meteorological_variables.jl +++ b/inst/fromR/meteorological_variables.jl @@ -61,7 +61,7 @@ end #' #' ``pressure = pressure_0 / (exp(g * elevation / (Rd Temp)))`` #' -#' #Note +#' # Note #' The hypsometric equation gives an estimate of the standard pressure #' at a given altitude. #' If VPD is provided, humidity correction is applied and the @@ -285,7 +285,7 @@ end #' See [`Esat_slope`](@ref). #' - constants Pa2kPa - conversion pascal (Pa) to kilopascal (kPa) #' -#' #Note +#' # Note #' Arguments `accuracy` and `Esat_formula` are passed to this function by wetbulb_temp(). #' #' @importFrom stats optimize @@ -386,7 +386,7 @@ end #' See [`Esat_slope`](@ref). #' - constants Pa2kPa - conversion pascal (Pa) to kilopascal (kPa) #' -#' #Note +#' # Note #' Arguments `accuracy` and `Esat_formula` are passed to this function by dew_point(). #' #' @importFrom stats optimize diff --git a/inst/fromR/stability_correction.jl b/inst/fromR/stability_correction.jl index 0a68405..048d456 100755 --- a/inst/fromR/stability_correction.jl +++ b/inst/fromR/stability_correction.jl @@ -26,7 +26,7 @@ #' # Value - L -: Monin-Obukhov length (m) #' -#' #Note +#' # Note #' Note that L gets very small for very low ustar values with implications #' for subsequent functions using L as input. It is recommended to filter #' data and exclude low ustar values (ustar < ~0.2) beforehand. diff --git a/inst/fromR/surface_conditions.jl b/inst/fromR/surface_conditions.jl index 853c281..1e9b9b7 100755 --- a/inst/fromR/surface_conditions.jl +++ b/inst/fromR/surface_conditions.jl @@ -57,7 +57,7 @@ #' the results of the functions represent conditions outside the canopy #' boundary layer, i.e. in the canopy airspace. #' -#' #Note +#' # Note #' The following sign convention for NEE is employed (relevant if #' `calc_surface_CO2 = TRUE`): #' negative values of NEE denote net CO2 uptake by the ecosystem. @@ -149,7 +149,7 @@ end #' replaced by the net exchange of the respective gas and Ga_CO2 by the Ga of #' that gas). #' -#' #Note +#' # Note #' the following sign convention is employed: negative values of NEE denote #' net CO2 uptake by the ecosystem. #' diff --git a/inst/fromR/surface_conductance.jl b/inst/fromR/surface_conductance.jl index 180eb77..acf6754 100755 --- a/inst/fromR/surface_conductance.jl +++ b/inst/fromR/surface_conductance.jl @@ -17,15 +17,15 @@ #' - VPD Vapor pressure deficit (kPa) #' - Ga Aerodynamic conductance to heat/water vapor (m s-1) #' - missing_G_as_NA if `TRUE`, missing G are treated as `NA`s, otherwise they are set to 0. -#' Only used if `formulation = Val(:Penman-Monteith)`. +#' Only used if `formulation = Val(:PenmanMonteith)`. #' - missing_S_as_NA if `TRUE`, missing S are treated as `NA`s, otherwise they are set to 0. -#' Only used if `formulation = Val(:Penman-Monteith)`. -#' - formulation Formulation used. Either `Val(:Penman-Monteith)` (the default) +#' Only used if `formulation = Val(:PenmanMonteith)`. +#' - formulation Formulation used. Either `Val(:PenmanMonteith)` (the default) #' using the inverted Penman-Monteith equation, or `"Flux-Gradient"`, #' for a simple flux-gradient approach requiring ET, pressure, and VPD only. #' - Esat_formula Optional: formula to be used for the calculation of esat and the slope of esat. #' One of `"Sonntag_1990"` (Default), `"Alduchov_1996"`, or `"Allen_1998"`. -#' Only used if `formulation = Val(:Penman-Monteith)`. See [`Esat_slope`](@ref). +#' Only used if `formulation = Val(:PenmanMonteith)`. See [`Esat_slope`](@ref). #' - constants cp - specific heat of air for constant pressure (J K-1 kg-1) #' eps - ratio of the molecular weight of water vapor to dry air (-) #' Rd - gas constant of dry air (J kg-1 K-1) @@ -36,7 +36,7 @@ #' #' #' # Details - If `formulation = Val(:Penman-Monteith)` (the default), surface conductance (Gs) in m s-1 + If `formulation = Val(:PenmanMonteith)` (the default), surface conductance (Gs) in m s-1 #' is calculated from the inverted Penman-Monteith equation: #' #' ``Gs = ( LE * Ga * \\gamma ) / ( \\Delta * A + \\rho * cp * Ga * VPD - LE * ( \\Delta + \\gamma ) )`` @@ -95,7 +95,7 @@ #' # Note that Ga is not added to the DataFrame 'DE_Tha_Jun_2014' #' Gs_PM = surface_conductance(DE_Tha_Jun_2014_2,Tair="Tair",pressure="pressure", #' Rn="Rn",G="G",S=NULL,VPD="VPD",Ga=Ga, -#' formulation=Val(:Penman-Monteith)) +#' formulation=Val(:PenmanMonteith)) #' summary(Gs_PM) #' #' @@ -103,7 +103,7 @@ #' DE_Tha_Jun_2014_2$Ga = Ga #' Gs_PM2 = surface_conductance(DE_Tha_Jun_2014_2,Tair="Tair",pressure="pressure", #' Rn="Rn",G="G",S=NULL,VPD="VPD",Ga="Ga", -#' formulation=Val(:Penman-Monteith)) +#' formulation=Val(:PenmanMonteith)) #' # note the difference to the previous version (Ga="Ga") #' summary(Gs_PM2) #' @@ -120,7 +120,7 @@ """ function surface_conductance(data,Tair="Tair",pressure="pressure",Rn="Rn",G=NULL,S=NULL, VPD="VPD",LE="LE",Ga="Ga_h",missing_G_as_NA=false,missing_S_as_NA=false, - formulation=c(Val(:Penman-Monteith),"Flux-Gradient"), + formulation=c(Val(:PenmanMonteith),"Flux-Gradient"), Esat_formula=c("Sonntag_1990","Alduchov_1996","Allen_1998"), constants=bigleaf_constants()) @@ -133,7 +133,7 @@ function surface_conductance(data,Tair="Tair",pressure="pressure",Rn="Rn",G=NULL Gs_mol = (LE_to_ET(LE,Tair)/constants[:Mw]) * pressure / VPD Gs_ms = mol_to_ms(Gs_mol,Tair,pressure) -else if (formulation == Val(:Penman-Monteith)) +else if (formulation == Val(:PenmanMonteith)) check_input(data,list(Tair,pressure,VPD,LE,Rn,Ga,G,S)) diff --git a/inst/fromR/surface_roughness.jl b/inst/fromR/surface_roughness.jl index c6a2d34..33f9ca1 100755 --- a/inst/fromR/surface_roughness.jl +++ b/inst/fromR/surface_roughness.jl @@ -252,7 +252,7 @@ end #' z0m is first estimated from the wind profile equation and then used in the equation #' above for the calculation of `u(z)` (see e.g. Newman & Klein 2014). #' -#' #Note +#' # Note #' Note that this equation is only valid for z >= d + z0m, and it is not #' meaningful to calculate values closely above d + z0m. All values in `heights` #' smaller than d + z0m will return 0. diff --git a/inst/walkthrough_todo.jmd b/inst/walkthrough_todo.jmd index 85b7d67..961846d 100644 --- a/inst/walkthrough_todo.jmd +++ b/inst/walkthrough_todo.jmd @@ -11,7 +11,7 @@ that accept a DataFrame with columnnames corresponding to required arguments. We can demonstrate the usage with a simple example: ```julia -potential_ET(tha,Tair="Tair",pressure="pressure",Rn="Rn",VPD="VPD",approach=Val(:Priestley-Taylor)) +potential_ET(tha,Tair="Tair",pressure="pressure",Rn="Rn",VPD="VPD",approach=Val(:PriestleyTaylor)) potential_ET(tha) potential_ET(tha,Tair=tha$Tair) potential_ET(tha,Tair=25) @@ -267,8 +267,8 @@ Here, the points denote the mean wind speed and the bars denote the standard dev For many hydrological applications, it is relevant to get an estimate on the potential evapotranspiration (PET). At the moment, the `Bigleaf.jl` package contains two formulations for the estimate of PET: the Priestley-Taylor equation, and the Penman-Monteith equation: ```julia -summary(potential_ET(tha_filtered,G="G",approach=Val(:Priestley-Taylor))) -summary(potential_ET(tha_filtered,G="G",approach=Val(:Penman-Monteith)), +summary(potential_ET(tha_filtered,G="G",approach=Val(:PriestleyTaylor))) +summary(potential_ET(tha_filtered,G="G",approach=Val(:PenmanMonteith)), Gs_pot=quantile(tha_filtered$Gs_mol,0.95,na_rm=TRUE)) ``` diff --git a/src/Bigleaf.jl b/src/Bigleaf.jl index 83b7c99..b3b0eaa 100644 --- a/src/Bigleaf.jl +++ b/src/Bigleaf.jl @@ -2,7 +2,7 @@ module Bigleaf #using DocStringExtensions using Optim -using StaticArrays, LabelledArrays, RecursiveArrayTools +using FillArrays using DataFrames using Dates, TimeZones using Pipe @@ -11,7 +11,7 @@ using Suppressor using Missings -export toDataFrame, frac_hour +export frac_hour export bigleaf_constants export Esat_slope, Esat_from_Tair, Esat_from_Tair_deriv, LE_to_ET, ET_to_LE, ms_to_mol, mol_to_ms, VPD_to_rH, rH_to_VPD, @@ -23,7 +23,8 @@ export air_density, pressure_from_elevation, psychrometric_constant, wetbulb_temp_from_e_Tair_gamma, wetbulb_temp export calc_sun_position_MOD, calc_sun_position_hor export potential_radiation, extraterrestrial_radiation, get_datetime_for_doy_hour -export potential_ET +export potential_ET, potential_ET!, fill_GS_missings!, equilibrium_imposed_ET, + surface_conductance include("util.jl") include("bigleaf_constants.jl") diff --git a/src/evapotranspiration.jl b/src/evapotranspiration.jl index 77e4bd5..f26b5d0 100755 --- a/src/evapotranspiration.jl +++ b/src/evapotranspiration.jl @@ -1,121 +1,203 @@ """ -Potential Evapotranspiration + potential_ET(Tair, pressure, Rn, ::Val{:PriestleyTaylor}; ...) + potential_ET(Tair, pressure, Rn, VPD, Ga, ::Val{:PenmanMonteith}; ...) + + potential_ET(Tair, pressure, Rn, G, S, ::Val{:PriestleyTaylor}; ...) + potential_ET(Tair, pressure, Rn, VPD, Ga, G, S, ::Val{:PenmanMonteith}; ...) + + potential_ET(df, approach; ...) + potential_ET!(df, approach; ...) Potential evapotranspiration according to Priestley & Taylor 1972 or - the Penman-Monteith equation with a prescribed surface conductance. +the Penman-Monteith equation with a prescribed surface conductance. # Arguments -- data: Data_frame or matrix containing all required variables; optional - Tair: Air temperature (degC) - pressure: Atmospheric pressure (kPa) - Rn: Net radiation (W m-2) -- G: Ground heat flux (W m-2); optional -- S: Sum of all storage fluxes (W m-2); optional -- VPD: Vapor pressure deficit (kPa); only used if `approach = Val(:Penman-Monteith)`. -- Ga: Aerodynamic conductance to heat/water vapor (m s-1); only used if `approach = Val(:Penman-Monteith)`. -- approach: Approach used. Either `Val(:Priestley-Taylor)` (default), or `Val(:Penman-Monteith)`. -- alpha: Priestley-Taylor coefficient; only used if `approach = Val(:Priestley-Taylor)`. -- Gs_pot: Potential/maximum surface conductance (mol m-2 s-1); defaults to 0.6 mol m-2 s-1; - only used if `approach = Val(:Penman-Monteith)`. -- missing_G_as_NA: if `TRUE`, missing G are treated as `NA`s, otherwise set to 0. -- missing_S_as_NA: if `TRUE`, missing S are treated as `NA`s, otherwise set to 0. -- Esat_formula: Optional: formula to be used for the calculation of esat and the slope of esat. - One of `"Sonntag_1990"` (Default), `"Alduchov_1996"`, or `"Allen_1998"`. - See [`Esat_slope`](@ref). +- VPD: Vapor pressure deficit (kPa) +- Ga: Aerodynamic conductance to heat/water vapor (m s-1) +- G: Ground heat flux (W m-2) +- S: Sum of all storage fluxes (W m-2) +- approach: Approach used. + Either `Val(:PriestleyTaylor)` (default), or `Val(:PenmanMonteith)`. +- df: Data_frame or matrix containing all required variables; optional +optional: +- `Esat_formula`: formula used in [`Esat_from_Tair`](@ref) - `constants=`[`bigleaf_constants`](@ref)`()`: Dictionary with entries - cp - specific heat of air for constant pressure (J K-1 kg-1) - eps - ratio of the molecular weight of water vapor to dry air - Pa2kPa - conversion pascal (Pa) to kilopascal (kPa) - - Rd - gas constant of dry air (J kg-1 K-1) (only used if `approach = Val(:Penman-Monteith)`) - - Rgas - universal gas constant (J mol-1 K-1) (only used if `approach = Val(:Penman-Monteith)`) - - Kelvin - conversion degree Celsius to Kelvin (only used if `approach = Val(:Penman-Monteith)`) + - for :PenmanMonteith: + - Rd - gas constant of dry air (J kg-1 K-1) + - Rgas - universal gas constant (J mol-1 K-1) + - Kelvin - conversion degree Celsius to Kelvin +additional optional arguments if G and S are not specified by postition +and in the non-mutating DataFrame variant. +- G and S: as in the positional forms, but checked for missing or containing missings +- missing_G_as_NA: if `true`, missing optional G are treated as `NA`s, + otherwise set to 0. +- missing_S_as_NA: if `true`, missing optional S are treated as `NA`s, + otherwise set to 0. +additional optional for PriestleyTaylor: +- alpha: Priestley-Taylor coefficient +additional optional for PenmanMonteith: +- Gs_pot: Potential/maximum surface conductance (mol m-2 s-1); + defaults to 0.6 mol m-2 s-1; # Details Potential evapotranspiration is calculated according to Priestley & Taylor, 1972 -if `approach = Val(:Priestley-Taylor)` (the defau -``LE_pot,PT = (\\alpha * \\Delta * (Rn - G - S)) / (\\Delta + \\gamma)`` +if `approach = Val(:PriestleyTaylor)` (the defau +``LE_{pot,PT} = (\\alpha * \\Delta * (Rn - G - S)) / (\\Delta + \\gamma)`` ``\\alpha`` is the Priestley-Taylor coefficient, ``\\Delta`` is the slope of the saturation vapor pressure curve (kPa K-1), and ``\\gamma`` is the psychrometric constant (kPa K-1). -if `approach = Val(:Penman-Monteith)`, potential evapotranspiration is calculated according +if `approach = Val(:PenmanMonteith)`, potential evapotranspiration is calculated according to the Penman-Monteith equat -``LE_pot,PM = (\\Delta * (Rn - G - S) + \\rho * cp * VPD * Ga) / (\\Delta + \\gamma * (1 + Ga/Gs_pot)`` +``LE_{pot,PM} = (\\Delta * (Rn - G - S) + \\rho * cp * VPD * Ga) / +(\\Delta + \\gamma * (1 + Ga/Gs_{pot})`` where ``\\Delta`` is the slope of the saturation vapor pressure curve (kPa K-1), -``\\rho`` is the air density (kg m-3), and ``\\gamma`` is the psychrometric constant (kPa K-1). +``\\rho`` is the air density (kg m-3), +and ``\\gamma`` is the psychrometric constant (kPa K-1). The value of `Gs_pot` is typically a maximum value of Gs observed at the site, e.g. the 90th percentile of Gs within the growing season. + +If keyword arguments `G` or `S` in the are set to `missing`, ground heat flux and storage flux +are assumed zero respectively. Note, that these keyword argument are not available in the +mutating form, where the caller has to add tree these columns before +(see [fill_GS_missings](@ref)). +Both methods are provided with several forms: +- all required inputs as positional arguments +- provideing G and S as positional arguments with handing of missing values +- providing a DataFrame with columns corresponding to required inputs + + # Value -a DataFrame with the following columns: -- ET_pot: Potential evapotranspiration (kg m-2 s-1) -- LE_pot: Potential latent heat flux (W m-2) +NamedTuple or DataFrame with the following entries: +- `ET_pot`: Potential evapotranspiration (kg m-2 s-1) +- `LE_pot`: Potential latent heat flux (W m-2) +For the mutating form, the original df with columns `ET_pot`, `LE_pot`, `G`, and `S` +updated or added. -# Note -If the first argument `data` is provided (either a matrix or a DataFrame), -the following variables can be provided as character (in which case they are interpreted as -the column name of `data`) or as numeric vectors, in which case they are taken -directly for the calculations. If `data` is not provided, all input variables have to be -numeric vectors. # References -Priestley, C_H_B., Taylor, R_J., 1972: On the assessment of surface heat flux +- Priestley, C_H_B., Taylor, R_J., 1972: On the assessment of surface heat flux and evaporation using large-scale parameters. Monthly Weather Review 100, 81-92. - -Allen, R_G., Pereira L_S., Raes D., Smith M., 1998: Crop evapotranspiration - +- Allen, R_G., Pereira L_S., Raes D., Smith M., 1998: Crop evapotranspiration - Guidelines for computing crop water requirements - FAO Irrigation and drainage paper 56. - -Novick, K_A., et al. 2016: The increasing importance of atmospheric demand +- Novick, K_A., et al. 2016: The increasing importance of atmospheric demand for ecosystem water and carbon fluxes. Nature Climate Change 6, 1023 - 1027. # See also [`surface_conductance`](@ref) - -```@example; output = false + +# Examples + +```jldoctest; output=false # Calculate potential ET of a surface that receives a net radiation of 500 Wm-2 # using Priestley-Taylor: -potential_ET(Tair=30,pressure=100,Rn=500,alpha=1.26,approach=Val(:Priestley-Taylor)) - +Tair,pressure,Rn = 30.0,100.0,500.0 +ET_pot, LE_pot = potential_ET(Tair,pressure,Rn, Val(:PriestleyTaylor); + alpha=1.26, infoGS = false) +≈(ET_pot, 0.0002035969; rtol = 1e-5) +# output +true +``` +```@jldoctest; output=false # Calculate potential ET for a surface with known Gs (0.5 mol m-2 s-1) and Ga (0.1 m s-1) # using Penman-Monteith: -LE_pot_PM = potential_ET(Gs_pot=0.5,Tair=20,pressure=100,VPD=2,Ga=0.1,Rn=400, - approach=Val(:Penman-Monteith))[,"LE_pot"] -LE_pot_PM - +Tair,pressure,Rn = 30.0,100.0,500.0 +VPD,Ga = 2.0, 0.1 +ET_pot,LE_pot = potential_ET(Tair,pressure,Rn,VPD, Ga, Val(:PenmanMonteith); + Gs_pot=0.5, infoGS=false) # now cross-check with the inverted equation -surface_conductance(Tair=20,pressure=100,VPD=2,Ga=0.1,Rn=400,LE=LE_pot_PM) +#Ga2 = surface_conductance(Tair=20,pressure=100,VPD=2,Ga=0.1,Rn=400,LE=LE_pot_PM) +#Ga2 ≈ GA +true +# output +true ``` """ -function potential_ET(Tair,pressure,Rn, VPD,Ga; - G=missing,S=missing, approach=Val(:Priestley-Taylor), - alpha=1.26,Gs_pot=0.6, - missing_G_as_NA=false, missing_S_as_NA=false, +function potential_ET(Tair, pressure, Rn, approach::Val{:PriestleyTaylor}; + G=missing,S=missing, missing_G_as_NA=false, missing_S_as_NA=false, + infoGS=true, + kwargs...) + # + G_, S_ = fill_GS_missings(G,S,missing_G_as_NA, missing_S_as_NA; infoGS) + potential_ET(Tair, pressure, Rn, G_, S_, approach; kwargs...) +end, +function potential_ET(Tair, pressure, Rn, G, S, ::Val{:PriestleyTaylor}; + alpha=1.26, Esat_formula=Val(:Sonntag_1990), constants=bigleaf_constants()) - - #TODO check_input(data,list(Tair,pressure,Rn,G,S)) - G,S = deal_GS_missings(G,S,missing_G_as_NA, missing_S_as_NA) - gamma = psychrometric_constant(Tair,pressure,constants) + # + gamma = psychrometric_constant(Tair,pressure;constants) + Delta = Esat_from_Tair_deriv(Tair; formula = Esat_formula,constants) + LE_pot = (alpha * Delta * (Rn - G - S)) / (Delta + gamma) + ET_pot = LE_to_ET(LE_pot,Tair) + (ET_pot = ET_pot, LE_pot = LE_pot) +end, +function potential_ET(Tair, pressure, Rn, VPD, Ga, approach::Val{:PenmanMonteith}; + G=missing,S=missing, missing_G_as_NA=false, missing_S_as_NA=false, + infoGS=true, + kwargs...) + # + G_, S_ = fill_GS_missings(G,S,missing_G_as_NA, missing_S_as_NA; infoGS) + G_tr, S_tr = 0,0 + potential_ET(Tair, pressure, Rn, VPD, Ga, G_tr, S_tr, approach; kwargs...) +end, +function potential_ET(Tair, pressure, Rn, VPD, Ga, G, S, ::Val{:PenmanMonteith}; + Gs_pot=0.6, + Esat_formula=Val(:Sonntag_1990), + constants=bigleaf_constants()) + # + gamma = psychrometric_constant(Tair,pressure;constants) Delta = Esat_from_Tair_deriv(Tair; formula = Esat_formula,constants) - # TODO replace by dispatch - if (approach == Val(:Priestley-Taylor)) - LE_pot = (alpha * Delta * (Rn - G - S)) / (Delta + gamma) - ET_pot = LE_to_ET(LE_pot,Tair) - elseif (approach == Val(:Penman-Monteith)) - #TODO check_input(data,list(Gs_pot,VPD,Ga)) - Gs_pot = mol_to_ms(Gs_pot,Tair,pressure;constants) - rho = air_density(Tair,pressure;constants) - LE_pot = (Delta * (Rn - G - S) + rho * constants[:cp] * VPD * Ga) / - (Delta + gamma * (1 + Ga / Gs_pot)) - ET_pot = LE_to_ET(LE_pot,Tair) - end + Gs_pot = mol_to_ms(Gs_pot,Tair,pressure;constants) + rho = air_density(Tair,pressure;constants) + LE_pot = (Delta * (Rn - G - S) + rho * constants[:cp] * VPD * Ga) / + (Delta + gamma * (1 + Ga / Gs_pot)) + ET_pot = LE_to_ET(LE_pot,Tair) (ET_pot = ET_pot, LE_pot = LE_pot) +end, +function potential_ET(df, approach::Val{:PriestleyTaylor}; + G=missing,S=missing, missing_G_as_NA=false, missing_S_as_NA=false, infoGS=true, + kwargs...) + # + dfGS = fill_GS_missings(df, G,S, missing_G_as_NA, missing_S_as_NA; infoGS) + f(args...) = potential_ET(args..., approach; kwargs...) + select(hcat(select(df,:Tair, :pressure, :Rn), dfGS; copycols = false), + All() => ByRow(f) => AsTable + ) +end, +function potential_ET(df, approach::Val{:PenmanMonteith}; + G=missing,S=missing, missing_G_as_NA=false, missing_S_as_NA=false, infoGS=true, + kwargs...) + # + dfGS = fill_GS_missings(df, G,S, missing_G_as_NA, missing_S_as_NA; infoGS) + f(args...) = potential_ET(args..., approach; kwargs...) + select(hcat(select(df,:Tair, :pressure, :Rn, :VPD, :Ga), dfGS; copycols = false), + All() => ByRow(f) => AsTable + ) +end, +function potential_ET!(df, approach::Val{:PriestleyTaylor}; kwargs...) + f(args...) = potential_ET(args..., approach; kwargs...) + transform!(df, + [:Tair, :pressure, :Rn, :G, :S] => ByRow(f) => AsTable + ) +end, +function potential_ET!(df, approach::Val{:PenmanMonteith}; kwargs...) + f(args...) = potential_ET(args..., approach; kwargs...) + transform!(df, + [:Tair, :pressure, :Rn, :VPD, :Ga, :G, :S] => ByRow(f) => AsTable + ) end - """ TODO @@ -143,7 +225,7 @@ Evapotranspiration (ET) split up into imposed ET and equilibrium ET. # Details Total evapotranspiration can be written in the form (Jarvis & McNaughton 6): -``ET = \\Omega ET_eq + (1 - \\Omega)ET_imp`` +``ET = \\Omega ET_{eq} + (1 - \\Omega)ET_{imp}`` where ``\\Omega`` is the decoupling coefficient as calculated from [`decoupling`](@ref). `ET_eq` is the equilibrium evapotranspiration e, @@ -162,7 +244,7 @@ that would occur under fully coupled conditions (when Ga -> inf): where ``\\rho`` is the air density (kg m-3). -#Note +# Note Surface conductance (Gs) can be calculated with [`surface_conductance`](@ref) Aerodynamic conductance (Ga) can be calculated using erodynamic_conductance`](@ref). @@ -194,7 +276,7 @@ function equilibrium_imposed_ET(Tair,pressure,VPD,Gs, Rn, constants=bigleaf_constants()) # #check_input(data,list(Tair,pressure,VPD,Rn,Gs,G,S)) - G,S = deal_GS_missings(G,S,missing_G_as_NA, missing_S_as_NA) + G,S = fill_GS_missings(G,S,missing_G_as_NA, missing_S_as_NA) rho = air_density(Tair,pressure,constants) gamma = psychrometric_constant(Tair,pressure,constants) Delta = Esat_from_Tair_deriv(Tair,Esat_formula,constants) @@ -206,18 +288,84 @@ function equilibrium_imposed_ET(Tair,pressure,VPD,Gs, Rn, (ET_pot = ET_pot, LE_pot = LE_pot, LE_imp = LE_imp) end -function deal_GS_missings(G,S,missing_G_as_NA, missing_S_as_NA) - if ismissing(G) - @info("Ground heat flux G is not provided and set to 0.") - G = 0 - elseif missing_G_as_NA == false - G = coalesce(G, 0) - end - if ismissing(S) - @info("Energy storage fluxes S are not provided and set to 0.") - S = 0 - elseif missing_S_as_NA false - S = coalesce(S, 0) - end - G,S + +function fill_GS_missings(G,S,missing_G_as_NA, missing_S_as_NA; infoGS=true) + # + G_ = ifelse( + ismissing(G), + (infoGS && @info("Ground heat flux G is not provided and set to 0."); 0.0), + ifelse(missing_G_as_NA, G, coalesce(G, 0.0)) + ) + S_ = ifelse( + ismissing(S), + (infoGS && @info("Storage heat flux S is not provided and set to 0."); 0.0), + ifelse(missing_S_as_NA, G, coalesce(S, 0.0)) + ) + G_,S_ +end + +function fill_GS_missings(df::DataFrame, G,S, missing_G_as_NA, missing_S_as_NA; infoGS=true) + nout = nrow(df) + G_ = ifelse( + ismissing(G), + (infoGS && @info("Ground heat flux G is not provided and set to 0."); Zeros(nout)), + @. ifelse(missing_G_as_NA, G, coalesce(G, 0.0)) + ) + S_ = ifelse( + ismissing(S), + (infoGS && @info("Storage heat flux S is not provided and set to 0."); Zeros(nout)), + @. ifelse(missing_S_as_NA, G, coalesce(S, 0.0)) + ) + DataFrame(G = G_, S = S_) +end + +""" + fill_GS_missings!(df::DataFrame, G=df.G, S=df.S, + missing_G_as_NA=false, missing_S_as_NA=false; infoGS=true) + +Fill missing values in ground heat flux and storage flux. + +# Arguments +- df: DataFrame where columns G and S should be updated +- G: Ground heat flux +- S: Storage heat flux +- missing_G_as_NA: set to true to not fill NAs in G to propagate to computations +- missing_S_as_NA: set to true to not fill NAs in S to propagate to computations +- infoGS: set to false to avoid log info message + +```@example +true +# using DataFrames +# df = DataFrame(Tair = 20.0:1.0:30.0,pressure = 100.0, Rn = 500.0) +# fill_GS_missings!(df, missing, missing) +# all( df.S .== df.G .== 0.0) +``` +""" +function fill_GS_missings!(df::DataFrame, G=df.G, S=df.S, + missing_G_as_NA=false, missing_S_as_NA=false; infoGS=true + ) + nout = nrow(df) + df.G .= ifelse( + ismissing(G), + (infoGS && @info("Ground heat flux G is not provided and set to 0."); Zeros(nout)), + @. ifelse(missing_G_as_NA, G, coalesce(G, 0.0)) + ) + df.S .= ifelse( + ismissing(S), + (infoGS && @info("Storage heat flux S is not provided and set to 0."); Zeros(nout)), + @. ifelse(missing_S_as_NA, G, coalesce(S, 0.0)) + ) + df +end + +""" + TODO; implement surface_conductance. + +This stub is there to satisfy links im Help-pages. +""" +function surface_conductance() + error("not yet implemented.") end + + + diff --git a/src/sun_position.jl b/src/sun_position.jl index d04cfe2..4b3aa33 100644 --- a/src/sun_position.jl +++ b/src/sun_position.jl @@ -8,7 +8,7 @@ Compute the Sun position at given time and observer coordinates in horizontal co - `lat`, `long`: latitude and longitude in degree # Value -`SLVector`: sun position with entries +`NamedTuple`: sun position with entries - `altitude`: angle above the horizon [rad]. - `azimuth`: angle ange the horizon plane eastwards of north [rad] - `hourangle`: [rad] as output by AstroLib.eq2hor @@ -69,7 +69,7 @@ The algorithm was adapted from [Vallado 2013, p. 277-279]. - `JD`: time given as Julian Day . # Value -`SLVector`: sun position where +`NamedTuple`: sun position where - Ecliptic coordinates (1:3) - λ: Ecliptic longitude of the Sun [rad]. - β: Ecliptic latitude of the Sun [rad] is assumed 0. diff --git a/src/util.jl b/src/util.jl index 0e3c412..aece4e3 100644 --- a/src/util.jl +++ b/src/util.jl @@ -1,18 +1,16 @@ -export toDataFrame +# """ +# toDataFrame(x::AbstractVector{<:SLArray}) -""" - toDataFrame(x::AbstractVector{<:SLArray}) - -Convert an Vector{SLVector} to DataFrame. +# Convert an Vector{SLVector} to DataFrame. -Such objects are returned when broadcasting on a function -that retuns an SLVector. -""" -function toDataFrame(x::AbstractVector{<:SLArray}) - names = collect(keys(first(x))) - df = DataFrame(Tables.table(VectorOfArray(x)')) - rename!(df, names) -end +# Such objects are returned when broadcasting on a function +# that retuns an SLVector. +# """ +# function toDataFrame(x::AbstractVector{<:SLArray}) +# names = collect(keys(first(x))) +# df = DataFrame(Tables.table(VectorOfArray(x)')) +# rename!(df, names) +# end # function vec_tuple_to_DataFrame(data; names = string.(keys(first(data)))) # DataFrame(collect(map(idx -> getindex.(data, idx), eachindex(collect(first(data))))), collect(names)) diff --git a/test/evapotranspiration.jl b/test/evapotranspiration.jl new file mode 100644 index 0000000..455b842 --- /dev/null +++ b/test/evapotranspiration.jl @@ -0,0 +1,46 @@ +@testset "potential_ET scalars" begin + Tair,pressure,Rn = 30.0,100.0,500.0 + ET_pot, LE_pot = @test_logs (:info,r"G is not provided") (:info,r"S is not provided") potential_ET(Tair,pressure,Rn, Val(:PriestleyTaylor); alpha=1.26) + @test ≈(ET_pot, 0.0002035969; rtol = 1e-5) + @test ≈(LE_pot, 494.7202; rtol = 1e-5) + # + VPD,Ga = 2.0, 0.1 + ET_pot,LE_pot = @test_logs (:info,r"G is not provided") (:info,r"S is not provided") potential_ET(Tair,pressure,Rn,VPD,Ga, Val(:PenmanMonteith)) + # + #TODO surface_conductance(Tair=20,pressure=100,VPD=2,Ga=0.1,Rn=400,LE=LE_pot_PM) +end + +@testset "potential_ET dataframe" begin + df = DataFrame( + Tair = 20.0:1.0:30.0,pressure = 100.0, Rn = 500.0) + df_ET = @test_logs (:info,r"G is not provided") (:info,r"S is not provided") potential_ET(df, Val(:PriestleyTaylor); alpha=1.26) + # non-mutating + @test ncol(df) == 3 + @test nrow(df_ET) == nrow(df) + @test ≈(last(df_ET).ET_pot, 0.0002035969; rtol = 1e-5) + @test ≈(last(df_ET).LE_pot, 494.7202; rtol = 1e-5) + # + df2 = copy(df) + df2.VPD .= 2.0 + df2.Ga .= 0.1 + # df2 = transform(df, + # [] => ByRow(() -> 2.0) => :VPD, + # [] => ByRow(() -> 0.1) => :Ga, + # ) + df_ET2 = @test_logs (:info,r"G is not provided") (:info,r"S is not provided") potential_ET(df2, Val(:PenmanMonteith)) + @test ncol(df2) == 5 + @test nrow(df_ET2) == nrow(df2) + #TODO surface_conductance(Tair=20,pressure=100,VPD=2,Ga=0.1,Rn=400,LE=LE_pot_PM) + # + # mutating + dfm = copy(df) + @test_throws Exception potential_ET!( + dfm, Val(:PriestleyTaylor); alpha=1.26) + dfm = @test_logs (:info,r"G is not provided") (:info,r"S is not provided") hcat(dfm, Bigleaf.fill_GS_missings(dfm, missing, missing, false, false); copycols = false) + potential_ET!(dfm, Val(:PriestleyTaylor); alpha=1.26) + @test ncol(dfm) == 3+4 # four columns added: G,S, ET_pot, LE_pot + dfm = @test_logs (:info,r"G is not provided") (:info,r"S is not provided") fill_GS_missings!(copy(df2), missing, missing) + potential_ET!(dfm, Val(:PenmanMonteith)) + @test ncol(dfm) == ncol(df2)+4 # four columns added: G,S, ET_pot, LE_pot +end + diff --git a/test/runtests.jl b/test/runtests.jl index 93f6cf3..a51cbf8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -12,4 +12,7 @@ using Pipe, DataFrames, Dates @testset "sun_position" begin include("sun_position.jl") end + @testset "evapotranspiration" begin + include("evapotranspiration.jl") + end end From b85c328f2d81f49eb6dca5b4aa6ebc207f490ac6 Mon Sep 17 00:00:00 2001 From: Thomas Wutzler Date: Tue, 26 Oct 2021 10:05:42 +0200 Subject: [PATCH 08/13] modify handling of G and S defaults TOOD adapt docu --- src/evapotranspiration.jl | 121 ++++++++++++++++++++----------------- test/evapotranspiration.jl | 50 ++++++++++++--- 2 files changed, 104 insertions(+), 67 deletions(-) diff --git a/src/evapotranspiration.jl b/src/evapotranspiration.jl index f26b5d0..e34ff6e 100755 --- a/src/evapotranspiration.jl +++ b/src/evapotranspiration.jl @@ -1,9 +1,6 @@ """ potential_ET(Tair, pressure, Rn, ::Val{:PriestleyTaylor}; ...) - potential_ET(Tair, pressure, Rn, VPD, Ga, ::Val{:PenmanMonteith}; ...) - potential_ET(Tair, pressure, Rn, G, S, ::Val{:PriestleyTaylor}; ...) - potential_ET(Tair, pressure, Rn, VPD, Ga, G, S, ::Val{:PenmanMonteith}; ...) potential_ET(df, approach; ...) potential_ET!(df, approach; ...) @@ -17,12 +14,12 @@ the Penman-Monteith equation with a prescribed surface conductance. - Rn: Net radiation (W m-2) - VPD: Vapor pressure deficit (kPa) - Ga: Aerodynamic conductance to heat/water vapor (m s-1) -- G: Ground heat flux (W m-2) -- S: Sum of all storage fluxes (W m-2) - approach: Approach used. Either `Val(:PriestleyTaylor)` (default), or `Val(:PenmanMonteith)`. - df: Data_frame or matrix containing all required variables; optional optional: +- G: Ground heat flux (W m-2). Defaults to zero. +- S: Sum of all storage fluxes (W m-2) . Defaults to zero. - `Esat_formula`: formula used in [`Esat_from_Tair`](@ref) - `constants=`[`bigleaf_constants`](@ref)`()`: Dictionary with entries - cp - specific heat of air for constant pressure (J K-1 kg-1) @@ -102,8 +99,7 @@ for ecosystem water and carbon fluxes. Nature Climate Change 6, 1023 - 1027. # Calculate potential ET of a surface that receives a net radiation of 500 Wm-2 # using Priestley-Taylor: Tair,pressure,Rn = 30.0,100.0,500.0 -ET_pot, LE_pot = potential_ET(Tair,pressure,Rn, Val(:PriestleyTaylor); - alpha=1.26, infoGS = false) +ET_pot, LE_pot = potential_ET(Tair,pressure,Rn, Val(:PriestleyTaylor)) ≈(ET_pot, 0.0002035969; rtol = 1e-5) # output true @@ -124,12 +120,9 @@ true ``` """ function potential_ET(Tair, pressure, Rn, approach::Val{:PriestleyTaylor}; - G=missing,S=missing, missing_G_as_NA=false, missing_S_as_NA=false, - infoGS=true, - kwargs...) + G=zero(Tair),S=zero(Tair), kwargs...) # - G_, S_ = fill_GS_missings(G,S,missing_G_as_NA, missing_S_as_NA; infoGS) - potential_ET(Tair, pressure, Rn, G_, S_, approach; kwargs...) + potential_ET(Tair, pressure, Rn, G, S, approach; kwargs...) end, function potential_ET(Tair, pressure, Rn, G, S, ::Val{:PriestleyTaylor}; alpha=1.26, @@ -143,13 +136,9 @@ function potential_ET(Tair, pressure, Rn, G, S, ::Val{:PriestleyTaylor}; (ET_pot = ET_pot, LE_pot = LE_pot) end, function potential_ET(Tair, pressure, Rn, VPD, Ga, approach::Val{:PenmanMonteith}; - G=missing,S=missing, missing_G_as_NA=false, missing_S_as_NA=false, - infoGS=true, - kwargs...) + G=zero(Tair),S=zero(Tair), kwargs...) # - G_, S_ = fill_GS_missings(G,S,missing_G_as_NA, missing_S_as_NA; infoGS) - G_tr, S_tr = 0,0 - potential_ET(Tair, pressure, Rn, VPD, Ga, G_tr, S_tr, approach; kwargs...) + potential_ET(Tair, pressure, Rn, VPD, Ga, G, S, approach; kwargs...) end, function potential_ET(Tair, pressure, Rn, VPD, Ga, G, S, ::Val{:PenmanMonteith}; Gs_pot=0.6, @@ -166,10 +155,9 @@ function potential_ET(Tair, pressure, Rn, VPD, Ga, G, S, ::Val{:PenmanMonteith}; (ET_pot = ET_pot, LE_pot = LE_pot) end, function potential_ET(df, approach::Val{:PriestleyTaylor}; - G=missing,S=missing, missing_G_as_NA=false, missing_S_as_NA=false, infoGS=true, - kwargs...) + G=missing,S=missing, infoGS=true, kwargs...) # - dfGS = fill_GS_missings(df, G,S, missing_G_as_NA, missing_S_as_NA; infoGS) + dfGS = get_df_GS(df, G,S; infoGS) f(args...) = potential_ET(args..., approach; kwargs...) select(hcat(select(df,:Tair, :pressure, :Rn), dfGS; copycols = false), All() => ByRow(f) => AsTable @@ -179,25 +167,74 @@ function potential_ET(df, approach::Val{:PenmanMonteith}; G=missing,S=missing, missing_G_as_NA=false, missing_S_as_NA=false, infoGS=true, kwargs...) # - dfGS = fill_GS_missings(df, G,S, missing_G_as_NA, missing_S_as_NA; infoGS) + dfGS = get_df_GS(df, G,S; infoGS) f(args...) = potential_ET(args..., approach; kwargs...) select(hcat(select(df,:Tair, :pressure, :Rn, :VPD, :Ga), dfGS; copycols = false), All() => ByRow(f) => AsTable ) end, -function potential_ET!(df, approach::Val{:PriestleyTaylor}; kwargs...) +function potential_ET!(df, approach::Val{:PriestleyTaylor}; + G=missing,S=missing, infoGS=true, kwargs...) + dfGS = get_df_GS(df, G,S; infoGS) + # temporarily add G and S to the DataFrame to mutate + df._tmp_G .= dfGS.G + df._tmp_S .= dfGS.S f(args...) = potential_ET(args..., approach; kwargs...) transform!(df, - [:Tair, :pressure, :Rn, :G, :S] => ByRow(f) => AsTable - ) + [:Tair, :pressure, :Rn, :_tmp_G, :_tmp_S] => ByRow(f) => AsTable + ) + select!(df, Not([:_tmp_G, :_tmp_S])) end, -function potential_ET!(df, approach::Val{:PenmanMonteith}; kwargs...) +function potential_ET!(df, approach::Val{:PenmanMonteith}; + G=missing,S=missing, infoGS=true, kwargs...) + dfGS = get_df_GS(df, G,S; infoGS) + df._tmp_G .= dfGS.G + df._tmp_S .= dfGS.S f(args...) = potential_ET(args..., approach; kwargs...) transform!(df, - [:Tair, :pressure, :Rn, :VPD, :Ga, :G, :S] => ByRow(f) => AsTable + [:Tair, :pressure, :Rn, :VPD, :Ga, :_tmp_G, :_tmp_S] => ByRow(f) => AsTable ) + select!(df, Not([:_tmp_G, :_tmp_S])) +end + +function get_df_GS(df, G, S; infoGS=true) + nout = nrow(df) + G_ = if ismissing(G) + infoGS && @info("Ground heat flux G is not provided and set to 0.") + Zeros(nout) + else + G + end + S_ = if ismissing(S) + infoGS && @info("Storage heat flux S is not provided and set to 0.") + Zeros(nout) + else + S + end + DataFrame(G = G_, S = S_) end +# function fill_GS_missings(df::DataFrame, G,S, missing_G_as_NA, missing_S_as_NA; infoGS=true) +# nout = nrow(df) +# G_ = ifelse( +# ismissing(G), +# (infoGS && @info("Ground heat flux G is not provided and set to 0."); Zeros(nout)), +# @. ifelse(missing_G_as_NA, G, coalesce(G, 0.0)) +# ) +# S_ = ifelse( +# ismissing(S), +# (infoGS && @info("Storage heat flux S is not provided and set to 0."); Zeros(nout)), +# @. ifelse(missing_S_as_NA, G, coalesce(S, 0.0)) +# ) +# DataFrame(G = G_, S = S_) +# end + +function fill_vec(G; is_replace_missing = true, fillvalue = zero(G)) + @. ifelse(is_replace_missing, coalesce(G, fillvalue), G) +end + + + """ TODO @@ -289,36 +326,6 @@ function equilibrium_imposed_ET(Tair,pressure,VPD,Gs, Rn, end -function fill_GS_missings(G,S,missing_G_as_NA, missing_S_as_NA; infoGS=true) - # - G_ = ifelse( - ismissing(G), - (infoGS && @info("Ground heat flux G is not provided and set to 0."); 0.0), - ifelse(missing_G_as_NA, G, coalesce(G, 0.0)) - ) - S_ = ifelse( - ismissing(S), - (infoGS && @info("Storage heat flux S is not provided and set to 0."); 0.0), - ifelse(missing_S_as_NA, G, coalesce(S, 0.0)) - ) - G_,S_ -end - -function fill_GS_missings(df::DataFrame, G,S, missing_G_as_NA, missing_S_as_NA; infoGS=true) - nout = nrow(df) - G_ = ifelse( - ismissing(G), - (infoGS && @info("Ground heat flux G is not provided and set to 0."); Zeros(nout)), - @. ifelse(missing_G_as_NA, G, coalesce(G, 0.0)) - ) - S_ = ifelse( - ismissing(S), - (infoGS && @info("Storage heat flux S is not provided and set to 0."); Zeros(nout)), - @. ifelse(missing_S_as_NA, G, coalesce(S, 0.0)) - ) - DataFrame(G = G_, S = S_) -end - """ fill_GS_missings!(df::DataFrame, G=df.G, S=df.S, missing_G_as_NA=false, missing_S_as_NA=false; infoGS=true) diff --git a/test/evapotranspiration.jl b/test/evapotranspiration.jl index 455b842..3cfe069 100644 --- a/test/evapotranspiration.jl +++ b/test/evapotranspiration.jl @@ -1,11 +1,11 @@ @testset "potential_ET scalars" begin Tair,pressure,Rn = 30.0,100.0,500.0 - ET_pot, LE_pot = @test_logs (:info,r"G is not provided") (:info,r"S is not provided") potential_ET(Tair,pressure,Rn, Val(:PriestleyTaylor); alpha=1.26) + ET_pot, LE_pot = potential_ET(Tair,pressure,Rn, Val(:PriestleyTaylor); alpha=1.26) @test ≈(ET_pot, 0.0002035969; rtol = 1e-5) @test ≈(LE_pot, 494.7202; rtol = 1e-5) # VPD,Ga = 2.0, 0.1 - ET_pot,LE_pot = @test_logs (:info,r"G is not provided") (:info,r"S is not provided") potential_ET(Tair,pressure,Rn,VPD,Ga, Val(:PenmanMonteith)) + ET_pot,LE_pot = potential_ET(Tair,pressure,Rn,VPD,Ga, Val(:PenmanMonteith)) # #TODO surface_conductance(Tair=20,pressure=100,VPD=2,Ga=0.1,Rn=400,LE=LE_pot_PM) end @@ -34,13 +34,43 @@ end # # mutating dfm = copy(df) - @test_throws Exception potential_ET!( - dfm, Val(:PriestleyTaylor); alpha=1.26) - dfm = @test_logs (:info,r"G is not provided") (:info,r"S is not provided") hcat(dfm, Bigleaf.fill_GS_missings(dfm, missing, missing, false, false); copycols = false) - potential_ET!(dfm, Val(:PriestleyTaylor); alpha=1.26) - @test ncol(dfm) == 3+4 # four columns added: G,S, ET_pot, LE_pot - dfm = @test_logs (:info,r"G is not provided") (:info,r"S is not provided") fill_GS_missings!(copy(df2), missing, missing) - potential_ET!(dfm, Val(:PenmanMonteith)) - @test ncol(dfm) == ncol(df2)+4 # four columns added: G,S, ET_pot, LE_pot + #@test_throws Exception + @test_logs (:info,r"G is not provided") (:info,r"S is not provided") potential_ET!(dfm, Val(:PriestleyTaylor); alpha=1.26) + #dfm = @test_logs (:info,r"G is not provided") (:info,r"S is not provided") hcat(dfm, Bigleaf.fill_GS_missings(dfm, missing, missing, false, false); copycols = false) + #potential_ET!(dfm, Val(:PriestleyTaylor); alpha=1.26) + @test ncol(dfm) == 3+2 # two columns added: ET_pot, LE_pot + dfm = @test_logs (:info,r"G is not provided") (:info,r"S is not provided") potential_ET!(copy(df2), Val(:PenmanMonteith)) + @test ncol(dfm) == ncol(df2)+2 +end + +@testset "potential_ET dataframe missings in G" begin + df = @pipe DataFrame(Tair = 20.0:1.0:30.0,pressure = 100.0, Rn = 500.0, G = 105.0) |> + allowmissing(_, Cols(:G)) + df.G[1] = missing + df_ET = @test_logs (:info,r"S is not provided") potential_ET(df, Val(:PriestleyTaylor); G = df.G) + # non-mutating + @test ncol(df) == 4 + @test nrow(df_ET) == nrow(df) + @test last(df_ET).ET_pot < 0.0002035969 # smaller because less energy available + @test ismissing(first(df_ET).LE_pot) + # + df2 = copy(df) + df2.VPD .= 2.0 + df2.Ga .= 0.1 + df_ET2 = @test_logs (:info,r"G is not provided") potential_ET(df2, Val(:PenmanMonteith), S = df.G) + @test ncol(df2) == 6 + @test nrow(df_ET2) == nrow(df2) + @test ismissing(first(df_ET).LE_pot) + #TODO surface_conductance(Tair=20,pressure=100,VPD=2,Ga=0.1,Rn=400,LE=LE_pot_PM) + # + # mutating + dfm = copy(df) + #@test_throws Exception + @test_logs (:info,r"G is not provided") potential_ET!(dfm, Val(:PriestleyTaylor); S = dfm.G) + #dfm = @test_logs (:info,r"G is not provided") (:info,r"S is not provided") hcat(dfm, Bigleaf.fill_GS_missings(dfm, missing, missing, false, false); copycols = false) + #potential_ET!(dfm, Val(:PriestleyTaylor); alpha=1.26) + @test ncol(dfm) == ncol(df)+2 # two columns added: ET_pot, LE_pot + dfm = @test_logs (:info,r"S is not provided") potential_ET!(copy(df2), Val(:PenmanMonteith); G = dfm.G) + @test ncol(dfm) == ncol(df2)+2 end From 970a375018c7be92e63a5bd706c47237195f7796 Mon Sep 17 00:00:00 2001 From: Thomas Wutzler Date: Tue, 26 Oct 2021 13:36:12 +0200 Subject: [PATCH 09/13] test and docu equilibrium_imposed_ET --- .gitignore | 1 + docs/src/evapotranspiration.md | 2 - docs/src/walkthrough.md | 22 +++- src/Bigleaf.jl | 4 +- src/evapotranspiration.jl | 222 ++++++++++++++++++--------------- test/evapotranspiration.jl | 25 ++++ 6 files changed, 165 insertions(+), 111 deletions(-) diff --git a/.gitignore b/.gitignore index a22dafe..9117cbf 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /Manifest.toml /docs/build/ /tmp +docs/Manifest.toml diff --git a/docs/src/evapotranspiration.md b/docs/src/evapotranspiration.md index fc755c6..6dfa6ab 100644 --- a/docs/src/evapotranspiration.md +++ b/docs/src/evapotranspiration.md @@ -6,6 +6,4 @@ Pages = ["evapotranspiration.md",] ```@docs potential_ET equilibrium_imposed_ET -fill_GS_missings! -surface_conductance ``` \ No newline at end of file diff --git a/docs/src/walkthrough.md b/docs/src/walkthrough.md index e6004f6..e33020b 100644 --- a/docs/src/walkthrough.md +++ b/docs/src/walkthrough.md @@ -98,14 +98,30 @@ potential_ET(tha, Val(:PriestleyTaylor)) potential_ET(transform(tha, :Tair => x -> 25.0; renamecols=false), Val(:PriestleyTaylor)) # varying one input only Tair_vec = 10.0:1.0:20.0 -DataFrame(potential_ET.(Tair_vec, pressure, Rn, Val(:PriestleyTaylor); infoGS=false)) +DataFrame(potential_ET.(Tair_vec, pressure, Rn, Val(:PriestleyTaylor))) nothing # hide ``` ## Ground heat flux and storage fluxes -Many functions require the available energy ($A$), which is defined as ($A = R_n - G - S$, all in $\text{W m}^{-2}$), where $R_n$ is the net radiation, $G$ is the ground heat flux, and $S$ is the sum of all storage fluxes of the ecosystem (see e.g. Leuning et al. 2012 for an overview). For some sites, $G$ is not available, and for most sites, only a few components of $S$ are measured. In `Bigleaf.jl` it is not a problem if $G$ and/or $S$ are missing (other than the results might be (slightly) biased), but special options exist for the treatment of missing $S$ and $G$ values. If the options `missing_G_as_NA = TRUE` or `missing_S_as_NA = TRUE`, then the output variable is not calculated for that time period. Otherwise missing $S$ and $G$ values are set to O automatically. Please note that the default is to ignore $S$ and $G$ values. If $G$ and/or $S$ are available, they usually have to be added explicitly to the function call by explicitly using the optional arguments. The positional forms do not check for missing -values. +Many functions require the available energy ($A$), which is defined as ($A = R_n - G - S$, +all in $\text{W m}^{-2}$), where $R_n$ is the net radiation, $G$ is the ground heat flux, +and $S$ is the sum of all storage fluxes of the ecosystem +(see e.g. Leuning et al. 2012 for an overview). For some sites, $G$ is not available, +and for most sites, only a few components of $S$ are measured. + +In `Bigleaf.jl` it is not a problem if $G$ and/or $S$ are missing (other than the results might be (slightly) biased), but special options exist for the treatment of missing $S$ and $G$ values. + +Note that the default for G and S in the dataframe variant is missing (and assumed zero), +even if those columns are +present in the DataFrame. You need to explictly pass those columns with the optional +arguments: e.g. `potential_ET(df, Val(:PriestleyTaylor); G = df.G)` + +Note that in difference to the bigleaf R package missing entries in a provide +vector are not relaced by zero by default. +You need to explitly use coalesce when specifying a ground heat flux +for which missings should be replaced by zero: `;G = coalesce(df.G, zero(df.G))` + # Function walkthrough # diff --git a/src/Bigleaf.jl b/src/Bigleaf.jl index b3b0eaa..5cd056e 100644 --- a/src/Bigleaf.jl +++ b/src/Bigleaf.jl @@ -23,8 +23,8 @@ export air_density, pressure_from_elevation, psychrometric_constant, wetbulb_temp_from_e_Tair_gamma, wetbulb_temp export calc_sun_position_MOD, calc_sun_position_hor export potential_radiation, extraterrestrial_radiation, get_datetime_for_doy_hour -export potential_ET, potential_ET!, fill_GS_missings!, equilibrium_imposed_ET, - surface_conductance +export potential_ET, potential_ET!, equilibrium_imposed_ET, equilibrium_imposed_ET! +#export surface_conductance include("util.jl") include("bigleaf_constants.jl") diff --git a/src/evapotranspiration.jl b/src/evapotranspiration.jl index e34ff6e..b95f3be 100755 --- a/src/evapotranspiration.jl +++ b/src/evapotranspiration.jl @@ -29,13 +29,9 @@ optional: - Rd - gas constant of dry air (J kg-1 K-1) - Rgas - universal gas constant (J mol-1 K-1) - Kelvin - conversion degree Celsius to Kelvin -additional optional arguments if G and S are not specified by postition -and in the non-mutating DataFrame variant. -- G and S: as in the positional forms, but checked for missing or containing missings -- missing_G_as_NA: if `true`, missing optional G are treated as `NA`s, - otherwise set to 0. -- missing_S_as_NA: if `true`, missing optional S are treated as `NA`s, - otherwise set to 0. +additional optional arguments with data.frame variants +- infoGS=ture: sete to false to avoid infor log-message if G or S is not + specified additional optional for PriestleyTaylor: - alpha: Priestley-Taylor coefficient additional optional for PenmanMonteith: @@ -62,25 +58,27 @@ and ``\\gamma`` is the psychrometric constant (kPa K-1). The value of `Gs_pot` is typically a maximum value of Gs observed at the site, e.g. the 90th percentile of Gs within the growing season. -If keyword arguments `G` or `S` in the are set to `missing`, ground heat flux and storage flux -are assumed zero respectively. Note, that these keyword argument are not available in the -mutating form, where the caller has to add tree these columns before -(see [fill_GS_missings](@ref)). - +Ground heat flux and storage heat flux `G` or `S` are provided as optional +arguments. In the input-explicit variants, they default to zero. +In the data-frame arguments, they default to missing, which results +in assuming them to be zero which is displayed in a log-message. +Note that in difference ot the bigleaf R package, you explitly need to +care for missing values (see examples). + Both methods are provided with several forms: - all required inputs as positional arguments -- provideing G and S as positional arguments with handing of missing values - providing a DataFrame with columns corresponding to required inputs - + returning a DataFrame with only the result columns. +- a mutating DataFrame version that returns the original DataFrame with + result columns added or modified. # Value NamedTuple or DataFrame with the following entries: - `ET_pot`: Potential evapotranspiration (kg m-2 s-1) - `LE_pot`: Potential latent heat flux (W m-2) -For the mutating form, the original df with columns `ET_pot`, `LE_pot`, `G`, and `S` +For the mutating form, the original df with columns `ET_pot`, `LE_pot` updated or added. - # References - Priestley, C_H_B., Taylor, R_J., 1972: On the assessment of surface heat flux and evaporation using large-scale parameters. Monthly Weather Review 100, 81-92. @@ -94,23 +92,22 @@ for ecosystem water and carbon fluxes. Nature Climate Change 6, 1023 - 1027. [`surface_conductance`](@ref) # Examples - +Calculate potential ET of a surface that receives a net radiation of 500 Wm-2 +using Priestley-Taylor: ```jldoctest; output=false -# Calculate potential ET of a surface that receives a net radiation of 500 Wm-2 -# using Priestley-Taylor: Tair,pressure,Rn = 30.0,100.0,500.0 ET_pot, LE_pot = potential_ET(Tair,pressure,Rn, Val(:PriestleyTaylor)) ≈(ET_pot, 0.0002035969; rtol = 1e-5) # output true ``` -```@jldoctest; output=false -# Calculate potential ET for a surface with known Gs (0.5 mol m-2 s-1) and Ga (0.1 m s-1) -# using Penman-Monteith: + +Calculate potential ET for a surface with known Gs (0.5 mol m-2 s-1) and Ga (0.1 m s-1) +using Penman-Monteith: +```jldoctest; output=false Tair,pressure,Rn = 30.0,100.0,500.0 -VPD,Ga = 2.0, 0.1 -ET_pot,LE_pot = potential_ET(Tair,pressure,Rn,VPD, Ga, Val(:PenmanMonteith); - Gs_pot=0.5, infoGS=false) +VPD, Ga = 2.0, 0.1 +ET_pot, LE_pot = potential_ET(Tair,pressure,Rn,VPD, Ga, Val(:PenmanMonteith); Gs_pot=0.5,) # now cross-check with the inverted equation #Ga2 = surface_conductance(Tair=20,pressure=100,VPD=2,Ga=0.1,Rn=400,LE=LE_pot_PM) #Ga2 ≈ GA @@ -118,6 +115,23 @@ true # output true ``` + +DataFrame variant with explicitly replacing missings: +```jldoctest; output=false +using DataFrames +df = DataFrame(Tair = 20.0:1.0:30.0,pressure = 100.0, Rn = 500.0, G = 105.0, VPD = 2.0, Ga = 0.1) +allowmissing!(df, Cols(:G)); df.G[1] = missing +# +# need to provide G explicitly +df_ET = potential_ET(df, Val(:PriestleyTaylor); G = df.G, infoGS = false) +ismissing(df_ET.ET_pot[1]) +# +# use coalesce to replace missing values +df_ET = potential_ET(df, Val(:PriestleyTaylor); G = coalesce.(df.G, zero(df.G)), infoGS = false) +!ismissing(df_ET.ET_pot[1]) +# output +true +``` """ function potential_ET(Tair, pressure, Rn, approach::Val{:PriestleyTaylor}; G=zero(Tair),S=zero(Tair), kwargs...) @@ -164,11 +178,12 @@ function potential_ET(df, approach::Val{:PriestleyTaylor}; ) end, function potential_ET(df, approach::Val{:PenmanMonteith}; - G=missing,S=missing, missing_G_as_NA=false, missing_S_as_NA=false, infoGS=true, - kwargs...) + G=missing,S=missing, infoGS=true, kwargs...) # dfGS = get_df_GS(df, G,S; infoGS) - f(args...) = potential_ET(args..., approach; kwargs...) + function f(args...) + potential_ET(args..., approach; kwargs...) + end select(hcat(select(df,:Tair, :pressure, :Rn, :VPD, :Ga), dfGS; copycols = false), All() => ByRow(f) => AsTable ) @@ -229,32 +244,28 @@ end # DataFrame(G = G_, S = S_) # end -function fill_vec(G; is_replace_missing = true, fillvalue = zero(G)) - @. ifelse(is_replace_missing, coalesce(G, fillvalue), G) -end - - +# function fill_vec(G; is_replace_missing = true, fillvalue = zero(G)) +# @. ifelse(is_replace_missing, coalesce(G, fillvalue), G) +# end """ - TODO + equilibrium_imposed_ET(Tair,pressure,VPD,Gs, Rn; ...) + equilibrium_imposed_ET(df; ...) + equilibrium_imposed_ET!(df; ...) Evapotranspiration (ET) split up into imposed ET and equilibrium ET. +# Argumens - Tair: Air temperature (deg C) - pressure: Atmospheric pressure (kPa) - VPD: Air vapor pressure deficit (kPa) - Gs: surface conductance to water vapor (m s-1) - Rn: Net radiation (W m-2) +optional - G: Ground heat flux (W m-2); optional - S: Sum of all storage fluxes (W m-2); optional -- missing_G_as_NA: if `TRUE`, missing G are treated as `NA`s, otherwise set 0. -- missing_S_as_NA: if `TRUE`, missing S are treated as `NA`s, otherwise set 0. -- Esat_formula: Optional: formula to be used for the calculation of esat and slope of esat. - One of `"Sonntag_1990"` (Default), `"Alduchov_1996"`, `"Allen_1998"`. - See [`Esat_slope`](@ref). +- `Esat_formula`: formula used in [`Esat_from_Tair`](@ref) - `constants=`[`bigleaf_constants`](@ref)`()`: Dictionary with entries - -- constants - cp - specific heat of air for constant pressure (J K-1 kg-1) - eps - ratio of the molecular weight of water vapor to dry (-) - Pa2kPa - conversion pascal (Pa) to kilopascal (kPa) @@ -265,106 +276,102 @@ Total evapotranspiration can be written in the form (Jarvis & McNaughton 6): ``ET = \\Omega ET_{eq} + (1 - \\Omega)ET_{imp}`` where ``\\Omega`` is the decoupling coefficient as calculated from -[`decoupling`](@ref). `ET_eq` is the equilibrium evapotranspiration e, -the ET rate that would occur under uncoupled conditions, where tbudget +[`decoupling`](@ref). `ET_eq` is the equilibrium evapotranspiration i.e., +the ET rate that would occur under uncoupled conditions, where the budget is dominated by radiation (when Ga -> 0): - ``ET_eq = (\\Delta * (Rn - G - S) * \\lambda) / (\\Del\\gamma) +``ET_{eq} = (\\Delta * (Rn - G - S) * \\lambda) / ( \\Delta \\gamma)`` where ``\\Delta`` is the slope of the saturation vapor pressur(kPa K-1), -``\\lambda`` is the latent heat of vaporization (J kg-1), and \\gamma`` +``\\lambda`` is the latent heat of vaporization (J kg-1), and ``\\gamma`` is the psychrometric constant (kPa K-1). `ET_imp` is the imposed evapotranspiration rate, the ET rate that would occur under fully coupled conditions (when Ga -> inf): - ``ET_imp = (\\rho * cp * VPD * Gs * \\lambda) / \\gamma`` +``ET_{imp} = (\\rho * cp * VPD * Gs * \\lambda) / \\gamma`` where ``\\rho`` is the air density (kg m-3). # Note Surface conductance (Gs) can be calculated with [`surface_conductance`](@ref) -Aerodynamic conductance (Ga) can be calculated using erodynamic_conductance`](@ref). +Aerodynamic conductance (Ga) can be calculated using [`aerodynamic_conductance`](@ref). # Value -A DataFrame with the following columns: -- ET_eq: Equilibrium ET (kg m-2 s-1) -- ET_imp: Imposed ET (kg m-2 s-1) -- LE_eq: Equilibrium LE (W m-2) -- LE_imp: Imposed LE (W m-2) +A `NamedTuple` or `DataFrame` with the following columns: +- `ET_eq`: Equilibrium ET (kg m-2 s-1) +- `ET_imp`: Imposed ET (kg m-2 s-1) +- `LE_eq`: Equilibrium LE (W m-2) +- `LE_imp`: Imposed LE (W m-2) -#References +# References - Jarvis, P_G., McNaughton, K_G., 1986: Stomatal control of transpiration: -scaling up from leaf to region. Advances in Ecological Rese1-49. + scaling up from leaf to region. Advances in Ecological Rese1-49. - Monteith, J_L., Unsworth, M_H., 2008: Principles of ironmPhysics. -3rd edition. Academic Press, London. - -#See also -[`decoupling`](@ref) + 3rd edition. Academic Press, London. -```@example; output = false -df = DataFrame(Tair=20,pressure=100,VPD=seq(0.5,4,0.5), - Gs_ms=seq(0.01,0.002,length_out=8),Rn=seq(50,400,50) -equilibrium_imposed_ET(df) +# Examples +```jldoctest; output = false +Tair,pressure,Rn, VPD, Gs = 20.0,100.0,50.0, 0.5, 0.01 +ET_eq, ET_imp, LE_eq, LE_imp = equilibrium_imposed_ET(Tair,pressure,VPD,Gs, Rn) +≈(ET_eq, 1.399424e-05; rtol = 1e-5) +# output +true ``` """ -function equilibrium_imposed_ET(Tair,pressure,VPD,Gs, Rn, - G=NULL,S=NULL,missing_G_as_NA=false,missing_S_as_NA=false, +function equilibrium_imposed_ET(Tair,pressure,VPD,Gs, Rn; + G=zero(Tair),S=zero(Tair), kwargs...) + equilibrium_imposed_ET(Tair,pressure,VPD,Gs, Rn, G, S; kwargs...) +end, +function equilibrium_imposed_ET(Tair,pressure,VPD,Gs, Rn, G, S; Esat_formula=Val(:Sonntag_1990), constants=bigleaf_constants()) # - #check_input(data,list(Tair,pressure,VPD,Rn,Gs,G,S)) - G,S = fill_GS_missings(G,S,missing_G_as_NA, missing_S_as_NA) - rho = air_density(Tair,pressure,constants) - gamma = psychrometric_constant(Tair,pressure,constants) - Delta = Esat_from_Tair_deriv(Tair,Esat_formula,constants) + rho = air_density(Tair, pressure; constants) + gamma = psychrometric_constant(Tair, pressure; constants) + Delta = Esat_from_Tair_deriv(Tair; formula = Esat_formula, constants) LE_eq = (Delta * (Rn - G - S)) / (gamma + Delta) LE_imp = (rho * constants[:cp] * Gs * VPD) / gamma # ET_imp = LE_to_ET(LE_imp,Tair) ET_eq = LE_to_ET(LE_eq,Tair) - (ET_pot = ET_pot, LE_pot = LE_pot, LE_imp = LE_imp) + (;ET_eq, ET_imp, LE_eq, LE_imp) +end, +function equilibrium_imposed_ET(df; + G=missing,S=missing, infoGS=true, kwargs...) + # + dfGS = get_df_GS(df, G,S; infoGS) + function f(args...) + equilibrium_imposed_ET(args...; kwargs...) + end + dfb = hcat(select(df,:Tair, :pressure, :VPD, :Gs, :Rn), dfGS; copycols = false) + select(dfb, All() => ByRow(f) => AsTable ) +end, +function equilibrium_imposed_ET!(df; + G=missing,S=missing, infoGS=true, kwargs...) + # + dfGS = get_df_GS(df, G,S; infoGS) + # temporarily add G and S to the DataFrame to mutate + df._tmp_G .= dfGS.G + df._tmp_S .= dfGS.S + f(args...) = equilibrium_imposed_ET(args...; kwargs...) + transform!(df, + [:Tair, :pressure, :VPD, :Gs, :Rn, :_tmp_G, :_tmp_S] => ByRow(f) => AsTable + ) + select!(df, Not([:_tmp_G, :_tmp_S])) end -""" - fill_GS_missings!(df::DataFrame, G=df.G, S=df.S, - missing_G_as_NA=false, missing_S_as_NA=false; infoGS=true) -Fill missing values in ground heat flux and storage flux. - -# Arguments -- df: DataFrame where columns G and S should be updated -- G: Ground heat flux -- S: Storage heat flux -- missing_G_as_NA: set to true to not fill NAs in G to propagate to computations -- missing_S_as_NA: set to true to not fill NAs in S to propagate to computations -- infoGS: set to false to avoid log info message +""" + TODO; implement decoupling. -```@example -true -# using DataFrames -# df = DataFrame(Tair = 20.0:1.0:30.0,pressure = 100.0, Rn = 500.0) -# fill_GS_missings!(df, missing, missing) -# all( df.S .== df.G .== 0.0) -``` +This stub is there to satisfy links im Help-pages. """ -function fill_GS_missings!(df::DataFrame, G=df.G, S=df.S, - missing_G_as_NA=false, missing_S_as_NA=false; infoGS=true - ) - nout = nrow(df) - df.G .= ifelse( - ismissing(G), - (infoGS && @info("Ground heat flux G is not provided and set to 0."); Zeros(nout)), - @. ifelse(missing_G_as_NA, G, coalesce(G, 0.0)) - ) - df.S .= ifelse( - ismissing(S), - (infoGS && @info("Storage heat flux S is not provided and set to 0."); Zeros(nout)), - @. ifelse(missing_S_as_NA, G, coalesce(S, 0.0)) - ) - df +function decoupling() + error("not yet implemented.") end + """ TODO; implement surface_conductance. @@ -374,5 +381,12 @@ function surface_conductance() error("not yet implemented.") end +""" + TODO; implement aerodynamic_conductance. +This stub is there to satisfy links im Help-pages. +""" +function aerodynamic_conductance() + error("not yet implemented.") +end diff --git a/test/evapotranspiration.jl b/test/evapotranspiration.jl index 3cfe069..04680c1 100644 --- a/test/evapotranspiration.jl +++ b/test/evapotranspiration.jl @@ -74,3 +74,28 @@ end @test ncol(dfm) == ncol(df2)+2 end +@testset "equilibrium_imposed_ET scalars" begin + # regression from R package example + Tair,pressure,Rn, VPD, Gs = 20.0,100.0,50.0, 0.5, 0.01 + ET_eq, ET_imp, LE_eq, LE_imp = equilibrium_imposed_ET(Tair,pressure,VPD,Gs, Rn) + @test ≈(ET_eq, 1.399424e-05; rtol = 1e-5) + @test ≈(ET_imp, 3.695727e-05; rtol = 1e-5) + @test ≈(LE_eq, 34.33628; rtol = 1e-5) + @test ≈(LE_imp, 90.67837; rtol = 1e-5) + # + df = DataFrame(Tair = 20.0:1.0:22.0, pressure = 100.0, Rn = 50.0, VPD = 0.5, Gs = 0.01) + ncoldf0 = ncol(df) + df_ET = @test_logs (:info,r"G is not provided") (:info,r"S is not provided") equilibrium_imposed_ET(df) + @test ncol(df) == ncoldf0 + @test nrow(df_ET) == nrow(df) + @test ≈(first(df_ET).ET_eq, ET_eq) + @test ≈(first(df_ET).ET_imp, ET_imp) + # + dfm = copy(df) + dfm_ET = equilibrium_imposed_ET!(dfm; infoGS = false) + @test ncol(dfm) == ncoldf0 + 4 + @test nrow(dfm) == nrow(df) + @test ≈(first(dfm_ET).ET_eq, ET_eq) + @test ≈(first(dfm_ET).ET_imp, ET_imp) + #TODO surface_conductance(Tair=20,pressure=100,VPD=2,Ga=0.1,Rn=400,LE=LE_pot_PM) +end \ No newline at end of file From c0cfa0f9d5f8609c7cd78cc2a0a928986818fa8f Mon Sep 17 00:00:00 2001 From: Thomas Wutzler Date: Tue, 26 Oct 2021 14:43:28 +0200 Subject: [PATCH 10/13] revert to old syntax of adding broadcasted columns to DataFrame. Tests failed in Julia 1..3 --- src/evapotranspiration.jl | 12 ++++++------ test/evapotranspiration.jl | 10 ++++++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/evapotranspiration.jl b/src/evapotranspiration.jl index b95f3be..e2a30f7 100755 --- a/src/evapotranspiration.jl +++ b/src/evapotranspiration.jl @@ -192,8 +192,8 @@ function potential_ET!(df, approach::Val{:PriestleyTaylor}; G=missing,S=missing, infoGS=true, kwargs...) dfGS = get_df_GS(df, G,S; infoGS) # temporarily add G and S to the DataFrame to mutate - df._tmp_G .= dfGS.G - df._tmp_S .= dfGS.S + df[!, :_tmp_G] .= dfGS.G + df[!, :_tmp_S] .= dfGS.S f(args...) = potential_ET(args..., approach; kwargs...) transform!(df, [:Tair, :pressure, :Rn, :_tmp_G, :_tmp_S] => ByRow(f) => AsTable @@ -203,8 +203,8 @@ end, function potential_ET!(df, approach::Val{:PenmanMonteith}; G=missing,S=missing, infoGS=true, kwargs...) dfGS = get_df_GS(df, G,S; infoGS) - df._tmp_G .= dfGS.G - df._tmp_S .= dfGS.S + df[!, :_tmp_G] .= dfGS.G + df[!, :_tmp_S] .= dfGS.S f(args...) = potential_ET(args..., approach; kwargs...) transform!(df, [:Tair, :pressure, :Rn, :VPD, :Ga, :_tmp_G, :_tmp_S] => ByRow(f) => AsTable @@ -351,8 +351,8 @@ function equilibrium_imposed_ET!(df; # dfGS = get_df_GS(df, G,S; infoGS) # temporarily add G and S to the DataFrame to mutate - df._tmp_G .= dfGS.G - df._tmp_S .= dfGS.S + df[!, :_tmp_G] .= dfGS.G + df[!, :_tmp_S] .= dfGS.S f(args...) = equilibrium_imposed_ET(args...; kwargs...) transform!(df, [:Tair, :pressure, :VPD, :Gs, :Rn, :_tmp_G, :_tmp_S] => ByRow(f) => AsTable diff --git a/test/evapotranspiration.jl b/test/evapotranspiration.jl index 04680c1..bb18b46 100644 --- a/test/evapotranspiration.jl +++ b/test/evapotranspiration.jl @@ -21,8 +21,10 @@ end @test ≈(last(df_ET).LE_pot, 494.7202; rtol = 1e-5) # df2 = copy(df) - df2.VPD .= 2.0 - df2.Ga .= 0.1 + # df2.VPD .= 2.0 # fail in older versions + # df2.Ga .= 0.1 + df2[!, :VPD] .= 2.0 + df2[!, :Ga] .= 0.1 # df2 = transform(df, # [] => ByRow(() -> 2.0) => :VPD, # [] => ByRow(() -> 0.1) => :Ga, @@ -55,8 +57,8 @@ end @test ismissing(first(df_ET).LE_pot) # df2 = copy(df) - df2.VPD .= 2.0 - df2.Ga .= 0.1 + df2[!, :VPD] .= 2.0 + df2[!, :Ga] .= 0.1 df_ET2 = @test_logs (:info,r"G is not provided") potential_ET(df2, Val(:PenmanMonteith), S = df.G) @test ncol(df2) == 6 @test nrow(df_ET2) == nrow(df2) From 446cfe2640072609eb5e6b3abe2f9555c466ac82 Mon Sep 17 00:00:00 2001 From: Thomas Wutzler Date: Tue, 26 Oct 2021 15:05:51 +0200 Subject: [PATCH 11/13] add tests for potential radiation --- .gitignore | 1 + Project.toml | 2 +- test/Manifest.toml | 265 ------------------------------------ test/Project.toml | 1 + test/potential_radiation.jl | 5 - test/runtests.jl | 8 +- test/util.jl | 4 + 7 files changed, 14 insertions(+), 272 deletions(-) delete mode 100644 test/Manifest.toml create mode 100644 test/util.jl diff --git a/.gitignore b/.gitignore index 9117cbf..cb7d064 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ /docs/build/ /tmp docs/Manifest.toml +test/Manifest.toml diff --git a/Project.toml b/Project.toml index 468ddf1..868faf7 100644 --- a/Project.toml +++ b/Project.toml @@ -24,7 +24,7 @@ LabelledArrays = "1" Optim = "1" RecursiveArrayTools = "2" StaticArrays = "1" -julia = "1" +julia = "1.6, 1.7" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/Manifest.toml b/test/Manifest.toml deleted file mode 100644 index 616778b..0000000 --- a/test/Manifest.toml +++ /dev/null @@ -1,265 +0,0 @@ -# This file is machine-generated - editing it directly is not advised - -julia_version = "1.7.0-rc1" -manifest_format = "2.0" - -[[deps.ArgTools]] -uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f" - -[[deps.Artifacts]] -uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" - -[[deps.Base64]] -uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" - -[[deps.Compat]] -deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] -git-tree-sha1 = "31d0151f5716b655421d9d75b7fa74cc4e744df2" -uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" -version = "3.39.0" - -[[deps.CompilerSupportLibraries_jll]] -deps = ["Artifacts", "Libdl"] -uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae" - -[[deps.Crayons]] -git-tree-sha1 = "3f71217b538d7aaee0b69ab47d9b7724ca8afa0d" -uuid = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f" -version = "4.0.4" - -[[deps.DataAPI]] -git-tree-sha1 = "cc70b17275652eb47bc9e5f81635981f13cea5c8" -uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" -version = "1.9.0" - -[[deps.DataFrames]] -deps = ["Compat", "DataAPI", "Future", "InvertedIndices", "IteratorInterfaceExtensions", "LinearAlgebra", "Markdown", "Missings", "PooledArrays", "PrettyTables", "Printf", "REPL", "Reexport", "SortingAlgorithms", "Statistics", "TableTraits", "Tables", "Unicode"] -git-tree-sha1 = "d785f42445b63fc86caa08bb9a9351008be9b765" -uuid = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" -version = "1.2.2" - -[[deps.DataStructures]] -deps = ["Compat", "InteractiveUtils", "OrderedCollections"] -git-tree-sha1 = "7d9d316f04214f7efdbb6398d545446e246eff02" -uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" -version = "0.18.10" - -[[deps.DataValueInterfaces]] -git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6" -uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464" -version = "1.0.0" - -[[deps.Dates]] -deps = ["Printf"] -uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" - -[[deps.DelimitedFiles]] -deps = ["Mmap"] -uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" - -[[deps.Distributed]] -deps = ["Random", "Serialization", "Sockets"] -uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" - -[[deps.Downloads]] -deps = ["ArgTools", "LibCURL", "NetworkOptions"] -uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6" - -[[deps.Formatting]] -deps = ["Printf"] -git-tree-sha1 = "8339d61043228fdd3eb658d86c926cb282ae72a8" -uuid = "59287772-0a20-5a39-b81b-1366585eb4c0" -version = "0.4.2" - -[[deps.Future]] -deps = ["Random"] -uuid = "9fa8497b-333b-5362-9e8d-4d0656e87820" - -[[deps.InteractiveUtils]] -deps = ["Markdown"] -uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" - -[[deps.InvertedIndices]] -git-tree-sha1 = "bee5f1ef5bf65df56bdd2e40447590b272a5471f" -uuid = "41ab1584-1d38-5bbf-9106-f11c6c58b48f" -version = "1.1.0" - -[[deps.IteratorInterfaceExtensions]] -git-tree-sha1 = "a3f24677c21f5bbe9d2a714f95dcd58337fb2856" -uuid = "82899510-4779-5014-852e-03e436cf321d" -version = "1.0.0" - -[[deps.LibCURL]] -deps = ["LibCURL_jll", "MozillaCACerts_jll"] -uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21" - -[[deps.LibCURL_jll]] -deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"] -uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0" - -[[deps.LibGit2]] -deps = ["Base64", "NetworkOptions", "Printf", "SHA"] -uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" - -[[deps.LibSSH2_jll]] -deps = ["Artifacts", "Libdl", "MbedTLS_jll"] -uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8" - -[[deps.Libdl]] -uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" - -[[deps.LinearAlgebra]] -deps = ["Libdl", "libblastrampoline_jll"] -uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" - -[[deps.Logging]] -uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" - -[[deps.Markdown]] -deps = ["Base64"] -uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" - -[[deps.MbedTLS_jll]] -deps = ["Artifacts", "Libdl"] -uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1" - -[[deps.Missings]] -deps = ["DataAPI"] -git-tree-sha1 = "bf210ce90b6c9eed32d25dbcae1ebc565df2687f" -uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" -version = "1.0.2" - -[[deps.Mmap]] -uuid = "a63ad114-7e13-5084-954f-fe012c677804" - -[[deps.MozillaCACerts_jll]] -uuid = "14a3606d-f60d-562e-9121-12d972cd8159" - -[[deps.NetworkOptions]] -uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908" - -[[deps.OpenBLAS_jll]] -deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"] -uuid = "4536629a-c528-5b80-bd46-f80d51c5b363" - -[[deps.OrderedCollections]] -git-tree-sha1 = "85f8e6578bf1f9ee0d11e7bb1b1456435479d47c" -uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" -version = "1.4.1" - -[[deps.Pipe]] -git-tree-sha1 = "6842804e7867b115ca9de748a0cf6b364523c16d" -uuid = "b98c9c47-44ae-5843-9183-064241ee97a0" -version = "1.3.0" - -[[deps.Pkg]] -deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"] -uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" - -[[deps.PooledArrays]] -deps = ["DataAPI", "Future"] -git-tree-sha1 = "a193d6ad9c45ada72c14b731a318bedd3c2f00cf" -uuid = "2dfb63ee-cc39-5dd5-95bd-886bf059d720" -version = "1.3.0" - -[[deps.PrettyTables]] -deps = ["Crayons", "Formatting", "Markdown", "Reexport", "Tables"] -git-tree-sha1 = "d940010be611ee9d67064fe559edbb305f8cc0eb" -uuid = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d" -version = "1.2.3" - -[[deps.Printf]] -deps = ["Unicode"] -uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" - -[[deps.REPL]] -deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"] -uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" - -[[deps.Random]] -deps = ["Serialization"] -uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" - -[[deps.Reexport]] -git-tree-sha1 = "45e428421666073eab6f2da5c9d310d99bb12f9b" -uuid = "189a3867-3050-52da-a836-e630ba90ab69" -version = "1.2.2" - -[[deps.SHA]] -uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" - -[[deps.Serialization]] -uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" - -[[deps.SharedArrays]] -deps = ["Distributed", "Mmap", "Random", "Serialization"] -uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" - -[[deps.Sockets]] -uuid = "6462fe0b-24de-5631-8697-dd941f90decc" - -[[deps.SortingAlgorithms]] -deps = ["DataStructures"] -git-tree-sha1 = "b3363d7460f7d098ca0912c69b082f75625d7508" -uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c" -version = "1.0.1" - -[[deps.SparseArrays]] -deps = ["LinearAlgebra", "Random"] -uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" - -[[deps.Statistics]] -deps = ["LinearAlgebra", "SparseArrays"] -uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" - -[[deps.Suppressor]] -git-tree-sha1 = "a819d77f31f83e5792a76081eee1ea6342ab8787" -uuid = "fd094767-a336-5f1f-9728-57cf17d0bbfb" -version = "0.2.0" - -[[deps.TOML]] -deps = ["Dates"] -uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76" - -[[deps.TableTraits]] -deps = ["IteratorInterfaceExtensions"] -git-tree-sha1 = "c06b2f539df1c6efa794486abfb6ed2022561a39" -uuid = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c" -version = "1.0.1" - -[[deps.Tables]] -deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "TableTraits", "Test"] -git-tree-sha1 = "fed34d0e71b91734bf0a7e10eb1bb05296ddbcd0" -uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" -version = "1.6.0" - -[[deps.Tar]] -deps = ["ArgTools", "SHA"] -uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e" - -[[deps.Test]] -deps = ["InteractiveUtils", "Logging", "Random", "Serialization"] -uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" - -[[deps.UUIDs]] -deps = ["Random", "SHA"] -uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" - -[[deps.Unicode]] -uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" - -[[deps.Zlib_jll]] -deps = ["Libdl"] -uuid = "83775a58-1f1d-513f-b197-d71354ab007a" - -[[deps.libblastrampoline_jll]] -deps = ["Artifacts", "Libdl", "OpenBLAS_jll"] -uuid = "8e850b90-86db-534c-a0d3-1478176c7d93" - -[[deps.nghttp2_jll]] -deps = ["Artifacts", "Libdl"] -uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d" - -[[deps.p7zip_jll]] -deps = ["Artifacts", "Libdl"] -uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0" diff --git a/test/Project.toml b/test/Project.toml index 41d023f..6ea5027 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -4,3 +4,4 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" Pipe = "b98c9c47-44ae-5843-9183-064241ee97a0" Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53" diff --git a/test/potential_radiation.jl b/test/potential_radiation.jl index 840c4e7..283b032 100644 --- a/test/potential_radiation.jl +++ b/test/potential_radiation.jl @@ -1,8 +1,3 @@ -@testset "frac_hour" begin - p = frac_hour(1+1/60) - @test p == Hour(1) + Minute(1) -end - @testset "get_datetime_for_doy_hour summer" begin hours = [0,π,24] dts = get_datetime_for_doy_hour.(1, hours; year = 2021) diff --git a/test/runtests.jl b/test/runtests.jl index a51cbf8..ee4f73c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,8 +1,11 @@ using Bigleaf using Test -using Pipe, DataFrames, Dates +using Pipe, DataFrames, Dates, TimeZones @testset "Bigleaf" begin + @testset "util" begin + include("util.jl") + end @testset "unit_conversions" begin include("unit_conversions.jl") end @@ -12,6 +15,9 @@ using Pipe, DataFrames, Dates @testset "sun_position" begin include("sun_position.jl") end + @testset "potential_radiation" begin + include("potential_radiation.jl") + end @testset "evapotranspiration" begin include("evapotranspiration.jl") end diff --git a/test/util.jl b/test/util.jl new file mode 100644 index 0000000..a28d2b3 --- /dev/null +++ b/test/util.jl @@ -0,0 +1,4 @@ +@testset "frac_hour" begin + @test frac_hour(Minute, 1+1/60) == Hour(1) + Minute(1) + @test frac_hour(1+1/60) == Hour(1) + Minute(1) +end From 7c1768ff53456450777ff76ace4f89cb8b12cfc7 Mon Sep 17 00:00:00 2001 From: Thomas Wutzler Date: Tue, 26 Oct 2021 15:19:31 +0200 Subject: [PATCH 12/13] remove suppress_err in setup block --- docs/src/walkthrough.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/src/walkthrough.md b/docs/src/walkthrough.md index e33020b..55b9990 100644 --- a/docs/src/walkthrough.md +++ b/docs/src/walkthrough.md @@ -28,7 +28,8 @@ using Latexify using DataDeps, Suppressor using RData import CodecBzip2, CodecXz -@suppress_err register(DataDep( +#@suppress_err # error in github-actions: GitHubActionsLogger has no field stream +register(DataDep( "DE_Tha_Jun_2014.rda", "downloading exampple dataset DE_Tha_Jun_2014 from bitbucket.org/juergenknauer/bigleaf", "https://bitbucket.org/juergenknauer/bigleaf/raw/0ebe11626b4409305951e8add9f6436703c82584/data/DE_Tha_Jun_2014.rda", From 41a234bdd1c2859d64701d531da77d7cd0811cec Mon Sep 17 00:00:00 2001 From: Thomas Wutzler Date: Tue, 26 Oct 2021 15:33:40 +0200 Subject: [PATCH 13/13] remove suppress_err in example blocks --- docs/src/walkthrough.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/src/walkthrough.md b/docs/src/walkthrough.md index 55b9990..e7de8d9 100644 --- a/docs/src/walkthrough.md +++ b/docs/src/walkthrough.md @@ -209,7 +209,7 @@ lat,long = 51.0, 13.6 # Dresden Germany #deg2second = 24*3600/360 doy = 160 datetimes = DateTime(2021) .+Day(doy-1) .+ Hour.(hours) #.- Second(round(long*deg2second)) -res3 = @suppress_err @pipe calc_sun_position_hor.(datetimes, lat, long) |> DataFrame(_) +res3 = @pipe calc_sun_position_hor.(datetimes, lat, long) |> DataFrame(_) @df res3 scatter(datetimes, cols([:altitude,:azimuth]), legend = :topleft, xlab="Date and Time", ylab = "rad") ``` @@ -219,7 +219,7 @@ about 55min ahead of local winter time. ```@example doc summernoon = DateTime(2021) +Day(doy-1) + Hour(12) -sunpos = @suppress_err calc_sun_position_hor(summernoon, lat, long) +sunpos = calc_sun_position_hor(summernoon, lat, long) sunpos.hourangle * 24*60/(2*π) # convert angle to minutes ```