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

Update README Instructions for requests etc with new async client #167

Open
jbusecke opened this issue May 15, 2024 · 1 comment
Open

Update README Instructions for requests etc with new async client #167

jbusecke opened this issue May 15, 2024 · 1 comment

Comments

@jbusecke
Copy link
Collaborator

Waiting on https://github.com/jbusecke/pangeo-forge-esgf/pulls

Once that is merged, I want to update the instructions in a few places:

All of these should support passing wildcard/square bracket strings.

@jbusecke
Copy link
Collaborator Author

An example (requires installing the pangeo-forge-esgf PR branch):

from pangeo_forge_esgf.async_client import ESGFAsyncClient;import asyncio

import intake

def zstore_to_iid(zstore: str):
    # this is a bit whacky to account for the different way of storing old/new stores
    iid =  '.'.join(zstore.replace('gs://','').replace('.zarr','').replace('.','/').split('/')[-11:-1])
    if not iid.startswith('CMIP6'):
        iid =  '.'.join(zstore.replace('gs://','').replace('.zarr','').replace('.','/').split('/')[-10:])
    return iid

def search_iids(col_url:str):
    col = intake.open_esm_datastore(col_url)
    iids_all= [zstore_to_iid(z) for z in col.df['zstore'].tolist()]
    return [iid for iid in iids_all if iid in iids_requested]

async with ESGFAsyncClient() as client:
        iids_requested = await client.expand_iids(["CMIP6.*.*.*.[historical, ssp245].*.[Amon,mon].tas.*.*"])

url_dict = {
    'qc':"https://storage.googleapis.com/cmip6/cmip6-pgf-ingestion-test/catalog/catalog.json",
    'non-qc':"https://storage.googleapis.com/cmip6/cmip6-pgf-ingestion-test/catalog/catalog_noqc.json",
    'retracted':"https://storage.googleapis.com/cmip6/cmip6-pgf-ingestion-test/catalog/catalog_retracted.json"
}

iids_found = []
for catalog,url in url_dict.items():
    iids = search_iids(url)
    iids_found.extend(iids)
    print(f"Found in {catalog=}: {iids=}\n")

missing_iids = list(set(iids_requested) - set(iids_found))
print(f"\n\nStill missing {len(missing_iids)} of {len(iids_requested)}: \n{missing_iids=}")

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

No branches or pull requests

1 participant