11from intake_esgf import ESGFCatalog
2+ from intake_esgf .exceptions import NoSearchResults
23
34
45def test_search ():
5- cat = ESGFCatalog ().search (
6- activity_id = "CMIP" ,
6+ cat = ESGFCatalog (esgf1_indices = "esgf-node.llnl.gov" )
7+ print (cat )
8+ cat = ESGFCatalog (esgf1_indices = ["esgf-node.llnl.gov" ]).search (
79 experiment_id = "historical" ,
8- source_id = "CESM2 " ,
9- variable_id = ["gpp" , "areacella" , "sftlf" ],
10+ source_id = "CanESM5 " ,
11+ variable_id = ["gpp" ],
1012 variant_label = ["r1i1p1f1" ],
1113 )
12- assert len (cat .df ) == 3
14+ print (cat )
15+ ds = cat .to_dataset_dict ()
16+ assert "gpp" in ds
17+ assert "sftlf" in ds ["gpp" ]
1318
1419
15- def test_global_search ():
16- cat = ESGFCatalog (esgf1_indices = True ).search (
17- activity_id = "CMIP" ,
20+ def test_esgroot ():
21+ cat = ESGFCatalog ()
22+ cat .set_esgf_data_root (cat .local_cache )
23+ cat .search (
1824 experiment_id = "historical" ,
19- source_id = "CESM2 " ,
20- variable_id = ["gpp" , "areacella" , "sftlf" ],
25+ source_id = "CanESM5 " ,
26+ variable_id = ["gpp" ],
2127 variant_label = ["r1i1p1f1" ],
2228 )
23- assert len (cat .df ) == 3
29+ ds = cat .to_dataset_dict (add_measures = False )
30+ assert "gpp" in ds
31+ log = cat .session_log ()
32+ assert "download" not in log
33+ assert f"accessed { cat .esgf_data_root } " in cat .session_log ()
34+
35+
36+ def test_noresults ():
37+ cat = ESGFCatalog ()
38+ try :
39+ cat .search (variable_id = "does_not_exist" )
40+ except NoSearchResults :
41+ pass
2442
2543
2644def test_tracking_ids ():
@@ -32,24 +50,49 @@ def test_tracking_ids():
3250 [
3351 "hdl:21.14100/0577d84f-9954-494f-8cc8-465aa4fd910e" ,
3452 "hdl:21.14100/0972f78b-158e-4c6b-bcdf-7d0d75d7a8cd" ,
35- "hdl:21.14100/0e4dfb8f-b677-456e-abc7-71e1ebc16deb" ,
36- "hdl:21.14100/17b6c62f-455b-49bc-8674-564f7ca5ed6a" ,
37- "hdl:21.14100/1bd030c9-1761-4fca-911e-6ea2b6407bc7" ,
38- "hdl:21.14100/2844ea5a-4589-4ed4-bbb7-c13e9964a4b7" ,
3953 ]
4054 )
41- assert len (cat .df ) == 7
55+ assert len (cat .df ) == 2
4256
4357
4458def test_add_cell_measures ():
4559 # these measures are in r1i1p1f2 / piControl
4660 cat = ESGFCatalog ().search (
47- variable_id = "gpp " ,
61+ variable_id = "mrros " ,
4862 source_id = "UKESM1-0-LL" ,
4963 variant_label = "r2i1p1f2" ,
5064 frequency = "mon" ,
5165 experiment_id = "historical" ,
5266 )
53- ds = cat .to_dataset_dict ()["gpp " ]
67+ ds = cat .to_dataset_dict ()["mrros " ]
5468 assert "sftlf" in ds
5569 assert "areacella" in ds
70+
71+
72+ def test_modelgroups ():
73+ cat = ESGFCatalog ().search (
74+ experiment_id = "historical" ,
75+ source_id = ["CanESM5" , "GFDL-CM4" ],
76+ variable_id = ["tas" , "pr" ],
77+ variant_label = ["r1i1p1f1" , "r2i1p1f1" ],
78+ table_id = "day" ,
79+ )
80+ assert len (cat .model_groups ()) == 4
81+
82+
83+ def test_remove_ensemble ():
84+ cat = ESGFCatalog ().search (
85+ experiment_id = "historical" ,
86+ source_id = ["UKESM1-0-LL" ],
87+ variable_id = ["tas" ],
88+ table_id = "Amon" ,
89+ )
90+ assert len (cat .model_groups ()) > 1
91+ cat .remove_ensembles ()
92+ assert len (cat .df ) == 1
93+ assert cat .df .iloc [0 ]["member_id" ] == "r1i1p1f2"
94+
95+
96+ def test_download_dbase ():
97+ cat = ESGFCatalog ()
98+ assert len (cat .download_summary ().columns )
0 commit comments