cfdm.configuration

cfdm.configuration(atol=None, rtol=None, log_level=None)[source]

View or set any number of constants in the project-wide configuration.

The full list of global constants that are provided in a dictionary to view, and can be set in any combination, are:

These are all constants that apply throughout cfdm, except for in specific functions only if overridden by the corresponding keyword argument to that function.

The value of None, either taken by default or supplied as a value, will result in the constant in question not being changed from the current value. That is, it will have no effect.

Note that setting a constant using this function is equivalent to setting it by means of a specific function of the same name, e.g. via cfdm.atol, but in this case multiple constants can be set at once.

New in version (cfdm): 1.8.6

See also

atol, rtol, log_level

Parameters
atol: number or Constant, optional

The new value of absolute tolerance. The default is to not change the current value.

rtol: number or Constant, optional

The new value of relative tolerance. The default is to not change the current value.

log_level: str or int or Constant, optional

The new value of the minimal log severity level. This can be specified either as a string equal (ignoring case) to the named set of log levels or identifier 'DISABLE', or an integer code corresponding to each of these, namely:

  • 'DISABLE' (0);

  • 'WARNING' (1);

  • 'INFO' (2);

  • 'DETAIL' (3);

  • 'DEBUG' (-1).

Returns
Configuration

The dictionary-like object containing the names and values of the project-wide constants prior to the change, or the current names and values if no new values are specified.

Examples:

View full global configuration of constants:

>>> cfdm.configuration()
<{{repr}}Configuration: {'atol': 2.220446049250313e-16,
                 'rtol': 2.220446049250313e-16,
                 'log_level': 'WARNING'}>
>>> print(cfdm.configuration())
{'atol': 2.220446049250313e-16,
 'rtol': 2.220446049250313e-16,
 'log_level': 'WARNING'}

Make a change to one constant and see that it is reflected in the configuration:

>>> cfdm.log_level('DEBUG')
<{{repr}}Constant: 'WARNING'>
>>> print(cfdm.configuration())
{'atol': 2.220446049250313e-16,
 'rtol': 2.220446049250313e-16,
 'log_level': 'DEBUG'}

Access specific values by key querying, noting the equivalency to using its bespoke function:

>>> cfdm.configuration()['atol']
2.220446049250313e-16
>>> cfdm.configuration()['atol'] == cfdm.atol()
True

Set multiple constants simultaneously:

>>> print(cfdm.configuration(atol=5e-14, log_level='INFO'))
{'atol': 2.220446049250313e-16,
 'rtol': 2.220446049250313e-16,
 'log_level': 'DEBUG'}
>>> print(cfdm.configuration())
{'atol': 5e-14, 'rtol': 2.220446049250313e-16, 'log_level': 'INFO'}

Set a single constant without using its bespoke function:

>>> print(cfdm.configuration(rtol=1e-17))
{'atol': 5e-14, 'rtol': 2.220446049250313e-16, 'log_level': 'INFO'}
>>> cfdm.configuration()
{'atol': 5e-14, 'rtol': 1e-17, 'log_level': 'INFO'}

Use as a context manager:

>>> print(cfdm.configuration())
{'atol': 2.220446049250313e-16,
 'rtol': 2.220446049250313e-16,
 'log_level': 'WARNING'}
>>> with cfdm.configuration(atol=9, rtol=10):
...     print(cfdm.configuration())
...
{'atol': 9.0, 'rtol': 10.0, 'log_level': 'WARNING'}
>>> print(cfdm.configuration())
{'atol': 2.220446049250313e-16,
 'rtol': 2.220446049250313e-16,
 'log_level': 'WARNING'}