if (FALSE) {
library(terra)
random.raster <- function(rows=50, cols=50, l=20, min=0, max=1){
do.call(c, replicate(l, rast(matrix(runif(rows * cols, min, max),
rows , cols))))
}
r <- random.raster()
#### Smooth time-series using raster stack/brick
r.smooth <- smooth.time.series(r, f = 0.4, smooth.data = TRUE)
# extract pixel 100 for plotting
y <- as.numeric(r[100])
ys <- as.numeric(r.smooth[100])
# plot results
plot(y, type="l")
lines(ys, col="red")
legend("bottomright", legend=c("original","smoothed"),
lty=c(1,1), col=c("black","red"))
}
Run the code above in your browser using DataLab