在R中创建多维NetCDF [英] Creating multi-dimensional NetCDF in R

查看:92
本文介绍了在R中创建多维NetCDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用R包 ncdf .我正在用1500点的每日气候观测值进行工作,每个点的观测值数量约为18250. 问题在于NetCDF文件( create.ncdf )的结构占用4Gb,每个点使文件大小增加了3 Gb( put.var.ncdf )

I am trying to create a multi-dimensional NetCDF file using the R package ncdf. I am working with climatic daily observations for a set of 1500 points, the number of observations is ~ 18250 for each point. The problem is that the structure of the NetCDF file (create.ncdf) occupies 4Gb and each point makes the size of the file increase by more than 3 Gb (put.var.ncdf)

这是我正在使用的代码:

This is the code I am using:

# Make a few dimensions we can use
dimX <- dim.def.ncdf( "Long", "degrees", Longvector )
dimY <- dim.def.ncdf( "LAT", "degrees", Latvector )
dimT <- dim.def.ncdf( "Time", "days", 1:18250, unlim=FALSE )

# Make varables of various dimensionality, for illustration purposes
mv <- -9999 # missing value to use
var1d <- var.def.ncdf( "var1d", "units", dimX, mv,prec="double" )
var2d <- var.def.ncdf( "var2d", "units", list(dimX,dimY), mv,prec="double" )
var3d <- var.def.ncdf( "var3d", "units", list(dimX,dimY,dimT), mv,prec="double" )

# Create the test file
nc <- create.ncdf( "writevals.nc", list(var1d,var2d,var3d) )
# !!Creates a nc file with + 4 Gb

# Adding the complete time series for one point (the first point in the list of the dataset)
put.var.ncdf( nc, var3d,dataset[[1]], start=c(Longvector[1],Latvector[1],1),         count=c(1,1,-1))

Longvector和Latvector是从矩阵中获取的矢量,每个点的Long和Lat值都相同.数据集是一种列表格式,对于每个点,我都有一个数值列表.

Longvector and Latvector are vectors taken from the matrix with the Long and Lat for each point. The dataset is a list format and for each point I have a list of numeric values.

dataset[[1]]=c(0,0,0,9.7,0,7.5,3.6,2.9,0,0.5,....) 

我丢失了什么东西还是应该尝试其他包裹?

Am I missing something or should I try other packages??

推荐答案

您的不可复制代码中存在一些错误,据我估算,该文件为219Mb(1500 * 18250 * 8字节).

There are some errors in your non-reproducible code, and by my reckoning the file is 219Mb (1500 * 18250 * 8 bytes).

library(ncdf)

提供前两个暗的向量和数据集,以匹配至少一个切片

Provide the vectors for the first two dims and the dataset to match at least one slice

Longvector = seq(-180, 180, length = 50)
Latvector = seq(-90, 90, length = 30)
dataset <- list(1:18250)

dimX <- dim.def.ncdf("Long", "degrees", Longvector)
dimY <- dim.def.ncdf("LAT", "degrees", Latvector)
dimT <- dim.def.ncdf("Time", "days", 1:18250, unlim = FALSE)

mv <- -9999 
var1d <- var.def.ncdf( "var1d", "units", dimX, mv,prec="double")
var2d <- var.def.ncdf( "var2d", "units", list(dimX,dimY), mv,prec="double")
var3d <- var.def.ncdf( "var3d", "units", list(dimX,dimY,dimT), mv,prec="double")

nc <- create.ncdf( "writevals.nc", list(var1d,var2d,var3d))

计数是尺寸的索引,而不是轴位置值,因此我们将start校正为1,并使用第3尺寸的计数(长度)(而不是-1).

Count is the index of the dimension, not the axis position value, so we correct start to 1, and use the count (length) of the 3rd dimension (not -1).

put.var.ncdf(nc, var3d, dataset[[1]], start = c(1, 1, 1),  count = c(1, 1, length(dataset[[1]])))

close.ncdf(nc)

询问文件大小.

file.info("writevals.nc")$size/1e6
[1] 219.0866

这篇关于在R中创建多维NetCDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆