File tree Expand file tree Collapse file tree 4 files changed +14
-3
lines changed Expand file tree Collapse file tree 4 files changed +14
-3
lines changed Original file line number Diff line number Diff line change
1
+ Preserve event-to-epoch mapping when exporting EEGLAB .set files by `Scott Huberty `_
Original file line number Diff line number Diff line change 2
2
# License: BSD-3-Clause
3
3
# Copyright the MNE-Python contributors.
4
4
5
+ from inspect import getfullargspec
6
+
5
7
import numpy as np
6
8
7
9
from ..annotations import _sync_onset
@@ -64,6 +66,11 @@ def _export_epochs(fname, epochs):
64
66
else :
65
67
annot = None
66
68
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
+
67
74
eeglabio .epochs .export_set (
68
75
fname ,
69
76
data = epochs .get_data (picks = ch_names ),
@@ -75,6 +82,7 @@ def _export_epochs(fname, epochs):
75
82
event_id = epochs .event_id ,
76
83
ch_locs = cart_coords ,
77
84
annotations = annot ,
85
+ ** kwargs ,
78
86
)
79
87
80
88
Original file line number Diff line number Diff line change 35
35
_check_edfio_installed ,
36
36
_record_warnings ,
37
37
_resource_path ,
38
+ check_version ,
38
39
object_diff ,
39
40
)
40
41
@@ -534,7 +535,7 @@ def test_export_raw_edf_does_not_fail_on_empty_header_fields(tmp_path):
534
535
raw .export (tmp_path / "test.edf" , add_ch_type = True )
535
536
536
537
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 " )
538
539
@pytest .mark .parametrize ("preload" , (True , False ))
539
540
def test_export_epochs_eeglab (tmp_path , preload ):
540
541
"""Test saving an Epochs instance to EEGLAB's set format."""
Original file line number Diff line number Diff line change @@ -631,13 +631,14 @@ def __init__(
631
631
event_type = "/" .join ([str (et ) for et in ep .eventtype ])
632
632
event_name .append (event_type )
633
633
# 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 )
635
636
ev_idx += len (ep .eventtype )
636
637
warn_multiple_events = True
637
638
else :
638
639
event_type = ep .eventtype
639
640
event_name .append (ep .eventtype )
640
- event_latencies .append (events [ev_idx ].latency )
641
+ event_latencies .append (events [ev_idx ].latency - 1 )
641
642
ev_idx += 1
642
643
643
644
if event_type not in unique_ev :
You can’t perform that action at this time.
0 commit comments