Pan*_*kaj 1 gis r netcdf cdo-climate
我有从此处获得的netCDF文件,名称为precip.mon.total.v6.nc。我正在ncdfR中使用软件包打开和分析文件。
new <- open.ncdf("precip.mon.total.v6.nc")
> new
[1] "file precip.mon.total.v6.nc has 4 dimensions:"
[1] "lat Size: 360"
[1] "lon Size: 720"
[1] "nbnds Size: 2"
[1] "time Size: 1320"
[1] "------------------------"
[1] "file precip.mon.total.v6.nc has 1 variables:"
[1] "float precip[lon,lat,time] Longname:GPCC Monthly total of precipitation Missval:-9.96920996838687e+36"
Run Code Online (Sandbox Code Playgroud)
但是当我提取变量时,我得到了错误
> get.var.ncdf(new, "precip")
Error: cannot allocate vector of size 2.5 Gb
In addition: Warning messages:
1: In double(totvarsize) :
Reached total allocation of 2047Mb: see help(memory.size)
2: In double(totvarsize) :
Reached total allocation of 2047Mb: see help(memory.size)
3: In double(totvarsize) :
Reached total allocation of 2047Mb: see help(memory.size)
4: In double(totvarsize) :
Reached total allocation of 2047Mb: see help(memory.size)
Run Code Online (Sandbox Code Playgroud)
我的查询是:(a)如何处理内存问题?(b)如何将该netCDF文件的分辨率从0.5 * 0.5更改为0.25 * 0.25数据?我已经在MATLAB中尝试过类似的问题。对于netCDF文件,它可以比R更好地解决内存问题。但是更改分辨率仍然是一个问题,因为我不擅长MATLAB。在这方面的任何帮助,我将非常感谢。
提取变量时,需要指定所需的尺寸。目前,您正在要求R获得所有内容,因此我怀疑它正在创建一个3D阵列,该阵列可能很大。
ncdf4软件包通常会取代ncdf,您应该尝试使用它代替。您需要确定是要按时间读取数据还是按时间步读取数据。这在普通的2D网格上更容易设想:
您的时间跨度是3D网格(尽管第3维只有两个带),但是您的变量似乎未使用带维。这是一个基于ncdf4的2D工作流程,忽略了您的乐队:
包:
install.packages("ncdf4")
library(ncdf4)
Run Code Online (Sandbox Code Playgroud)
打开连接:
nc = nc_open("~/dir/dir/file.nc")
Run Code Online (Sandbox Code Playgroud)
一次生成一个网格
阅读尺寸:
precip = list()
precip$x = ncvar_get(nc, "lon")
precip$y = ncvar_get(nc, "lat")
Run Code Online (Sandbox Code Playgroud)
读取数据(注意start是开始的维度索引,count是从该点开始的观察数,因此这里我们在第一步中读取了整个网格):
precip$z = ncvar_get(nc, "precip", start=c(1, 1, 1), count=c(-1, -1, 1))
# Convert to a raster if required
precip.r = raster(precip)
Run Code Online (Sandbox Code Playgroud)
随时读取单个单元格
您需要找到您的单元格索引,precip$x并且precip$y会有所帮助。一旦拥有它(例如,单元格x = 5和y = 10):
precip.cell = ncvar_get(nc, "precip", start=c(5, 10, 1), count=c(1, 1, -1))
Run Code Online (Sandbox Code Playgroud)