I am working with two global raster stacks, each containing 60 layers using the R Software. The layers are global raster files (in GTiff format) at a resolution of 5 min of arc. The first stack contains cultivated areas for 60 crops, while the second stack contains the grid-cell yield of the same 60 crops.
my objective is to multiply the two raster stacks, in order to obtain the production for the 60 crops for each grid-cell. I am running this calculation using the raster
package and using its parallelizing function clusterR
together with the fuction calc
. I am running the process using 24 cores. The code looks like this:
rasters_production <- clusterR(rasters_land_use_hectars, calc, args=list(fun=function(x){x*rasters_yield}),
export="rasters_yield", exclude="parallel", filename=paste0("Script_generated_files/", "organic_rasters_production_1.tif"), format="GTiff", overwrite=T, cl=cluster)
When I run it, the code generate the following error:
Error in clusterR(rasters_land_use_hectars, calc, args = list(fun = function(x) { : cluster error
Nevertheless, if I run the same multiplication but multiplying a raster stack for a vector of 60 coefficient (and not for a second raster stack), the calculation works correctly?
Does somebody know why the calculation between the two raster stacks does not work instead?