我有五个 netcdf 文件,其中每个文件都包含一个时间段的数据。我想单独计算每个单元格的整个时间跨度的第 98 个百分位数。netcdf 文件的累积文件大小约为 250 MB。
我的做法是:
library(raster)
fileType="\\.nc$"
filenameList <- list.files(path=getwd(), pattern=fileType, full.names=F, recursive=FALSE)
#rasterStack for all layers
rasterStack <- stack()
#stack all data
for(i in 1:length(filenameList)){
filename <- filenameList[i]
stack.temp<-stack(filename)
rasterStack<-stack(rasterStack, stack.temp)
}
#calculate raster containing the 98th percentiles
result <- calc(rasterStack, fun = function(x) {quantile(x,probs = .98,na.rm=TRUE)} )
但是,我收到此错误:
Error in ncdf4::nc_close(x@file@con) :
no slot of name "con" for this object of class ".RasterFile"
我的代码的堆叠部分有效,崩溃发生在 calc 函数期间。你知道这可能来自哪里吗?这可能是数据存储位置(内存/磁盘)的问题吗?