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

Explicitly request value for 'endStep' as integer #371

Closed Metamess closed 7 months ago

Metamess commented 9 months ago

Closes #370

This simple PR adds explicitly requesting an integer value from the ecCodes framework when reading the value for "endStep". This is done by leveraging the built-in support for this in the getitem of the Message class, which will attempt to partition a key formatted as key:key_type

iainrussell commented 8 months ago

Sorry for the big delay in looking at this, @Metamess, I've just been crazy busy! Thank you for your contribution. I've set the ci going now.

iainrussell commented 7 months ago

I've made some adjustments here because the suggested fix was not working by itself. Ultimately, cfgrib is always converting steps into hours (ideally it should be a shorter time increment, but that will come later). So I've ensured that we always ensure that the index knows that the units are hours rather than the encoded step units. That fixes the problem where we have a file (such as the sample file I added) where we have 0 and 60 minutes, which ecCodes returns as 0m and 1h respectively, and cfgrib does not recognise as a valid hypercube.

iainrussell commented 7 months ago

Thanks @Metamess, this was an important fix to get into cfgrib