Skip to content

Commit e9d93f1

Browse files
Improve config tutorial (mne-tools#14010)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent a52d4ec commit e9d93f1

3 files changed

Lines changed: 82 additions & 60 deletions

File tree

doc/changes/dev/14010.other.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add table with all available config options to :ref:`tut-configure-mne`, by `Clemens Brunner`_.

mne/utils/config.py

Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -98,67 +98,62 @@ def set_memmap_min_size(memmap_min_size):
9898
"tuple, width and height of the raw browser window (in inches)"
9999
),
100100
"MNE_BROWSER_BACKEND": (
101-
"str, the backend to use for the MNE Browse Raw window (qt or matplotlib)"
101+
'str, the backend to use for the raw browser ("qt" or "matplotlib")'
102102
),
103103
"MNE_BROWSER_OVERVIEW_MODE": (
104-
"str, the overview mode to use in the MNE Browse Raw window )"
105-
"(see mne.viz.plot_raw for valid options)"
104+
"str, the overview mode to use in the raw browser (see mne.viz.plot_raw() for "
105+
"valid options)"
106106
),
107107
"MNE_BROWSER_PRECOMPUTE": (
108-
"bool, whether to precompute raw data in the MNE Browse Raw window"
108+
"bool, whether to precompute raw data in the raw browser"
109+
),
110+
"MNE_BROWSER_THEME": (
111+
"str, the color theme (light or dark) to use for the raw browser"
109112
),
110-
"MNE_BROWSER_THEME": "str, the color theme (light or dark) to use for the browser",
111113
"MNE_BROWSER_USE_OPENGL": (
112-
"bool, whether to use OpenGL for rendering in the MNE Browse Raw window"
114+
"bool, whether to use OpenGL for rendering in the raw browser"
113115
),
114116
"MNE_CACHE_DIR": "str, path to the cache directory for parallel execution",
115117
"MNE_COREG_ADVANCED_RENDERING": (
116-
"bool, whether to use advanced OpenGL rendering in mne coreg"
118+
"bool, whether to use advanced OpenGL rendering in coreg"
117119
),
118120
"MNE_COREG_COPY_ANNOT": (
119121
"bool, whether to copy the annotation files during warping"
120122
),
121-
"MNE_COREG_FULLSCREEN": "bool, whether to use full-screen mode in mne coreg",
122-
"MNE_COREG_GUESS_MRI_SUBJECT": (
123-
"bool, whether to guess the MRI subject in mne coreg"
124-
),
125-
"MNE_COREG_HEAD_HIGH_RES": (
126-
"bool, whether to use high-res head surface in mne coreg"
127-
),
128-
"MNE_COREG_HEAD_OPACITY": ("bool, the head surface opacity to use in mne coreg"),
123+
"MNE_COREG_FULLSCREEN": "bool, whether to use full-screen mode in coreg",
124+
"MNE_COREG_GUESS_MRI_SUBJECT": "bool, whether to guess the MRI subject in coreg",
125+
"MNE_COREG_HEAD_HIGH_RES": "bool, whether to use high-res head surface in coreg",
126+
"MNE_COREG_HEAD_OPACITY": "bool, the head surface opacity to use in coreg",
129127
"MNE_COREG_HEAD_INSIDE": (
130-
"bool, whether to add an opaque inner scalp head surface to help "
131-
"occlude points behind the head in mne coreg"
132-
),
133-
"MNE_COREG_INTERACTION": (
134-
"str, interaction style in mne coreg (trackball or terrain)"
128+
"bool, whether to add an opaque inner scalp head surface to help occlude points"
129+
" behind the head in coreg"
135130
),
131+
"MNE_COREG_INTERACTION": ("str, interaction style in coreg (trackball or terrain)"),
136132
"MNE_COREG_MARK_INSIDE": (
137-
"bool, whether to mark points inside the head surface in mne coreg"
133+
"bool, whether to mark points inside the head surface in coreg"
138134
),
139135
"MNE_COREG_PREPARE_BEM": (
140-
"bool, whether to prepare the BEM solution after warping in mne coreg"
136+
"bool, whether to prepare the BEM solution after warping in coreg"
141137
),
142138
"MNE_COREG_ORIENT_TO_SURFACE": (
143-
"bool, whether to orient the digitization markers to the head surface "
144-
"in mne coreg"
139+
"bool, whether to orient the digitization markers to the head surface in coreg"
145140
),
146141
"MNE_COREG_SCALE_LABELS": (
147-
"bool, whether to scale the MRI labels during warping in mne coreg"
142+
"bool, whether to scale the MRI labels during warping in coreg"
148143
),
149144
"MNE_COREG_SCALE_BY_DISTANCE": (
150-
"bool, whether to scale the digitization markers by their distance from "
151-
"the scalp in mne coreg"
145+
"bool, whether to scale the digitization markers by their distance from the "
146+
"scalp in coreg"
152147
),
153148
"MNE_COREG_SCENE_SCALE": (
154-
"float, the scale factor of the 3D scene in mne coreg (default 0.16)"
149+
"float, the scale factor of the 3D scene in coreg (default 0.16)"
155150
),
156-
"MNE_COREG_WINDOW_HEIGHT": "int, window height for mne coreg",
157-
"MNE_COREG_WINDOW_WIDTH": "int, window width for mne coreg",
158-
"MNE_COREG_SUBJECTS_DIR": "str, path to the subjects directory for mne coreg",
151+
"MNE_COREG_WINDOW_HEIGHT": "int, window height for coreg",
152+
"MNE_COREG_WINDOW_WIDTH": "int, window width for coreg",
153+
"MNE_COREG_SUBJECTS_DIR": "str, path to the subjects directory for coreg",
159154
"MNE_CUDA_DEVICE": "int, CUDA device to use for GPU processing",
160155
"MNE_DATA": "str, default data directory",
161-
"MNE_DATASETS_BRAINSTORM_PATH": "str, path for brainstorm data",
156+
"MNE_DATASETS_BRAINSTORM_PATH": "str, path for Brainstorm data",
162157
"MNE_DATASETS_EEGBCI_PATH": "str, path for EEGBCI data",
163158
"MNE_DATASETS_EPILEPSY_ECOG_PATH": "str, path for epilepsy_ecog data",
164159
"MNE_DATASETS_HF_SEF_PATH": "str, path for HF_SEF data",
@@ -185,29 +180,28 @@ def set_memmap_min_size(memmap_min_size):
185180
"MNE_DATASETS_ERP_CORE_PATH": "str, path for erp_core data",
186181
"MNE_FORCE_SERIAL": "bool, force serial rather than parallel execution",
187182
"MNE_LOGGING_LEVEL": (
188-
"str or int, controls the level of verbosity of any function "
189-
"decorated with @verbose. See "
190-
"https://mne.tools/stable/auto_tutorials/intro/50_configure_mne.html#logging"
183+
"str or int, controls the level of verbosity of any function decorated with "
184+
"@verbose"
191185
),
192186
"MNE_MEMMAP_MIN_SIZE": (
193187
"str, threshold on the minimum size of arrays passed to the workers that "
194188
"triggers automated memory mapping, e.g., 1M or 0.5G"
195189
),
196190
"MNE_REPR_HTML": (
197-
"bool, represent some of our objects with rich HTML in a notebook environment"
191+
"bool, represent some objects with rich HTML in a notebook environment"
198192
),
199193
"MNE_SKIP_NETWORK_TESTS": (
200-
"bool, used in a test decorator (@requires_good_network) to skip "
201-
"tests that include large downloads"
194+
"bool, used in a test decorator (@requires_good_network) to skip tests that "
195+
"include large downloads"
202196
),
203197
"MNE_SKIP_TESTING_DATASET_TESTS": (
204-
"bool, used in test decorators (@requires_spm_data, "
205-
"@requires_bstraw_data) to skip tests that require specific datasets"
198+
"bool, used in test decorators (@requires_spm_data, @requires_bstraw_data) to "
199+
"skip tests that require specific datasets"
206200
),
207-
"MNE_STIM_CHANNEL": "string, the default channel name for mne.find_events",
201+
"MNE_STIM_CHANNEL": "str, the default channel name for mne.find_events()",
208202
"MNE_TQDM": (
209-
'str, either "tqdm", "tqdm.auto", or "off". Controls presence/absence '
210-
"of progress bars"
203+
'str, either "tqdm", "tqdm.auto", or "off". Controls presence/absence of '
204+
"progress bars"
211205
),
212206
"MNE_USE_CUDA": "bool, use GPU for filtering/resampling",
213207
"MNE_USE_NUMBA": (

tutorials/intro/50_configure_mne.py

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import os
2121

22+
import pandas as pd
23+
2224
import mne
2325

2426
# %%
@@ -34,12 +36,15 @@
3436
# if you want):
3537

3638
print(mne.get_config("MNE_USE_CUDA"))
37-
print(type(mne.get_config("MNE_USE_CUDA")))
3839

3940
# %%
40-
# Note that the string values read from the JSON file are not parsed in any
41-
# way, so :func:`~mne.get_config` returns a string even for true/false config
42-
# values, rather than a Python :ref:`boolean <python:typebool>`.
41+
# ``None`` is returned above if the requested key hasn't been set on your
42+
# system. In fact, :func:`~mne.get_config` never invents a default value for a
43+
# recognized key, it only reports what's actually stored in the JSON file or
44+
# the environment. Also note that the string values that are read from the
45+
# JSON file are not parsed in any way, so :func:`~mne.get_config` returns a
46+
# string even for true/false config values, rather than a Python
47+
# :ref:`boolean <python:typebool>`.
4348
# Similarly, :func:`~mne.set_config` will only set string values (or ``None``
4449
# values, to unset a variable):
4550

@@ -64,12 +69,36 @@
6469
print(mne.get_config()) # same as mne.get_config(key=None)
6570

6671
# %%
67-
# The second convenience mode will return a :class:`tuple` of all the keys that
68-
# MNE-Python recognizes and uses, regardless of whether they've been set on
69-
# your system. This is done by passing an empty string ``''`` as the ``key``:
72+
# The second convenience mode will return a :class:`dict` containing all the
73+
# keys that MNE-Python recognizes and uses, mapped to a short description of
74+
# each one, regardless of whether they've been set on your system. This is
75+
# done by passing an empty string as the ``key``:
7076

7177
print(mne.get_config(key=""))
7278

79+
# %%
80+
# Overview of all configuration keys
81+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
82+
#
83+
# Since the dictionary above can be hard to read, here it is again, sorted
84+
# alphabetically and displayed as a table (using a :class:`pandas.DataFrame`)
85+
# so you can get an overview of all the configuration keys MNE-Python
86+
# recognizes and what they're used for:
87+
88+
pd.set_option("display.max_rows", None)
89+
pd.set_option("display.max_colwidth", None)
90+
(
91+
pd.DataFrame(sorted(mne.get_config(key="").items()), columns=["Key", "Description"])
92+
.style.hide(axis="index")
93+
.set_table_attributes('class="dataframe" style="width: 100%;"')
94+
)
95+
96+
# %%
97+
# Restore the pandas defaults we changed above:
98+
99+
pd.reset_option("display.max_rows")
100+
pd.reset_option("display.max_colwidth")
101+
73102
# %%
74103
# It is possible to add config variables that are not part of the recognized
75104
# list, by passing any arbitrary key to :func:`~mne.set_config`. This will
@@ -99,7 +128,7 @@
99128
print(mne.get_config_path())
100129

101130
# %%
102-
# However it is not a good idea to directly edit files in the :file:`.mne`
131+
# However, it is not a good idea to directly edit files in the :file:`.mne`
103132
# directory; use the getting and setting functions described in :ref:`the
104133
# previous section <config-get-set>`.
105134
#
@@ -130,7 +159,7 @@
130159
# %%
131160
# Also by default, :func:`~mne.set_config` will set values in both the JSON
132161
# file and in :data:`os.environ`; to set a config variable *only* in the JSON
133-
# file use ``set_env=False``. Here we'll use :func:`print` statement to confirm
162+
# file use ``set_env=False``. Here we'll use a :func:`print` statement to confirm
134163
# that an environment variable is being created and deleted (we could have used
135164
# the Python :ref:`assert statement <assert>` instead, but it doesn't print any
136165
# output when it succeeds so it's a little less obvious):
@@ -150,13 +179,11 @@
150179
#
151180
# One important configuration variable is ``MNE_LOGGING_LEVEL``. Throughout the
152181
# module, messages are generated describing the actions MNE-Python is taking
153-
# behind-the-scenes. How you set ``MNE_LOGGING_LEVEL`` determines how many of
182+
# behind the scenes. How you set ``MNE_LOGGING_LEVEL`` determines how many of
154183
# those messages you see. The default logging level on a fresh install of
155-
# MNE-Python is ``info``:
156-
157-
print(mne.get_config("MNE_LOGGING_LEVEL"))
158-
159-
# %%
184+
# MNE-Python is ``info``.
185+
#
186+
#
160187
# The logging levels that can be set as config variables are ``debug``,
161188
# ``info``, ``warning``, ``error``, and ``critical``. Around 90% of the log
162189
# messages in MNE-Python are ``info`` messages, so for most users the choice is
@@ -169,7 +196,7 @@
169196
# :func:`mne.set_config` is used to change the logging level for the current
170197
# Python session and all future sessions. To change the logging level only for
171198
# the current Python session, you can use :func:`mne.set_log_level` instead.
172-
# The :func:`~mne.set_log_level` function takes the same five string options
199+
# This function takes the same five string options
173200
# that are used for the ``MNE_LOGGING_LEVEL`` config variable; additionally, it
174201
# can accept :class:`int` or :class:`bool` values that are equivalent to those
175202
# strings. The equivalencies are given in this table:
@@ -191,7 +218,7 @@
191218
# +----------+---------+---------+
192219
#
193220
# With many MNE-Python functions it is possible to change the logging level
194-
# temporarily for just that function call, by using the ``verbose`` parameter.
221+
# temporarily for just that function call by using the ``verbose`` parameter.
195222
# To illustrate this, we'll load some sample data with different logging levels
196223
# set. First, with log level ``warning``:
197224

0 commit comments

Comments
 (0)