I have observation with 12 layers and a list (1440) of future models. I have done calculation. ie added/multiplied each layer from observation to the respective layer in the future models. Since it takes time to write the files and save, I have used foreach. But to do this, I had to convert the output to rasterbrick as I did not know how to do it in terra. Could anyone help me how I can do the same calculation and filing writing and saving in terra? Below is my code:
# Perform calculationtasmax_down <- obs + mod_rastnames(tasmax_down) <- names(mod_rast)# Covert spatraster to rasterbrick tasmax_brick <- raster::brick(tasmax_down)# Parallel processcl <- makeCluster(10)registerDoParallel(cl)foreach(i = 1:nlayers(tasmax_brick)) %dopar% {r <- raster::raster(tasmax_brick, i)raster::writeRaster(r, filename = paste0("E:/Downscale/", gsub("\\.", "-", names(tasmax_brick[[i]])), ".tif"), format = "GTiff", overwrite=TRUE)}stopCluster(cl)