Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions doc/changes/dev/13428.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Preserve event-to-epoch mapping when exporting EEGLAB .set files by `Scott Huberty`_
8 changes: 8 additions & 0 deletions mne/export/_eeglab.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# License: BSD-3-Clause
# Copyright the MNE-Python contributors.

from inspect import getfullargspec

import numpy as np

from ..annotations import _sync_onset
Expand Down Expand Up @@ -64,6 +66,11 @@ def _export_epochs(fname, epochs):
else:
annot = None

# https://github.com/jackz314/eeglabio/pull/18
kwargs = dict()
if "epoch_indices" in getfullargspec(eeglabio.epochs.export_set).kwonlyargs:
kwargs["epoch_indices"] = epochs.selection

eeglabio.epochs.export_set(
fname,
data=epochs.get_data(picks=ch_names),
Expand All @@ -75,6 +82,7 @@ def _export_epochs(fname, epochs):
event_id=epochs.event_id,
ch_locs=cart_coords,
annotations=annot,
**kwargs,
)


Expand Down
3 changes: 2 additions & 1 deletion mne/export/tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
_check_edfio_installed,
_record_warnings,
_resource_path,
check_version,
object_diff,
)

Expand Down Expand Up @@ -534,7 +535,7 @@ def test_export_raw_edf_does_not_fail_on_empty_header_fields(tmp_path):
raw.export(tmp_path / "test.edf", add_ch_type=True)


@pytest.mark.xfail(reason="eeglabio (usage?) bugs that should be fixed")
@pytest.mark.skipif(not check_version("eeglabio", "0.1.2"), reason="fixed by 0.1.2")
@pytest.mark.parametrize("preload", (True, False))
def test_export_epochs_eeglab(tmp_path, preload):
"""Test saving an Epochs instance to EEGLAB's set format."""
Expand Down
5 changes: 3 additions & 2 deletions mne/io/eeglab/eeglab.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,13 +631,14 @@ def __init__(
event_type = "/".join([str(et) for et in ep.eventtype])
event_name.append(event_type)
# store latency of only first event
event_latencies.append(events[ev_idx].latency)
# -1 to account for Matlab 1-based indexing of samples
event_latencies.append(events[ev_idx].latency - 1)
ev_idx += len(ep.eventtype)
warn_multiple_events = True
else:
event_type = ep.eventtype
event_name.append(ep.eventtype)
event_latencies.append(events[ev_idx].latency)
event_latencies.append(events[ev_idx].latency - 1)
ev_idx += 1

if event_type not in unique_ev:
Expand Down
Loading