Skip to content

Commit e99ea74

Browse files
Mathieu Scheltiennedrammockpre-commit-ci[bot]larsoner
authored
[MRG] Improve docstring format and support floats for conductivity in make_bem_model (mne-tools#12020)
Co-authored-by: Daniel McCloy <dan@mccloy.info> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
1 parent 3eaf3c1 commit e99ea74

File tree

13 files changed

+107
-84
lines changed

13 files changed

+107
-84
lines changed

doc/_includes/bem_model.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Using the watershed algorithm
1717

1818
The watershed algorithm [Segonne *et al.*,
1919
2004] is part of the FreeSurfer software.
20-
The name of the program is mri_watershed .
20+
The name of the program is ``mri_watershed``.
2121
Its use in the MNE environment is facilitated by the script
2222
:ref:`mne watershed_bem`.
2323

@@ -39,6 +39,7 @@ a file called :file:`bem/watershed/ws.mgz` which contains the brain MRI
3939
volume. Furthermore, ``mne watershed_bem`` script converts the scalp surface to
4040
fif format and saves the result to :file:`bem/{<subject>}-head.fif`.
4141

42+
.. _bem_flash_algorithm:
4243

4344
Using FLASH images
4445
~~~~~~~~~~~~~~~~~~
@@ -50,7 +51,7 @@ reconstructions but it is strongly recommended that they are collected at the
5051
same time with the MPRAGEs or at least with the same scanner. For easy
5152
co-registration, the images should have FOV, matrix, slice thickness, gap, and
5253
slice orientation as the MPRAGE data. For information on suitable pulse
53-
sequences, see :footcite:`FischlEtAl2004`.
54+
sequences, see :footcite:t:`FischlEtAl2004`.
5455

5556
Creation of the BEM meshes using this method involves the following steps:
5657

doc/_includes/forward.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ MEG/EEG and MRI coordinate systems
2727
:class:`~mne.SourceSpaces`, etc), information about the coordinate frame is
2828
encoded as a constant integer value. The meaning of those integers is
2929
determined `in the source code
30-
<https://github.com/mne-tools/mne-python/blob/main/mne/io/constants.py#L186-L197>`__.
30+
<https://github.com/mne-tools/mne-python/blob/079c868240a898204bf82b2f1bf0e04cdee75da1/mne/_fiff/constants.py#L263-L275>`__.
3131

3232
The coordinate systems used in MNE software (and FreeSurfer) and their
3333
relationships are depicted in :ref:`coordinate_system_figure`. Except for the

doc/_includes/ssp.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ the brain, it is necessary to apply the projection to the forward solution in
8080
the course of inverse computations.
8181

8282
For more information on SSP, please consult the references listed in
83-
:footcite:`TescheEtAl1995,UusitaloIlmoniemi1997`.
83+
:footcite:t:`TescheEtAl1995,UusitaloIlmoniemi1997`.
8484

8585
Estimation of the noise subspace
8686
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

mne/bem.py

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@
8686

8787

8888
class ConductorModel(dict):
89-
"""BEM or sphere model."""
89+
"""BEM or sphere model.
90+
91+
See :func:`~mne.make_bem_model` and :func:`~mne.make_bem_solution` to create a
92+
:class:`mne.bem.ConductorModel`.
93+
"""
9094

9195
def __repr__(self): # noqa: D105
9296
if self["is_sphere"]:
@@ -646,30 +650,32 @@ def make_bem_model(
646650
):
647651
"""Create a BEM model for a subject.
648652
653+
Use :func:`~mne.make_bem_solution` to turn the returned surfaces into a
654+
:class:`~mne.bem.ConductorModel` suitable for forward calculation.
655+
649656
.. note:: To get a single layer bem corresponding to the --homog flag in
650657
the command line tool set the ``conductivity`` parameter
651-
to a list/tuple with a single value (e.g. [0.3]).
658+
to a float (e.g. ``0.3``).
652659
653660
Parameters
654661
----------
655-
subject : str
656-
The subject.
662+
%(subject)s
657663
ico : int | None
658664
The surface ico downsampling to use, e.g. ``5=20484``, ``4=5120``,
659665
``3=1280``. If None, no subsampling is applied.
660-
conductivity : array of int, shape (3,) or (1,)
666+
conductivity : float | array of float of shape (3,) or (1,)
661667
The conductivities to use for each shell. Should be a single element
662668
for a one-layer model, or three elements for a three-layer model.
663669
Defaults to ``[0.3, 0.006, 0.3]``. The MNE-C default for a
664-
single-layer model would be ``[0.3]``.
670+
single-layer model is ``[0.3]``.
665671
%(subjects_dir)s
666672
%(verbose)s
667673
668674
Returns
669675
-------
670676
surfaces : list of dict
671-
The BEM surfaces. Use `make_bem_solution` to turn these into a
672-
`~mne.bem.ConductorModel` suitable for forward calculation.
677+
The BEM surfaces. Use :func:`~mne.make_bem_solution` to turn these into a
678+
:class:`~mne.bem.ConductorModel` suitable for forward calculation.
673679
674680
See Also
675681
--------
@@ -682,9 +688,11 @@ def make_bem_model(
682688
-----
683689
.. versionadded:: 0.10.0
684690
"""
685-
conductivity = np.array(conductivity, float)
691+
conductivity = np.atleast_1d(conductivity).astype(float)
686692
if conductivity.ndim != 1 or conductivity.size not in (1, 3):
687-
raise ValueError("conductivity must be 1D array-like with 1 or 3 " "elements")
693+
raise ValueError(
694+
"conductivity must be a float or a 1D array-like with 1 or 3 elements"
695+
)
688696
subjects_dir = get_subjects_dir(subjects_dir, raise_error=True)
689697
subject_dir = subjects_dir / subject
690698
bem_dir = subject_dir / "bem"
@@ -851,7 +859,8 @@ def make_sphere_model(
851859
center will be calculated from the digitization points in info.
852860
head_radius : float | str | None
853861
If float, compute spherical shells for EEG using the given radius.
854-
If 'auto', estimate an appropriate radius from the dig points in Info,
862+
If ``'auto'``, estimate an appropriate radius from the dig points in the
863+
:class:`~mne.Info` provided by the argument ``info``.
855864
If None, exclude shells (single layer sphere model).
856865
%(info)s Only needed if ``r0`` or ``head_radius`` are ``'auto'``.
857866
relative_radii : array-like
@@ -1200,6 +1209,8 @@ def make_watershed_bem(
12001209
):
12011210
"""Create BEM surfaces using the FreeSurfer watershed algorithm.
12021211
1212+
See :ref:`bem_watershed_algorithm` for additional information.
1213+
12031214
Parameters
12041215
----------
12051216
subject : str
@@ -1209,9 +1220,9 @@ def make_watershed_bem(
12091220
volume : str
12101221
Defaults to T1.
12111222
atlas : bool
1212-
Specify the --atlas option for mri_watershed.
1223+
Specify the ``--atlas option`` for ``mri_watershed``.
12131224
gcaatlas : bool
1214-
Specify the --brain_atlas option for mri_watershed.
1225+
Specify the ``--brain_atlas`` option for ``mri_watershed``.
12151226
preflood : int
12161227
Change the preflood height.
12171228
show : bool
@@ -1425,7 +1436,7 @@ def read_bem_surfaces(
14251436
patch_stats : bool, optional (default False)
14261437
Calculate and add cortical patch statistics to the surfaces.
14271438
s_id : int | None
1428-
If int, only read and return the surface with the given s_id.
1439+
If int, only read and return the surface with the given ``s_id``.
14291440
An error will be raised if it doesn't exist. If None, all
14301441
surfaces are read and returned.
14311442
%(on_defects)s
@@ -1436,7 +1447,7 @@ def read_bem_surfaces(
14361447
Returns
14371448
-------
14381449
surf: list | dict
1439-
A list of dictionaries that each contain a surface. If s_id
1450+
A list of dictionaries that each contain a surface. If ``s_id``
14401451
is not None, only the requested surface will be returned.
14411452
14421453
See Also
@@ -1964,8 +1975,7 @@ def convert_flash_mris(
19641975
19651976
Parameters
19661977
----------
1967-
subject : str
1968-
Subject name.
1978+
%(subject)s
19691979
flash30 : bool | list of SpatialImage or path-like | SpatialImage | path-like
19701980
If False do not use 30-degree flip angle data.
19711981
The list of flash 5 echos to use. If True it will look for files
@@ -2084,10 +2094,11 @@ def make_flash_bem(
20842094
):
20852095
"""Create 3-Layer BEM model from prepared flash MRI images.
20862096
2097+
See :ref:`bem_flash_algorithm` for additional information.
2098+
20872099
Parameters
20882100
----------
2089-
subject : str
2090-
Subject name.
2101+
%(subject)s
20912102
overwrite : bool
20922103
Write over existing .surf files in bem folder.
20932104
show : bool

mne/cov.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -980,8 +980,8 @@ def compute_covariance(
980980
Returns
981981
-------
982982
cov : instance of Covariance | list
983-
The computed covariance. If method equals 'auto' or is a list of str
984-
and return_estimators equals True, a list of covariance estimators is
983+
The computed covariance. If method equals ``'auto'`` or is a list of str
984+
and ``return_estimators=True``, a list of covariance estimators is
985985
returned (sorted by log-likelihood, from high to low, i.e. from best
986986
to worst).
987987
@@ -1009,16 +1009,14 @@ def compute_covariance(
10091009
.. versionadded:: 0.16
10101010
* ``'ledoit_wolf'``
10111011
The Ledoit-Wolf estimator, which uses an
1012-
empirical formula for the optimal shrinkage value
1013-
:footcite:`LedoitWolf2004`.
1012+
empirical formula for the optimal shrinkage value :footcite:`LedoitWolf2004`.
10141013
* ``'oas'``
10151014
The OAS estimator :footcite:`ChenEtAl2010`, which uses a different
10161015
empricial formula for the optimal shrinkage value.
10171016
10181017
.. versionadded:: 0.16
10191018
* ``'shrunk'``
1020-
Like 'ledoit_wolf', but with cross-validation
1021-
for optimal alpha.
1019+
Like 'ledoit_wolf', but with cross-validation for optimal alpha.
10221020
* ``'pca'``
10231021
Probabilistic PCA with low rank :footcite:`TippingBishop1999`.
10241022
* ``'factor_analysis'``
@@ -1040,7 +1038,7 @@ def compute_covariance(
10401038
The ``method`` parameter allows to regularize the covariance in an
10411039
automated way. It also allows to select between different alternative
10421040
estimation algorithms which themselves achieve regularization.
1043-
Details are described in :footcite:`EngemannGramfort2015`.
1041+
Details are described in :footcite:t:`EngemannGramfort2015`.
10441042
10451043
For more information on the advanced estimation methods, see
10461044
:ref:`the sklearn manual <sklearn:covariance>`.

mne/forward/_make_forward.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -626,13 +626,15 @@ def make_forward_solution(
626626
src : path-like | instance of SourceSpaces
627627
Either a path to a source space file or a loaded or generated
628628
:class:`~mne.SourceSpaces`.
629-
bem : path-like | dict
629+
bem : path-like | ConductorModel
630630
Filename of the BEM (e.g., ``"sample-5120-5120-5120-bem-sol.fif"``) to
631-
use, or a loaded sphere model (dict).
631+
use, or a loaded :class:`~mne.bem.ConductorModel`. See
632+
:func:`~mne.make_bem_model` and :func:`~mne.make_bem_solution` to create a
633+
:class:`mne.bem.ConductorModel`.
632634
meg : bool
633-
If True (Default), include MEG computations.
635+
If True (default), include MEG computations.
634636
eeg : bool
635-
If True (Default), include EEG computations.
637+
If True (default), include EEG computations.
636638
mindist : float
637639
Minimum distance of sources from inner skull surface (in mm).
638640
ignore_ref : bool

mne/minimum_norm/inverse.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,15 +1896,17 @@ def make_inverse_operator(
18961896
%(info_not_none)s
18971897
Specifies the channels to include. Bad channels (in ``info['bads']``)
18981898
are not used.
1899-
forward : dict
1900-
Forward operator.
1899+
forward : instance of Forward
1900+
Forward operator. See :func:`~mne.make_forward_solution` to create the operator.
19011901
noise_cov : instance of Covariance
1902-
The noise covariance matrix.
1902+
The noise covariance matrix. See :func:`~mne.compute_raw_covariance` and
1903+
:func:`~mne.compute_covariance` to compute the noise covariance matrix on
1904+
:class:`~mne.io.Raw` and :class:`~mne.Epochs` respectively.
19031905
%(loose)s
19041906
%(depth)s
19051907
fixed : bool | 'auto'
19061908
Use fixed source orientations normal to the cortical mantle. If True,
1907-
the loose parameter must be "auto" or 0. If 'auto', the loose value
1909+
the loose parameter must be ``"auto"`` or ``0``. If ``'auto'``, the loose value
19081910
is used.
19091911
%(rank_none)s
19101912
%(use_cps)s
@@ -1951,7 +1953,7 @@ def make_inverse_operator(
19511953
and without this information.
19521954
19531955
For depth weighting, 0.8 is generally good for MEG, and between 2 and 5
1954-
is good for EEG, see :footcite:`LinEtAl2006a`.
1956+
is good for EEG, see :footcite:t:`LinEtAl2006a`.
19551957
19561958
References
19571959
----------

0 commit comments

Comments
 (0)