使用R语言的raster
包,我从文件中获取了一个brick
。这个文件具有以下ncdump
头部信息(这里展示了一个小文件的例子,实际文件要大得多):
dimensions:
lon = 2 ;
lat = 3 ;
time = UNLIMITED ; // (125000 currently)
variables:
float lon(lon) ;
lon:standard_name = "longitude" ;
lon:long_name = "longitude" ;
lon:units = "degrees_east" ;
lon:axis = "X" ;
float lat(lat) ;
lat:standard_name = "latitude" ;
lat:long_name = "latitude" ;
lat:units = "degrees_north" ;
lat:axis = "Y" ;
double time(time) ;
time:standard_name = "time" ;
time:long_name = "Time" ;
time:units = "seconds since 2001-1-1 00:00:00" ;
time:calendar = "standard" ;
time:axis = "T" ;
short por(time, lat, lon) ;
por:_FillValue = 0s ;
por:missing_value = 0s ;
在 R
中:
class : RasterBrick
dimensions : 3, 2, 6, 125000 (nrow, ncol, ncell, nlayers)
resolution : 0.008999825, 0.009000778 (x, y)
extent : 6.4955, 6.5135, 44.0955, 44.1225 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
data source : /home/clima-archive/afantini/chym/chym_output/test.nc
names : X0, X3600, X7200, X10800, X14400, X18000, X21600, X25200, X28800, X32400, X36000, X39600, X43200, X46800, X50400, ...
z-value : 0, 449996400 (min, max)
varname : por
然而,为了更快的访问和更高的压缩,文件的两个维度已经交换,以便我们需要的使用方式更好地进行分块。所以文件将是这样的(下载1MB文件的链接):
dimensions:
lon = UNLIMITED ; // (2 currently)
lat = 3 ;
time = 125000 ;
variables:
float lon(lon) ;
lon:standard_name = "longitude" ;
lon:long_name = "longitude" ;
lon:units = "degrees_east" ;
lon:axis = "X" ;
float lat(lat) ;
lat:standard_name = "latitude" ;
lat:long_name = "latitude" ;
lat:units = "degrees_north" ;
lat:axis = "Y" ;
double time(time) ;
time:standard_name = "time" ;
time:long_name = "Time" ;
time:units = "seconds since 2001-1-1 00:00:00" ;
time:calendar = "standard" ;
time:axis = "T" ;
short por(lon, lat, time) ;
por:_FillValue = 0s ;
por:missing_value = 0s ;
在R
中:
class : RasterBrick
dimensions : 3, 125000, 375000, 2 (nrow, ncol, ncell, nlayers)
resolution : 3600, 0.009000778 (x, y)
extent : -1800, 449998200, 44.0955, 44.1225 (xmin, xmax, ymin, ymax)
coord. ref. : NA
data source : /home/clima-archive/afantini/chym/chym_output/test_swapped.nc
names : X6.5, X6.50899982452393
degrees_east: 6.5, 6.50899982452393
varname : por
如您所见,该文件似乎以125000列的数量打开。我想交换列数和层数,而不必读取所有数据。从栅格手册中,我认为应该使用
layer
或lvar
,因为:
但是这似乎行不通,例如设置layer:整数。在多层文件中使用的层(变量), 或从RasterStack / Brick或SpatialPixelsDataFrame 或SpatialGridDataFrame中提取的层。如果‘layer = 0’则返回一个空的RasterLayer(没有关联值)。
.......
‘lvar’:integer> 0(默认值=3)。如果文件有4个维度(例如深度而不是时间),则选择要使用的“级别变量”(第三维变量)。
layer =“time”
,因为它不起作用。我该如何做呢?