Skip to content
New issue

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

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

Already on GitHub? # to your account

Add method to return information about catalog.keys() #461

Closed
matt-long opened this issue Mar 17, 2022 · 0 comments · Fixed by #515
Closed

Add method to return information about catalog.keys() #461

matt-long opened this issue Mar 17, 2022 · 0 comments · Fixed by #515

Comments

@matt-long
Copy link
Contributor

The keys returned by catalog.keys() point to unique datasets in an intake-esm catalog (if queries are constructed using only the catalog.groupby_attrs). I have found it useful in some circumstances to get the values of the fields used to construct the keys; rather than a parsing the key string itself, I think this merits a method and wonder whether this should be part of intake-esm.

Here's a prototype implementation of such a method.

def get_keys_info(cat):
    """return a dictionary with the values of components of the keys in an
    intake catalog

    Example:
    key_info = {
        "20C.ocn.pop.h.1": {
            "experiment": "20C",
            "component": "ocn",
            "stream": "pop.h",
            "member_id": 1,
        },
    }

    """
    # generate a list of lists with all possible values of each groupby_attr
    # this is already being done in intake-esm
    iterables = [cat.unique(columns=key)[key]['values'] for key in cat.groupby_attrs]

    # generate a dictionary of keys with the values of its attributes
    key_info = {}
    for values in product(*iterables):
        key = cat.sep.join([str(v) for v in values])
        if key in cat.keys():
            key_info[key] = {k: values[i] for i, k in enumerate(cat.groupby_attrs)}
    return key_info
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants