我想从netCDF文件创建一个光栅。我检查了一些基础知识,过程似乎很简单(https://www.youtube.com/watch?v=jWy_jGZo2oc)。
但是,当“分解”我的netCDF文件时,将交换行,列和层的尺寸。即使我手动定义它们。
# load libraries
library(ncdf4)
library(raster)
# Load Outflow file
ncfname = "C:/Users/stijn/OneDrive/Bureaublad/Thesis/Rscripts/Outputs/swit.nc"
swit = nc_open(ncfname)
print(swit)
[ 1 variables (excluding dimension variables):
float SWIT[time,y,x]
units: m/hr
missing_value: -9999
_FillValue: -9999
3 dimensions:
time Size:2904
units: days since 2018-12-01 00:00:00
y Size:127
units: Meter
x Size:147
units: Meter]
switbrick <- brick(ncfname, nrows = 127, ncols = 147, nl = 2904)
switbrick
[class : RasterBrick
dimensions : 127, 2904, 368808, 147 (nrow, ncol, ncell, nlayers)
resolution : 0.04166667, 5 (x, y)
extent : -0.02083333, 120.9792, 6615598, 6616233 (xmin, xmax, ymin, ymax)
crs : NA
source : directory/something/swit.nc
names : X603301.87, X603306.87, X603311.87, X603316.87, X603321.87, X603326.87, X603331.87, X603336.87, X603341.87, X603346.87, X603351.87, X603356.87, X603361.87, X603366.87, X603371.87, ...
x (Meter) : 603301.87, 604031.87 (min, max)
varname : SWIT ]
尺寸应符合规定,尽管没有规定。是什么导致此错误?
答案 0 :(得分:0)
问题是文件的顺序异常,以time
开头而不是结尾。您可以使用dims
参数对此进行更正(似乎没有记录)。
尝试
library(raster)
ncfname = "C:/Users/stijn/OneDrive/Bureaublad/Thesis/Rscripts/Outputs/swit.nc"
switbrick <- brick(ncfname, dims=c(3,1,2))
从文件创建对象时,不会考虑您提供的其他参数(nrow,ncols,nlayers)。