From c728bd71f915bf98943b266950e591c23b2d9d1b Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 27 Sep 2023 15:08:35 +0200 Subject: [PATCH 01/36] start changing coreg GUI to support inst directly --- mne/gui/_coreg.py | 6 +++--- mne/gui/_gui.py | 14 ++++++-------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/mne/gui/_coreg.py b/mne/gui/_coreg.py index c44bd71dd75..eb782984ee5 100644 --- a/mne/gui/_coreg.py +++ b/mne/gui/_coreg.py @@ -88,8 +88,8 @@ class CoregistrationUI(HasTraits): Parameters ---------- - info_file : None | str - The FIFF file with digitizer data for coregistration. + inst : Raw | Epochs | Evoked | path-like | None + Instance of path to an instance file containing the digitizer data. %(subject)s %(subjects_dir)s %(fiducials)s @@ -168,7 +168,7 @@ class CoregistrationUI(HasTraits): @verbose def __init__( self, - info_file, + inst, *, subject=None, subjects_dir=None, diff --git a/mne/gui/_gui.py b/mne/gui/_gui.py index 122e2dc772c..6bc3f7a21d5 100644 --- a/mne/gui/_gui.py +++ b/mne/gui/_gui.py @@ -53,12 +53,10 @@ def coregistration( width : int | None Specify the width for window (in logical pixels). Default is None, which uses ``MNE_COREG_WINDOW_WIDTH`` config value - (which defaults to 800). - inst : None | str - Path to an instance file containing the digitizer data. Compatible for - Raw, Epochs, and Evoked files. - subject : None | str - Name of the mri subject. + (which defaults to ``800``). + inst : Raw | Epochs | Evoked | path-like | None + Instance of path to an instance file containing the digitizer data. + %(subject)s %(subjects_dir)s guess_mri_subject : bool When selecting a new head shape file, guess the subject's name based @@ -68,9 +66,9 @@ def coregistration( Default is None, which uses ``MNE_COREG_WINDOW_WIDTH`` config value (which defaults to 400). head_opacity : float | None - The opacity of the head surface in the range [0., 1.]. + The opacity of the head surface in the range ``[0., 1.]``. Default is None, which uses ``MNE_COREG_HEAD_OPACITY`` config value - (which defaults to 1.). + (which defaults to ``1.``). head_high_res : bool | None Use a high resolution head surface. Default is None, which uses ``MNE_COREG_HEAD_HIGH_RES`` config value From 99670f6eb391fbb224e9270825989f450476e503 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 27 Sep 2023 15:11:36 +0200 Subject: [PATCH 02/36] fix style --- mne/minimum_norm/inverse.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mne/minimum_norm/inverse.py b/mne/minimum_norm/inverse.py index 0af04a9d07d..082b4dbf73e 100644 --- a/mne/minimum_norm/inverse.py +++ b/mne/minimum_norm/inverse.py @@ -922,7 +922,7 @@ def apply_inverse( use_cps=True, verbose=None, ): - """Apply inverse operator to evoked data. + r"""Apply inverse operator to evoked data. Parameters ---------- @@ -933,10 +933,10 @@ def apply_inverse( lambda2 : float The regularization parameter. method : "MNE" | "dSPM" | "sLORETA" | "eLORETA" - Use minimum norm :footcite:`HamalainenIlmoniemi1994`, - dSPM (default) :footcite:`DaleEtAl2000`, - sLORETA :footcite:`Pascual-Marqui2002`, or - eLORETA :footcite:`Pascual-Marqui2011`. + Use minimum norm\ :footcite:`HamalainenIlmoniemi1994`, + dSPM (default)\ :footcite:`DaleEtAl2000`, + sLORETA\ :footcite:`Pascual-Marqui2002`, or + eLORETA\ :footcite:`Pascual-Marqui2011`. %(pick_ori)s prepared : bool If True, do not call :func:`prepare_inverse_operator`. From bedf004265666e91afc78251b75c290627efe569 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 27 Sep 2023 15:18:08 +0200 Subject: [PATCH 03/36] support conductivity as float --- mne/bem.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mne/bem.py b/mne/bem.py index aa67c7f1fbf..f2634dfb8d0 100644 --- a/mne/bem.py +++ b/mne/bem.py @@ -648,7 +648,7 @@ def make_bem_model( .. note:: To get a single layer bem corresponding to the --homog flag in the command line tool set the ``conductivity`` parameter - to a list/tuple with a single value (e.g. [0.3]). + to a float (e.g. ``0.3``). Parameters ---------- @@ -657,11 +657,11 @@ def make_bem_model( ico : int | None The surface ico downsampling to use, e.g. ``5=20484``, ``4=5120``, ``3=1280``. If None, no subsampling is applied. - conductivity : array of int, shape (3,) or (1,) + conductivity : float | array of float of shape (3,) or (1,) The conductivities to use for each shell. Should be a single element for a one-layer model, or three elements for a three-layer model. Defaults to ``[0.3, 0.006, 0.3]``. The MNE-C default for a - single-layer model would be ``[0.3]``. + single-layer model is ``[0.3]``. %(subjects_dir)s %(verbose)s @@ -682,9 +682,11 @@ def make_bem_model( ----- .. versionadded:: 0.10.0 """ - conductivity = np.array(conductivity, float) + conductivity = np.atleast_1d(conductivity).astype(float) if conductivity.ndim != 1 or conductivity.size not in (1, 3): - raise ValueError("conductivity must be 1D array-like with 1 or 3 " "elements") + raise ValueError( + "conductivity must be a float or a 1D array-like with 1 or 3 elements" + ) subjects_dir = get_subjects_dir(subjects_dir, raise_error=True) subject_dir = subjects_dir / subject bem_dir = subject_dir / "bem" From bb444913d33a16c6a22b13ed0cf2ee528e7074e7 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 27 Sep 2023 15:32:31 +0200 Subject: [PATCH 04/36] better format --- mne/source_space/_source_space.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mne/source_space/_source_space.py b/mne/source_space/_source_space.py index 3e5f2eb91f3..9d4b2afa16a 100644 --- a/mne/source_space/_source_space.py +++ b/mne/source_space/_source_space.py @@ -1662,12 +1662,12 @@ def setup_volume_source_space( subject : str | None Subject to process. If None, the path to the MRI volume must be absolute to get a volume source space. If a subject name - is provided the T1.mgz file will be found automatically. + is provided the ``T1.mgz`` file will be found automatically. Defaults to None. pos : float | dict Positions to use for sources. If float, a grid will be constructed with the spacing given by ``pos`` in mm, generating a volume source - space. If dict, pos['rr'] and pos['nn'] will be used as the source + space. If dict, ``pos['rr']`` and ``pos['nn']`` will be used as the source space locations (in meters) and normals, respectively, creating a discrete source space. @@ -1683,7 +1683,7 @@ def setup_volume_source_space( or ``aseg.mgz``, respectively, else it will stay None. sphere : ndarray, shape (4,) | ConductorModel | None Define spherical source space bounds using origin and radius given - by (ox, oy, oz, rad) in ``sphere_units``. + by ``(Ox, Oy, Oz, rad)`` in ``sphere_units``. Only used if ``bem`` and ``surface`` are both None. Can also be a spherical ConductorModel, which will use the origin and radius. None (the default) uses a head-digitization fit. From 165c9d2d7b9c81faa1b87c7ce53eb21a05cb06bb Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 27 Sep 2023 15:36:28 +0200 Subject: [PATCH 05/36] better format --- mne/source_space/_source_space.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/source_space/_source_space.py b/mne/source_space/_source_space.py index 9d4b2afa16a..3f045c69257 100644 --- a/mne/source_space/_source_space.py +++ b/mne/source_space/_source_space.py @@ -1679,7 +1679,7 @@ def setup_volume_source_space( volume source space can then be morphed onto the MRI volume using this interpolator. If pos is a dict, this cannot be None. If subject name is provided, ``pos`` is a float or ``volume_label`` - are not provided then the ``mri`` parameter will default to 'T1.mgz' + are not provided then the ``mri`` parameter will default to ``'T1.mgz'`` or ``aseg.mgz``, respectively, else it will stay None. sphere : ndarray, shape (4,) | ConductorModel | None Define spherical source space bounds using origin and radius given From b3e5eb7831c49e90eefcb7ab3ef0dc5cc1030d20 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 27 Sep 2023 15:43:07 +0200 Subject: [PATCH 06/36] better style --- mne/cov.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/mne/cov.py b/mne/cov.py index 9566b6fd487..a2c304aa9a9 100644 --- a/mne/cov.py +++ b/mne/cov.py @@ -980,8 +980,8 @@ def compute_covariance( Returns ------- cov : instance of Covariance | list - The computed covariance. If method equals 'auto' or is a list of str - and return_estimators equals True, a list of covariance estimators is + The computed covariance. If method equals ``'auto'`` or is a list of str + and ``return_estimators`` equals ``True``, a list of covariance estimators is returned (sorted by log-likelihood, from high to low, i.e. from best to worst). @@ -1009,20 +1009,18 @@ def compute_covariance( .. versionadded:: 0.16 * ``'ledoit_wolf'`` The Ledoit-Wolf estimator, which uses an - empirical formula for the optimal shrinkage value - :footcite:`LedoitWolf2004`. + empirical formula for the optimal shrinkage value\ :footcite:`LedoitWolf2004`. * ``'oas'`` - The OAS estimator :footcite:`ChenEtAl2010`, which uses a different + The OAS estimator\ :footcite:`ChenEtAl2010`, which uses a different empricial formula for the optimal shrinkage value. .. versionadded:: 0.16 * ``'shrunk'`` - Like 'ledoit_wolf', but with cross-validation - for optimal alpha. + Like 'ledoit_wolf', but with cross-validation for optimal alpha. * ``'pca'`` - Probabilistic PCA with low rank :footcite:`TippingBishop1999`. + Probabilistic PCA with low rank\ :footcite:`TippingBishop1999`. * ``'factor_analysis'`` - Factor analysis with low rank :footcite:`Barber2012`. + Factor analysis with low rank\ :footcite:`Barber2012`. ``'ledoit_wolf'`` and ``'pca'`` are similar to ``'shrunk'`` and ``'factor_analysis'``, respectively, except that they use @@ -1040,7 +1038,7 @@ def compute_covariance( The ``method`` parameter allows to regularize the covariance in an automated way. It also allows to select between different alternative estimation algorithms which themselves achieve regularization. - Details are described in :footcite:`EngemannGramfort2015`. + Details are described in :footcite:t:`EngemannGramfort2015`. For more information on the advanced estimation methods, see :ref:`the sklearn manual `. From acf4932c9b840e62ce06075f83be48a299520c62 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 27 Sep 2023 15:59:00 +0200 Subject: [PATCH 07/36] fix type --- mne/minimum_norm/inverse.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/minimum_norm/inverse.py b/mne/minimum_norm/inverse.py index 082b4dbf73e..433a3dfde7b 100644 --- a/mne/minimum_norm/inverse.py +++ b/mne/minimum_norm/inverse.py @@ -1896,7 +1896,7 @@ def make_inverse_operator( %(info_not_none)s Specifies the channels to include. Bad channels (in ``info['bads']``) are not used. - forward : dict + forward : Forward Forward operator. noise_cov : instance of Covariance The noise covariance matrix. From 238a46265a4dccd5491327ff0f5f347bff97deb7 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 27 Sep 2023 16:06:19 +0200 Subject: [PATCH 08/36] better bib style --- mne/minimum_norm/inverse.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/minimum_norm/inverse.py b/mne/minimum_norm/inverse.py index 433a3dfde7b..3b7304a8ded 100644 --- a/mne/minimum_norm/inverse.py +++ b/mne/minimum_norm/inverse.py @@ -1951,7 +1951,7 @@ def make_inverse_operator( and without this information. For depth weighting, 0.8 is generally good for MEG, and between 2 and 5 - is good for EEG, see :footcite:`LinEtAl2006a`. + is good for EEG, see :footcite:t:`LinEtAl2006a`. References ---------- From d9ab5f486b527b629db89efe483e327d6c803be4 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 27 Sep 2023 16:15:52 +0200 Subject: [PATCH 09/36] better bib style --- mne/minimum_norm/inverse.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/minimum_norm/inverse.py b/mne/minimum_norm/inverse.py index 3b7304a8ded..34aea8f2bac 100644 --- a/mne/minimum_norm/inverse.py +++ b/mne/minimum_norm/inverse.py @@ -990,7 +990,7 @@ def apply_inverse( loose-orientation inverses and ``False`` for free- and fixed-orientation inverses. See below. - The eLORETA paper :footcite:`Pascual-Marqui2011` defines how to compute + The eLORETA paper\ :footcite:`Pascual-Marqui2011` defines how to compute inverses for fixed- and free-orientation inverses. In the free orientation case, the X/Y/Z orientation triplet for each location is effectively multiplied by a From 2d01909157e5fca7a7784769abf101914f17ce86 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 27 Sep 2023 16:16:50 +0200 Subject: [PATCH 10/36] add r to docstring --- mne/cov.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/cov.py b/mne/cov.py index a2c304aa9a9..b1dc29ba2b5 100644 --- a/mne/cov.py +++ b/mne/cov.py @@ -883,7 +883,7 @@ def compute_covariance( rank=None, verbose=None, ): - """Estimate noise covariance matrix from epochs. + r"""Estimate noise covariance matrix from epochs. The noise covariance is typically estimated on pre-stimulus periods when the stimulus onset is defined from events. From 60937194fce2a39761cd12d037df263b0ce56998 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 27 Sep 2023 16:26:18 +0200 Subject: [PATCH 11/36] Revert "start changing coreg GUI to support inst directly" This reverts commit c728bd71f915bf98943b266950e591c23b2d9d1b. --- mne/gui/_coreg.py | 6 +++--- mne/gui/_gui.py | 14 ++++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/mne/gui/_coreg.py b/mne/gui/_coreg.py index eb782984ee5..c44bd71dd75 100644 --- a/mne/gui/_coreg.py +++ b/mne/gui/_coreg.py @@ -88,8 +88,8 @@ class CoregistrationUI(HasTraits): Parameters ---------- - inst : Raw | Epochs | Evoked | path-like | None - Instance of path to an instance file containing the digitizer data. + info_file : None | str + The FIFF file with digitizer data for coregistration. %(subject)s %(subjects_dir)s %(fiducials)s @@ -168,7 +168,7 @@ class CoregistrationUI(HasTraits): @verbose def __init__( self, - inst, + info_file, *, subject=None, subjects_dir=None, diff --git a/mne/gui/_gui.py b/mne/gui/_gui.py index 6bc3f7a21d5..122e2dc772c 100644 --- a/mne/gui/_gui.py +++ b/mne/gui/_gui.py @@ -53,10 +53,12 @@ def coregistration( width : int | None Specify the width for window (in logical pixels). Default is None, which uses ``MNE_COREG_WINDOW_WIDTH`` config value - (which defaults to ``800``). - inst : Raw | Epochs | Evoked | path-like | None - Instance of path to an instance file containing the digitizer data. - %(subject)s + (which defaults to 800). + inst : None | str + Path to an instance file containing the digitizer data. Compatible for + Raw, Epochs, and Evoked files. + subject : None | str + Name of the mri subject. %(subjects_dir)s guess_mri_subject : bool When selecting a new head shape file, guess the subject's name based @@ -66,9 +68,9 @@ def coregistration( Default is None, which uses ``MNE_COREG_WINDOW_WIDTH`` config value (which defaults to 400). head_opacity : float | None - The opacity of the head surface in the range ``[0., 1.]``. + The opacity of the head surface in the range [0., 1.]. Default is None, which uses ``MNE_COREG_HEAD_OPACITY`` config value - (which defaults to ``1.``). + (which defaults to 1.). head_high_res : bool | None Use a high resolution head surface. Default is None, which uses ``MNE_COREG_HEAD_HIGH_RES`` config value From 2959a10269d25b04085eb7fe383e074aedd9812c Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 27 Sep 2023 16:38:20 +0200 Subject: [PATCH 12/36] use constrained_layout for plot_white --- mne/viz/evoked.py | 7 ++++++- tutorials/forward/90_compute_covariance.py | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/mne/viz/evoked.py b/mne/viz/evoked.py index c222400f0e3..79ac856064b 100644 --- a/mne/viz/evoked.py +++ b/mne/viz/evoked.py @@ -1623,7 +1623,12 @@ def whitened_gfp(x, rank=None): _validate_type(axes, (list, tuple, np.ndarray, None), "axes") if axes is None: _, axes = plt.subplots( - n_rows, n_columns, sharex=True, sharey=False, figsize=(8.8, 2.2 * n_rows) + n_rows, + n_columns, + sharex=True, + sharey=False, + figsize=(8.8, 2.2 * n_rows), + constrained_layout=True, ) else: axes = np.array(axes) diff --git a/tutorials/forward/90_compute_covariance.py b/tutorials/forward/90_compute_covariance.py index 71052ec33f6..b53df755d29 100644 --- a/tutorials/forward/90_compute_covariance.py +++ b/tutorials/forward/90_compute_covariance.py @@ -109,7 +109,7 @@ # available. Unfortunately it is not easy to tell the effective number of # samples, hence, to choose the appropriate regularization. # In MNE-Python, regularization is done using advanced regularization methods -# described in :footcite:p:`EngemannGramfort2015`. For this the 'auto' option +# described in :footcite:t:`EngemannGramfort2015`. For this the 'auto' option # can be used. With this option cross-validation will be used to learn the # optimal regularization: From f4a8f62d912b388f03fcc31712bde6f2e7821577 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 27 Sep 2023 16:41:44 +0200 Subject: [PATCH 13/36] fix style in covariance tutorial --- tutorials/forward/90_compute_covariance.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/tutorials/forward/90_compute_covariance.py b/tutorials/forward/90_compute_covariance.py index b53df755d29..8aec5587079 100644 --- a/tutorials/forward/90_compute_covariance.py +++ b/tutorials/forward/90_compute_covariance.py @@ -109,8 +109,8 @@ # available. Unfortunately it is not easy to tell the effective number of # samples, hence, to choose the appropriate regularization. # In MNE-Python, regularization is done using advanced regularization methods -# described in :footcite:t:`EngemannGramfort2015`. For this the 'auto' option -# can be used. With this option cross-validation will be used to learn the +# described in :footcite:t:`EngemannGramfort2015`. For this the ``'auto'`` option +# can be used. With this option, cross-validation will be used to learn the # optimal regularization: noise_cov_reg = mne.compute_covariance(epochs, tmax=0.0, method="auto", rank=None) @@ -142,7 +142,7 @@ # under-regularization. # # Note that if data have been processed using signal space separation -# (SSS) :footcite:`TauluEtAl2005`, +# (SSS)\ :footcite:`TauluEtAl2005`, # gradiometers and magnetometers will be displayed jointly because both are # reconstructed from the same SSS basis vectors with the same numerical rank. # This also implies that both sensor types are not any longer statistically @@ -160,14 +160,12 @@ evoked.plot_white(noise_covs, time_unit="s") -############################################################################## +# %% # This will plot the whitened evoked for the optimal estimator and display the # :term:`GFP` for all estimators as separate lines in the related panel. - - -############################################################################## +# # Finally, let's have a look at the difference between empty room and -# event related covariance, hacking the "method" option so that their types +# event related covariance, hacking the ``"method"`` option so that their types # are shown in the legend of the plot. evoked_meg = evoked.copy().pick("meg") @@ -175,13 +173,12 @@ noise_cov_baseline["method"] = "baseline" evoked_meg.plot_white([noise_cov_baseline, noise_cov], time_unit="s") -############################################################################## +# %% # Based on the negative log-likelihood, the baseline covariance # seems more appropriate. Improper regularization can lead to overestimation of # source amplitudes, see :footcite:p:`EngemannGramfort2015` for more # information and examples. - -# %% +# # References # ---------- # From 66f19b693d09b951005b338a4f92d2e0298eda4c Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 27 Sep 2023 16:49:26 +0200 Subject: [PATCH 14/36] improve citation style --- doc/_includes/channel_interpolation.rst | 2 +- doc/_includes/ssp.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/_includes/channel_interpolation.rst b/doc/_includes/channel_interpolation.rst index da2ae1dc12f..6c57e24c9d3 100644 --- a/doc/_includes/channel_interpolation.rst +++ b/doc/_includes/channel_interpolation.rst @@ -13,7 +13,7 @@ Spherical spline interpolation (EEG) can omit the title from the include: channel-interpolation-begin-content -In short, data repair using spherical spline interpolation :footcite:`PerrinEtAl1989` consists of the following steps: +In short, data repair using spherical spline interpolation\ :footcite:`PerrinEtAl1989` consists of the following steps: * Project the good and bad electrodes onto a unit sphere * Compute a mapping matrix that maps :math:`N` good channels to :math:`M` bad channels diff --git a/doc/_includes/ssp.rst b/doc/_includes/ssp.rst index 90b46d99c33..f28c91ddd5c 100644 --- a/doc/_includes/ssp.rst +++ b/doc/_includes/ssp.rst @@ -80,7 +80,7 @@ the brain, it is necessary to apply the projection to the forward solution in the course of inverse computations. For more information on SSP, please consult the references listed in -:footcite:`TescheEtAl1995,UusitaloIlmoniemi1997`. +:footcite:t:`TescheEtAl1995,UusitaloIlmoniemi1997`. Estimation of the noise subspace ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From fa7404fd02b581a930ba8633a8ca2377aa6b3e50 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 27 Sep 2023 16:52:46 +0200 Subject: [PATCH 15/36] better style --- doc/_includes/bem_model.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/_includes/bem_model.rst b/doc/_includes/bem_model.rst index 1985d85fc31..80c4e7ec05f 100644 --- a/doc/_includes/bem_model.rst +++ b/doc/_includes/bem_model.rst @@ -17,7 +17,7 @@ Using the watershed algorithm The watershed algorithm [Segonne *et al.*, 2004] is part of the FreeSurfer software. -The name of the program is mri_watershed . +The name of the program is ``mri_watershed``. Its use in the MNE environment is facilitated by the script :ref:`mne watershed_bem`. @@ -50,7 +50,7 @@ reconstructions but it is strongly recommended that they are collected at the same time with the MPRAGEs or at least with the same scanner. For easy co-registration, the images should have FOV, matrix, slice thickness, gap, and slice orientation as the MPRAGE data. For information on suitable pulse -sequences, see :footcite:`FischlEtAl2004`. +sequences, see :footcite::t:`FischlEtAl2004`. Creation of the BEM meshes using this method involves the following steps: From 44d22ef55aa079153b8a804de8ad9112fb233583 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 27 Sep 2023 16:57:08 +0200 Subject: [PATCH 16/36] add ref to overview doc --- doc/_includes/bem_model.rst | 1 + mne/bem.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/doc/_includes/bem_model.rst b/doc/_includes/bem_model.rst index 80c4e7ec05f..e36daca5407 100644 --- a/doc/_includes/bem_model.rst +++ b/doc/_includes/bem_model.rst @@ -39,6 +39,7 @@ a file called :file:`bem/watershed/ws.mgz` which contains the brain MRI volume. Furthermore, ``mne watershed_bem`` script converts the scalp surface to fif format and saves the result to :file:`bem/{}-head.fif`. +.. _bem_flash_algorithm: Using FLASH images ~~~~~~~~~~~~~~~~~~ diff --git a/mne/bem.py b/mne/bem.py index f2634dfb8d0..fd9aa0df768 100644 --- a/mne/bem.py +++ b/mne/bem.py @@ -1202,6 +1202,8 @@ def make_watershed_bem( ): """Create BEM surfaces using the FreeSurfer watershed algorithm. + See :ref:`bem_watershed_algorithm` for additional information. + Parameters ---------- subject : str @@ -2086,6 +2088,8 @@ def make_flash_bem( ): """Create 3-Layer BEM model from prepared flash MRI images. + See :ref:`bem_flash_algorithm` for additional information. + Parameters ---------- subject : str From 3b362771b77d1e257206cfe4fa2bfe34e900f374 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 27 Sep 2023 16:59:14 +0200 Subject: [PATCH 17/36] update link to something useful --- doc/_includes/forward.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/_includes/forward.rst b/doc/_includes/forward.rst index fecee06d918..9eef0f0fe14 100644 --- a/doc/_includes/forward.rst +++ b/doc/_includes/forward.rst @@ -27,7 +27,7 @@ MEG/EEG and MRI coordinate systems :class:`~mne.SourceSpaces`, etc), information about the coordinate frame is encoded as a constant integer value. The meaning of those integers is determined `in the source code - `__. + `__. The coordinate systems used in MNE software (and FreeSurfer) and their relationships are depicted in :ref:`coordinate_system_figure`. Except for the From 1b443186dfef431e7c2495e82b54d82746f99af1 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 27 Sep 2023 17:07:14 +0200 Subject: [PATCH 18/36] use note and code-block --- tutorials/inverse/30_mne_dspm_loreta.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tutorials/inverse/30_mne_dspm_loreta.py b/tutorials/inverse/30_mne_dspm_loreta.py index d77f0f98985..90d688eafc9 100644 --- a/tutorials/inverse/30_mne_dspm_loreta.py +++ b/tutorials/inverse/30_mne_dspm_loreta.py @@ -90,13 +90,18 @@ ) del fwd -# You can write it to disk with:: -# -# >>> from mne.minimum_norm import write_inverse_operator -# >>> write_inverse_operator('sample_audvis-meg-oct-6-inv.fif', -# inverse_operator) - # %% +# .. note:: +# +# You can write the inverse operator to disk with: +# +# .. code-block:: +# +# from mne.minimum_norm import write_inverse_operator +# write_inverse_operator( +# "sample_audvis-meg-oct-6-inv.fif", inverse_operator +# ) +# # Compute inverse solution # ------------------------ # We can use this to compute the inverse solution and obtain source time From 9d950be339da860dbda6618667fb1e94fe8e5912 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 27 Sep 2023 17:27:08 +0200 Subject: [PATCH 19/36] Update doc/_includes/bem_model.rst Co-authored-by: Daniel McCloy --- doc/_includes/bem_model.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/_includes/bem_model.rst b/doc/_includes/bem_model.rst index e36daca5407..9770d36a7fe 100644 --- a/doc/_includes/bem_model.rst +++ b/doc/_includes/bem_model.rst @@ -51,7 +51,7 @@ reconstructions but it is strongly recommended that they are collected at the same time with the MPRAGEs or at least with the same scanner. For easy co-registration, the images should have FOV, matrix, slice thickness, gap, and slice orientation as the MPRAGE data. For information on suitable pulse -sequences, see :footcite::t:`FischlEtAl2004`. +sequences, see :footcite:t:`FischlEtAl2004`. Creation of the BEM meshes using this method involves the following steps: From c7dfecc8301c867c4e08d71be12ecb58779380ff Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 27 Sep 2023 17:38:29 +0200 Subject: [PATCH 20/36] add x-ref [ci skip] --- mne/bem.py | 6 +++++- mne/source_space/_source_space.py | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/mne/bem.py b/mne/bem.py index fd9aa0df768..fcfdd95ad78 100644 --- a/mne/bem.py +++ b/mne/bem.py @@ -86,7 +86,11 @@ class ConductorModel(dict): - """BEM or sphere model.""" + """BEM or sphere model. + + See :func:`~mne.make_bem_model` and :func:`~mne.make_bem_solution` to create a + :class:`mne.bem.ConductorModel`. + """ def __repr__(self): # noqa: D105 if self["is_sphere"]: diff --git a/mne/source_space/_source_space.py b/mne/source_space/_source_space.py index 3f045c69257..3e4a0e703f5 100644 --- a/mne/source_space/_source_space.py +++ b/mne/source_space/_source_space.py @@ -1690,6 +1690,8 @@ def setup_volume_source_space( bem : path-like | None | ConductorModel Define source space bounds using a BEM file (specifically the inner skull surface) or a ConductorModel for a 1-layer of 3-layers BEM. + See :func:`~mne.make_bem_model` and :func:`~mne.make_bem_solution` to create a + :class:`~mne.bem.ConductorModel`. surface : path-like | dict | None Define source space bounds using a FreeSurfer surface file. Can also be a dictionary with entries ``'rr'`` and ``'tris'``, such as From 13effead030372befddb88bbb244030cc58cbc7f Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 27 Sep 2023 17:39:32 +0200 Subject: [PATCH 21/36] include perma-link [ci skip] --- doc/_includes/forward.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/_includes/forward.rst b/doc/_includes/forward.rst index 9eef0f0fe14..f92632f8220 100644 --- a/doc/_includes/forward.rst +++ b/doc/_includes/forward.rst @@ -27,7 +27,7 @@ MEG/EEG and MRI coordinate systems :class:`~mne.SourceSpaces`, etc), information about the coordinate frame is encoded as a constant integer value. The meaning of those integers is determined `in the source code - `__. + `__. The coordinate systems used in MNE software (and FreeSurfer) and their relationships are depicted in :ref:`coordinate_system_figure`. Except for the From f9462d9720f937611594e18c4fb0685c44e75184 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 27 Sep 2023 17:49:32 +0200 Subject: [PATCH 22/36] add x-ref [ci skip] --- mne/bem.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/mne/bem.py b/mne/bem.py index fcfdd95ad78..1affb10f502 100644 --- a/mne/bem.py +++ b/mne/bem.py @@ -650,14 +650,16 @@ def make_bem_model( ): """Create a BEM model for a subject. + Use :func:`~mne.make_bem_solution` to turn the returned surfaces into a + :class:`~mne.bem.ConductorModel` suitable for forward calculation. + .. note:: To get a single layer bem corresponding to the --homog flag in the command line tool set the ``conductivity`` parameter to a float (e.g. ``0.3``). Parameters ---------- - subject : str - The subject. + %(subject)s ico : int | None The surface ico downsampling to use, e.g. ``5=20484``, ``4=5120``, ``3=1280``. If None, no subsampling is applied. @@ -672,8 +674,8 @@ def make_bem_model( Returns ------- surfaces : list of dict - The BEM surfaces. Use `make_bem_solution` to turn these into a - `~mne.bem.ConductorModel` suitable for forward calculation. + The BEM surfaces. Use :func:`~mne.make_bem_solution` to turn these into a + :class:`~mne.bem.ConductorModel` suitable for forward calculation. See Also -------- @@ -857,7 +859,8 @@ def make_sphere_model( center will be calculated from the digitization points in info. head_radius : float | str | None If float, compute spherical shells for EEG using the given radius. - If 'auto', estimate an appropriate radius from the dig points in Info, + If ``'auto'``, estimate an appropriate radius from the dig points in the + :class:`~mne.Info` provided by the argument ``info``. If None, exclude shells (single layer sphere model). %(info)s Only needed if ``r0`` or ``head_radius`` are ``'auto'``. relative_radii : array-like @@ -1217,9 +1220,9 @@ def make_watershed_bem( volume : str Defaults to T1. atlas : bool - Specify the --atlas option for mri_watershed. + Specify the ``--atlas option`` for ``mri_watershed``. gcaatlas : bool - Specify the --brain_atlas option for mri_watershed. + Specify the ``--brain_atlas`` option for ``mri_watershed``. preflood : int Change the preflood height. show : bool @@ -1433,7 +1436,7 @@ def read_bem_surfaces( patch_stats : bool, optional (default False) Calculate and add cortical patch statistics to the surfaces. s_id : int | None - If int, only read and return the surface with the given s_id. + If int, only read and return the surface with the given ``s_id``. An error will be raised if it doesn't exist. If None, all surfaces are read and returned. %(on_defects)s @@ -1444,7 +1447,7 @@ def read_bem_surfaces( Returns ------- surf: list | dict - A list of dictionaries that each contain a surface. If s_id + A list of dictionaries that each contain a surface. If ``s_id`` is not None, only the requested surface will be returned. See Also @@ -1972,8 +1975,7 @@ def convert_flash_mris( Parameters ---------- - subject : str - Subject name. + %(subject)s flash30 : bool | list of SpatialImage or path-like | SpatialImage | path-like If False do not use 30-degree flip angle data. The list of flash 5 echos to use. If True it will look for files @@ -2096,8 +2098,7 @@ def make_flash_bem( Parameters ---------- - subject : str - Subject name. + %(subject)s overwrite : bool Write over existing .surf files in bem folder. show : bool From 5087b42334bf085e23954cbc318161c95cda8264 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 27 Sep 2023 18:14:09 +0200 Subject: [PATCH 23/36] add x-ref [ci skip] --- mne/forward/_make_forward.py | 10 ++++++---- mne/minimum_norm/inverse.py | 8 +++++--- mne/utils/docs.py | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/mne/forward/_make_forward.py b/mne/forward/_make_forward.py index 491f1dc5e9c..8bd50339529 100644 --- a/mne/forward/_make_forward.py +++ b/mne/forward/_make_forward.py @@ -626,13 +626,15 @@ def make_forward_solution( src : path-like | instance of SourceSpaces Either a path to a source space file or a loaded or generated :class:`~mne.SourceSpaces`. - bem : path-like | dict + bem : path-like | ConductorModel Filename of the BEM (e.g., ``"sample-5120-5120-5120-bem-sol.fif"``) to - use, or a loaded sphere model (dict). + use, or a loaded :class:`~mne.bem.ConductorModel`. See + :func:`~mne.make_bem_model` and :func:`~mne.make_bem_solution` to create a + :class:`mne.bem.ConductorModel`. meg : bool - If True (Default), include MEG computations. + If True (default), include MEG computations. eeg : bool - If True (Default), include EEG computations. + If True (default), include EEG computations. mindist : float Minimum distance of sources from inner skull surface (in mm). ignore_ref : bool diff --git a/mne/minimum_norm/inverse.py b/mne/minimum_norm/inverse.py index 34aea8f2bac..8c29f522bcd 100644 --- a/mne/minimum_norm/inverse.py +++ b/mne/minimum_norm/inverse.py @@ -1897,14 +1897,16 @@ def make_inverse_operator( Specifies the channels to include. Bad channels (in ``info['bads']``) are not used. forward : Forward - Forward operator. + Forward operator. See :func:`~mne.make_forward_solution` to create the operator. noise_cov : instance of Covariance - The noise covariance matrix. + The noise covariance matrix. See :func:`~mne.compute_raw_covariance` and + :func:`~mne.compute_covariance` to compute the noise covariance matrix on + :classl:`~mne.io.Raw` and :class:`~mne.Epochs` respectively. %(loose)s %(depth)s fixed : bool | 'auto' Use fixed source orientations normal to the cortical mantle. If True, - the loose parameter must be "auto" or 0. If 'auto', the loose value + the loose parameter must be ``"auto"`` or ``0``. If ``'auto'``, the loose value is used. %(rank_none)s %(use_cps)s diff --git a/mne/utils/docs.py b/mne/utils/docs.py index 9367562c7a1..eef8b8f5b0e 100644 --- a/mne/utils/docs.py +++ b/mne/utils/docs.py @@ -4660,7 +4660,7 @@ def _reflow_param_docstring(docstring, has_first_line=True, width=75): docdict[ "trans" ] = f""" -trans : path-like | dict | instance of Transform | None +trans : path-like | dict | instance of Transform | ``"fsaverage"`` | None {_trans_base} If trans is None, an identity matrix is assumed. """ From 5356d09ea6a487da7e771dd6380b07199c330fc6 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 27 Sep 2023 18:28:14 +0200 Subject: [PATCH 24/36] better doc [ci skip] --- mne/source_space/_source_space.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mne/source_space/_source_space.py b/mne/source_space/_source_space.py index 3e4a0e703f5..7162412314c 100644 --- a/mne/source_space/_source_space.py +++ b/mne/source_space/_source_space.py @@ -1653,6 +1653,7 @@ def setup_volume_source_space( add_interpolator=True, sphere_units="m", single_volume=False, + *, verbose=None, ): """Set up a volume source space with grid spacing or discrete source space. @@ -1689,13 +1690,14 @@ def setup_volume_source_space( None (the default) uses a head-digitization fit. bem : path-like | None | ConductorModel Define source space bounds using a BEM file (specifically the inner - skull surface) or a ConductorModel for a 1-layer of 3-layers BEM. - See :func:`~mne.make_bem_model` and :func:`~mne.make_bem_solution` to create a - :class:`~mne.bem.ConductorModel`. + skull surface) or a :class:`~mne.bem.ConductorModel` for a 1-layer of 3-layers + BEM. See :func:`~mne.make_bem_model` and :func:`~mne.make_bem_solution` to + create a :class:`~mne.bem.ConductorModel`. If provided, ``surface`` must be + None. surface : path-like | dict | None Define source space bounds using a FreeSurfer surface file. Can also be a dictionary with entries ``'rr'`` and ``'tris'``, such as - those returned by :func:`mne.read_surface`. + those returned by :func:`mne.read_surface`. If provided, ``bem`` must be None. mindist : float Exclude points closer than this distance (mm) to the bounding surface. exclude : float @@ -1783,7 +1785,7 @@ def setup_volume_source_space( ) if bem is not None and surface is not None: - raise ValueError('Only one of "bem" and "surface" should be ' "specified") + raise ValueError("Only one of "bem" and "surface" should be specified.") if mri is None and subject is not None: if volume_label is not None: From 651b031d06cb1b38f54c8e3845c43324811e3029 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 27 Sep 2023 18:28:31 +0200 Subject: [PATCH 25/36] fix typo [ci skip] --- mne/source_space/_source_space.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/source_space/_source_space.py b/mne/source_space/_source_space.py index 7162412314c..955c602ff95 100644 --- a/mne/source_space/_source_space.py +++ b/mne/source_space/_source_space.py @@ -1785,7 +1785,7 @@ def setup_volume_source_space( ) if bem is not None and surface is not None: - raise ValueError("Only one of "bem" and "surface" should be specified.") + raise ValueError("Only one of 'bem' and 'surface' should be specified.") if mri is None and subject is not None: if volume_label is not None: From 95035ce2e058319250076dfb0bba34b34bb9c7d3 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 27 Sep 2023 18:34:08 +0200 Subject: [PATCH 26/36] add argument n_jobs to setup_volume_source_space [ci skip] --- mne/source_space/_source_space.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mne/source_space/_source_space.py b/mne/source_space/_source_space.py index 955c602ff95..9f71494cd1f 100644 --- a/mne/source_space/_source_space.py +++ b/mne/source_space/_source_space.py @@ -1653,6 +1653,7 @@ def setup_volume_source_space( add_interpolator=True, sphere_units="m", single_volume=False, + n_jobs=None, *, verbose=None, ): @@ -1729,6 +1730,7 @@ def setup_volume_source_space( when many labels are used. .. versionadded:: 0.21 + %(n_jobs)s %(verbose)s Returns @@ -1912,6 +1914,7 @@ def setup_volume_source_space( mindist, mri, volume_label, + n_jobs=n_jobs, vol_info=vol_info, single_volume=single_volume, ) From 495b771c9a3014e7c4a4f0c4476bf026ff50a57b Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Thu, 28 Sep 2023 12:43:32 +0200 Subject: [PATCH 27/36] rm backslashes for bibliography --- doc/_includes/channel_interpolation.rst | 2 +- mne/cov.py | 8 ++++---- mne/minimum_norm/inverse.py | 10 +++++----- mne/time_frequency/multitaper.py | 2 +- mne/utils/docs.py | 4 ++-- tutorials/forward/90_compute_covariance.py | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/doc/_includes/channel_interpolation.rst b/doc/_includes/channel_interpolation.rst index 6c57e24c9d3..da2ae1dc12f 100644 --- a/doc/_includes/channel_interpolation.rst +++ b/doc/_includes/channel_interpolation.rst @@ -13,7 +13,7 @@ Spherical spline interpolation (EEG) can omit the title from the include: channel-interpolation-begin-content -In short, data repair using spherical spline interpolation\ :footcite:`PerrinEtAl1989` consists of the following steps: +In short, data repair using spherical spline interpolation :footcite:`PerrinEtAl1989` consists of the following steps: * Project the good and bad electrodes onto a unit sphere * Compute a mapping matrix that maps :math:`N` good channels to :math:`M` bad channels diff --git a/mne/cov.py b/mne/cov.py index b1dc29ba2b5..18c200eeaac 100644 --- a/mne/cov.py +++ b/mne/cov.py @@ -1009,18 +1009,18 @@ def compute_covariance( .. versionadded:: 0.16 * ``'ledoit_wolf'`` The Ledoit-Wolf estimator, which uses an - empirical formula for the optimal shrinkage value\ :footcite:`LedoitWolf2004`. + empirical formula for the optimal shrinkage value :footcite:`LedoitWolf2004`. * ``'oas'`` - The OAS estimator\ :footcite:`ChenEtAl2010`, which uses a different + The OAS estimator :footcite:`ChenEtAl2010`, which uses a different empricial formula for the optimal shrinkage value. .. versionadded:: 0.16 * ``'shrunk'`` Like 'ledoit_wolf', but with cross-validation for optimal alpha. * ``'pca'`` - Probabilistic PCA with low rank\ :footcite:`TippingBishop1999`. + Probabilistic PCA with low rank :footcite:`TippingBishop1999`. * ``'factor_analysis'`` - Factor analysis with low rank\ :footcite:`Barber2012`. + Factor analysis with low rank :footcite:`Barber2012`. ``'ledoit_wolf'`` and ``'pca'`` are similar to ``'shrunk'`` and ``'factor_analysis'``, respectively, except that they use diff --git a/mne/minimum_norm/inverse.py b/mne/minimum_norm/inverse.py index 8c29f522bcd..4ca893211d3 100644 --- a/mne/minimum_norm/inverse.py +++ b/mne/minimum_norm/inverse.py @@ -933,10 +933,10 @@ def apply_inverse( lambda2 : float The regularization parameter. method : "MNE" | "dSPM" | "sLORETA" | "eLORETA" - Use minimum norm\ :footcite:`HamalainenIlmoniemi1994`, - dSPM (default)\ :footcite:`DaleEtAl2000`, - sLORETA\ :footcite:`Pascual-Marqui2002`, or - eLORETA\ :footcite:`Pascual-Marqui2011`. + Use minimum norm :footcite:`HamalainenIlmoniemi1994`, + dSPM (default) :footcite:`DaleEtAl2000`, + sLORETA :footcite:`Pascual-Marqui2002`, or + eLORETA :footcite:`Pascual-Marqui2011`. %(pick_ori)s prepared : bool If True, do not call :func:`prepare_inverse_operator`. @@ -990,7 +990,7 @@ def apply_inverse( loose-orientation inverses and ``False`` for free- and fixed-orientation inverses. See below. - The eLORETA paper\ :footcite:`Pascual-Marqui2011` defines how to compute + The eLORETA paper :footcite:`Pascual-Marqui2011` defines how to compute inverses for fixed- and free-orientation inverses. In the free orientation case, the X/Y/Z orientation triplet for each location is effectively multiplied by a diff --git a/mne/time_frequency/multitaper.py b/mne/time_frequency/multitaper.py index b5e63b62682..a3ccad28080 100644 --- a/mne/time_frequency/multitaper.py +++ b/mne/time_frequency/multitaper.py @@ -341,7 +341,7 @@ def psd_array_multitaper( r"""Compute power spectral density (PSD) using a multi-taper method. The power spectral density is computed with DPSS - tapers\ :footcite:p:`Slepian1978`. + tapers :footcite:p:`Slepian1978`. Parameters ---------- diff --git a/mne/utils/docs.py b/mne/utils/docs.py index eef8b8f5b0e..53a394022a3 100644 --- a/mne/utils/docs.py +++ b/mne/utils/docs.py @@ -2542,8 +2542,8 @@ def _reflow_param_docstring(docstring, has_first_line=True, width=75): _method_psd = r""" method : ``'welch'`` | ``'multitaper'``{} Spectral estimation method. ``'welch'`` uses Welch's - method\ :footcite:p:`Welch1967`, ``'multitaper'`` uses DPSS - tapers\ :footcite:p:`Slepian1978`.{} + method :footcite:p:`Welch1967`, ``'multitaper'`` uses DPSS + tapers :footcite:p:`Slepian1978`.{} """ docdict["method_plot_psd_auto"] = _method_psd.format( " | ``'auto'``", diff --git a/tutorials/forward/90_compute_covariance.py b/tutorials/forward/90_compute_covariance.py index 8aec5587079..20992900e73 100644 --- a/tutorials/forward/90_compute_covariance.py +++ b/tutorials/forward/90_compute_covariance.py @@ -142,7 +142,7 @@ # under-regularization. # # Note that if data have been processed using signal space separation -# (SSS)\ :footcite:`TauluEtAl2005`, +# (SSS) :footcite:`TauluEtAl2005`, # gradiometers and magnetometers will be displayed jointly because both are # reconstructed from the same SSS basis vectors with the same numerical rank. # This also implies that both sensor types are not any longer statistically From e41951af6b37aabfce5b657eb325245a368ca1c7 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Thu, 28 Sep 2023 12:45:56 +0200 Subject: [PATCH 28/36] Update mne/cov.py Co-authored-by: Daniel McCloy --- mne/cov.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/cov.py b/mne/cov.py index 18c200eeaac..1c19312df89 100644 --- a/mne/cov.py +++ b/mne/cov.py @@ -981,7 +981,7 @@ def compute_covariance( ------- cov : instance of Covariance | list The computed covariance. If method equals ``'auto'`` or is a list of str - and ``return_estimators`` equals ``True``, a list of covariance estimators is + and ``return_estimators=True``, a list of covariance estimators is returned (sorted by log-likelihood, from high to low, i.e. from best to worst). From e6c83b3af511710a49223685cba3d4c2b3ac1d50 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Thu, 28 Sep 2023 12:53:33 +0200 Subject: [PATCH 29/36] rm unneeded r""" --- mne/cov.py | 2 +- mne/minimum_norm/inverse.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mne/cov.py b/mne/cov.py index 1c19312df89..4fa6fe44e6c 100644 --- a/mne/cov.py +++ b/mne/cov.py @@ -883,7 +883,7 @@ def compute_covariance( rank=None, verbose=None, ): - r"""Estimate noise covariance matrix from epochs. + """Estimate noise covariance matrix from epochs. The noise covariance is typically estimated on pre-stimulus periods when the stimulus onset is defined from events. diff --git a/mne/minimum_norm/inverse.py b/mne/minimum_norm/inverse.py index 4ca893211d3..2c871ff671c 100644 --- a/mne/minimum_norm/inverse.py +++ b/mne/minimum_norm/inverse.py @@ -922,7 +922,7 @@ def apply_inverse( use_cps=True, verbose=None, ): - r"""Apply inverse operator to evoked data. + """Apply inverse operator to evoked data. Parameters ---------- From 719c9521f415b3ec4d23fb86b7ad00efe369f1ee Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Thu, 28 Sep 2023 13:07:25 +0200 Subject: [PATCH 30/36] improvements to SourceSpaces --- mne/source_space/_source_space.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/mne/source_space/_source_space.py b/mne/source_space/_source_space.py index 9f71494cd1f..1236bc3535e 100644 --- a/mne/source_space/_source_space.py +++ b/mne/source_space/_source_space.py @@ -119,18 +119,17 @@ class SourceSpaces(list): ---------- source_spaces : list A list of dictionaries containing the source space information. - info : dict + info : dict | None Dictionary with information about the creation of the source space - file. Has keys 'working_dir' and 'command_line'. + file. Has keys ``'working_dir'`` and ``'command_line'``. Attributes ---------- - kind : str - The kind of source space, one of - ``{'surface', 'volume', 'discrete', 'mixed'}``. + kind : ``'surface'`` | ``'volume'`` | ``'discrete'`` | ``'mixed'`` + The kind of source space. info : dict Dictionary with information about the creation of the source space - file. Has keys 'working_dir' and 'command_line'. + file. Has keys ``'working_dir'`` and ``'command_line'``. See Also -------- @@ -510,7 +509,7 @@ def save(self, fname, overwrite=False, *, verbose=None): Parameters ---------- fname : path-like - File to write. + File to write, which should end with ``-src.fif`` or ``-src.fif.gz``. %(overwrite)s %(verbose)s """ @@ -540,8 +539,8 @@ def export_volume( include_discrete : bool If True, include discrete source spaces. dest : ``'mri'`` | ``'surf'`` - If 'mri' the volume is defined in the coordinate system of the - original T1 image. If 'surf' the coordinate system of the + If ``'mri'`` the volume is defined in the coordinate system of the + original T1 image. If ``'surf'`` the coordinate system of the FreeSurfer surface is used (Surface RAS). trans : dict, str, or None Either a transformation filename (usually made using mne_analyze) @@ -559,7 +558,7 @@ def export_volume( source point. .. versionchanged:: 0.21.0 - Support for "sparse" was added. + Support for ``"sparse"`` was added. use_lut : bool If True, assigns a numeric value to each source space that corresponds to a color on the freesurfer lookup table. From 3317fac6a49f4a8d6997caf68f0e7afe4c822314 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Thu, 28 Sep 2023 13:11:24 +0200 Subject: [PATCH 31/36] fix style --- mne/viz/evoked.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/viz/evoked.py b/mne/viz/evoked.py index 79ac856064b..dff72b6bfbc 100644 --- a/mne/viz/evoked.py +++ b/mne/viz/evoked.py @@ -1635,7 +1635,7 @@ def whitened_gfp(x, rank=None): for ai, ax in enumerate(axes.flat): _validate_type(ax, plt.Axes, "axes.flat[%d]" % (ai,)) if axes.shape != want_shape: - raise ValueError(f"axes must have shape {want_shape}, got " f"{axes.shape}") + raise ValueError(f"axes must have shape {want_shape}, got {axes.shape}.") fig = axes.flat[0].figure if n_columns > 1: suptitle = ( From 866d9c36017ebdf4bc003efb0abe670dc7a4559a Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Thu, 28 Sep 2023 13:15:44 +0200 Subject: [PATCH 32/36] check for constrained layout --- mne/viz/evoked.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mne/viz/evoked.py b/mne/viz/evoked.py index dff72b6bfbc..441754053b7 100644 --- a/mne/viz/evoked.py +++ b/mne/viz/evoked.py @@ -1570,6 +1570,7 @@ def plot_evoked_white( """ from ..cov import whiten_evoked, Covariance, _ensure_cov import matplotlib.pyplot as plt + from matplotlib.layout_engine import ConstrainedLayoutEngine time_unit, times = _check_time_unit(time_unit, evoked.times) @@ -1729,12 +1730,13 @@ def whitened_gfp(x, rank=None): ) else: ax.legend(loc="upper right", prop=dict(size=10)) - params = dict( - top=[0.69, 0.82, 0.87][n_rows - 1], bottom=[0.22, 0.13, 0.09][n_rows - 1] - ) - if has_sss: - params["hspace"] = 0.49 - fig.subplots_adjust(**params) + if not isinstance(fig.get_layout_engine(), ConstrainedLayoutEngine): + params = dict( + top=[0.69, 0.82, 0.87][n_rows - 1], bottom=[0.22, 0.13, 0.09][n_rows - 1] + ) + if has_sss: + params["hspace"] = 0.49 + fig.subplots_adjust(**params) fig.canvas.draw() plt_show(show) From a721bb4d9a18c35becf91c71696c8aed4ccd3627 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 28 Sep 2023 11:18:22 +0000 Subject: [PATCH 33/36] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mne/viz/evoked.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mne/viz/evoked.py b/mne/viz/evoked.py index 441754053b7..36bdee02bc6 100644 --- a/mne/viz/evoked.py +++ b/mne/viz/evoked.py @@ -1732,7 +1732,8 @@ def whitened_gfp(x, rank=None): ax.legend(loc="upper right", prop=dict(size=10)) if not isinstance(fig.get_layout_engine(), ConstrainedLayoutEngine): params = dict( - top=[0.69, 0.82, 0.87][n_rows - 1], bottom=[0.22, 0.13, 0.09][n_rows - 1] + top=[0.69, 0.82, 0.87][n_rows - 1], + bottom=[0.22, 0.13, 0.09][n_rows - 1], ) if has_sss: params["hspace"] = 0.49 From 0ca563a16c99079ec4c92550826aa4404e61d646 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Thu, 28 Sep 2023 13:55:19 +0200 Subject: [PATCH 34/36] fix typo --- mne/minimum_norm/inverse.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/minimum_norm/inverse.py b/mne/minimum_norm/inverse.py index 2c871ff671c..c2965da29f9 100644 --- a/mne/minimum_norm/inverse.py +++ b/mne/minimum_norm/inverse.py @@ -1901,7 +1901,7 @@ def make_inverse_operator( noise_cov : instance of Covariance The noise covariance matrix. See :func:`~mne.compute_raw_covariance` and :func:`~mne.compute_covariance` to compute the noise covariance matrix on - :classl:`~mne.io.Raw` and :class:`~mne.Epochs` respectively. + :class:`~mne.io.Raw` and :class:`~mne.Epochs` respectively. %(loose)s %(depth)s fixed : bool | 'auto' From 7f31f6af223ede13aaed931b57c1f87d0a08cf52 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Thu, 28 Sep 2023 16:11:00 +0200 Subject: [PATCH 35/36] apply suggestion from larsoner [ci skip] Co-authored-by: Eric Larson --- mne/minimum_norm/inverse.py | 2 +- mne/source_space/_source_space.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/mne/minimum_norm/inverse.py b/mne/minimum_norm/inverse.py index c2965da29f9..e505b155490 100644 --- a/mne/minimum_norm/inverse.py +++ b/mne/minimum_norm/inverse.py @@ -1896,7 +1896,7 @@ def make_inverse_operator( %(info_not_none)s Specifies the channels to include. Bad channels (in ``info['bads']``) are not used. - forward : Forward + forward : instance of Forward Forward operator. See :func:`~mne.make_forward_solution` to create the operator. noise_cov : instance of Covariance The noise covariance matrix. See :func:`~mne.compute_raw_covariance` and diff --git a/mne/source_space/_source_space.py b/mne/source_space/_source_space.py index 1236bc3535e..653645a59ed 100644 --- a/mne/source_space/_source_space.py +++ b/mne/source_space/_source_space.py @@ -1652,8 +1652,8 @@ def setup_volume_source_space( add_interpolator=True, sphere_units="m", single_volume=False, - n_jobs=None, *, + n_jobs=None, verbose=None, ): """Set up a volume source space with grid spacing or discrete source space. @@ -1730,6 +1730,8 @@ def setup_volume_source_space( .. versionadded:: 0.21 %(n_jobs)s + + .. versionadded:: 1.6 %(verbose)s Returns From aae79b9fcaf7f8e4e65901a3f51d7d8ff3b0535f Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Thu, 28 Sep 2023 16:11:28 +0200 Subject: [PATCH 36/36] remove layout section --- mne/viz/evoked.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/mne/viz/evoked.py b/mne/viz/evoked.py index 36bdee02bc6..34a9d60dfe3 100644 --- a/mne/viz/evoked.py +++ b/mne/viz/evoked.py @@ -1570,7 +1570,6 @@ def plot_evoked_white( """ from ..cov import whiten_evoked, Covariance, _ensure_cov import matplotlib.pyplot as plt - from matplotlib.layout_engine import ConstrainedLayoutEngine time_unit, times = _check_time_unit(time_unit, evoked.times) @@ -1730,14 +1729,6 @@ def whitened_gfp(x, rank=None): ) else: ax.legend(loc="upper right", prop=dict(size=10)) - if not isinstance(fig.get_layout_engine(), ConstrainedLayoutEngine): - params = dict( - top=[0.69, 0.82, 0.87][n_rows - 1], - bottom=[0.22, 0.13, 0.09][n_rows - 1], - ) - if has_sss: - params["hspace"] = 0.49 - fig.subplots_adjust(**params) fig.canvas.draw() plt_show(show)