1+ .. _api_configuration :
2+
13Configuration
24=============
35
46This section describes the :py:class: `~esmvalcore.config ` module.
57
6- Config
7- ******
8+ CFG
9+ ***
810
9- Configuration of ESMValCore/Tool is done via the :py:class : `~esmvalcore.config.Config ` object.
10- The global configuration can be imported from the :py:mod: ` esmvalcore.config ` module as :py:data: ` ~esmvalcore.config.CFG ` :
11+ Configuration of ESMValCore/Tool is done via :py:data : `~esmvalcore.config.CFG `
12+ object :
1113
1214.. code-block :: python
1315
@@ -16,7 +18,6 @@ The global configuration can be imported from the :py:mod:`esmvalcore.config` mo
1618 Config({' auxiliary_data_dir' : PosixPath(' /home/user/auxiliary_data' ),
1719 ' compress_netcdf' : False ,
1820 ' config_developer_file' : None ,
19- ' config_file' : PosixPath(' /home/user/.esmvaltool/config-user.yml' ),
2021 ' drs' : {' CMIP5' : ' default' , ' CMIP6' : ' default' },
2122 ' exit_on_warning' : False ,
2223 ' log_level' : ' info' ,
@@ -30,9 +31,10 @@ The global configuration can be imported from the :py:mod:`esmvalcore.config` mo
3031 ' default' : ' ~/default_inputpath' },
3132 ' save_intermediary_cubes' : False )
3233
33- The parameters for the user configuration file are listed :ref:`here < user configuration file > ` .
34+ All configuration parameters are listed :ref:`here < config_options > ` .
3435
35- :py:data:`~ esmvalcore.config.CFG ` is essentially a python dictionary with a few extra functions, similar to :py:data:`matplotlib.rcParams` .
36+ :py:data:`~ esmvalcore.config.CFG ` is essentially a python dictionary with a few
37+ extra functions, similar to :py:data:`matplotlib.rcParams` .
3638This means that values can be updated like this:
3739
3840.. code- block:: python
@@ -41,8 +43,10 @@ This means that values can be updated like this:
4143 >> > CFG [' output_dir' ]
4244 PosixPath(' /home/user/esmvaltool_output' )
4345
44- Notice that :py:data:`~ esmvalcore.config.CFG ` automatically converts the path to an instance of `` pathlib.Path`` and expands the home directory.
45- All values entered into the config are validated to prevent mistakes, for example, it will warn you if you make a typo in the key:
46+ Notice that :py:data:`~ esmvalcore.config.CFG ` automatically converts the path
47+ to an instance of :class :`pathlib.Path` and expands the home directory.
48+ All values entered into the config are validated to prevent mistakes, for
49+ example, it will warn you if you make a typo in the key:
4650
4751.. code- block:: python
4852
@@ -56,43 +60,53 @@ Or, if the value entered cannot be converted to the expected type:
5660 >> > CFG [' max_parallel_tasks' ] = ' 🐜'
5761 InvalidConfigParameter: Key `max_parallel_tasks` : Could not convert ' 🐜' to int
5862
59- :py:class :`~ esmvalcore.config.Config` is also flexible, so it tries to correct the type of your input if possible:
63+ :py:data:`~ esmvalcore.config.CFG ` is also flexible, so it tries to correct the
64+ type of your input if possible:
6065
6166.. code- block:: python
6267
6368 >> > CFG [' max_parallel_tasks' ] = ' 8' # str
6469 >> > type (CFG [' max_parallel_tasks' ])
6570 int
6671
67- By default, the config is loaded from the default location (`` / home/ user/ .esmvaltool/ config- user.yml`` ).
68- If it does not exist, it falls back to the default values.
69- to load a different file :
72+ By default, the configuration is loaded from YAML files in the user' s home
73+ directory at `` ~ / .config/ esmvaltool`` .
74+ If set , this can be overwritten with the `` ESMVALTOOL_CONFIG_DIR `` environment
75+ variable.
76+ Defaults for options that are not specified explicitly are listed :ref:`here
77+ < config_options> `.
78+ To reload the current configuration object according to these rules, use:
7079
7180.. code- block:: python
7281
73- >> > CFG .load_from_file( ' ~/my-config.yml ' )
82+ >> > CFG .reload( )
7483
75- Or to reload the current config :
84+ To load the configuration object from custom directories, use :
7685
7786.. code- block:: python
7887
79- >> > CFG .reload()
88+ >> > dirs = [' my/default/config' , ' my/custom/config' ]
89+ >> > CFG .load_from_dirs(dirs)
8090
8191
8292Session
8393*******
8494
8595Recipes and diagnostics will be run in their own directories.
86- This behaviour can be controlled via the :py:data:`~ esmvalcore.config.Session` object .
87- A :py:data:`~ esmvalcore.config.Session` can be initiated from the global :py:class :`~ esmvalcore.config.Config` .
96+ This behavior can be controlled via the :py:data:`~ esmvalcore.config.Session`
97+ object .
98+ A :py:data:`~ esmvalcore.config.Session` must always be initiated from the
99+ global :py:data:`~ esmvalcore.config.CFG ` object :
88100
89101.. code- block:: python
90102
91103 >> > session = CFG .start_session(name = ' my_session' )
92104
93105A :py:data:`~ esmvalcore.config.Session` is very similar to the config.
94- It is also a dictionary, and copies all the keys from the :py:class :`~ esmvalcore.config.Config` .
95- At this moment, `` session`` is essentially a copy of :py:data:`~ esmvalcore.config.CFG ` :
106+ It is also a dictionary, and copies all the keys from the
107+ :py:data:`~ esmvalcore.config.CFG ` object .
108+ At this moment, `` session`` is essentially a copy of
109+ :py:data:`~ esmvalcore.config.CFG ` :
96110
97111.. code- block:: python
98112
@@ -102,7 +116,8 @@ At this moment, ``session`` is essentially a copy of :py:data:`~esmvalcore.confi
102116 >> > print (session == CFG ) # False
103117 False
104118
105- A :py:data:`~ esmvalcore.config.Session` also knows about the directories where the data will stored.
119+ A :py:data:`~ esmvalcore.config.Session` also knows about the directories where
120+ the data will stored.
106121The session name is used to prefix the directories.
107122
108123.. code- block:: python
@@ -118,7 +133,8 @@ The session name is used to prefix the directories.
118133 >> > session.plot_dir
119134 / home/ user/ my_output_dir/ my_session_20201203_155821/ plots
120135
121- Unlike the global configuration, of which only one can exist, multiple sessions can be initiated from :py:class :`~ esmvalcore.config.Config` .
136+ Unlike the global configuration, of which only one can exist, multiple sessions
137+ can be initiated from :py:data:`~ esmvalcore.config.CFG ` .
122138
123139
124140API reference
0 commit comments