pythongdalgribpygribeccodes

alternative (faster) way to get grib values given boundary?


I've used pygrib to extract all grib values for a specific band within given boundaries. The function will return a Json object that contains all the values for each analyzed data.

Now that I've to read approximately 73 grib for each run, the response is slow and it's now at approximately 3 minutes.

The result should be something like: Grid Result

Do you know another way to extract data within a bbox, using other tools like GDAL or ECCODES?

I cant use grib2json as it doesn't recognize the GRIB.

Thanks in advance


Solution

  • do you had a look to cfgrib. It is the grib engine for xarray. And with xarray you are having a large amount of services and applications for grib datasets. xarray is following the data cube principle.

    E.g. if you have load your data into a xarray.Dataset you can use where function to slice the data to your bbox:

    import xarray
    
    dataset = xarray.open_dataset('path to grib file', engine='cfgrib')
    
    # or for multiple files 
    dataset = xarray.open_dataset(['path_to_grib1', 'path_to_grib2', ...], engine='cfgrib')
    
    dataset.where((dataset.latitude > min_lat) & 
                  (dataset.latitude < max_lat) & 
                  (dataset.longitude > min_lon) &
                  (dataset.longitude < max_lon), drop=True)