1

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?

InsuredApple
  • 63
  • 1
  • 3
  • 12
  • 1
    convert to json using a tool like https://github.com/cambecc/grib2json. Next you can populate a DB with the data or do a direct search using python – balderman Mar 15 '21 at 17:18
  • Thank you. I am working on getting this going. Thank you. Internet is a bit slow on the boat right now.. and I am working on getting mvn. – InsuredApple Mar 17 '21 at 01:21

1 Answers1

1

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.

Craeft
  • 227
  • 1
  • 11
  • Thank you!!! I will give this a shot. Just trying to get my python IDE going again. This is great!!! – InsuredApple Mar 17 '21 at 01:21
  • Thank you @Craeft this worked. It looks like PredictWind doesn't actually download "propper" grib files, but truncated files. So I'll need to figure out their file format. – InsuredApple Mar 17 '21 at 13:24
  • 1
    What do you mean by "proper grib files"? – Craeft Mar 17 '21 at 13:28
  • 1
    You can get NOAA's forecast data from https://www.ncdc.noaa.gov/data-access/model-data/model-datasets/global-forcast-system-gfs – Craeft Mar 17 '21 at 13:29
  • 1
    Scroll down to GFS Forecasts. Those are proper gribs and cover the whole world – Craeft Mar 17 '21 at 13:30
  • I found the GRIB files from Predict Wind. cfgrib accepts all of them, other than the ECMWF files for some reason. -- EOFError: No valid message found in file: '/Users/kevin/Downloads/Gribs/ECMWF_WaG_50k_14d_3h_37N_19S_-68E_-89W_20210316_0300.grb' -- not sure why this is happening. I am trying to figure out if I can validate that it is the file (which is likely) rather than cfgrib. And THANK YOU for your help!! – InsuredApple Mar 17 '21 at 15:51