#!/usr/bin/env python # coding: utf-8 # # Load CMIP6 Data with Intake ESM # # [Intake ESM](https://intake-esm.readthedocs.io/en/latest/) is an experimental new package that aims to provide a higher-level interface to searching and loading Earth System Model data archives, such as CMIP6. The packages is under very active development, and features may be unstable. Please report any issues or suggestions [on github](https://github.com/NCAR/intake-esm/issues). # In[1]: import xarray as xr xr.set_options(display_style='html') import intake get_ipython().run_line_magic('matplotlib', 'inline') # Intake ESM works by parsing an [ESM Collection Spec](https://github.com/NCAR/esm-collection-spec/) and converting it to an [intake catalog](https://intake.readthedocs.io/en/latest). The collection spec is stored in a .json file. Here we open it using intake. # In[2]: cat_url = "https://storage.googleapis.com/cmip6/pangeo-cmip6.json" col = intake.open_esm_datastore(cat_url) col # We can now use intake methods to search the collection, and, if desired, export a pandas dataframe. # In[3]: cat = col.search(experiment_id=['historical', 'ssp585'], table_id='Oyr', variable_id='o2', grid_label='gn') cat.df # Intake knows how to automatically open the datasets using xarray. Furthermore, intake esm contains special logic to concatenate and merge the individual results of our query into larger, more high-level aggregated xarray datasets. # In[4]: dset_dict = cat.to_dataset_dict(zarr_kwargs={'consolidated': True}) list(dset_dict.keys()) # In[5]: ds = dset_dict['CMIP.CCCma.CanESM5.historical.Oyr.gn'] ds # In[ ]: