-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix EEGLAB events after dropped epochs #14067
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fix :meth:`mne.Epochs.export` producing invalid EEGLAB event latencies and dummy events after epochs were dropped, by :newcontrib:`Daria Agafonova`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,16 +66,24 @@ def _export_epochs(fname, epochs): | |
| else: | ||
| annot = None | ||
|
|
||
| # eeglabio uses column 0 as latency in the concatenated epochs array and | ||
| # column 2 as event type; the original recording sample is not stored here. | ||
| events = epochs.events.copy() | ||
| events[:, 0] = ( | ||
| np.arange(len(epochs)) * len(epochs.times) + epochs.time_as_index(0)[0] | ||
| ) | ||
|
|
||
| # https://github.com/jackz314/eeglabio/pull/18 | ||
| kwargs = dict() | ||
| if "epoch_indices" in getfullargspec(eeglabio.epochs.export_set).kwonlyargs: | ||
| kwargs["epoch_indices"] = epochs.selection | ||
| # This also handles zero time falling on the final sample (tmax=0). | ||
| kwargs["epoch_indices"] = np.arange(1, len(epochs) + 1) | ||
|
Comment on lines
78
to
+80
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any reason to pass this at all anymore? I assume if you don't pass it, it defaults to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question. In most cases, omitting |
||
|
|
||
| eeglabio.epochs.export_set( | ||
| fname, | ||
| data=epochs.get_data(picks=ch_names), | ||
| sfreq=epochs.info["sfreq"], | ||
| events=epochs.events, | ||
| events=events, | ||
| tmin=epochs.tmin, | ||
| tmax=epochs.tmax, | ||
| ch_names=ch_names, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is odd... if you do this there is no longer any reference to the absolute time in the original recording. It suggests
events[:, 2]is the only thing correctly used byeeglabio.epochs.export_set. Is it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the absolute sample from the original continuous recording is intentionally not retained in this field. For epoched EEGLAB files, eeglabio uses column 0 as latency in the concatenated epochs array and column 2 as the event type; column 1 is unused. Keeping the original sample numbers is what caused events to point to the wrong epochs after dropping epochs. I clarified this in the code comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohhh.... so I think this fix actually belongs in
eeglabio. It should handle the translation from MNE-Pythonevents(which it currently takes) to whatevereeglabwants.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. I moved the translation into eeglabio and added tests for dropped epochs and the
tmax=0boundary: jackz314/eeglabio#26. I’ll update this PR once the upstream behavior is settled.