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

Read levels into separated datasets #408

Open
julienvienne opened this issue Dec 11, 2024 · 1 comment
Open

Read levels into separated datasets #408

julienvienne opened this issue Dec 11, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@julienvienne
Copy link

Is your feature request related to a problem? Please describe.

Hi,
I am currently struggling for reading a mixed parameter grib file which contains (among others) temperature parameter ('t') at 100m and 200m. I would like these to be read in separated datasets, but it seems that the cfgrib.open_datasets() method automatically merge the record into the heightAboveLevel dimension (see example below).
Is there a workaround to read all grib record independantly and create one dataset for each, letting enduser merge the datasets by himself ?

Describe the solution you'd like

  • use level filtering key to create separated datasets
  • make the squeeze=False option working for this
  • add new method or option to read all records without merging

Describe alternatives you've considered

I have tried to include the level keys for making separated datasets, but the levels are merged anyway into the same variable :

                datasets = cfgrib.open_datasets(
                    grib_file,
                    chunks={'latitude': 2000, 'longitude': 2000},
                    backend_kwargs={'indexpath': idx_path,
                                    'read_keys': ['shortName', 'typeOfLevel', 'level'],
                                    'squeeze': False,
                                    'filter_by_keys': {
                                        'typeOfLevel': 'heightAboveGround',
                                        "level": [0,2,100,200]
                                    }
                                    }
                )

Additional context

No response

Organisation

Weathernews

@julienvienne julienvienne added the enhancement New feature or request label Dec 11, 2024
@DWesl
Copy link

DWesl commented Mar 10, 2025

Does this do what you want?

[cfgrib.open_dataset(
     grib_file, backend_kwargs={"filter_by_keys": {"typeOfLevel": "heightAboveGround", "level": level}})
    for level in [0, 2, 100, 200]]

I am curious that you got it to load multiple values of a single key: when I tried doing that ("shortName", to skip warnings about other variables not being available at all levels), it didn't work for me: is that new behavior, or only present when using the filter_by_keys keyword-argument through the backend_kwargs keyword-argument, rather than passing it directly to cfgrib.open_dataset*?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants