R/climate_index_add_data.R

Defines functions excessFallMoistureComponentRating earlySpringMoistureComponentRating temperatureComponentRating moistureComponentRating

Documented in earlySpringMoistureComponentRating excessFallMoistureComponentRating moistureComponentRating temperatureComponentRating

################ Additional Data Tools ################
#' Moisture Component Rating
#'
#' The moisture component rating is designed to return the point deduction for
#' the moisture component.
#' @param ratingTableArrayMC Rating table lower and upper bounds for deduction for the moisture component.
#' @param ppe Precipitation minus potential evapotranspiration
#' @return Deduction points for the moisture component rating.
#' @export
moistureComponentRating <- function(ratingTableArrayMC, ppe){

  moistureFactor <- moistureComponent(ratingTableArrayMC, ppe)

  return(moistureFactor)

}

#' Temperature Component Rating
#'
#' The temperature component rating is designed to return the point deduction for
#' the temperature component.
#' @param ratingTableArrayMC Rating table lower and upper bounds for deduction for the temperature component.
#' @param ratingTableArrayTF Rating table lower and upper bounds for deduction for temperature factors.
#' @param temperatureFactor Input effective growing degree days or crop heat units for
#' the study site.
#' @param type If the crop uses effective growing degree days (EGDD) use EGDD else
#' if the crop uses crop heat units (CHU) use CHU.
#' @return Deduction points for the temperature component rating.
#' @export
temperatureComponentRating <- function(ratingTableArrayTF,temperatureFactor,type){

  # Need to determine if it's EGDD or CHU
  if(type == "EGDD"){
    temperatureFactor <- egddComponent(ratingTableArrayTF, temperatureFactor)
  } else if(type == "CHU"){
    temperatureFactor <- chuComponent(ratingTableArrayTF, temperatureFactor)
  } else {
    stop("Error determining if the crop uses effective growing degree days or
         crop heat units. Please specify EGDD or CHU")
  }

  return(temperatureFactor)

}

#' Early Spring Moisture Component Rating
#'
#' The early spring moisture component rating is a designed to return rating for
#' early spring moisture.
#' @param ratingTableArrayESM Rating table lower and upper bounds for deduction for ESM.
#' @param ppeSpring Precipitation minus potential evapotranspiration for spring
#' @return Early spring moisture component rating
#' @export
earlySpringMoistureComponentRating <- function(ratingTableArrayESM, ppeSpring){

  # Early spring moisture
  esm <- esmComponent(ratingTableArrayESM, ppeSpring)

  return(100 - esm)

}

#' Excess Fall Moisture Component Rating
#'
#' The excess fall moisture component rating is a designed to return rating for
#' excess fall moisture.
#' @param ratingTableArrayEFM Rating table lower and upper bounds for deduction for EFM.
#' @param ppeFall Precipitation minus potential evapotranspiration for fall
#' @return Excess fall moisture component rating
#' @export
excessFallMoistureComponentRating <- function(ratingTableArrayEFM, ppeFall){

  # Excess fall moisture
  efm <- efmComponent(ratingTableArrayEFM, ppeFall)

  return(100 - efm)

}
mitmon/SRS documentation built on Jan. 12, 2023, 12:15 a.m.