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

Fixed length epochs overlap #9096

Merged
merged 9 commits into from
Mar 18, 2021
4 changes: 4 additions & 0 deletions doc/changes/latest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ Current (0.23.dev0)

.. |Matteo Anelli| replace:: **Matteo Anelli**

.. |Silvia Cotroneo| replace:: **Silvia Cotroneo**

Enhancements
~~~~~~~~~~~~
- Add parameter ``overlap=0.`` to :func:`mne.epochs.make_fixed_length_epochs` to allow creating overlapping fixed length epochs (:gh:`9096` **by new contributor** |Silvia Cotroneo|_)
hoechenberger marked this conversation as resolved.
Show resolved Hide resolved

- Add :meth:`mne.Dipole.to_mni` for more convenient dipole.pos to MNI conversion (:gh:`9043` **by new contributor** |Valerii Chirkov|_)

- Update citations in maxwell.py (:gh:`9043` **by new contributor** |Valerii Chirkov|_)
Expand Down
2 changes: 2 additions & 0 deletions doc/changes/names.inc
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,5 @@
.. _Valerii Chirkov: https://github.com/vagechirkov

.. _Matteo Anelli: https://github.com/matteoanelli

.. _Silvia Cotroneo: https://github.com/sfc-neuro
10 changes: 8 additions & 2 deletions mne/epochs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3668,7 +3668,7 @@ def average_movements(epochs, head_pos=None, orig_sfreq=None, picks=None,

@verbose
def make_fixed_length_epochs(raw, duration=1., preload=False,
reject_by_annotation=True, proj=True,
reject_by_annotation=True, proj=True, overlap=0.,
verbose=None):
"""Divide continuous raw data into equal-sized consecutive epochs.

Expand All @@ -3685,6 +3685,11 @@ def make_fixed_length_epochs(raw, duration=1., preload=False,
%(proj_epochs)s

.. versionadded:: 0.22.0
overlap : float
The overlap between epochs. Must be ``0 <= overlap < duration``.
Default is 0.
hoechenberger marked this conversation as resolved.
Show resolved Hide resolved

.. versionadded:: 0.23.0
%(verbose)s

Returns
Expand All @@ -3696,7 +3701,8 @@ def make_fixed_length_epochs(raw, duration=1., preload=False,
-----
.. versionadded:: 0.20
"""
events = make_fixed_length_events(raw, 1, duration=duration)
events = make_fixed_length_events(raw, 1, duration=duration,
overlap=overlap)
delta = 1. / raw.info['sfreq']
return Epochs(raw, events, event_id=[1], tmin=0, tmax=duration - delta,
baseline=None, preload=preload,
Expand Down
12 changes: 12 additions & 0 deletions mne/tests/test_epochs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3254,6 +3254,18 @@ def test_make_fixed_length_epochs():
assert len(epochs_annot) > 10
assert len(epochs) > len(epochs_annot)

# overlaps
epochs = make_fixed_length_epochs(raw, duration=1)
assert len(epochs.events) > 10
epochs_ol = make_fixed_length_epochs(raw, duration=1, overlap=0.5)
assert len(epochs_ol.events) > 20
epochs_ol_2 = make_fixed_length_epochs(raw, duration=1, overlap=0.9)
assert len(epochs_ol_2.events) > 100
assert_array_equal(epochs_ol_2.events[:, 0],
np.unique(epochs_ol_2.events[:, 0]))
with pytest.raises(ValueError, match='overlap must be'):
make_fixed_length_epochs(raw, duration=1, overlap=1.1)


def test_epochs_huge_events(tmpdir):
"""Test epochs with event numbers that are too large."""
Expand Down