[R-sig-Geo] Problem with raster package and netcdf file
Julian Burgos
julian at hafro.is
Fri Mar 8 11:18:09 CET 2013
Dear list,
I am having some troubles opening accessing a raster in the netCDF format.
The file is bathimetric data from GEBCO:
http://www.gebco.net/data_and_products/gridded_bathymetry_data/
If I use the ncdf4 package to open and access the data, I have no issues:
library(ncdf4)
> d <- nc_open("gebco_08_-82_37_63_80.nc")
> z <- as.vector(ncvar_get(d,varid="z"))
> head(z)
[1] 19 40 61 83 106 128
But if I try to use the raster package to access the file and create a
raster object, I get the following error:
bat <- raster(file="gebco_08_-82_37_63_80",varname="z")
Error in .varName(nc, varname, warn = warn) :
varname: z does not exist in the file. Select one from:
... and no varnames are listed.
If I do not define a variable name and let the raster package choose it, I
get this:
> bat <- raster(file="gebco_08_-82_37_63_80",varname="z")
Error in .varName(nc, varname, warn = warn) :
The description of the netCDF file is as following:
> d
[1] "File gebco_08_-82_37_63_80.nc (NC_FORMAT_CLASSIC):"
[1] ""
[1] " 6 variables:"
[1] " double x_range[side] "
[1] " units: user_x_unit"
[1] " double y_range[side] "
[1] " units: user_y_unit"
[1] " short z_range[side] "
[1] " units: user_z_unit"
[1] " double spacing[side] "
[1] " int dimension[side] "
[1] " short z[xysize] "
[1] " scale_factor: 1"
[1] " add_offset: 0"
[1] " node_offset: 1"
[1] ""
[1] " 2 dimensions:"
[1] " side Size:2"
[1] " xysize Size:89784000"
[1] ""
[1] " 2 global attributes:"
[1] " title: GEBCO_08 Grid"
[1] " source: 20100927"
I am using R 15.2 on Linux (Fedora), raster 2.1-8, and ncdf4 version
ncdf4_1.6.1_20120411.
Any help will be welcomed!
Julian
--
Julian Mariano Burgos, PhD
Hafrannsóknastofnunin/Marine Research Institute
Skúlagata 4, 121 Reykjavík, Iceland
Sími/Telephone : +354-5752037
Bréfsími/Telefax: +354-5752001
Netfang/Email: julian at hafro.is
More information about the R-sig-Geo
mailing list