[Bfast-commits] running bfast on a 3D image

Jan Verbesselt janverbesselt at gmail.com
Fri Feb 17 14:33:13 CET 2012


Hi Cheney,

Hopefully you are receiving this mail.
Please have a look at the 
raster package and the calc() function which is great for implementing functions like bfast on raster bricks (3d matrix).
I am exploring possibilities myself at the moment as the raster package is a great step forward to handle and analyse satellite images.
As such Q 1 and 2 can be answered. As for Q3 can you send a reproducible example for one time series that gives this error? As such I can try to solve/explain this.
sorry for the late reply but I did not receive a message in my inbox about this post on the mailing list. This should hopefully be fixed now so please reply to the mailing list (I'll keep an eye on it).

As for this:
     #I know this is wrong, but don’t know what my sin is.
    output.matrix[i,j]<-as.vector(majorbps)
   # I also tried just output.matrix[i,j]=majorbps but got an error

Check the dimensions of majorbps and select 1 value you want to assign to matrix[i,j]

I you have a reproducible example via e.g. dropbox and a R script and can try to improve your code.
Hope this helps,

Best,
Jan




require(bfast)
require(caTools)
require(tseries)

loop.test<-function(infile){
    data=read.ENVI(infile)
#infile is just a test (subset) array of time series data  [20,20,383]	

	#find the dimensions of input image
	x<-ncol(data)
	y<-nrow(data)
	z<-dim(data)[3]
	
     #set up an output array to hold results
    output.matrix<-matrix(NA,x,y)
    for (i in 1:x){
    for (j in 1:y) {
	#isolate the time series for a single pixel
	pixel<-data[i,j,1:z]
 	gpp<-ts(pixel,start=c(2002,23),end=c(2010,38),frequency=46)
    fit<-bfast(gpp,h=0.15,max.iter=1,breaks=NULL)
    niter <- length(fit$output)
    out <- fit$output[[niter]]

     if (out$Vt.bp[1]>0) {
       (tnrbps <- time(gpp)[(out$Vt.bp)])
        majorbps<-tnrbps[1]
      } else {
      	
      	majorbps=0     	
      	}

     #I know this is wrong, but don’t know what my sin is.
    output.matrix[i,j]<-as.vector(majorbps)
   # I also tried just output.matrix[i,j]=majorbps but got an error



about dimensions being incorrect. It doesn't make sense to me that
  # it would need to be a vector, but for some reason using, as.vector
doesn't throw an error?

     }
}
write.ENVI(output.matrix, “output.bil”, interleave=c(“bil”))
}


Thanks in advance for your help and patience.

Kind regards,

Cheney




More information about the Bfast-commits mailing list