jswhit / pygrib

Python interface for reading and writing GRIB data
https://jswhit.github.io/pygrib
MIT License
328 stars 97 forks source link

Grib reading issue #148

Closed jiacheng-atmos closed 3 years ago

jiacheng-atmos commented 4 years ago

Dear maintaners,

I have a grib file named *.grib2. I used ncl_filedump .grib2 to check the available variables, which are written as follows:

filename: apcp_sfc_2009010100_c00 path: xxxx/xxxx/apcp_sfc_2009010100_c00.grib2 file global attributes: dimensions: forecast_time0 = 40 lat_0 = 721 lon_0 = 1440 forecast_time1 = 40 variables: float APCP_P11_L1_GLL0_acc6h ( forecast_time0, lat_0, lon_0 ) center : US National Weather Service - NCEP (WMC) production_status : Operational products long_name : Total precipitation units : kg m-2 _FillValue : 1e+20 grid_type : Latitude/longitude parameter_discipline_and_category : Meteorological products, Moisture parameter_template_discipline_category_number : ( 11, 0, 1, 8 ) level_type : Ground or water surface level : 0 type_of_statistical_processing : Accumulation statistical_process_duration : 6 hours (ending at forecast time) initial_time : 01/01/2009 (00:00)

  float APCP_P11_L1_GLL0_acc3h ( forecast_time1, lat_0, lon_0 )
     center : US National Weather Service - NCEP (WMC)
     production_status :  Operational products
     long_name :  Total precipitation
     units :  kg m-2
     _FillValue : 1e+20
     grid_type :  Latitude/longitude
     parameter_discipline_and_category :  Meteorological products, Moisture
     parameter_template_discipline_category_number :  ( 11, 0, 1, 8 )
     level_type : Ground or water surface
     level :   0
     type_of_statistical_processing : Accumulation
     statistical_process_duration :   3 hours (ending at forecast time)
     initial_time :   01/01/2009 (00:00)

  integer forecast_time1 ( forecast_time1 )
     long_name :  Forecast offset from initial time
     units :  hours

  float lat_0 ( lat_0 )
     long_name :  latitude
     grid_type :  Latitude/Longitude
     units :  degrees_north
     Dj : 0.25
     Di : 0.25
     Lo2 :    359.75
     La2 :    -90
     Lo1 :     0
     La1 :    90

  float lon_0 ( lon_0 )
     long_name :  longitude
     grid_type :  Latitude/Longitude
     units :  degrees_east
     Dj : 0.25
     Di : 0.25
     Lo2 :    359.75
     La2 :    -90
     Lo1 :     0
     La1 :    90

  integer forecast_time0 ( forecast_time0 )
     long_name :  Forecast offset from initial time
     units :  hours 

This grib file has two precip variables APCP_P11_L1_GLL0_acc6h and APCP_P11_L1_GLL0_acc3h. I know one way to read the data is

grbs = pygrib.open(file) for var in grbs.select(name='Total Precipitation'): print(var)

But this method will mix acc6h and acc3h teogether. I tried to read the acc6h variable with:**

grbs = pygrib.open(file) for var in grbs.select(name='APCP_P11_L1_GLL0_acc6h'): print(var)

but end up with failure. I wonder what is the correct way to do so

Thanks.

jswhit commented 4 years ago

You probably want to add the accumulation period to the select criteria. Try running 'grib_list' on the file to see what the key name is for accumulation interval.