[R-sig-Geo] Raster multi-band time series analysis

Victor Maus mausv at uni-muenster.de
Tue Oct 27 14:47:32 CET 2015


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:
> Check out the spatial.tools package for parallel processing with the raster
> package.
>
>
>
> On Mon, Oct 26, 2015 at 7:22 AM, Loïc Dutrieux <loic.dutrieux at wur.nl> wrote:
>
>> Hi Victor,
>>
>> I don't have much experience with beginCluster; however, I have written a
>> parallel version of raster::calc a little while ago that uses forking.
>> https://github.com/dutri001/bfastSpatial/blob/master/R/mc.calc.R
>>
>> calc and overlay are analogue so that it shouldn't be too hard to extend
>> this function to overlay, using an undefined number of rasterStack or
>> Bricks as input. You will need a bit more checks and control flow at the
>> beginning of the function though.
>> I'm not sure at all whether this is the most efficient way of
>> parallelizing things, but it will for sure speed up your processing
>> compared to single core processing.
>>
>> Hope this helps,
>> Cheers,
>> Loïc
>>
>>
>> On 10/26/2015 12:23 PM, Victor Maus wrote:
>>
>>> Hi Loïc,
>>>
>>> Thank your very much for your answer. I am working on your suggestion.
>>> But I still have a question.
>>>
>>> The function raster::overlay works for multiple RasterBrick objects.
>>> However, I noticed that raster::beginCluster works with raster::overlay
>>> as long as a single RasterStack or RasterBrick is provided as the first
>>> argument. Do you have any suggestion for parallel processing of multiple
>>> RasterBrick objects?
>>>
>>> Thank you!
>>>
>>> Best,
>>> Victor
>>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
> 	[[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

-- 
Victor Maus, MSc
Assistant Researcher
Institute for Geoinformatics (IFGI), University of Münster, Germany
PhD candidate in Earth System Science
National Institute for Space Research (INPE), Brazil



More information about the R-sig-Geo mailing list