我知道周围有类似的问题和问题,但我的问题非常具体。
我正在使用 30 角秒分辨率的 WorldClim 和 Chelsa 气候数据集。在此过程中,我想将特定数据集放入 ncdf4 文件中。在此过程中,必须将数据转换为要转换为矩阵的向量。然后将该矩阵反转并最终转置。然后将输出数据转换为一个数组,稍后将其放入 ncdf 文件中。
我的示例代码如下所示。
library(raster)
library(ncdf4)
# Download of one of the raster files (here 110 Mb .tif-Raster from the Chelsa server)
temp.raster <- raster("https://envidatrepo.wsl.ch/uploads/chelsa/chelsa_V1/bioclim/integer/CHELSA_bio10_08.tif")
#determining the cellsize
cellsize <- (temp.raster@extent@xmax-temp.raster@extent@xmin)/temp.raster@ncols
# Set Longitudes
lon <- as.array(seq(temp.raster@extent@xmin+cellsize/2,
temp.raster@extent@xmax-cellsize/2,
(temp.raster@extent@xmax-temp.raster@extent@xmin)/temp.raster@ncols))
nlon <- length(lon)
# Set Latitudes
lat <- as.array(seq(temp.raster@extent@ymin+cellsize/2,
temp.raster@extent@ymax-cellsize/2,
(temp.raster@extent@xmax-temp.raster@extent@xmin)/temp.raster@ncols))
nlat <- length(lat)
temp.raster.data <- t(apply(matrix(data = as.numeric(values(temp.raster)),
nrow = nlat,
ncol = nlon,
byrow = TRUE),
2,
rev))
temp.raster.data <- array(temp.raster.data, dim=c(nlon,nlat,1))
在从光栅文件中提取值的过程中,该错误发生在values()
-function 处。
如其他问题中建议的那样设置更高的内存限制不起作用,并且添加更多 RAM 不是一种选择。
有人建议解决此问题的解决方法或更简单的方法吗?
我sessionInfo()
的是
R 版本 4.0.2 (2020-06-22)
平台:x86_64-w64-mingw32/x64(64位)
运行于:Windows 10 x64(内部版本 18363)
配备 12 GB 内存 ( memory.limit()
--> 11984)
感谢您的时间!