Skip to content

Commit 5f7c9b9

Browse files
ruuskasdrammocklarsoner
authored
DOC: Morlet wavelet length in tfr_morlet (mne-tools#12073)
Co-authored-by: Daniel McCloy <dan@mccloy.info> Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
1 parent 92f5dd8 commit 5f7c9b9

File tree

4 files changed

+50
-23
lines changed

4 files changed

+50
-23
lines changed

doc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@
201201
"path-like": ":term:`path-like`",
202202
"array-like": ":term:`array_like <numpy:array_like>`",
203203
"Path": ":class:`python:pathlib.Path`",
204-
"bool": ":ref:`python:typebool`",
204+
"bool": ":ref:`bool <python:typebool>`",
205205
# Matplotlib
206206
"colormap": ":ref:`colormap <matplotlib:colormaps>`",
207207
"color": ":doc:`color <matplotlib:api/colors_api>`",

mne/time_frequency/multitaper.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,8 @@ def tfr_array_multitaper(
534534
535535
Notes
536536
-----
537-
%(temporal-window_tfr_notes)s
537+
%(temporal_window_tfr_intro)s
538+
%(temporal_window_tfr_multitaper_notes)s
538539
%(time_bandwidth_tfr_notes)s
539540
540541
.. versionadded:: 0.14.0

mne/time_frequency/tfr.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def morlet(sfreq, freqs, n_cycles=7.0, sigma=None, zero_mean=False):
114114
115115
Notes
116116
-----
117-
%(morlet_notes)s
117+
%(morlet_reference)s
118118
%(fwhm_morlet_notes)s
119119
120120
References
@@ -948,9 +948,9 @@ def tfr_morlet(
948948
949949
Notes
950950
-----
951-
%(morlet_notes)s
952-
%(temporal-window_tfr_notes)s
953-
%(fwhm_morlet_notes)s
951+
%(morlet_reference)s
952+
%(temporal_window_tfr_intro)s
953+
%(temporal_window_tfr_morlet_notes)s
954954
955955
See :func:`mne.time_frequency.morlet` for more information about the
956956
Morlet wavelet.
@@ -997,7 +997,7 @@ def tfr_array_morlet(
997997
Sampling frequency of the data.
998998
%(freqs_tfr)s
999999
%(n_cycles_tfr)s
1000-
zero_mean : bool | False
1000+
zero_mean : bool
10011001
If True, make sure the wavelets have a mean of zero. default False.
10021002
use_fft : bool
10031003
Use the FFT for convolutions or not. default True.
@@ -1039,8 +1039,9 @@ def tfr_array_morlet(
10391039
10401040
Notes
10411041
-----
1042-
%(morlet_notes)s
1043-
%(temporal-window_tfr_notes)s
1042+
%(morlet_reference)s
1043+
%(temporal_window_tfr_intro)s
1044+
%(temporal_window_tfr_morlet_notes)s
10441045
10451046
.. versionadded:: 0.14.0
10461047
@@ -1121,7 +1122,8 @@ def tfr_multitaper(
11211122
11221123
Notes
11231124
-----
1124-
%(temporal-window_tfr_notes)s
1125+
%(temporal_window_tfr_intro)s
1126+
%(temporal_window_tfr_multitaper_notes)s
11251127
%(time_bandwidth_tfr_notes)s
11261128
11271129
.. versionadded:: 0.9.0

mne/utils/docs.py

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,7 +1829,7 @@ def _reflow_param_docstring(docstring, has_first_line=True, width=75):
18291829
of the wavelet is determined by the ``sigma`` parameter, which gives the
18301830
standard deviation of the wavelet's Gaussian envelope (our wavelets extend to
18311831
±5 standard deviations to ensure values very close to zero at the endpoints).
1832-
Some authors (e.g., :footcite:`Cohen2019`) recommend specifying and reporting
1832+
Some authors (e.g., :footcite:t:`Cohen2019`) recommend specifying and reporting
18331833
wavelet duration in terms of the full-width half-maximum (FWHM) of the
18341834
wavelet's Gaussian envelope. The FWHM is related to ``sigma`` by the following
18351835
identity: :math:`\mathrm{FWHM} = \sigma \times 2 \sqrt{2 \ln{2}}` (or the
@@ -1852,7 +1852,7 @@ def _reflow_param_docstring(docstring, has_first_line=True, width=75):
18521852
frequency in ``freqs``. If you want different FWHM values at each frequency,
18531853
do the same computation with ``desired_fwhm`` as an array of the same shape as
18541854
``freqs``.
1855-
""" # noqa E501
1855+
"""
18561856

18571857
# %%
18581858
# G
@@ -2344,7 +2344,7 @@ def _reflow_param_docstring(docstring, has_first_line=True, width=75):
23442344
] = """
23452345
label_tc : array | list (or generator) of array, shape (n_labels[, n_orient], n_times)
23462346
Extracted time course for each label and source estimate.
2347-
""" # noqa: E501
2347+
"""
23482348

23492349
docdict[
23502350
"labels_eltc"
@@ -2668,10 +2668,9 @@ def _reflow_param_docstring(docstring, has_first_line=True, width=75):
26682668
"""
26692669

26702670
docdict[
2671-
"morlet_notes"
2671+
"morlet_reference"
26722672
] = """
2673-
The Morlet wavelets follow the formulation in
2674-
:footcite:`Tallon-BaudryEtAl1997`.
2673+
The Morlet wavelets follow the formulation in :footcite:t:`Tallon-BaudryEtAl1997`.
26752674
"""
26762675

26772676
docdict[
@@ -4178,7 +4177,7 @@ def _reflow_param_docstring(docstring, has_first_line=True, width=75):
41784177
41794178
.. versionadded:: 0.20
41804179
.. versionchanged:: 1.1 Added ``'eeglab'`` option.
4181-
""" # noqa E501
4180+
"""
41824181

41834182
docdict[
41844183
"split_naming"
@@ -4438,8 +4437,8 @@ def _reflow_param_docstring(docstring, has_first_line=True, width=75):
44384437
"""
44394438

44404439
docdict[
4441-
"temporal-window_tfr_notes"
4442-
] = r"""
4440+
"temporal_window_tfr_intro"
4441+
] = """
44434442
In spectrotemporal analysis (as with traditional fourier methods),
44444443
the temporal and spectral resolution are interrelated: longer temporal windows
44454444
allow more precise frequency estimates; shorter temporal windows "smear"
@@ -4457,18 +4456,43 @@ def _reflow_param_docstring(docstring, has_first_line=True, width=75):
44574456
smoothing increases with frequency.*
44584457
Source: `FieldTrip tutorial: Time-frequency analysis using Hanning window,
44594458
multitapers and wavelets <https://www.fieldtriptoolbox.org/tutorial/timefrequencyanalysis>`_.
4459+
""" # noqa: E501
4460+
4461+
docdict[
4462+
"temporal_window_tfr_morlet_notes"
4463+
] = r"""
4464+
In MNE-Python, the length of the Morlet wavelet is affected by the arguments
4465+
``freqs`` and ``n_cycles``, which define the frequencies of interest
4466+
and the number of cycles, respectively. For the time-frequency representation,
4467+
the length of the wavelet is defined such that both tails of
4468+
the wavelet extend five standard deviations from the midpoint of its Gaussian
4469+
envelope and that there is a sample at time zero.
4470+
4471+
The length of the wavelet is thus :math:`10\times\mathtt{sfreq}\cdot\sigma-1`,
4472+
which is equal to :math:`\frac{5}{\pi} \cdot \frac{\mathtt{n\_cycles} \cdot
4473+
\mathtt{sfreq}}{\mathtt{freqs}} - 1`, where
4474+
:math:`\sigma = \frac{\mathtt{n\_cycles}}{2\pi f}` corresponds to the standard
4475+
deviation of the wavelet's Gaussian envelope. Note that the length of the
4476+
wavelet must not exceed the length of your signal.
4477+
4478+
For more information on the Morlet wavelet, see :func:`mne.time_frequency.morlet`.
4479+
"""
44604480

4461-
In MNE-Python, the temporal window length is defined by the arguments ``freqs``
4462-
and ``n_cycles``, respectively defining the frequencies of interest and the
4463-
number of cycles: :math:`T = \frac{\mathtt{n\_cycles}}{\mathtt{freqs}}`
4481+
docdict[
4482+
"temporal_window_tfr_multitaper_notes"
4483+
] = r"""
4484+
In MNE-Python, the multitaper temporal window length is defined by the arguments
4485+
``freqs`` and ``n_cycles``, respectively defining the frequencies of interest
4486+
and the number of cycles: :math:`T = \frac{\mathtt{n\_cycles}}{\mathtt{freqs}}`
44644487
44654488
A fixed number of cycles for all frequencies will yield a temporal window which
44664489
decreases with frequency. For example, ``freqs=np.arange(1, 6, 2)`` and
44674490
``n_cycles=2`` yields ``T=array([2., 0.7, 0.4])``.
44684491
44694492
To use a temporal window with fixed length, the number of cycles has to be
44704493
defined based on the frequency. For example, ``freqs=np.arange(1, 6, 2)`` and
4471-
``n_cycles=freqs / 2`` yields ``T=array([0.5, 0.5, 0.5])``.""" # noqa: E501
4494+
``n_cycles=freqs / 2`` yields ``T=array([0.5, 0.5, 0.5])``.
4495+
"""
44724496

44734497
_theme = """\
44744498
theme : str | path-like

0 commit comments

Comments
 (0)