ecmwf / earthkit-data

A format-agnostic Python interface for geospatial data
Apache License 2.0
47 stars 9 forks source link

Metadata interface #267

Open corentincarton opened 7 months ago

corentincarton commented 7 months ago

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

sandorkertesz commented 7 months ago

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?