Skip to content

Create a raster brick from a netcdf using all levels

5 messages · Thiago V. dos Santos, Robert J. Hijmans

#
? Dear list,

? I have a netcdf file that contains 6 levels. Below is the structure of the file:

require(ncdf)
require(raster)
[1] "file /data/input-inland/soita.clay.nc has 5 dimensions:"
[1] "longitude ? Size: 720"
[1] "latitude ? Size: 360"
[1] "layer ? Size: 6"
[1] "time ? Size: 1"
[1] "lengthd ? Size: 10"
[1] "------------------------"
[1] "file /data/input-inland/soita.clay.nc has 1 variables:"
[1] "double claypct[longitude,latitude,layer,time] ?Longname:claypct Missval:1e+30"
??
? What I need to do is to load this netcdf to a brick raster object using all levels. When creating the brick file, specifying "nl=6" results in loading only the last level:
Warning messages:
1: In .rasterObjectFromCDF(x, type = objecttype, band = band, ...) :
? "level" set to 1 (there are 6 levels)
2: In .doTime(r, nc, zvar, dim3, ncdf4) : assuming a standard calender:0
class ? ? ? : RasterBrick?
dimensions ?: 360, 720, 259200, 1 ?(nrow, ncol, ncell, nlayers)
resolution ?: 0.5, 0.5 ?(x, y)
extent ? ? ?: -180, 180, -90, 90 ?(xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84?
data source : /data/input-inland/soita.clay.nc?
names ? ? ? : X1958.01.01?
Date ? ? ? ?: 1958-01-01?
varname ? ? : claypct?
level ? ? ? : 1?

? I have also tested another approach, for example specifying "nl=1:6", however with no sucess at all.?Does anyone know a workaround to load all leves of a netcdf file in a single raster brick object?

? Many thanks in advance,
? Thiago.
1 day later
#
? Robert,

? This "lvar=4" argument was the magic word I was looking for! It would be really useful to include it in the next version of raster manual.

? I also thought that this file is odd, and working with netcdf files is really a Pandora's box. There should have a more specific standard to produce and distribute this type of file...

? The second option would have worked as well (although not as elegant). Another technique learned!

? Thank you very much again for the patience,
? Thiago.