[R-sig-Geo] Create a raster brick from a netcdf using all levels

Thiago Veloso thi_veloso at yahoo.com.br
Thu Sep 27 15:41:03 CEST 2012


  Dear list,

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

require(ncdf)
require(raster)
> nctemp <- open.ncdf('/data/input-inland/soita.clay.nc')

> nctemp
[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:

> clay <- brick('/data/input-inland/soita.clay.nc', nl=6)
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
> clay
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.



More information about the R-sig-Geo mailing list