Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cfgrib fails to write endStep and stepUnits with error failed to set key "'endStep:int' to 0" and "failed to set key 'stepUnits:int' to 1" #411

Open
jsSvensson opened this issue Jan 23, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@jsSvensson
Copy link

jsSvensson commented Jan 23, 2025

What happened?

I tried to write a cononical datasset and got the errors error failed to set key "'endStep:int' to 0" and "failed to set key 'stepUnits:int' to 1". The error seems to that eccodes does not recognize the keywords "endStep:int" and "stepUnits:int". The problem was solved when adding a line that removed ":int" from the message item this in message.py definition message_set:

def message_set(self, item: str, value: T.Any) -> None:
    arr = isinstance(value, (np.ndarray, T.Sequence)) and not isinstance(value, str)
    if arr:
        eccodes.codes_set_array(self.codes_id, item, value)
    else:
        if ":int" in item:
            newItem = item.split(":")[0]
        else: 
             newItem=item
        eccodes.codes_set(self.codes_id, newItem, value)

My suggestion is to add a similar piece of code to the next update of cfgrib.

What are the steps to reproduce the bug?

Read a canonical grib message and try to print write it out again with:

from cfgrib.xarray_to_grib import to_grib
to_grib(ds, 'test.grib') 

I used hybrid level data on regular lat-lon from ECMWF web API. To write model level data one needs to make a template for that grid in eccodes/samples-library, e.g. by change the template for regular_ll_sfc_grib2.tmpl with e.g.
grib_set -s typeOfLevel=hybrid,level=137 regular_ll_sfc_grib2.tmpl regular_ll_ml_grib2.tmpl.

Version

cfgrib v0.9.14.1. eccodes 2.38.3

Platform (OS and architecture)

Ubuntu 20.04.6 LTS

Relevant log output

Accompanying data

No response

Organisation

No response

@jsSvensson jsSvensson added the bug Something isn't working label Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant