Skip to content

Commit

Permalink
functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ytarazona committed Oct 27, 2020
1 parent 4feaebb commit 7fab9e2
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions R/smootH.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,23 @@
#' of this method of removing outliers implies the non-modification of the first and last
#' values of the historical series, so that the near real-time detections of ecosystem
#' disturbances will not be affected in any way.

#' @param x Numeric, matrix.
#' @param interp Four interpolation methods are presented, "na.interp",
#' "na.approx" and "na.spline". By default is the method "na.interp".
#'
#' @importFrom forecast na.interp
#' @importFrom zoo na.approx na.spline
#' @importFrom zoo rollapply
#'
#' @param x Numeric, matrix.
#' @param interp Four interpolation methods are presented, "na.interp",
#' "na.approx" and "na.spline". By default is the method "na.interp".
#'
#' @examples
#'
#' library(ForesToolboxRS)
#'
#' # Here a vector with an outlier
#' x <- c(80,78,75,76,79,-100,82,76,81,77,76)
#' plot(x, type="o", col="red")
#'
#' # Applying a smoothing
#' smth <- smootH(x)
#' plot(x, type="o", ylab="Reflectance %", xlab="Time")
#' lines(smth, col="blue", type="o")
Expand Down Expand Up @@ -64,7 +68,7 @@ smootH <- function(x, method.interp = "na.interp"){
} else stop("Unsupported interpolation method.", call. = TRUE)
}

# We apply Hamunyela Smoothing
# Apply Hamunyela Smoothing
for (j in 2:(length(x)-1)) {
x[j] <- ifelse(((x[j]-x[j-1]) < -0.01*x[j-1]) & ((x[j]-x[j+1]) < -0.01*x[j+1]),
(x[j-1]+x[j+1])/2, x[j])
Expand Down Expand Up @@ -93,7 +97,7 @@ smootH <- function(x, method.interp = "na.interp"){
}
}

# We apply Hamunyela Smoothing
# Apply Hamunyela Smoothing
for(i in 1:dim(x)[1]){
for(j in 2:(dim(x)[2]-1)){
x[i,][j]<-ifelse(((x[i,][j]-x[i,][j-1])< -0.01*x[i,][j-1]) & ((x[i,][j]-x[i,][j+1])< -0.01*x[i,][j+1]),
Expand Down

0 comments on commit 7fab9e2

Please sign in to comment.