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

Metadata interface #267

Open
corentincarton opened this issue Nov 30, 2023 · 3 comments
Open

Metadata interface #267

corentincarton opened this issue Nov 30, 2023 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@corentincarton
Copy link
Contributor

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

When I extract specific values from the earthkit metadata, I get a list of tuples:

>>> source.metadata("param", "units")
[('2t', 'K'), ('2t', 'K'), ('2t', 'K'), ('2t', 'K'), ('2t', 'K'), ('2t', 'K'), ('2t', 'K'), ('2t', 'K'), ('2t', 'K'), ('2t', 'K'), ('2t', 'K'), ('2t', 'K'), ('2t', 'K'), ('2t', 'K'), ('2t', 'K'), ('2t', 'K'), ('2t', 'K'), ('2t', 'K'), ('2t', 'K'), ('2t', 'K'), ('2t', 'K'), ('2t', 'K'), ('2t', 'K'), ('2t', 'K'), ('2t', 'K'), ('2t', 'K'), ('2t', 'K'), ('2t', 'K'), ('2t', 'K'), ('2t', 'K')]

Describe the solution you'd like

Shouldn't it be more natural to return a dictionary with "param" and "units" as keys and a bunch of lists as values?

Describe alternatives you've considered

No response

Additional context

No response

Organisation

No response

@corentincarton corentincarton added the enhancement New feature or request label Nov 30, 2023
@sandorkertesz
Copy link
Collaborator

Hi @corentincarton, I am not sure if it would be more natural in this case, it is highly subjective.
But it certainly could be a useful alternative output format. Maybe we could trigger it by using the as_dict kwarg?

source.metadata("param", "units", as_dict=True)

However, metadata() already has an astype kwargs to control the data type for the keys, so maybe as_dict is not the right name. Please see the documentation here:
https://earthkit-data.readthedocs.io/en/latest/_api/data/readers/grib/codes/index.html#data.readers.grib.codes.GribField.metadata

@tlmquintino What do you think?

@sandorkertesz
Copy link
Collaborator

Another aspect to consider:

On a fieldlist we can get back the dictionary metadata output in two ways:

as list of dictionaries (one per field):

[{"param": "t", "units": "K"},
 {"param": "2t", "units": "K"},
...]

or as a dictionary containing lists (one list per key):

{"param": ["t", "2t",....], 
  "units": ["K", "K",...]}

Of course this is also true for the current list based output. So we need to find an extra keyword to control this behaviour too.

@iainrussell
Copy link
Member

If it's any help, Metview has a similar notion in its grib_get function. It uses the kwarg grouping:
grouping: “field”
grouping: “key”
See the link for an example usage.

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

3 participants