[R-sig-Geo] Raster package issue when using calc and clusterR
Rafael Wüest
rafael.wueest at gmail.com
Tue May 12 09:34:10 CEST 2015
Hi Malone
try the export argument of the clusterR function.
beginCluster(3)
param<- 15
f1<- function(x) tabulate(x, nbins=param)
clusterR(stk, calc, args=list(fun=f1), export = 'param')
endCluster()
Is this what you are after?
HTH, Rafael
On 12/05/2015 08:23, Brendan Malone wrote:
>
>
> 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]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Rafael Wüest
rafael.wueest at gmail.com
http://www.rowueest.net
More information about the R-sig-Geo
mailing list