Background information on configurations

This tutorial gives a short introduction to MNE configurations.

import os.path as op

import mne
from mne.datasets.sample import data_path

fname = op.join(data_path(), 'MEG', 'sample', 'sample_audvis_raw.fif')
raw = mne.io.read_raw_fif(fname).crop(0, 10)
original_level = mne.get_config('MNE_LOGGING_LEVEL', 'INFO')

Out:

Opening raw data file /home/ubuntu/mne_data/MNE-sample-data/MEG/sample/sample_audvis_raw.fif...
    Read a total of 3 projection items:
        PCA-v1 (1 x 102)  idle
        PCA-v2 (1 x 102)  idle
        PCA-v3 (1 x 102)  idle
    Range : 25800 ... 192599 =     42.956 ...   320.670 secs
Ready.
Current compensation grade : 0

MNE-python stores configurations to a folder called .mne in the user’s home directory, or to AppData directory on Windows. The path to the config file can be found out by calling mne.get_config_path().

Out:

/home/ubuntu/.mne/mne-python.json

These configurations include information like sample data paths and plotter window sizes. Files inside this folder should never be modified manually. Let’s see what the configurations contain.

print(mne.get_config())

Out:

{u'MNE_DATASETS_SOMATO_PATH': u'/home/ubuntu/mne_data', u'MNE_DATASETS_EEGBCI_PATH': u'/home/ubuntu/mne_data', u'MNE_DATASETS_TESTING_PATH': u'/home/ubuntu/mne_data', u'MNE_DATASETS_SAMPLE_PATH': u'/home/ubuntu/mne_data', u'MNE_DATASETS_BRAINSTORM_PATH': u'/home/ubuntu/mne_data', u'MNE_DATASETS_MEGSIM_PATH': u'/home/ubuntu/mne_data', u'MNE_DATASETS_MISC_PATH': u'/home/ubuntu/mne_data', 'SUBJECTS_DIR': u'/home/ubuntu/mne_data/MNE-sample-data/subjects', u'MNE_DATASETS_SPM_FACE_PATH': u'/home/ubuntu/mne_data', u'MNE_DATASETS_MULTIMODAL_PATH': u'/home/ubuntu/mne_data'}

We see fields like “MNE_DATASETS_SAMPLE_PATH”. As the name suggests, this is the path the sample data is downloaded to. All the fields in the configuration file can be modified by calling mne.set_config().

Logging

Configurations also include the default logging level for the functions. This field is called “MNE_LOGGING_LEVEL”.

mne.set_config('MNE_LOGGING_LEVEL', 'INFO')
print(mne.get_config(key='MNE_LOGGING_LEVEL'))

Out:

INFO

The default value is now set to INFO. This level will now be used by default every time we call a function in MNE. We can set the global logging level for only this session by calling mne.set_log_level() function.

mne.set_log_level('WARNING')
print(mne.get_config(key='MNE_LOGGING_LEVEL'))

Out:

INFO

Notice how the value in the config file was not changed. Logging level of WARNING only applies for this session. Let’s see what logging level of WARNING prints for mne.compute_raw_covariance().

Nothing. This means that no warnings were emitted during the computation. If you look at the documentation of mne.compute_raw_covariance(), you notice the verbose keyword. Setting this parameter does not touch the configurations, but sets the logging level for just this one function call. Let’s see what happens with logging level of INFO.

cov = mne.compute_raw_covariance(raw, verbose=True)

Out:

Using up to 49 segments
Number of samples used : 5880
[done]

As you see there is some info about what the function is doing. The logging level can be set to ‘DEBUG’, ‘INFO’, ‘WARNING’, ‘ERROR’ or ‘CRITICAL’. It can also be set to an integer or a boolean value. The correspondance to string values can be seen in the table below. verbose=None uses the default value from the configuration file.

String Integer Boolean
DEBUG 10  
INFO 20 True
WARNING 30 False
ERROR 40  
CRITICAL 50  
mne.set_config('MNE_LOGGING_LEVEL', original_level)

Total running time of the script: ( 0 minutes 0.529 seconds)

Generated by Sphinx-Gallery