Skip to content

Commit

Permalink
Dan review
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrockhill committed Dec 21, 2023
1 parent 517c789 commit 1290aac
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
2 changes: 1 addition & 1 deletion doc/changes/devel/12311.newfeature.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
:class:`mne.Epochs` can now be constructed using :class:`mne.Annotations` stored in the ``raw`` object, allowing ``events=None``. By `Alex Rockhill`_.
:class:`mne.Epochs` can now be constructed using :class:`mne.Annotations` stored in the ``raw`` object, by specifying ``events=None``. By `Alex Rockhill`_.
32 changes: 13 additions & 19 deletions mne/epochs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3114,14 +3114,14 @@ class Epochs(BaseEpochs):
%(raw_epochs)s
.. note::
``Epochs`` can be constructed using only a ``raw`` object from the
``annotations`` stored in the ``raw`` object, however, the duration of
the ``annotations`` is ignored since ``Epochs`` must be the same
time length by design.
If ``raw`` contains annotations, ``Epochs`` can be constructed around
``raw.annotations.onset``, but note that the durations of the annotations
are ignored in this case.
%(events_epochs)s
.. versionchanged:: 1.7
Allow ``events=None`` to use ``raw.annotations``.
Allow ``events=None`` to use ``raw.annotations.onset`` as the source of
epoch times.
%(event_id)s
%(epochs_tmin_tmax)s
%(baseline_epochs)s
Expand Down Expand Up @@ -3271,28 +3271,22 @@ def __init__(
)
if any(raw.annotations.duration > 0):
logger.info(
"Ignoring annotation durations, only fixed "
"duration epochs are currently supported"
"Ignoring annotation durations and creating fixed-duration epochs "
"around annotation onsets."
)
if event_id is None:
event_id = event_id_tmp
# if event_id is the names of events, map to events integers
elif isinstance(event_id, (str, list, tuple)):
if isinstance(event_id, str):
event_id = [event_id]
if all([my_id in event_id_tmp for my_id in event_id]):
if isinstance(event_id, str):
event_id = [event_id]
if isinstance(event_id, (list, tuple, set)):
if set(event_id).issubset(set(event_id_tmp)):
event_id = {my_id: event_id_tmp[my_id] for my_id in event_id}
# remove any non-selected annotations
annotations.delete(
[
i
for i, desc in enumerate(raw.annotations.description)
if desc not in event_id
]
)
annotations.delete(~np.isin(raw.annotations.description, list(event_id)))
else:
raise RuntimeError(
f"event_id(s) {set(event_id).difference(set(event_id_tmp))} "
f"event_id(s) {set(event_id) -set(event_id_tmp)} "
"not found in annotations"
)

Expand Down
2 changes: 0 additions & 2 deletions mne/tests/test_epochs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1006,8 +1006,6 @@ def test_epochs_from_annotations():
)
with pytest.raises(RuntimeError, match="not found in annotations"):
Epochs(raw, event_id="foo")
with pytest.raises(RuntimeError, match="not found in annotations"):
Epochs(raw, event_id=["foo"])


def test_epochs_hash():
Expand Down

0 comments on commit 1290aac

Please sign in to comment.