我有一个大型栅格数据集,我正在尝试使用Maxent来预测栖息地的适用性。我在速度方面遇到了麻烦,因此我根据此post将代码重写为并行进程。
ncores = 4
cl = parallel::makeCluster(ncores)
doParallel::registerDoParallel(cl,ncores)
rows=1:nrow(env)
split=sort(rows%%ncores)+1
outname="envOut"
prediction = foreach(i=unique(split), .combine=c) %dopar% {
rows_sub=rows[split==i]
sub = raster::crop(env,raster::extent(env,min(rows_sub),max(rows_sub),1,ncol(env)))
raster::predict(object=env, model = model1,
filename=paste("I:/GIS/Projects/LISU/",outname,i,".tif",sep=""))
gc()
}
stopCluster(cl)
然而,当我这样做时,使用了超过500 GB的硬盘空间,我无法生成输出栅格。我在基于这些posts的代码块之前添加了以下行。
rasterOptions(tmpdir="I:/GIS/tmpdir")
I驱动器是外部硬盘驱动器位置,具有大量空间。然而,这个命令似乎被忽略了,因为当我重新进行并行预测时,我的硬盘再次被填满。有什么建议吗?
答案 0 :(得分:0)
在Windows中,我设置了我的环境变量TMPDIR=I:\GIS\tmpdir.
当我启动R时,键入tempdir()
检索到我想要使用的临时目录的正确路径。
我仍然不确定rasterOptions(tmpdir=...)
实际上做了什么。