[gdal-dev] gdal reading in grib values in awrong state?

mafunk at nmsu.edu mafunk at nmsu.edu
Thu May 5 16:57:12 EDT 2011


Hi,
i am a little confused. I am using the gdal/python and trying to read
values from a grib file (i can email the file if needed). I am using
pygrib to compare against. I do this with the following code:

import struct

import pygrib

from osgeo import gdal
from osgeo import ogr
from osgeo import osr
from osgeo import gdal_array
from osgeo import gdalconst
from osgeo.gdalconst import *

import numpy as np
from numpy import *

#path = "../Data"
#filename = "%s/ds.temp.bin" % (path)
filename = "ds.temp.bin"

print "\n\nTesting with pygrib, opening file: %s\n" % (filename)
grbs = pygrib.open(filename)
rows = -1
cols = -1
grbs.seek(0)
for grb in grbs:
    print "grb:"
    grb
    print "grb.keys():"
    print grb.keys()
    for key in grb.keys():
        print "\nKey: " + key
        print "data:"
        print grb[key]



    #print "grb['values']"
    #print grb['values']
    #print "grb['codedValues']"
    #print grb['codedValues']

    (pg_lats,pg_lons) = grb.latlons()
    pg_rows = pg_lats.shape[0]
    pg_cols = pg_lats.shape[1]
            #print test
            #print lats.shape, lats.min(), lats.max(), lons.shape,
lons.min(), lons.max()
            #lat_pygrib_arr = []
    print size(pg_lats)
print "\n\n"


## open with gdal
ds = gdal.Open(filename)
band = ds.GetRasterBand(1)
data = band.ReadAsArray(0,0,band.XSize,band.YSize)#.flatten()
print "data:"
print data


The data values i get from pygrib are:
data:
[[ 294.5   294.5   294.5  ...,  298.31  298.32  298.32]
 [ 294.5   294.5   294.5  ...,  298.32  298.22  298.22]
 [ 294.4   294.4   294.4  ...,  298.22  298.22  298.22]
 ...,
 [ 280.91  280.91  280.81 ...,  264.2   264.3   264.5 ]
 [ 280.81  280.81  280.81 ...,  263.5   263.7   263.9 ]
 [ 280.81  280.81  280.81 ...,  262.8   263.    263.3 ]]

The values i get from gdal are:
data:
[[  7.65999756   7.65999756   7.65999756 ..., -10.35001221 -10.15
   -9.85001221]
 [  7.65999756   7.65999756   7.65999756 ...,  -9.65        -9.45001831
   -9.2500061 ]
 [  7.76000366   7.76000366   7.65999756 ...,  -8.95001831  -8.85001221
   -8.65      ]
 ...,
 [ 21.2499939   21.2499939   21.2499939  ...,  25.07000122  25.07000122
   25.07000122]
 [ 21.35        21.35        21.35       ...,  25.17000732  25.07000122
   25.07000122]
 [ 21.35        21.35        21.35       ...,  25.15999756  25.17000732
   25.17000732]]

Is there anything obvious that i am doing wrong?

thanks
matt




More information about the gdal-dev mailing list