ecmwf / cfgrib

A Python interface to map GRIB files to the NetCDF Common Data Model following the CF Convention using ecCodes
Apache License 2.0
400 stars 77 forks source link

I don't find the Total Precipitation inside of grib file #213

Open rrodrigojrr opened 3 years ago

rrodrigojrr commented 3 years ago

I try to get the Total Precipitation using this code:

data = xr.open_dataset('gfs.t12z.pgrb2full.0p50.f012', engine='cfgrib', backend_kwargs={'filter_by_keys': {'cfVarName': 'apcp','typeOfLevel': 'surface'}})
data

But i get a keyerror:

KeyError                                  Traceback (most recent call last)
<ipython-input-118-3f7161642cbd> in <module>()
----> 1 ver = xr.open_dataset('gfs.t12z.pgrb2full.0p50.f012', engine='cfgrib', backend_kwargs={'filter_by_keys': {'cfVarName': 'apcp','typeOfLevel': 'surface'}})
      2 ver

4 frames
/usr/local/lib/python3.7/dist-packages/cfgrib/messages.py in __getitem__(self, item)
    389     def __getitem__(self, item):
    390         # type: (str) -> list
--> 391         return self.header_values[item]
    392 
    393     def getone(self, item):

KeyError: 'paramId'

The the APCP is the parameter of Total Precipitation in this link

Anyone have any idea how can i get this field?

iainrussell commented 3 years ago

Hi @rrodrigojrr, my guess is that you will need local ecCodes tables in order to correctly process this data (cfgrib uses ecCodes for the actual decoding of the GRIB data). If you have the ecCodes tools installed, you should be able to type grib_ls gfs.t12z.pgrb2full.0p50.f012 on the command line, and it will probably tell you that the parameter is unknown. ecCodes comes supplied with tables required in order to decode WMO and ECMWF GRIB data, but this does not cover data from all Centres. However, it is often possible to obtain tables for various data, but I don't know about this particular one. Please let us know what you find out!

shahramn commented 3 years ago

Please note: According to the WMO, the use of local tables in messages intended for non-local or international exchange is strongly discouraged.