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
Support writing custom event durations #33
Conversation
I don't see any use of such a public function in mne but I may be wrong. |
We could change the behavior of |
it would not be a MNE event array then. The second column of the MNE
events tell you what was the previous
value of the stim channel channel. So events and the stim channel
capture the same information.
This may be clarifier in https://mne.tools/dev/glossary.html event paragraph.
|
Yes, I know that this won't be an event array then, but currently we lose information when using events instead of annotations (namely the durations). But I understand that this might not fit into MNE, unless we want to facilitate exporting data to BrainVision. |
I could include these functions in MNELAB, but |
Another idea: maybe |
This seems unobtrusive to me 👍 and it would be a nice addition to have |
+1 for |
ok with me
… |
I remember to have had a discussion about the durations. (with pretty much the same conclusions). Apart from that, I'm not sure that with the current API you need the private functions of your snippet. You should be able to unpack it and do the very same at once: event_1 = np.stack(raw.samples(annot.onset),
annot.info['sfreq'] * annot.duration, #raw.samples(annot.duration) is abusing but it should also work
some_maping(annot.description)) But I need look at it better. |
Then to me, the right move would it be to be able to construct epochs from annotations directly. Without this |
I agree, directly supporting annotations would be the way to go. The best solution would be to add support for exporting to BV directly in MNE. However, we don't have an API for that yet because there's only |
Codecov Report
@@ Coverage Diff @@
## master #33 +/- ##
==========================================
+ Coverage 95.39% 95.45% +0.06%
==========================================
Files 3 3
Lines 217 220 +3
==========================================
+ Hits 207 210 +3
Misses 10 10
Continue to review full report at Codecov.
|
From my side this is ready to merge. I'll create a PR to extend the functionality of |
Sounds practical to me, and we don't lose anything by already including this in pybv. Thanks @cbrnr ! |
Fixes #30. I have written some custom functions to convert
mne.Annotations
into a suitable (n, 3) ndarray - the question is where should I include these functions? Maybe the best place would be directly in MNE. Here's the code:So if you want to convert existing annotations, you call
events = annotations_to_array(raw.annotations, raw.info["sfreq"])
. This gives something very similar to what you get withmne.events_from_annotations
, but with a valid duration column and better(TM) mapping of descriptions to event IDs.Example using this dataset:
Original
raw.annotations.description
:events1
(note that the numbers match the numbers found in 'T0', 'T1', and 'T2', plus there is a valid durations column):events2
(note that event IDs start at 1 so they don't match 'T0', 'T1', and 'T2', plus the second column is redundant and doesn't contain any information):Of course,
annotations_to_array
could also return the mapping just likemne.events_from_annotations
does.WDYT (also including @agramfort, @massich, and @larsoner regarding the inclusion of these functions into MNE)?