【发布时间】:2019-11-22 04:34:27
【问题描述】:
我想在 netcdf 文件中创建一个具有 3 维(经度、纬度、时间[无限])的时间序列。应该从其他 netcdf 文件创建时间序列。他们每个人只有一个时间点[例如 17856]。 我知道如何创建新的 netcdf 文件,如何从 netcdf 文件中提取数据作为二维数组以及数据的时间。 我的问题是: 如何使用正确的时间将二维数组放入 netcdf 文件中? "ncvar_put" 函数中的 start 和 count 参数是如何工作的?
我使用 ncdf4 包并阅读教程:
http://geog.uoregon.edu/bartlein/courses/geog490/week04-netCDF.html#create-and-write-a-netcdf-file 并搜索了答案,但我仍然不明白。我仍然对 netcdf 文件不熟悉。
示例
e of my problem:
# data from other netcdf file
values = array(data = c(1:9)/10, dim = c(3,3))
values_2 = array(data = c(9:25)/10, dim = c(3,3))
time = 25
time_2 = 23
# set parameters
lon = 1:3
lat = 1:3
# define dimensions
# Longitude
londim = ncdim_def(name = "longitude", units = "degrees", vals = as.double(lon),
longname = "longitude")
# Latitude
latdim = ncdim_def(name = "latitude", units = "degrees", vals = as.double(lat),
longname = "latitude")
# Time
timedim = ncdim_def(name = "time", units ="days since 1582-10-15 00:00", vals = as.double(1),
unlim = TRUE, calendar = "gregorian")
# define variables
B01 = ncvar_def(name = "B01",
units ="percent",
list(londim,latdim,timedim),
missval = NA,
prec="double")
# create netcdf
nc_test = nc_create("test.nc", list(B01), force_v4 = TRUE)
# Add values
### Here is somethin missing --> How do I add the timestamp?
ncvar_put(nc_test, "B01", values, start=c(1,1,1), count=c(-1,-1,1))
ncvar_put(nc_test, "B01", values2, start=c(1,1,2), count=c(-1,-1,1))
当我想提取数据时,我得到了 3-3-2 数组,但时间步长不正确,因为我没有添加它们。我该怎么做呢? 我想要 3-3-2 数组,当我花时间时,我想要正确的时间以正确的顺序。
【问题讨论】:
标签: r time-series netcdf netcdf4