Create a loop for a list of list from RasterBrick in R -


i'm on project in remote sensing running on r. i've got rasterbrick(x) raster dates i'm interested in, time serie dates corresponding (called time in function), , function works want when processed manually (z pixel want) :

function(x,z) { d<-bfastts(as.vector(x[as.numeric(z)]),time,type="16-day") n<-bfast(d, h=0.15, season="harmonic", max.iter = 1) l[[z]]<-list(n$output[[1]]$tt) } 

the bfastts function used create ts object containing values of 1 pixel along time serie, bfast processing statisticals of want 1 result (this third line)? none of 2 functions mine, , stable , foundable in r package repository.

so, add "another level" of function (sorry vocabulary may not precise) allow run function automatically. expected result list of result of function above, in other words list of each pixel's time series.

i've tried (x still rasterbrick) :

function(x) {   z<-nrow(x)*ncol(x)   j<-last(z[[1]])   l<-vector('list',length = j)   index<-function(x)     {     d<-bfastts(as.vector(x[as.numeric(z)]),time,type="16-day")     n<-bfast(d, h=0.15, season="harmonic", max.iter = 1)     l[[z]]<-list(n$output[[1]]$tt) # add newly created element list   }   lapply(x, fun='index') } 

but i'm getting answer not possible coerce s4 object vector, guess problem in lapply doesn't rasterbrick class... furthermore want list of list in output, , not list of rasterbrick (i think understood lapply returns list of object same class x).

i've tried different workaround, none succesfully, not surprising giving low level in programming, , 1 seems me closest need. don't think understand neither how lapply works nor use of function in function.

thank if can me. cheers guillaume

so, in case useful someone, here how solved problem (it seems rather simple finally), "brick" object rasterbrick:

pixelts<- as.list(as.data.frame(t(as.data.frame(brick)))) 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -