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
409 stars 77 forks source link

Incorrect writing of regular Gaussian grids as GRIB #330

Closed iainrussell closed 1 year ago

iainrussell commented 1 year ago

This was exposed when using ecCodes 2.28.0, which has stricter checking of a GRIB file's geography.

------------------------------------------------------------------------------ Captured stderr call ------------------------------------------------------------------------------
ECCODES ERROR   :  Failed to find index for latitude=87.864
ECCODES ERROR   :  Geoiterator factory: Error instantiating iterator gaussian (Problem with calculation of geographic attributes)
ECCODES ERROR   :  latitudes: Unable to create iterator
------------------------------------------------------------------------------- Captured log call --------------------------------------------------------------------------------
WARNING  cfgrib.messages:messages.py:555 Ignoring index file '/perm/cgi/dev/git/mpy/cfgrib/tests/sample-data/regular_gg_pl.grib.923a8.idx' incompatible with GRIB file
============================================================================ short test summary info =============================================================================
FAILED test_50_sample_data.py::test_canonical_dataset_to_grib[regular_gg_sfc] - gribapi.errors.GeocalculusError: Problem with calculation of geographic attributes
FAILED test_50_sample_data.py::test_canonical_dataset_to_grib[regular_gg_pl] - gribapi.errors.GeocalculusError: Problem with calculation of geographic attributes
======================================================= 2 failed, 30 passed, 84 deselected, 3 xfailed, 2 xpassed in 4.99s ========================================================

The reason behind the failure is that cfgrib is not storing and therefore not writing the first and last latitude coordinates when dealing with regular Gaussian grids. Therefore, the written GRIB file contains these values as they are set in the template, rather than as they are set in the original data.