[R-sig-Geo] ECMWF grib and raster
bart
bart at njn.nl
Wed Jan 26 11:58:24 CET 2011
Hi All
I'm trying to read grib files using Raster, form the ECMWF interim
dataset (example file linked below). I don't get errors but the
coordinate system of the read raster does not seem to match.
> raster("tmp.grib")
class : RasterLayer
filename : /home/bart/Desktop/tmp.grib
nrow : 121
ncol : 240
ncell : 29040
min value : ?
max value : ?
projection : +proj=longlat +a=6367470 +b=6367470 +no_defs
extent : -180, 180, -91.5, 90 (xmin, xmax, ymin, ymax)
resolution : 1.5, 1.5 (x, y)
Notice the minimal latitude outside this world. For comparison i
extracted the same data using the grib_get_data program with the
following command: grib_get_data tmp.grib > bla.tab (small manual format
conversion for reading in R). grib_get_data is provided by:
libgrib-api-tools (http://packages.ubuntu.com/maverick/libgrib-api-tools) .
Comparing the datasets gives the following results
> summary(b<-read.csv("bla.tab", sep=","))
Latitude Longitude Value
Min. :-90 Min. :-180.00 Min. :2.093
1st Qu.:-45 1st Qu.: -90.38 1st Qu.:2.695
Median : 0 Median : -0.75 Median :2.836
Mean : 0 Mean : -0.75 Mean :2.791
3rd Qu.: 45 3rd Qu.: 88.88 3rd Qu.:2.969
Max. : 90 Max. : 178.50 Max. :3.147
> summary(a<-rasterToPoints(raster("tmp.grib")))
x y V3
Min. :-179.25 Min. :-90.75 Min. :209.3
1st Qu.: -89.62 1st Qu.:-45.75 1st Qu.:269.5
Median : 0.00 Median : -0.75 Median :283.6
Mean : 0.00 Mean : -0.75 Mean :279.1
3rd Qu.: 89.62 3rd Qu.: 44.25 3rd Qu.:296.9
Max. : 179.25 Max. : 89.25 Max. :314.7
It seems the raster grid is offset by half a grid cell size. I'm not
sure what the grib file format specification is but since
libgrib-api-tools seems to be provided by ECMWF i tend to believe their
correct.
Bart
ps tmp.grib is downloadable here:
https://depot.uni-konstanz.de/cgi-bin/exchange.pl?g=nv3xd (less than 100kb)
More information about the R-sig-Geo
mailing list