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

Thiago V. dos Santos thi_veloso at yahoo.com.br
Fri Oct 20 01:36:02 CEST 2017


Yes, it works!
Thank you very much for the alternative! Greetings, -- Thiago V. dos Santos
Postdoctoral Research FellowDepartment of Climate and Space Science and EngineeringUniversity of Michigan 

    On Thursday, October 19, 2017 7:10 PM, Vijay Lulla <vijaylulla at gmail.com> wrote:
 

 Maybe you can try something like this?

h2osoil.l1 <- do.call(stack, lapply(files, function(file) raster(file, varname='H2OSOI', level=1)))
h2osoil.l2 <- do.call(stack, lapply(files, function(file) raster(file, varname='H2OSOI', level=2)))
...
h2osoil.l15 <- do.call(stack, lapply(files, function(file) raster(file, varname='H2OSOI', level=15)))


On Thu, Oct 19, 2017 at 6:33 PM, Thiago V. dos Santos via R-sig-Geo <r-sig-geo at r-project.org> wrote:

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

______________________________ _________________
R-sig-Geo mailing list
R-sig-Geo at r-project.org
https://stat.ethz.ch/mailman/ listinfo/r-sig-geo



-- 
Vijay Lulla, Ph.D.
Assistant Professor,Dept. of Geography,Indiana University Purdue University Indianapolis (IUPUI)425 University Blvd, CA-207C.Indianapolis, IN-46202vlulla at iupui.edu

http://vijaylulla.com

   
	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list