[R-sig-Geo] Multi-file raster stack from netcdf specifying levels

Thiago V. dos Santos thi_veloso at yahoo.com.br
Fri Oct 20 00:33:53 CEST 2017


Dear all,

I am working with several netcdf files that contain soil moisture in 15 soil layers.

I am trying to create raster stacks of individual layers, but I am getting a strange error.

# Get list of files
files <- list.files('~/Downloads', pattern='.nc', full.names=T)

# Stack all the files
h2osoil.l1 <- stack(files, varname='H2OSOI', level=1) # this would be the first layer
h2osoil.l2 <- stack(files, varname='H2OSOI', level=2) # this would be the second layer

And this is the error I get:

Error in (function (classes, fdef, mtable)  : 
unable to find an inherited method for function ‘raster’ for signature ‘"numeric"’
In addition: Warning messages:
1: In .rasterObjectFromCDF(x, type = objecttype, band = band, ...) :
"level" set to 1 (there are 15 levels)
2: In .rasterObjectFromCDF(x, type = objecttype, band = band, ...) :
"level" set to 1 (there are 15 levels)
3: In .rasterObjectFromCDF(x, type = objecttype, band = band, ...) :
"level" set to 1 (there are 15 levels)

Here are some files to reproduce this issue (3 MB each file):

https://www.dropbox.com/s/9z3fnadqdf1rzuz/cam5clm45_ctl.clm2.h0.1980-01.nc?dl=0
https://www.dropbox.com/s/0snz58au8ic196p/cam5clm45_ctl.clm2.h0.1980-02.nc?dl=0
https://www.dropbox.com/s/v5ps5bkyrkflki7/cam5clm45_ctl.clm2.h0.1980-03.nc?dl=0


I know netcdf files can be quite tricky to work with, but is there any way to get this file read in the right way using the raster package? Any other option?

 
Greetings,
 -- Thiago V. dos Santos

Postdoctoral Research Fellow
Department of Climate and Space Science and Engineering
University of Michigan



More information about the R-sig-Geo mailing list