Match coordinate names against list of vertical levels from eccodes in extract_dataset_chunk_index#552
Merged
martindurant merged 2 commits intofsspec:mainfrom Apr 19, 2025
Conversation
Contributor
Author
|
This might also address issue 546 |
Member
|
@emfdavid , any thoughts on this? I think it's OK... Do we have any datasets to hand to serve for testing? |
kerchunk/_grib_idx.py
Outdated
| in ("valid_time", "time", "step", "latitude", "longitude") | ||
| else "level" | ||
| ) | ||
| cname = "level" if cname in ECCODES_VERTICAL_LEVEL_LIST else cname |
Member
There was a problem hiding this comment.
Isn't this inversed? If cname="time", the previous code would return "time", but now it is "level".
Contributor
Author
There was a problem hiding this comment.
Isn't the suggested implementation correct? If cname=time then it is not in the list ECCODES_VERTICAL_LEVEL_LIST and consequently cname itself will be returned i.e. "time" will map to "time"
Member
There was a problem hiding this comment.
Oh, so none of the names I had were in this list. Sorry for the confusion.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The issue
The current logic for grib files in
extract_dataset_chunk_indexassumes that any coordinate that doesn't matchvalid_time,time,step,latitudeorlongitudemust correspond to a vertical level. From the current implementation :This has the unfortunate effect of overwriting level values if non-compliant coordinates are processed after the vertical level.
For instance, building a map from a gefs forecast:
yields the kerchunk index:
Note that every
levelvalue is 0!The issue stems from the
"number"coordinate being renamed to"level"inextract_dataset_chunk_indexand overwriting the level value with 0.Suggested solution
I suggest only renaming coordinate names matching the list of valid vertical coordinates used by eccodes. I couldn't find any way of accessing this through the eccodes python interface, so I just parsed https://github.com/ecmwf/eccodes/blob/develop/definitions/grib2/typeOfLevelConcept.def to a list
ECCODES_VERTICAL_LEVEL_LIST.The relevant logic in
extract_dataset_chunk_indexcan then be changed to:This does however introduce the restriction that the vertical coordinate must either correspond to an entry on the list of be "level".