Extracting Lon and Lat range of a grib file

2.9k Views Asked by At

I am pretty new to the GRIB format but I currently need to deal with it. Using wgrib, I managed to extract the fields I wanted, corresponding times, etc ..

But I miss the coordinates of the points of th grid, or the latitude and longitude range of the grid.

How can I get that ? I would prefer using only python and wgrib but if there is any other simple way please let me know ! What I've found on the web seems to mainly concern wgrib2 format.

1

There are 1 best solutions below

1
On BEST ANSWER

As mentioned in comments you have to use module pygrib.

I post a sample code to get lat and lon arrays from all messages of a grib file by method latlons. After extracting I convert data to numpy arrays:

import pygrib
import numpy as np

grib = pygrib.open('test.grib')
for g in grib:
    lt, ln = g.latlons() # lt - latitude, ln - longitude
    lt, ln = np.array(lt), np.array(ln)
    print (lt, ln)