Skip to content

Clarification about parameter sign (negative or positive) in compute.thetaAtGivenPSoil.Camp

Hi Nico!

I was working with the compute.thetaAtGivenPSoil.Camp from the soil.utils.R and is not clear to me if the params should be always positive or negative.

In the function psie and b_camp can be either negative or positive:

compute.thetaAtGivenPSoil.Camp <- function(thetaSat, PsiTarget, psie, b_camp) {
  
  thetaAtGivenPSoil =  thetaSat*(PsiTarget/-psie)^(1/-b_camp)
  
  return(thetaAtGivenPSoil)
}

However, this creates confusion since the positive values will be converted to negative and the negative values to positive because of the sign in the formula:

thetaSat*(PsiTarget/-psie)^(1/-b_camp)

For example, if the function is run as:

compute.thetaAtGivenPSoil.Camp(thetaSat = 1, PsiTarget = 2, psie = 3, b_camp = 4)
 

psie and b_camp will be treated as negatives, and if the function is run as:

compute.thetaAtGivenPSoil.Camp(thetaSat = 1, PsiTarget = 2, psie = -3, b_camp = -4)

psie and b_camp will be treated as positives.

I think this might confuse users. If somebody specifies a negative value, the expectation is that the value be treated as negative inside the function.

  • Also, what is the meaning of psie and b_camp? I couldn't find any definition of these two parameters in the source code.

One possible solution to this could be to make sure that psie and b_camp (assuming that psie is a water potential?) are always negative:


#' Calculate theta parameter at give soil water potential (P) for the campbell equation (?) 
#'
#' @param thetaSat [Missing definition]
#' @param PsiTarget [Missing definition]
#' @param psie [Missing definition]
#' @param b_camp [Missing definition]
#' @return [Missing]
#' @export
#'
#' @examples compute.thetaAtGivenPSoil.Camp(thetaSat = 1, PsiTarget = -2, psie = -3, b_camp = -4)


compute.thetaAtGivenPSoil.Camp <- function(thetaSat, PsiTarget, psie, b_camp) {
  
  testthat::expect_true(all(psie < 0))
  testthat::expect_true(all(PsiTarget < 0))
  testthat::expect_true(all(b_camp < 0))
  
  # Orginal line:
  # thetaAtGivenPSoil =  thetaSat*(PsiTarget/-psie)^(1/-b_camp)
  
  # New line: -psie and -b_camp changed to psie and b_camp
  thetaAtGivenPSoil =  thetaSat*(PsiTarget/psie)^(1/b_camp)
  
  return(thetaAtGivenPSoil)
}

Pura Vida; Erick

Edited by Erick Calderon-Morales