chaosmagpy.config_utils.BasicConfig

class chaosmagpy.config_utils.BasicConfig(*args, **kwargs)[source]

Bases: dict

Class for creating CHAOS configuration dictionary.

Methods

context(key, value)

Use context manager to temporarily change setting.

fullreset()

Load all default values.

load(filepath)

Load configuration dictionary from file.

reset(key)

Load default values.

save(filepath)

Save configuration dictionary to a file.

context(key, value)[source]

Use context manager to temporarily change setting.

Parameters:
keystr

BasicConfig configuration key.

value

Value compatible with key.

Examples

Temporarily change the radius of Earth’s surface for a computation and then change it back to the original value.

from chaosmagpy import basicConfig

print('Before: ', basicConfig['params.r_surf'])

# change Earth's radius to 10 km
with basicConfig.context('params.r_surf', 10):
    # do something at r_surf = 10 km ...
    print('Inside: ', basicConfig['params.r_surf'])

print('After: ', basicConfig['params.r_surf'])
fullreset()[source]

Load all default values.

load(filepath)[source]

Load configuration dictionary from file.

Parameters:
filepathstr

Filepath and name to json-formatted configuration txt-file.

reset(key)[source]

Load default values.

Parameters:
keystr

Single keyword that is reset to the default.

save(filepath)[source]

Save configuration dictionary to a file.

Parameters:
filepathstr

Filepath and name of the textfile that will be saved with the configuration values.