0

I want to use an aggregate function for my raster file to change the resolution from 30 30 to 300 300. The top code(For loop) is working very well. I want to use multiple cores to use the aggregate function to change the resolution. I think the bottom code is working except the stack part. Now i am trying to understand doparallel function.

full_dataset = stack()
for(i in 1:length(files)){
  Covariate <- raster(files[i])
  Covariates_sub <- aggregate(Covariate, fact=10)
  full_dataset = stack(full_dataset,Covariates_sub)
}

plot(full_dataset)




library(doSNOW)
### below is eds code for parallel processing 
require(parallel) # package we need
numCores <- detectCores() # how many cores in our computer?
numCores # this is how many
cl <- makeCluster(numCores-2) # if we have 8, let us use 6 cores
registerDoSNOW(cl)

full_dataset = stack()
foreach(i = 1:length(files), .packages = "raster",'ithir','MASS','rgdal','sp','dplyr') %dopar% {  
Covariate <- raster(files[i])
Covariates_sub <- aggregate(Covariate, fact=10)
full_dataset = stack(full_dataset,Covariates_sub)
}
full_dataset

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.