[Bfast-commits] FW: Running bfast on raster bricks
Polyanne Aguiar
polyanneaguiar at gmail.com
Mon Feb 18 17:08:37 CET 2013
Hello,
I am using the bfast in my jobs. But, I am attempting run the bfastmonitor
on a raster brick (time serie MODIS EVI), I not get.
I followed the script proposed by you in this forum. But I did not succeed.
Following is the script used:
############################################################################
####
## TUTORIAL for processing raster bricks (satellite image time series of
16-day NDVI images)
file<- brick("MT_micro.tif", native, package="raster")
file
## helper function for the calc function
xbfast <- function(file) {
ndvi <- ts(file, frequency=23, start=c(2000,9))
result <- bfast(ndvi, season="harmonic", max.iter=1, breaks=2)
return(cbind(result$Magnitude,result$Time)) ## save magnitude and
time of the biggest break
}
## apply on a single pixel for testing
pixel <- as.vector(file[50])
ndvi <- ts(pixel, frequency=23, start=c(2000,9))
plot(ndvi)
result <- bfast(ndvi, season="harmonic", max.iter=1, breaks=2)
plot(result)
## apply on a single pixel using the xbfast function
output <- xbfast(pixel)
output
## optimise function that takes into account the percentage of NA's within a
time series
bfastfun <- function(y) {
percNA <- apply(y, 1, FUN=function(x) (sum(is.na(x))/length(x)) ) ##
checks the percentage of NA's with the time series
i <- (percNA<0.2)
res <- matrix(NA, length(i), 2)
if (sum(i) > 0) {
res[i,] <- t(apply(y[i,], 1, xbfast))
}
res
}
##apply on the full satellite image time series
magntime <- calc(data, fun=bfastfun)
layerNames(magntime) <- c("Magnitude", "Time of biggest Break")
plot(magntime)
## two rasters are returned: i.e. the magnitude and time of the biggest
break ## WARNING: this is requires some time :-).
############################################################################
###################
Thanks,
Polyanne Aguiar dos Santos
Master in Applied Ecology - UFLA
Specialist in Environmental Management - UNISAM
Biologist - ESFA
Phone: +55 35 9178 3275
Skype: polyanne.aguiar
cid:image001.png at 01CDF3FB.781F9910
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/bfast-commits/attachments/20130218/e1f222c4/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 11326 bytes
Desc: not available
URL: <http://lists.r-forge.r-project.org/pipermail/bfast-commits/attachments/20130218/e1f222c4/attachment.png>
More information about the Bfast-commits
mailing list