[R-sig-Geo] How to write functions with mutiple large raster data file (MOD13Q1, 2000-2012)
Robert J. Hijmans
r.hijmans at gmail.com
Wed May 8 17:40:32 CEST 2013
Francisco,
I think what you want to do can be accomplished with 'calc' (as was
pointed out in another thread).
library(raster)
in <- stack(list.files(pattern=*..tif$))
out <- calc(in, fun=function(x) lowess(x,f=7/n,iter=10)$y)
But to answer your question, I think you could do:
in <- stack(list.files(pattern=*..tif$))
# and, here is the trick
out <- brick(in, values=FALSE)
Also, in your loop you could do:
getValues(in, ...
writeValues(out, ....
Best, Robert
On Tue, May 7, 2013 at 7:35 AM, Francisco Zambrano <frzambra at gmail.com> wrote:
> Hi everybody,
>
> I'm working with MODIS data MOD13Q1 and the NDVI index between 2000- today.
> I have been trying to do a function, but I have a problem when stack the
> 310 files and then I tried to use the writeStart function. I had an error
> because the startFuction work with rasterLayer or RasterBrick. But, when I
> tried to make the brick with the rasterStack (>brick(rasterStack)) the
> operation took too much time (11 hours)
>
> My question, is what is the most efficiently way to make a rasterBrick from
> multiple raster (geoTIFF) files?
>
> save the rasterStack and then open it with brick?
>
> My code is something like:
>
>>out<-stack(list.files(pattern=*..tif$))
>>out<-brick(mod) #too much time (11 hours appox)
>
> >out<-writeStart(out,filename,overwrite=TRUE)
> >bs<-blockSize(out)
> >pb<-pbCreate(bs$n)
> >for (i in 1:bs$n){
> v<-getValues(out,row=bs$row[i],nrows=bs$nrows[i])
> s<-t(sapply(apply(v,1,lowess,f=7/n,iter=10),"[[","y"))
> out<-writeValues(out,s,bs$row[i])
> pbStep(pb,i)
> }
>
> Kind Regards
>
> Francisco Zambrano Bigiarini
>
> from Chile, latin america
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
More information about the R-sig-Geo
mailing list