Using the R raster package, I have a brick derived from a file with the following ncdump header (I am showing a small example file, the actual file is much larger):
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 ;
And in 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
However, for faster access and higher compression, the two file sizes have been replaced, so chunking is better for the kind of use we need. Thus, the file will be like this ( to download a 1MB file ):
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 ;
And in 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
As you can see, the file opens as if the number of columns was 125,000. I want to change the number of columns to the number of layers without reading all the data. I think from the raster manual I should use layer or lvar , since:
layer: integer. A layer (variable) for use in a multilayer file, or a layer to extract from RasterStack / Brick or SpatialPixelsDataFrame or SpatialGridDataFrame. An empty RasterLayer (without associated values) is returned if 'layer = 0
.......
'lvar: integer> 0 (default = 3). To select a “level variable”, (3rd dimension variable) if the file has 4 dimensions (for example, depth instead of time)
But this does not seem to work, for example, layer="time" , since it does not change anything.
How can i do this?