# NOT RUN {
random.raster <- function(r=50, c=50, l=10, min=0, max=1){
do.call(stack, replicate(l, raster(matrix(runif(r*c, min, max),r,c))))
}
r <- random.raster()
#### Smooth time-series using raster stack/brick
r.smooth <- smooth.time.series(r, f = 0.6, smooth.data = TRUE)
#### sp SpatialPixelsDataFrame example
r <- as(r, "SpatialPixelsDataFrame")
# extract pixel 100 for plotting
y <- as.numeric(r@data[100,])
# Smooth data
r@data <- smooth.time.series(r, f = 0.6, smooth.data = TRUE)
# plot results
plot(y, type="l")
lines(as.numeric(r@data[100,]), col="red")
legend("bottomright", legend=c("original","smoothed"),
lty=c(1,1), col=c("black","red"))
# coerce back to raster stack object
r <- stack(r)
# }
Run the code above in your browser using DataLab