You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Events and annotations can only be specified for all channels.
Describe your solution
A way to assign an event to a specific channel, along with plotting and analysis routines that handle that would be extremely helpful for removing specific segments of specific bad channels, or for any decoding/classification of channel-wise EEG features. Maybe an extra column in the events array which specifies the channel would be a good way to input this information.
Additional context
I understand this is a large request, but id like to start a discussion here and see if anyone else is interested in this feature.
@bdyetton this feature has been requested in the past by Boris Burle in Marseille. He had goor arguments. I think it's doable in the near future with the Annotations object. Can I ask what is your use case?
We are interested in sleep features such as spindles, k-complexes, and slow oscillations. These short (~0.5-2s) generally occur in each channel independently (although sometimes they appear in many at the same time).
It would be great to:
a) Mark these events, by hand, in the plotting tool (much like you can highlight segments currently)
b) Be able to add the output of sleep feature detection algorithms (start, duration, channel) to a mne.io.RawArray so we can then plot and view them
c) Be able to save these annotation locations back to disk with the EEG data (as .fif or preferable, as .edf).
How these single channel annotations would work with the mne.Epochs object is not something I've thought about as we don't use the epochs object that much.
Marking per-channel artifacts would be nice also, as sometimes an electrode can go bad halfway through a night of sleep, but we don't want to throw away the whole channel (by marking electrode as bad), or throw away half the night (by marking a segment of all channels as bad).
p.s. @agramfort Great work on that sleep staging algorithm, we are hoping to give it a go soon ;)
O wow! I had this same idea and was tempted to try it out this year.
Glad it worked out! Will the code be made available after the conference? I'd love to try it out.
Annotations currently has onset, duration, description. I suggest we add ch_names which is a tuple-of-tuples of channel names that the annotations apply to (like our epochs.drop_log). If the tuple-of-tuples is all empty, we don't write it to disk (I/O the same). If it's not empty, we write it to disk, probably however we do with drop_log. I think this gets people what they want in a backward-compatible way. Then we "just" have to figure out how to draw this in raw.plot, which I think means drawing either a single fill_between like we do now when it applies to all channels, or M fill_betweens for the M visible channels out of the N channels the annotation currently applies to.
yes changing annotations is not too hard but it means the plotting code
needs to deal with it.
I feel it's much more painful... you need to be able to annotate a subset
of channels that may not be
below eachother
Having worked on the plotting code I actually don't think it's going to be very difficult actually. So if that's all that's stopping us I could give it a shot
I say we start by treating them like any other annotation -- i.e., ignore the ch_names attribute -- and things will proceed as normal, so it's just an aesthetic and bookkeeping change for people to make if they want to. For example, if some marks manually a BAD_flux_jump just for MEG0111, that entire segment would still be ignored in epoching, and treated like an acquisition skip in filtering, etc. just as it is now depending on the skip_by_annotation parameter.
However, in future PRs things like this become possible:
We could modify find_bad_channels_maxwell and annotate_flat to mark badness channel-by channel over time (easy)
Modify maxwell_filter to reconstruct BAD_-marked MEG channels just during their bad times (hard)
In other words, we implement the marking and storage, then make things annotations-channels-aware gradually as we can. This is analogous to how we implemented annotations in the first place, then gradually made downstream functions and methods annotation-aware as we found it beneficial or necessary to do so. Most places we have a skip_by_annotation or similar argument came into being this way, and it seemed to work as both a creator of some of those PRs and as a consumer.
The first PR, namely to add ch_names to Annotations, is not new-contributor friendly, and is a prerequisite for everything else enumerated above. So I think I should make first make a PR to add ch_names as tuple of tuples of ch_names as above. Then someone (probably @drammock) makes the plotting code handle it properly using fill_betweens or rectangle patches or whatever is necessary in a follow-up PR.
Then the rest of the items can be saved for the sprint, but really the preprocessing enhancements in (1) above are probably the only ones suitable for new contributors.
At the risk of sounding repetitive, I wouldn't implement showing channel-specific annotations in our plotting code without the option to create them. Or do you think people will not want to create/edit them (as opposed to just view) if they happen to have channel-specific annotations?
At the risk of sounding repetitive, I wouldn't implement showing channel-specific annotations in our plotting code without the option to create them
Agreed. Displaying them is the easy part. I've been scratching my head a bit over how to do the UI/UX for creating them (I have some ideas, but there's no obvious "right" way IMO)
At the risk of sounding repetitive, I wouldn't implement showing channel-specific annotations in our plotting code without the option to create them
Agreed
I disagree with this. We're about to have a PR that implements the ability to make these manually via Annotations(..., ch_names=...), we might as well show them / this information properly.
Moreover, the PRs to make them via find_* or mark_* functions and the one(s) to make them interactively in the GUI would benefit from actually showing them properly for testing/iteration purposes, and also be easier to review.
I can see the benefits you mention @larsoner. In that case I think we need a (temporary) clear signal somewhere (docstring? Annotation UI window?) making it clear that per-channel annotations cannot (yet) be created through the raw.plot() GUI.
Indeed I would just add a note somewhere that the functionality has not been implemented / annotations created interactively apply to all channels, probably in small text at the bottom of the interactive annotations window (with the buttons and such)
Activity
agramfort commentedon Sep 11, 2018
@bdyetton this feature has been requested in the past by Boris Burle in Marseille. He had goor arguments. I think it's doable in the near future with the Annotations object. Can I ask what is your use case?
bdyetton commentedon Sep 12, 2018
We are interested in sleep features such as spindles, k-complexes, and slow oscillations. These short (~0.5-2s) generally occur in each channel independently (although sometimes they appear in many at the same time).
It would be great to:
a) Mark these events, by hand, in the plotting tool (much like you can highlight segments currently)
b) Be able to add the output of sleep feature detection algorithms (start, duration, channel) to a mne.io.RawArray so we can then plot and view them
c) Be able to save these annotation locations back to disk with the EEG data (as .fif or preferable, as .edf).
How these single channel annotations would work with the mne.Epochs object is not something I've thought about as we don't use the epochs object that much.
Marking per-channel artifacts would be nice also, as sometimes an electrode can go bad halfway through a night of sleep, but we don't want to throw away the whole channel (by marking electrode as bad), or throw away half the night (by marking a segment of all channels as bad).
p.s. @agramfort Great work on that sleep staging algorithm, we are hoping to give it a go soon ;)
agramfort commentedon Sep 12, 2018
bdyetton commentedon Sep 12, 2018
O wow! I had this same idea and was tempted to try it out this year.
Glad it worked out! Will the code be made available after the conference? I'd love to try it out.
You might be interested in this: https://osf.io/8bma7/ if you want higher quality spindles for the MASS dataset.
agramfort commentedon Sep 12, 2018
cool ! I did not know about these data.
ping @Slasnista
Yes we should make the code available at some point. We're about to send the journal paper.
larsoner commentedon Feb 19, 2021
Annotationscurrently hasonset,duration,description. I suggest we addch_nameswhich is a tuple-of-tuples of channel names that the annotations apply to (like ourepochs.drop_log). If the tuple-of-tuples is all empty, we don't write it to disk (I/O the same). If it's not empty, we write it to disk, probably however we do withdrop_log. I think this gets people what they want in a backward-compatible way. Then we "just" have to figure out how to draw this inraw.plot, which I think means drawing either a singlefill_betweenlike we do now when it applies to all channels, or Mfill_betweens for the M visible channels out of the N channels the annotation currently applies to.agramfort commentedon Feb 20, 2021
larsoner commentedon Feb 20, 2021
Having worked on the plotting code I actually don't think it's going to be very difficult actually. So if that's all that's stopping us I could give it a shot
agramfort commentedon Feb 20, 2021
cbrnr commentedon Feb 20, 2021
Visual channel-specific annotations is one thing, but are you planning to support creating them as well?
drammock commentedon Feb 21, 2021
I am less worried about the plotting and more worried about downstream processing. See recent discussion here: https://mne.discourse.group/t/annotations-per-channels/2693/4
larsoner commentedon Feb 22, 2021
I say we start by treating them like any other annotation -- i.e., ignore the
ch_namesattribute -- and things will proceed as normal, so it's just an aesthetic and bookkeeping change for people to make if they want to. For example, if some marks manually aBAD_flux_jumpjust for MEG0111, that entire segment would still be ignored in epoching, and treated like an acquisition skip in filtering, etc. just as it is now depending on theskip_by_annotationparameter.However, in future PRs things like this become possible:
find_bad_channels_maxwellandannotate_flatto mark badness channel-by channel over time (easy)maxwell_filterto reconstructBAD_-marked MEG channels just during their bad times (hard)In other words, we implement the marking and storage, then make things annotations-channels-aware gradually as we can. This is analogous to how we implemented annotations in the first place, then gradually made downstream functions and methods annotation-aware as we found it beneficial or necessary to do so. Most places we have a
skip_by_annotationor similar argument came into being this way, and it seemed to work as both a creator of some of those PRs and as a consumer.cbrnr commentedon Feb 22, 2021
Sounds good!
raw.plot(medium to hard)drammock commentedon Feb 22, 2021
Are any of these tasks suitable for the upcoming sprint @larsoner ? If so let's wait until then to implement.
larsoner commentedon Feb 22, 2021
The first PR, namely to add
ch_namesto Annotations, is not new-contributor friendly, and is a prerequisite for everything else enumerated above. So I think I should make first make a PR to addch_namesas tuple of tuples of ch_names as above. Then someone (probably @drammock) makes the plotting code handle it properly usingfill_betweens or rectangle patches or whatever is necessary in a follow-up PR.Then the rest of the items can be saved for the sprint, but really the
preprocessingenhancements in (1) above are probably the only ones suitable for new contributors.cbrnr commentedon Feb 22, 2021
At the risk of sounding repetitive, I wouldn't implement showing channel-specific annotations in our plotting code without the option to create them. Or do you think people will not want to create/edit them (as opposed to just view) if they happen to have channel-specific annotations?
drammock commentedon Feb 22, 2021
Agreed. Displaying them is the easy part. I've been scratching my head a bit over how to do the UI/UX for creating them (I have some ideas, but there's no obvious "right" way IMO)
larsoner commentedon Feb 22, 2021
I disagree with this. We're about to have a PR that implements the ability to make these manually via
Annotations(..., ch_names=...), we might as well show them / this information properly.Moreover, the PRs to make them via
find_*ormark_*functions and the one(s) to make them interactively in the GUI would benefit from actually showing them properly for testing/iteration purposes, and also be easier to review.drammock commentedon Feb 22, 2021
I can see the benefits you mention @larsoner. In that case I think we need a (temporary) clear signal somewhere (docstring? Annotation UI window?) making it clear that per-channel annotations cannot (yet) be created through the
raw.plot()GUI.larsoner commentedon Feb 22, 2021
Indeed I would just add a note somewhere that the functionality has not been implemented / annotations created interactively apply to all channels, probably in small text at the bottom of the interactive annotations window (with the buttons and such)