I have a GRIB file from NOAA that contains several variables for a specific subregion in Norht-East Atlantic.
I'm using ECMWF grip-api Python library to parse the file. While I'm able to get the values for each {latitude, longitude} pair for each GRIB message with this code:
def iterate_latitude_longitude():
f = open(INPUT)
while 1:
gid = grib_new_from_file(f)
if gid is None: break
iterid = grib_iterator_new(gid,0)
#Get the missingValue for this GRIB message (e.g. NaN)
missingValue = grib_get_double(gid,"missingValue")
i=0
while 1:
#Get the value from the geo iterator obtained previously, value is a tuple with [latitude, longitude, value]
result = grib_iterator_next(iterid)
if not result: break
[lat,lon,value] = result
sys.stdout.write("-Point # %d - lat=%.6f lon=%.6f value=" % (i,lat,lon))
#Check if missing value is present or not
if value == missingValue:
print "missing"
else:
print "%.6f" % value
#increase iterator
i += 1
grib_iterator_delete(iterid)
grib_release(gid)
f.close()
While this is great, this file contains forecast data, it was extracted from this place, more precisely, this file:
multi_1.nww3.t00z.grib2
Which contains world data. There are other files for different times: 00-60-12-18-00, thus, every 6 hours.
What I'm missing is the relation between the value obtained for each latitude,longitude and the time dimension. Does anybody know how to extract this info from a grib file, whether using Python or Java?
I know I can use things like wgrib2 or pygrib to convert to CSV and do the other way around...but it just looks so inefficient