Skip to content
Prev 23607 / 29559 Next

Raster multi-band time series analysis

Hi Dominik and Lo?c,

thank you for your suggestions. I solved the problem using 
spatial.tools::rasterEngine. Please see the example below.

Lo?c, I tried to adapt your function "mc.calc" to use raster::overlay, 
however it didn't work out. The raster::overlay iterates over layers, 
therefore, I didn't get the whole time series in my analysis.


### A simple example using spatial.tools
# Computes the average of the time series for each pixel

library(spatial.tools)

ndvi = brick("./MOD13Q1/0___TIFF/250m_16_days_NDVI.tif") # Each layer is 
a sample in the time series
evi = brick("./MOD13Q1/0___TIFF/250m_16_days_EVI.tif")   # Each layer is 
a sample in the time series

fun = function(ndvi, evi, P, ...){
   # Receive rasters as 3D arrays (col, row, band)
   N = nrow(ndvi)
   M = ncol(ndvi)
   avg = array(NA, dim = c(N,M,P) )
   for(i in 1:nrow(ndvi))
     for(j in 1:ncol(ndvi)){
       avg[i,j,1] = mean(ndvi[i,j,])
       avg[i,j,2] = mean(evi[i,j,])
     }
   avg
}

P = 2 # Number of layers in the output
sfQuickInit(cpus=2)
res = rasterEngine(
   fun = fun,
   args = list(P=P),
   ndvi = ndvi,
   evi  = evi,
   outbands = P)
sfQuickStop()


Thank you!


Best,
Victor
On 10/26/2015 04:18 PM, Dominik Schneider wrote: