将栅格堆栈写入NetCDF [英] Writing R raster stack to NetCDF
问题描述
我有一个 R网格文件,其中包含我阅读的1981年的每月温度数据并尝试使用以下代码写入NetCDF:
I've got an R grid file containing monthly temperature data for the year 1981 which I read in and tried to write to NetCDF using the following code:
library(raster)
library(ncdf4)
library(RNetCDF)
test <- raster('.../TavgM_1981.gri', package = "raster")
rstack = stack(test)
writeRaster(rstack, "rstack.nc", overwrite=TRUE, format="CDF", varname="Temperature", varunit="degC",
longname="Temperature -- raster stack to netCDF", xname="X", yname="Y",zname="nbands",
zunit="numeric")
这将写入 NetCDF文件,但它似乎只有一个月的时间(我不是确定哪一个),而不是一年中我用panoply检查它的12个月.
This writes the NetCDF file, but it only seems to have one month (I'm not sure which), instead of the 12 months of the year when I examine it using panoply.
是否可以写入NetCDF文件并保留来自R-grid文件的尽可能多的数据?特别是每个月的数据!
Is it possible to write the NetCDF file and keep as much of the data from the R-grid file as possible? Especially the data for each month!
新的工作代码:
test <- brick('/TavgM_1981.gri')
writeRaster(test, "rstack.nc", overwrite=TRUE, format="CDF", varname="Temperature", varunit="degC",
longname="Temperature -- raster stack to netCDF", xname="Longitude", yname="Latitude", zname="Time (Month)")
推荐答案
正如dww指出的,要获取所有图层,请
As dww pointed out, to get all layers, this
test <- raster('.../TavgM_1981.gri', package = "raster")
应该是
test <- brick('TavgM_1981.grd')
主要是将raster
替换为brick
.同样,三个点.../
没有任何意义.可能是一个或两个点(或不必要),并且package = "raster"
参数毫无意义.
The main thing is to replace raster
with brick
. Also, the three dots .../
make no sense. It could be one or two dots (or unnecessary), and the package = "raster"
argument is meaningless.
这篇关于将栅格堆栈写入NetCDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!