Skip to content

Commit 3e29187

Browse files
scott-hubertypre-commit-ci[bot]larsoner
authored
FIX, TST: Try to get test_export_epochs_eeeglab passing again (#13428)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Eric Larson <[email protected]>
1 parent 3fbf986 commit 3e29187

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

doc/changes/dev/13428.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Preserve event-to-epoch mapping when exporting EEGLAB .set files by `Scott Huberty`_

mne/export/_eeglab.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# License: BSD-3-Clause
33
# Copyright the MNE-Python contributors.
44

5+
from inspect import getfullargspec
6+
57
import numpy as np
68

79
from ..annotations import _sync_onset
@@ -64,6 +66,11 @@ def _export_epochs(fname, epochs):
6466
else:
6567
annot = None
6668

69+
# https://github.com/jackz314/eeglabio/pull/18
70+
kwargs = dict()
71+
if "epoch_indices" in getfullargspec(eeglabio.epochs.export_set).kwonlyargs:
72+
kwargs["epoch_indices"] = epochs.selection
73+
6774
eeglabio.epochs.export_set(
6875
fname,
6976
data=epochs.get_data(picks=ch_names),
@@ -75,6 +82,7 @@ def _export_epochs(fname, epochs):
7582
event_id=epochs.event_id,
7683
ch_locs=cart_coords,
7784
annotations=annot,
85+
**kwargs,
7886
)
7987

8088

mne/export/tests/test_export.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
_check_edfio_installed,
3636
_record_warnings,
3737
_resource_path,
38+
check_version,
3839
object_diff,
3940
)
4041

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

536537

537-
@pytest.mark.xfail(reason="eeglabio (usage?) bugs that should be fixed")
538+
@pytest.mark.skipif(not check_version("eeglabio", "0.1.2"), reason="fixed by 0.1.2")
538539
@pytest.mark.parametrize("preload", (True, False))
539540
def test_export_epochs_eeglab(tmp_path, preload):
540541
"""Test saving an Epochs instance to EEGLAB's set format."""

mne/io/eeglab/eeglab.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,13 +631,14 @@ def __init__(
631631
event_type = "/".join([str(et) for et in ep.eventtype])
632632
event_name.append(event_type)
633633
# store latency of only first event
634-
event_latencies.append(events[ev_idx].latency)
634+
# -1 to account for Matlab 1-based indexing of samples
635+
event_latencies.append(events[ev_idx].latency - 1)
635636
ev_idx += len(ep.eventtype)
636637
warn_multiple_events = True
637638
else:
638639
event_type = ep.eventtype
639640
event_name.append(ep.eventtype)
640-
event_latencies.append(events[ev_idx].latency)
641+
event_latencies.append(events[ev_idx].latency - 1)
641642
ev_idx += 1
642643

643644
if event_type not in unique_ev:

0 commit comments

Comments
 (0)