pythongribnoaa

Pulling weather data from a GRIB file for specific coordinates and date/times


I've got a GRIB file with ECMWF forecast, and I'm keen to pull data from it based on coordinate inputs. As in, provide coordinates, and get the forecast for the next 5 days, for a specific time (wind speed, gust speed, wind direction, wave height..).

I think Python is probably the best option to accomplish this. Can someone point me in the right direction? Give me some bits.

I'm guessing the binary needs to be converted to a JSON (or another readable format), and then I can parse through and look for the data based on the coordinates provided?


Solution

  • One way of doing this in native Python is using xarray and cfgrib. Here is a tutorial. Here is the key code from the tutorial:

        import xarray as xr
        ds = xr.tutorial.load_dataset('<your_grib>.grib', engine='cfgrib')
    

    Once you have done this, all the fields in the grib file will be available. The general form is

        ds.<field_name>[<index>].values
    

    Be warned that this code is very slow compared to using the GRIB tools provided by the US National Weather Service. Check out degrib. Most of the weather processing code is written in C and Fortran, because it is so much faster than Python. Depending on your available compute resources and data size, you may not be able to process a whole grib file in Python before the forecast it contains expires.

    Finally, this topic is discussed more extensively on the GIS stack exchange. "grib" is a tag over there.