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
This relates partly to reproducing the brainstorm results in #2587. Currently, mne-python does not have the semantics to handle annotations with durations. One usecase is to visualize bad segments in the raw data using raw.plot(). I am opening the issue so that the API can be discussed.
as discussed one option to avoid introducing a new concept in MNE would be
use events.
e.g.
[[100 0 1],
[200 1 0]]
would code for a event of type 1 from 100 to 200 milliseconds.
consequence is that it's not obvious if it's a bad segment or not, unless
for example we say that if the event id is negative it is bad segment.
it's a bit more cryptic than having some kind of event id and look for the
work
bad in it.
can you give an example how it would look if there were more than one segment + a few experiment-related events? Would you allow for overlapping events?
The first column contains the event time in samples and the third column contains the event id. For output = 'onset' or 'step', the second column contains the value of the stim channel immediately before the the event/step.
The second column does not agree with what you propose
How we save and load the annotations is to me a mostly separate issue from how we use them. I'd prefer to have an annotation format that is compact and simple to understand, ideally requiring no new IO functions (onset-offset-kind fits this), and then work on how to use that annotation in a nice way from an API standpoint.
But since you asked, I originally implemented a function that worked on epochs to eliminate any epochs that were considered "bad". I don't think that's the best approach, though. Instead we could "attach" them to raw objects (in memory only for now), then:
They can easily be plotted with raw.plot
When Epochs get constructed, they can be aware of the annotations attached to the Raw instance and drop any events (+/- tmin/tmax) that live in "bad" segments. Maybe the user needs to then pass bad_id in addition to event_id to mark which annotated segments are not to be used using key, value pairs, and we can mark in the drop log the right reason using the bad_idvalue.
This to me is pretty simple from a user perspective, and also shouldn't be too difficult to implement from an API perspective.
The other nice thing about onset-offset-kind is that one can easily get to this format from other readers/annotation software, since it can be easily written out as plain test and read using our read_events function.
@jasmainak I know. It wouldn't be an "event" or -eve file anymore but an "annotation" or -ann file or so. I don't see a problem with redefining what the columns mean here.
Does anyone use annotation software, or work with anyone who does? It might be good to know what their saving formats look like. My guess is that it's onset, offset, and some form of text entry that allows the user to say what the event is. We'd be pretty close to that, only we'd force people to construct the bad_id dict, which I don't think is a bad thing.
I like Eric's proposal too. I'm just wondering how to handle cropped data. With Eric's system it doesn't matter if the end part of the segment gets cut off, but if the beginning gets cut off, the segmentation data is lost.
One option would be to use negative values for segments in combination with Alex's solution. This way it would be possible to infer the segments, but I'm not sure how it would behave with overlapping events without looking into the code.
@jaeilepp I'm not sure I follow. My system and Alex's system contain the same information, but just represent it differently. So if you e.g. add an annotation and crop the raw data, I don't see any problem with having / converting to negative times in the representation, and thus preserving the information.
We should use a new parameter with a clean annotation semantics. Combining events and annotations is than easy as semantics are clear defined (and separated from another). I'm afraid of a new objects here and the maintenance they bring with, let's stick with numpy arrays and simple structures. My 2 cents.
Yeah, I agree with Denis now. I noticed that when reading events from kit files (with files for testing), the second column has some data. So there are already semantics tied to it.
fwiw, I already do this on my neuromag system. I simply raise a trigger when a stimulus appears and don't lower it until the stimulus disappears. Thus the length of presentation is present in the file directly.
It works fine in my cases. If my event is code 1 and the button response is code 255. I can still separate them using the "ignore" feature in the C code, or just deconvolving the signal into their binary values. Then I get the length of all.
The overlapping events can be masked out in MNE, so basically this is a question of where and how we want to separate the triggers. It would be nice to have separate annotations for events and segments, so it would be easier to deal with them separately (visualization, rejection etc.)
Hey all - I know this issue has been closed and it looks like people's needs have been met here. That said, I just wanted to share a code snippet for an Events class that I've been using to keep track of metadata, trial lengths, etc for my trials. I've found it useful for quickly generating MNE events arrays using different kinds of trial types etc. Maybe somebody will find it useful :)
Activity
agramfort commentedon Dec 2, 2015
jasmainak commentedon Dec 2, 2015
can you give an example how it would look if there were more than one segment + a few experiment-related events? Would you allow for overlapping events?
jasmainak commentedon Dec 2, 2015
what happens when you have some events which have a duration and others which don't have a duration?
dengemann commentedon Dec 2, 2015
we could have lists of arrays or 3D arrays
open to the user, you can put in your array whatever you want
we could have a user defined bads tag or as you say negative
larsoner commentedon Dec 2, 2015
I was thinking:
i.e., onset-offset-kind.
dengemann commentedon Dec 2, 2015
but how do you then combine this with the exisiting approach?
jasmainak commentedon Dec 2, 2015
@Eric89GXL : the documentation currently says:
The second column does not agree with what you propose
larsoner commentedon Dec 2, 2015
How we save and load the annotations is to me a mostly separate issue from how we use them. I'd prefer to have an annotation format that is compact and simple to understand, ideally requiring no new IO functions (onset-offset-kind fits this), and then work on how to use that annotation in a nice way from an API standpoint.
But since you asked, I originally implemented a function that worked on
epochsto eliminate any epochs that were considered "bad". I don't think that's the best approach, though. Instead we could "attach" them to raw objects (in memory only for now), then:raw.plotRawinstance and drop any events (+/- tmin/tmax) that live in "bad" segments. Maybe the user needs to then passbad_idin addition toevent_idto mark which annotated segments are not to be used usingkey, valuepairs, and we can mark in the drop log the right reason using thebad_idvalue.This to me is pretty simple from a user perspective, and also shouldn't be too difficult to implement from an API perspective.
larsoner commentedon Dec 2, 2015
The other nice thing about onset-offset-kind is that one can easily get to this format from other readers/annotation software, since it can be easily written out as plain test and read using our
read_eventsfunction.larsoner commentedon Dec 2, 2015
@jasmainak I know. It wouldn't be an "event" or
-evefile anymore but an "annotation" or-annfile or so. I don't see a problem with redefining what the columns mean here.dengemann commentedon Dec 2, 2015
I like this proposal a lot @Eric89GXL
dengemann commentedon Dec 2, 2015
It would be terribly useful to generate new raw files from sleep annotations(!) and so on.
larsoner commentedon Dec 2, 2015
Does anyone use annotation software, or work with anyone who does? It might be good to know what their saving formats look like. My guess is that it's onset, offset, and some form of text entry that allows the user to say what the event is. We'd be pretty close to that, only we'd force people to construct the
bad_iddict, which I don't think is a bad thing.dengemann commentedon Dec 2, 2015
why bad_id? why not annotation_id?
jasmainak commentedon Dec 2, 2015
@Eric89GXL , the problem is that you are going to break a lot of scripts if you redefine what it means
5 remaining items
agramfort commentedon Dec 2, 2015
jaeilepp commentedon Dec 3, 2015
I like Eric's proposal too. I'm just wondering how to handle cropped data. With Eric's system it doesn't matter if the end part of the segment gets cut off, but if the beginning gets cut off, the segmentation data is lost.
One option would be to use negative values for segments in combination with Alex's solution. This way it would be possible to infer the segments, but I'm not sure how it would behave with overlapping events without looking into the code.
larsoner commentedon Dec 3, 2015
@jaeilepp I'm not sure I follow. My system and Alex's system contain the same information, but just represent it differently. So if you e.g. add an annotation and crop the raw data, I don't see any problem with having / converting to negative times in the representation, and thus preserving the information.
jaeilepp commentedon Dec 3, 2015
Yeah, that was a mistake on my part. Realized it myself too after writing the comment.
dengemann commentedon Dec 3, 2015
We should use a new parameter with a clean annotation semantics. Combining events and annotations is than easy as semantics are clear defined (and separated from another). I'm afraid of a new objects here and the maintenance they bring with, let's stick with numpy arrays and simple structures. My 2 cents.
jaeilepp commentedon Dec 10, 2015
Yeah, I agree with Denis now. I noticed that when reading events from kit files (with files for testing), the second column has some data. So there are already semantics tied to it.
dgwakeman commentedon Dec 11, 2015
fwiw, I already do this on my neuromag system. I simply raise a trigger when a stimulus appears and don't lower it until the stimulus disappears. Thus the length of presentation is present in the file directly.
agramfort commentedon Dec 11, 2015
dgwakeman commentedon Dec 11, 2015
It works fine in my cases. If my event is code 1 and the button response is code 255. I can still separate them using the "ignore" feature in the C code, or just deconvolving the signal into their binary values. Then I get the length of all.
jaeilepp commentedon Dec 12, 2015
The overlapping events can be masked out in MNE, so basically this is a question of where and how we want to separate the triggers. It would be nice to have separate annotations for events and segments, so it would be easier to deal with them separately (visualization, rejection etc.)
larsoner commentedon Feb 3, 2016
Closing, we have this now. Thanks @jaeilepp
choldgraf commentedon Feb 4, 2016
Hey all - I know this issue has been closed and it looks like people's needs have been met here. That said, I just wanted to share a code snippet for an
Eventsclass that I've been using to keep track of metadata, trial lengths, etc for my trials. I've found it useful for quickly generating MNE events arrays using different kinds of trial types etc. Maybe somebody will find it useful :)https://github.com/choldgraf/ecogtools/blob/master/mneutils.py#L35
If you guys think there's any place in the MNE repo for this, then I'm happy to contribute, but it sounds like people are satisfied already.