[R-sig-Geo] Raster package issue when using calc and clusterR
Brendan Malone
brendan.malone at sydney.edu.au
Tue May 12 08:23:35 CEST 2015
Hi everyone,
I have come into a bit of a problem when using the clusterR function from raster. My problem is on a much larger scale but I can recreate it more-or-less with the example below:
require(raster)
a <- raster(matrix(c(12,11,11,
11,11,11,
11,11,13),nrow=3))
b <- raster(matrix(c(12,12,12,
11,12,12,
14,12,13),nrow=3))
c <- raster(matrix(c(13,9,13,
11,13,13,
13,11,13),nrow=3))
d <- raster(matrix(c(10,10,10,
11,10,10,
10,10,10),nrow=3))
stk <- stack(a,b,c,d)
#works
calc(stk, function(x) tabulate(x, nbins=15))
#works
beginCluster(3)
f1<- function(x) tabulate(x, nbins=15)
clusterR(stk, calc, args=list(fun=f1))
endCluster()
#Does not work
beginCluster(3)
param<- 15
f1<- function(x) tabulate(x, nbins=param)
clusterR(stk, calc, args=list(fun=f1, param=15))
endCluster()
#Does not work
beginCluster(3)
param<- 15
f1<- function(x) tabulate(x, nbins=param)
clusterR(stk, calc, args=list(fun=f1))
endCluster()
I am a little mystified as to why the last two examples do not work. Ideally in this example I would like to change the number of bins on the fly, but presently I cannot and do not know why. The scale of my problem really requires me to use the clusterR function.
Maybe the answer is glaring me in the face. Maybe someone could share their wisdom on this perhaps.
Regards,
Brendan
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list