Is it possible to download a smaller GRIB GFS file with specific parameters only (e.g. surface wind and temperature values) rather than hundreds of MB of data? If so, what is the usual approach to achieve this?
[GIS] Downloading GRIB GFS files with specific filters
grib-2noaa
Related Solutions
You probably didn't want to just iterate over the whole file, but rather iterate over each of the (interesting) values, for each of the time steps you want.
Here is some code adapted from the sample code
import traceback
import sys
from gribapi import *
INPUT='multi_1.nww3.t00z.grib2'
VERBOSE=1 # verbose error reporting
def example():
f = open(INPUT)
keys = [
'stepRange',
'shortName',
]
while 1:
gid = grib_new_from_file(f)
if gid is None: break
for key in keys:
if not grib_is_defined(gid, key): raise Exception("Key was not defined")
print '%s=%s' % (key, grib_get(gid, key))
missingValue = grib_get_double(gid,"missingValue")
iterid = grib_iterator_new(gid,0)
i=0
while 1:
result = grib_iterator_next(iterid)
if not result: break
[lat,lon,value] = result
sys.stdout.write("- %d - lat=%.6f lon=%.6f value=" % (i,lat,lon))
if value == missingValue:
print "missing"
else:
print "%.6f" % value
i += 1
grib_iterator_delete(iterid)
grib_release(gid)
f.close()
def main():
try:
example()
except GribInternalError,err:
if VERBOSE:
traceback.print_exc(file=sys.stderr)
else:
print >>sys.stderr,err.msg
return 1
if __name__ == "__main__":
sys.exit(main())
And some sample output:
stepRange=0
shortName=unknown
....
- 288 - lat=77.000000 lon=0.000000 value=4.890000
- 289 - lat=77.000000 lon=1.250000 value=5.720000
- 290 - lat=77.000000 lon=2.500000 value=6.690000
- 291 - lat=77.000000 lon=3.750000 value=7.620000
- 292 - lat=77.000000 lon=5.000000 value=8.350000
- 293 - lat=77.000000 lon=6.250000 value=8.810000
- 294 - lat=77.000000 lon=7.500000 value=9.090000
- 295 - lat=77.000000 lon=8.750000 value=9.250000
....
stepRange=3
shortName=ws
....
- 288 - lat=77.000000 lon=0.000000 value=34.030000
- 289 - lat=77.000000 lon=1.250000 value=20.160000
- 290 - lat=77.000000 lon=2.500000 value=4.290000
- 291 - lat=77.000000 lon=3.750000 value=351.300000
- 292 - lat=77.000000 lon=5.000000 value=342.490000
- 293 - lat=77.000000 lon=6.250000 value=337.310000
- 294 - lat=77.000000 lon=7.500000 value=334.990000
- 295 - lat=77.000000 lon=8.750000 value=334.460000
- 296 - lat=77.000000 lon=10.000000 value=334.800000
- 297 - lat=77.000000 lon=11.250001 value=335.990000
- 298 - lat=77.000000 lon=12.500001 value=337.970000
- 299 - lat=77.000000 lon=13.750001 value=338.940000
Note that per your comments on the other answer, the results are in 3 hour blocks (not 6 hour as noted in the question).
The easiest way is to download the regional subset of the GFS data from nomads.ncep.noaa.gov. Just select the grib_filter and fill in the blanks. The grib_filter web page has been using wgrib2 and the -small_grib option for 7 years, so the -small_grib option works.
Best Answer
Well, after a bit more of search and after forgetting how I even ended up on this page, there is one very helpful (official) filtering page right here on NOAA "website". Combining "levels" with "variables" (all acronyms are described here, also on official NOAA "NCEP Products Inventory" page) I managed to filter the data.
Selecting "Show the URL only for web programming" checkbox on the bottom of the "filtering" page shows up the URL needed to download specific file, e.g.