I'm trying to find out the uvIndex of a particular set of lat,lng. I'm getting the data file from this link. I'm using pygrib to read the file.

import pygrib
grbs = pygrib.open('uv.t12z.grbf01.grib2')
grb = grbs.select(name='UV index')[0]
print grb.data(23.5,55.5)

This prints 3 numpy arrays. But I'm not able to figure out how to extract data from it.


Based in PyGrib Documentation from Arulalan, you can see that:

>>>import pygrib
>>>grbs = pygrib.open('/home/zeito/Desktop/uv.t12z.grbf01.grib2') #path in my system
>>>grb = grbs.select(name='UV index')[0]
>>>print grb.data(23.5,55.5)
... a long array of data
>>>print grbs.messages
>>>g = grbs[1]
>>>print g
1:UV index:Numeric (instant):regular_ll:surface:level 0:fcst time 1 hrs:from 201606021200
>>>my_values = g['values']
>>>print my_values[69][46]
>>>my_lats = g['distinctLatitudes']
>>>print my_lats[69]
>>>my_longs = g['distinctLongitudes']
>>>print my_longs[46]

Afterward, I opened this kind of file in QGIS (supported by GDAL) and, with the help of 'Value Tool' plugin, I corroborated that results at the Python Console of QGIS were as expected (see next image).

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.