Parallel overlay of undefined multi-layer rasters

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Parallel overlay of undefined multi-layer rasters

Hugo Costa
Dear list

I have an undefined number of multi-layer rasters (TIFF files with 10
bands), and I need to find the maximum (or median, etc.) among the rasters.
The calculations should operate band by band, so the expected output is one
stack also with 10 bands.

I thought of overlay, like this:


library(raster)
r <- raster(ncol=10, nrow=10)
r1 <- init(r, fun=runif)
r2 <- init(r, fun=runif)
r3 <- init(r, fun=runif)
r4 <- init(r, fun=runif)
s1<-stack(r1,r2)
s2<-stack(r3,r4)
s3<-stack(r1,r4)
f<-function(...){max(...,na.rm = TRUE)}

# do.call works for undefined stacks, but not in parallel
list1<-list(s1,s2,fun=f)
list2<-list(s1,s2,s3,fun=f)
do.call(overlay, list1)
do.call(overlay, list2)


As for parallel processing, I thought of clusteR, but it accepts only one
Raster* object.
The problem is that for running overlay with multi-layer rasters, they
cannot be stacked, because if stacked, the function will apply to all bands
and hence output a single band, while in this case the function should
apply band by band.

An alternative to this, is to split the bands of all images, process the
bands individually in parallel inside a loop (i.e. band 1 of all images,
band 2 of all images, etc.),
and then combine the outputs in a multi-layer raster. However, this is
inefficient, specially with large rasters not hold in memory.

Is there an elegant way to do this?

Thanks
Hugo

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo