Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRG] Improve docstring format and support floats for conductivity in make_bem_model #12020

Merged
merged 40 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
c728bd7
start changing coreg GUI to support inst directly
mscheltienne Sep 27, 2023
99670f6
fix style
mscheltienne Sep 27, 2023
bedf004
support conductivity as float
mscheltienne Sep 27, 2023
bb44491
better format
mscheltienne Sep 27, 2023
165c9d2
better format
mscheltienne Sep 27, 2023
b3e5eb7
better style
mscheltienne Sep 27, 2023
acf4932
fix type
mscheltienne Sep 27, 2023
238a462
better bib style
mscheltienne Sep 27, 2023
d9ab5f4
better bib style
mscheltienne Sep 27, 2023
2d01909
add r to docstring
mscheltienne Sep 27, 2023
6093719
Revert "start changing coreg GUI to support inst directly"
mscheltienne Sep 27, 2023
2959a10
use constrained_layout for plot_white
mscheltienne Sep 27, 2023
f4a8f62
fix style in covariance tutorial
mscheltienne Sep 27, 2023
66f19b6
improve citation style
mscheltienne Sep 27, 2023
fa7404f
better style
mscheltienne Sep 27, 2023
44d22ef
add ref to overview doc
mscheltienne Sep 27, 2023
3b36277
update link to something useful
mscheltienne Sep 27, 2023
1b44318
use note and code-block
mscheltienne Sep 27, 2023
9d950be
Update doc/_includes/bem_model.rst
mscheltienne Sep 27, 2023
c7dfecc
add x-ref [ci skip]
mscheltienne Sep 27, 2023
a9673ca
Merge branch 'dev' of https://github.com/mscheltienne/mne-python into…
mscheltienne Sep 27, 2023
13effea
include perma-link [ci skip]
mscheltienne Sep 27, 2023
f9462d9
add x-ref [ci skip]
mscheltienne Sep 27, 2023
5087b42
add x-ref [ci skip]
mscheltienne Sep 27, 2023
5356d09
better doc [ci skip]
mscheltienne Sep 27, 2023
651b031
fix typo [ci skip]
mscheltienne Sep 27, 2023
95035ce
add argument n_jobs to setup_volume_source_space [ci skip]
mscheltienne Sep 27, 2023
495b771
rm backslashes for bibliography
mscheltienne Sep 28, 2023
e41951a
Update mne/cov.py
mscheltienne Sep 28, 2023
e6c83b3
rm unneeded r"""
mscheltienne Sep 28, 2023
42044bf
Merge branch 'main' into dev
mscheltienne Sep 28, 2023
719c952
improvements to SourceSpaces
mscheltienne Sep 28, 2023
3317fac
fix style
mscheltienne Sep 28, 2023
866d9c3
check for constrained layout
mscheltienne Sep 28, 2023
d82af6e
Merge branch 'dev' of https://github.com/mscheltienne/mne-python into…
mscheltienne Sep 28, 2023
a721bb4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 28, 2023
0ca563a
fix typo
mscheltienne Sep 28, 2023
7f31f6a
apply suggestion from larsoner [ci skip]
mscheltienne Sep 28, 2023
aae79b9
remove layout section
mscheltienne Sep 28, 2023
66ed3d2
Merge branch 'dev' of https://github.com/mscheltienne/mne-python into…
mscheltienne Sep 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions doc/_includes/bem_model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand All @@ -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/{<subject>}-head.fif`.

.. _bem_flash_algorithm:

Using FLASH images
~~~~~~~~~~~~~~~~~~
Expand All @@ -50,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:`FischlEtAl2004`.
sequences, see :footcite:t:`FischlEtAl2004`.

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

Expand Down
2 changes: 1 addition & 1 deletion doc/_includes/forward.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
<https://github.com/mne-tools/mne-python/blob/main/mne/io/constants.py#L186-L197>`__.
<https://github.com/mne-tools/mne-python/blob/079c868240a898204bf82b2f1bf0e04cdee75da1/mne/_fiff/constants.py#L263-L275>`__.

The coordinate systems used in MNE software (and FreeSurfer) and their
relationships are depicted in :ref:`coordinate_system_figure`. Except for the
Expand Down
2 changes: 1 addition & 1 deletion doc/_includes/ssp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
49 changes: 30 additions & 19 deletions mne/bem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]:
Expand Down Expand Up @@ -646,30 +650,32 @@ 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 list/tuple with a single value (e.g. [0.3]).
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.
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

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
--------
Expand All @@ -682,9 +688,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"
)
Comment on lines -685 to +695
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First code-change in this PR, supporting floats directly for conductivity instead of array of shape (1, ) for single-layer model.

subjects_dir = get_subjects_dir(subjects_dir, raise_error=True)
subject_dir = subjects_dir / subject
bem_dir = subject_dir / "bem"
Expand Down Expand Up @@ -851,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
Expand Down Expand Up @@ -1200,6 +1209,8 @@ def make_watershed_bem(
):
"""Create BEM surfaces using the FreeSurfer watershed algorithm.

See :ref:`bem_watershed_algorithm` for additional information.

Parameters
----------
subject : str
Expand All @@ -1209,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
Expand Down Expand Up @@ -1425,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
Expand All @@ -1436,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
Expand Down Expand Up @@ -1964,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
Expand Down Expand Up @@ -2084,10 +2094,11 @@ 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
Subject name.
%(subject)s
overwrite : bool
Write over existing .surf files in bem folder.
show : bool
Expand Down
12 changes: 5 additions & 7 deletions mne/cov.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=True``, a list of covariance estimators is
returned (sorted by log-likelihood, from high to low, i.e. from best
to worst).

Expand Down Expand Up @@ -1009,16 +1009,14 @@ 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
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`.
* ``'factor_analysis'``
Expand All @@ -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 <sklearn:covariance>`.
Expand Down
10 changes: 6 additions & 4 deletions mne/forward/_make_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions mne/minimum_norm/inverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1896,15 +1896,17 @@ def make_inverse_operator(
%(info_not_none)s
Specifies the channels to include. Bad channels (in ``info['bads']``)
are not used.
forward : dict
Forward operator.
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.
The noise covariance matrix. See :func:`~mne.compute_raw_covariance` and
:func:`~mne.compute_covariance` to compute the noise covariance matrix on
:class:`~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
Expand Down Expand Up @@ -1951,7 +1953,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
----------
Expand Down
Loading
Loading