在HPC群集中使用gDistance R软件包时出现段错误

时间:2018-12-02 23:49:16

标签: r cluster-computing geospatial

我正尝试在群集计算机的帮助下(通过gdistance R软件包)计算约900张光栅图像的通勤距离。我的脚本将遍历大约三张图像,并在大约一个小时后失败,并显示以下错误:

*** caught segfault *** address 0x2ab1a25456cc, cause 'memory not mapped'

一旦引入大的栅格图像,故障似乎就会发生:数据集中的第三张图像为91000KB,而第一张和第二张图像分别为44KB和18KB。群集作业正在使用64GB内存,10个内核和大量的时间。

我的R代码如下:

library(gdistance)
library(stringr)
library(data.table)
setwd("H:/GIS_Isolation/Isolation_by_Resistance/NetworkX/Dataset/Rasters/Compiled_Rasters")
rasterList = list.files(pattern = 'FID(.*).asc')

coordTable <- read.delim2(file = 'H:/IAS Data/Island IsolationIndex/ResistanceDistanceCalcs/Island_CoordTable_Complete.txt',header= TRUE, sep = ",")

cdTable <- data.frame(FID = integer(), Name = character(), resDist = double(), stringsAsFactors = FALSE)

# iterate through each raster in the dataset
for (raster in rasterList){

#setup specific raster for analysis and extract important metadata
print(raster)
FID <- str_extract(raster, pattern =("(?<=FID).*(?=.asc)"))
print(FID)
r <- raster(x = raster, package = "gdistance")
crs(r) <- "+proj=tmerc +lat_0=0 +lon_0=173 +k=0.9996 +x_0=1600000 +y_0=10000000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m"
r_proj <- projectRaster(r, crs = '+proj=longlat +datum=WGS84 + zone=60')

#extract specific raster source/dest coords from coordTable
filterTable <- subset.data.frame(coordTable, FID_Unique == FID)
name <- toString(filterTable[1,4])
sourceX <- toString(filterTable[1,2])
sourceX <- as.numeric(sourceX)
sourceY <- toString(filterTable[1,3])
sourceY <- as.numeric(sourceY)
destX <-toString(filterTable[1,7])
destX <-as.numeric(destX)
destY <-toString(filterTable[1,8])
destY <-as.numeric(destY)
startPt <- c(sourceX, sourceY)
finishPt <- c(destX, destY)
sp <- rbind(startPt, finishPt) #commute distance function takes both coordinate points as single input
print(sp)

#establish transition function: defines movement through landscape
#use the reciprocal of mean to model landscape permeability (as opposed to friction)
#cells connected to eight nearest orthogonal and diagonal neigbors, common for macro-biological systems
tr <- transition(r_proj, transitionFunction = function(x) 1/mean(x), directions = 8)

#commute distance
cd <- commuteDistance(tr, sp)
cd <- toString(cd)
print(cd)

#append data to dataframe
cdTable[nrow(cdTable)+1, ] <- c(FID, name, cd)
}

write.csv(cdTable, file = "CommuteDistance_Complete.csv")

我认为该问题可能与gdistance软件包有关,因为一旦引入了转移函数,该错误就总是失败。我也将gdistance更新为群集上的最新版本。我是集群计算的新手,所以任何想法或建议都将不胜感激!

0 个答案:

没有答案