11---
22title : " What is ESMValCore API and using it in a Jupyter notebook"
33teaching : 20
4- exercises : 30
4+ exercises : 40
55compatibility : ESMValTool, ESMValCore v2.11.0
66
77questions :
@@ -17,20 +17,35 @@ keypoints:
1717- " Use `datasets_to_recipe` helper to start making recipes"
1818---
1919
20- In this episode we will introduce the ESMValCore API in a jupyter notebook. ESMValTool acts as a
20+ In this episode we will introduce the ESMValCore API in a jupyter notebook. ESMValTool acts as a
2121wrapper and collection of recipes and diagnostics and CMORisers for observations that is built on
22- top of ESMValCore which has the core functionality. This episode is reformatted
22+ top of ESMValCore which has the core functionality.
23+ A schematic overview is depicted below.
24+ ![ image] ( ../fig/esmvaltool_architecture.png )
25+ Using the functionalities in the ESMValCore light blue box in this modular way allows users to
26+ use existing code to explore and build insights in the data and can help them build and write a
27+ recipeand diagnostic script with the previous episodes Writing your own [ recipe] ({{ page.root
28+ }}{% link _ episodes/06-preprocessor.md %}) / [ diagnostic script] ({{ page.root }}{% link
29+ _ episodes/08-diagnostics.md %})
30+
31+ This episode is reformatted
2332from material from this [ blog post] [ easy-ipcc-blog ] {: target ="_ blank"}
24- by Peter Kalverla. There's also material from the
33+ by Peter Kalverla. There's also material from the
2534[ example notebooks] [ docs-notebooks ] {: target ="_ blank"} and the
2635[ API reference documentation] [ api-reference ] {: target ="_ blank"}.
2736
2837## Start JupyterLab
2938A [ jupyter notebook] ( https://jupyter.org/ ) {: target ="_ blank"} is an interactive document where
30- you can run code. If using a HPC server they may provide a service which can start up an interactive job
31- with Jupyter running for you which is convenient for this exercise, for example,
32- [ ARE] ( https://opus.nci.org.au/spaces/Help/pages/162431120/ARE+User+Guide ) at NCI's Gadi in Australia or
33- [ Jupyterhub@DKRZ] ( https://docs.dkrz.de/doc/software%26services/jupyterhub/index.html ) .
39+ you can run code. All python code in this episode was written to be in a python sell of a
40+ Jupyter Notebook.
41+
42+ If using a HPC server they may provide a service which can start up an interactive job
43+ with Jupyter running for you. This would be convenient for this exercise where you can also
44+ access the data stored at those HPC servers, for example,
45+ - [ ARE] ( https://opus.nci.org.au/spaces/Help/pages/162431120/ARE+User+Guide )
46+ at NCI's Gadi in Australia or
47+ - [ Jupyterhub@DKRZ] ( https://docs.dkrz.de/doc/software%26services/jupyterhub/index.html ) .
48+
3449You will need to use a python environment with ESMValTool and ESMValCore installed.
3550
3651## Configuration in the notebook
@@ -61,10 +76,12 @@ This `CFG` object is from the `config` module in the ESMValCore API, for more de
6176{: .challenge}
6277
6378# # Find Datasets with facets
64- We have seen from running available recipes that ESMValTool is able to find data from facets that
65- were given in the recipe. We can use this in a Notebook, including filling out the facets for
66- data definition.
67- To do this we will use the `Dataset` object from the API . Let' s look at this example which you
79+ Facets are key names and their values which help define the dataset. They are used to find the
80+ particular dataset. See ** Adding a dataset entry** section in the [Writing your own recipe]({{
81+ page.root }}{% link _episodes/ 06 - preprocessor.md % })
82+ episode for examples.
83+ We can use this in a Notebook, including filling out the facets for data definition.
84+ To do this we will use the `Dataset` object from the API . Let' s look at this example, which you
6885can copy to a Jupyter notebook.
6986
7087```python
@@ -85,13 +102,17 @@ print(dataset)
85102> # # Pro tip: Augmented facets in the output
86103> When running a recipe there is a `_filled` recipe `yml` file in the output `/ run` folder which
87104> augments the facets.
105+ > ```
106+ > esmvaltool run examples/ recipe_python.yml
107+ > ```
88108> > # # Example recipe output folder
89109> > ```output
90- > > esmvaltool_output/ flato13ipcc_figure914_20240729_043707 / run
110+ > > esmvaltool_output/ recipe_python_20240729_043707 / run
91111> > ├── cmor_log.txt
92- > > ├── fig09- 14
93- > > ├── flato13ipcc_figure914_filled.yml
94- > > ├── flato13ipcc_figure914.yml
112+ > > ├── map
113+ > > ├── timeseries
114+ > > ├── recipe_python_filled.yml
115+ > > ├── recipe_python.yml
95116> > ├── main_log_debug.txt
96117> > ├── main_log.txt
97118> > └── resource_usage.txt
@@ -277,6 +298,15 @@ See the [documentation][recipe-section-preprocessors]{:target="_blank"} to read
277298> {: .solution}
278299{: .challenge}
279300
301+ > # # Note: Warnings
302+ > When the notebook cell runs you may get some warnings. These would be similar to what is in the
303+ > * main_log.txt* and * main_log_debug.txt* files in the output of a recipe run. The warnings can come
304+ > from any of the python libraries used to process the data. If they are just warnings the cell can
305+ > still complete and return an output
306+ > > # # Example warnings
307+ > > 
308+ > {: .solution}
309+ {: .callout}
280310
281311# # Custom code
282312We have so far solely used ESMValCore, however, you can use your own custom code and
@@ -445,7 +475,7 @@ quickplot.plot(cube)
445475> - Using variable `siconc` which is a fraction percent(0 - 100 )
446476> - Using datasets:
447477> - `dataset:' ACCESS-ESM1-5' , exp:' historical' , ensemble:' r1i1p1f1' , timerange:' 1960/2010' `
448- > - `dataset :' ACCESS-OM2 ' , exp:' omip2 ' , ensemble=' r1i1p1f1' , timerange:' 0306/0366 ' `
478+ > - `dataset :' BCC-CSM2-MR ' , exp:' piControl ' , ensemble=' r1i1p1f1' , timerange:' 1960/2010 ' `
449479> - Using observations:
450480> - `dataset:' NSIDC-G02202-sh' , tier:' 3' , version:' 4' , timerange:' 1979/2018' `
451481>
@@ -473,19 +503,19 @@ quickplot.plot(cube)
473503> > timerange = ' 1960/2010' , institute = ' *' ,
474504> > )
475505> >
476- > > om_facets ={' dataset' :' ACCESS-OM2 ' , ' exp' :' omip2 ' , ' activity' :' OMIP ' , ' timerange ' : ' 0306/0366 ' }
506+ > > pi_facets = {' dataset' :' BCC-CSM2-MR ' , ' exp' :' piControl ' , ' activity' :' CMIP ' }
477507> >
478508> > model.add_supplementary(short_name = ' areacello' , mip = ' Ofx' )
479509> >
480- > > model_om = model.copy(** om_facets )
510+ > > model_pi = model.copy(** pi_facets )
481511> > ```
482512> {: .solution}
483513> > # # Tip: Check dataset files can be found
484514> > The observational dataset used is a Tier 3 , so with some licensing restrictions.
485515> > Check files can be found for all the datasets:
486516> >
487517> > ```python
488- > > for ds in [model, model_om , obs]:
518+ > > for ds in [model, model_pi , obs]:
489519> > print (ds[' dataset' ],' : ' ,ds.files)
490520> > print (ds.supplementaries[0 ].files)
491521> > ```
@@ -512,7 +542,7 @@ quickplot.plot(cube)
512542> > )
513543> > # model_om - at index 1 to offset years
514544> >
515- > > load_data = [model, model_om , obs]
545+ > > load_data = [model, model_pi , obs]
516546> >
517547> > # function to use for both min and max ['max','min']
518548> >
@@ -526,8 +556,6 @@ quickplot.plot(cube)
526556> > cube = annual_statistics(cube, min_max)
527557> > iris.util.promote_aux_coord_to_dim_coord(cube, ' year' )
528558> > cube.convert_units(' km2' )
529- > > if i == 1 : # # om years 306/366 apply offset
530- > > cube.coord(' year' ).points = [y + 1652 for y in cube.coord(' year' ).points]
531559> > label_name = data[' dataset' ]
532560> > print (label_name, cube.shape)
533561> > quickplot.plot(cube, label = label_name)
0 commit comments