No, apparently it is still a brick: > class(b) [1] "RasterBrick" attr(,"package") [1] "raster"
Here is a minimum (not)-working example, based on this post, which seems to be having similar problems: http://r-sig-geo.2731867.n2.nabble.com/Subset-a-Raster-object-read-from-a-4D-NetCDF-file-td7586200.html Example follows: > library(raster) Loading required package: sp > b <- brick(' http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/godas/pottmp.2013.nc', lvar=3, level=1, varname='pottmp') > b class : RasterBrick dimensions : 418, 360, 150480, 12 (nrow, ncol, ncell, nlayers) resolution : 1, 0.3333309 (x, y) extent : 0, 360, -74.66667, 64.66567 (xmin, xmax, ymin, ymax) coord. ref. : +proj=longlat +datum=WGS84 data source : http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/godas/pottmp.2013.nc names : X2013.01.01, X2013.02.01, X2013.03.01, X2013.04.01, X2013.05.01, X2013.06.01, X2013.07.01, X2013.08.01, X2013.09.01, X2013.10.01, X2013.11.01, X2013.12.01 Date : 2013-01-01, 2013-02-01, 2013-03-01, 2013-04-01, 2013-05-01, 2013-06-01, 2013-07-01, 2013-08-01, 2013-09-01, 2013-10-01, 2013-11-01, 2013-12-01 varname : pottmp level : 1 > dropLayer(b,1) Error in (function (classes, fdef, mtable) : unable to find an inherited method for function âextentâ for signature â"character"â In addition: Warning message: In .stackCDF(x, varname = varname, bands = bands) : pottmp has 4 dimensions, I am using the last one > On 29 July 2014 13:24, Michael Sumner <mdsum...@gmail.com> wrote: > Are you sure that your "b" is still really a RasterBrick? That message > comes if you give the functions character: > > library(raster) > dropLayer("sometext", 1) > Error in (function (classes, fdef, mtable) : > unable to find an inherited method for function âdropLayerâ for > signature â"character"â > > (Basically because the functions are all generics, they scans through > available methods and tells you it can't find one for "character"). > > It works for me, see contrived example below that I had on hand due to > obscure testing many years ago. > (There is warning related to subsetting a linked-4D file, but that > seems harmless). > > But, also try selecting only the bands you want at read time (or even > just use a stack), so > > b <- brick("/blah/blah/ncep_07c_tho_all_1948-2010.mon.nc", level = 3, > band = 1:5) > > Cheers, Mike. > > ## create a 4D NetCDF file in R > ## load NetCDF package > library(RNetCDF) > ## generate 4D data - 1:N > dims <- c(2, 3, 2, 2) > a <- array(data = 1:prod(dims), dim = dims) > > ## create NetCDF file > nc <- create.nc("test-1.nc") > ## coordinate values for NetCDF (to test transform and band metadata) > x <- seq(0, 5, length = dim(a)[1]) > y <- seq(0, 2, length = dim(a)[2]) > c3 <- seq(0, 1, length = dim(a)[3]) > c4 <- seq(0, 1, length = dim(a)[4]) > > ## dimensions > dim.def.nc(nc, "x", length(x)) > dim.def.nc(nc, "y", length(y)) > dim.def.nc(nc, "c3", length(c3)) > dim.def.nc(nc, "c4", length(c4)) > > ## variables > var.def.nc(nc, "a", "NC_DOUBLE", c(0, 1, 2, 3)) > var.def.nc(nc, "x", "NC_DOUBLE", 0) > var.def.nc(nc, "y", "NC_DOUBLE", 1) > var.def.nc(nc, "c3", "NC_DOUBLE", 2) > var.def.nc(nc, "c4", "NC_DOUBLE", 3) > ## write the data (all at once, no start/count) > var.put.nc(nc, "a", a) > var.put.nc(nc, "x", x) > var.put.nc(nc, "y", y) > var.put.nc(nc, "c3", c3) > var.put.nc(nc, "c4", c4) > ## finish up > close.nc(nc) > > library(raster) > b <- brick("test-1.nc", level = 2) > nlevels(b) > dropLayer(b, 1) > class : RasterLayer > band : 2 (of 2 bands) > dimensions : 3, 2, 6 (nrow, ncol, ncell) > resolution : 5, 1 (x, y) > extent : -2.5, 7.5, -0.5, 2.5 (xmin, xmax, ymin, ymax) > coord. ref. : NA > data source : C:\temp\test-1.nc > names : X1 > z-value : 1 > zvar : a > level : 1 > > Warning message: > In .rasterObjectFromCDF(x, type = objecttype, band = band, ...) : > "level" set to 1 (there are 2 levels) > > > On Tue, Jul 29, 2014 at 7:43 PM, Mark Payne <markpayneatw...@gmail.com> > wrote: > > Hi, > > > > I have a 4D climate model output that I am trying to work with via > raster, > > and that is unfortunately giving problems. I create the object as a > brick: > > > >> b > > class : RasterBrick > > dimensions : 220, 254, 55880, 756 (nrow, ncol, ncell, nlayers) > > resolution : 1, 1 (x, y) > > extent : 0.5, 254.5, 0.5, 220.5 (xmin, xmax, ymin, ymax) > > coord. ref. : +proj=longlat +datum=WGS84 > > data source : /home/mpayne/Documents/NACLIM/ > > ncep_07c_tho_all_1948-2010.mon.nc > > names : X19480131, X19480229, X19480331, X19480430, X19480531, > > X19480630, X19480731, X19480831, X19480930, X19481031, X19481130, > > X19481231, X19490131, X19490228, X19490331, ... > > z-value : 19480131, 20101231 (min, max) > > varname : var2 > > level : 3 > > > > But I would like to drop a lot of the layers, so I try: > > > >> dropLayer(b,1:5) > > Error in (function (classes, fdef, mtable) : > > unable to find an inherited method for function âextentâ for signature > > â"character"â > >> > > > > And get a rather strange error.... Trying subset instead: > > > >> subset(b,1:5) > > Error in (function (classes, fdef, mtable) : > > unable to find an inherited method for function âextentâ for signature > > â"character"â > >> > > Gives the same error. I'm assuming that this is related to the 4D nature > of > > the data, as I can't reproduce it elsewise, e.g. using the examples... > Any > > ideas? > > > > Best wishes, > > > > Mark > > > > [[alternative HTML version deleted]] > > > > > > _______________________________________________ > > R-sig-Geo mailing list > > R-sig-Geo@r-project.org > > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > > > > > > -- > Michael Sumner > Software and Database Engineer > Australian Antarctic Division > Hobart, Australia > e-mail: mdsum...@gmail.com > [[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo