You have a lot of control over how you want they keys of the output dictionary to appear. For demonstration purposes, consider the following search.
from intake_esgf import ESGFCatalog
cat = ESGFCatalog().search(
experiment_id="historical",
variant_label="r1i1p1f1",
frequency="mon",
source_id=["IPSL-CM6A-LR", "CanESM5"],
variable_id=["tas", "gpp"],
)Summary information for 6 results:
mip_era [CMIP6]
activity_drs [CMIP]
institution_id [CCCma, IPSL]
source_id [CanESM5, IPSL-CM6A-LR]
experiment_id [historical]
member_id [r1i1p1f1]
table_id [Amon, Lmon, ImonAnt, ImonGre]
variable_id [tas, gpp]
grid_label [gn, gr, gra, grg]
dtype: objectBy default, we will build keys out of the facet values that are different among the entries in the output dictionary. So since all the datasets are in the same activity, experiment and use the same variant and grid labels, these facets need not be in the output dictionary keys.
dsd = cat.to_dataset_dict()
print(dsd.keys())CCCma.CanESM5.Amon.tas.gn
CCCma.CanESM5.Lmon.gpp.gn
IPSL.IPSL-CM6A-LR.Amon.tas.gr
IPSL.IPSL-CM6A-LR.ImonAnt.tas.gra
IPSL.IPSL-CM6A-LR.ImonGre.tas.grg
IPSL.IPSL-CM6A-LR.Lmon.gpp.gr
Ignoring Some Facets¶
However, on inspection you will notice that the institution and table are not needed either, but because they have different values were included in the keys by default. You can specify that certain facets be ignored in the output dictionary keys.
dsd = cat.to_dataset_dict(ignore_facets=["institution_id", "table_id"])
print(dsd.keys())CanESM5.tas.gn
CanESM5.gpp.gn
IPSL-CM6A-LR.tas.gr
IPSL-CM6A-LR.tas.gra
IPSL-CM6A-LR.tas.grg
IPSL-CM6A-LR.gpp.gr
Use All Facets¶
You may decide that you do not like our attempt to provide simpler keys in which case you may use the full set of facets.
dsd = cat.to_dataset_dict(minimal_keys=False)
print(dsd.keys())CMIP6.CMIP.CCCma.CanESM5.historical.r1i1p1f1.Amon.tas.gn
CMIP6.CMIP.CCCma.CanESM5.historical.r1i1p1f1.Lmon.gpp.gn
CMIP6.CMIP.IPSL.IPSL-CM6A-LR.historical.r1i1p1f1.Amon.tas.gr
CMIP6.CMIP.IPSL.IPSL-CM6A-LR.historical.r1i1p1f1.ImonAnt.tas.gra
CMIP6.CMIP.IPSL.IPSL-CM6A-LR.historical.r1i1p1f1.ImonGre.tas.grg
CMIP6.CMIP.IPSL.IPSL-CM6A-LR.historical.r1i1p1f1.Lmon.gpp.gr
Change the Separator¶
You may also use a different separator. By default use the . symbol, but you may choose any character. This can be useful if you wish to use xarray.DataTree.
dsd = cat.to_dataset_dict(minimal_keys=False,separator="/")
print(dsd.keys())CMIP6/CMIP/CCCma/CanESM5/historical/r1i1p1f1/Amon/tas/gn
CMIP6/CMIP/CCCma/CanESM5/historical/r1i1p1f1/Lmon/gpp/gn
CMIP6/CMIP/IPSL/IPSL-CM6A-LR/historical/r1i1p1f1/Amon/tas/gr
CMIP6/CMIP/IPSL/IPSL-CM6A-LR/historical/r1i1p1f1/ImonAnt/tas/gra
CMIP6/CMIP/IPSL/IPSL-CM6A-LR/historical/r1i1p1f1/ImonGre/tas/grg
CMIP6/CMIP/IPSL/IPSL-CM6A-LR/historical/r1i1p1f1/Lmon/gpp/gr