R/utils.R

Defines functions minmax maxmin classify_func

Documented in classify_func maxmin minmax

# utility functions

#' Convert coefficient of variation to sigma parameter of lognormal diistribution
#'
#' @param cv Coefficient of variation
#' @export

cv2sigma <- function (cv) {
  sqrt(log(cv^2 + 1))
}



# functions for getting Q bounds.

#' Minimum across xs of max across time of width
#'
#' @param x a numeric matrix
minmax <- function(x)
  min(apply(x, 1, max))

#' Maximum across xs of min across time of width
#'
#' @param x a numeric matrix
maxmin <- function(x) {
  max(apply(x, 1, min))
}


#'Classify river for supervised framework
#'
#'@param Wobs observed widths matrix
classify_func <- function(Wobs) {
  lwbar <- mean(log(Wobs), na.rm=TRUE)#apply(log(Wobs), 1, mean, na.rm = TRUE)
  lwsd <- sd(log(Wobs), na.rm= TRUE)#apply(log(Wobs), 1, sd, na.rm = TRUE)

  maxWidth = 6.5
  classes <- c(2.641197894, 3.143289838,3.376904689,
               3.548754946,3.823191792,4.150094577,
               4.626687029,5.248706866) #median width of each river type

  ifelse(lwbar > maxWidth, 100,
         ifelse(lwsd >= 0.45, 9, which.min(abs(classes-lwbar)))) #100 for big rivers, 9 for width-variable rivers
}
craigbrinkerhoff/geoBAM documentation built on Dec. 25, 2019, 3:18 a.m.