ecmwf / cfgrib

A Python interface to map GRIB files to the NetCDF Common Data Model following the CF Convention using ecCodes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug in grib writing

dasarkisov opened this issue · comments

Got a grib file from grib filter with only one field - 2-m temperature. Here I open, the grib, write it right away to a test file, and then reopen to see the results. Have a look at how it does the writing:

ds = xr.open_dataset('gfs.t00z.pgrb2.0p25.f000', engine='cfgrib')
print(ds)

to_grib(ds, 'test.grb')

ds1 = xr.open_dataset('test.grb', engine='cfgrib')
print(ds1) 

Output:

# original
<xarray.Dataset>
Dimensions:            (latitude: 5, longitude: 5)
Coordinates:
    time               datetime64[ns] ...
    step               timedelta64[ns] ...
    heightAboveGround  float64 ...
  * latitude           (latitude) float64 65.0 65.25 65.5 65.75 66.0
  * longitude          (longitude) float64 50.0 50.25 50.5 50.75 51.0
    valid_time         datetime64[ns] ...
Data variables:
    t2m                (latitude, longitude) float32 ...
Attributes: ...
# written
<xarray.Dataset>
Dimensions:            (latitude: 5, longitude: 5)
Coordinates:
    time               datetime64[ns] ...
    step               timedelta64[ns] ...
    heightAboveGround  float64 ...
  * latitude           (latitude) float64 65.0 65.25 65.5 65.75 66.0
  * longitude          (longitude) float64 50.0 50.25 50.5 50.75 51.0
    valid_time         datetime64[ns] ...
Data variables:
    lftx               (latitude, longitude) float32 ...
Attributes: ...

The question: why on earth does it change the name of 2-m temperature data variable 't2m' to lifted index 'lftx'??

Another question: along with the 't2m' data variable, I need to build a side (custom) data variable (as dataarray) within the same grib file, that would mimic the 't2m' (have the same dimensions/coordinates), but have custom values. Is it possible to build such custom data variable and write it together with the original 't2m' data variable?