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
let me share here some thoughts of how working with EEG sleep data could be simplified once we have the annotations API in place. Given let's say 2 files (one raw data and one annotations) it should be as easy as doing:
import mne
raw = mne.io.read_raw_edf('data.edf')
annotations = mne.read_annotations('sleep_annots.edf')
raw.set_annotations(annotations)
events, event_id = mne.events_from_annotations(raw)
epochs = mne.Epochs(raw, events, event_id, tmin=0., tmax=30., baseline=None)
epochs['N1'] # to get all epochs of N1 type etc.
Then you could easily loop over segments, recast a 30 seconds epoch into a
RawArray, re-epoch, etc.
On Wed, Nov 7, 2018 at 1:22 PM Denis-Alexander Engemann <
[email protected]> wrote:
Just a question, can multiple process access to the same edf record at the same time ? It would be great to use it in a batch generator for deep learning.
Oh, sorry. I thought you referred to the tailing annotation. Not to the
time when epoching. But I would not do that either.
I would use the onset from annotations for epoching and then decide about
the time to window
@jasmainak I am not sure I get your concern here. Many formats use annotations to mark stim onsets like events. We just allow this with event and event_id. If the durations are not 0 or fixed for some annotations then we'll need to invent something new. But we'll need a good use case.
I'm concerned about the use case you shared in your code snippet above. The duration is not 0 there and the annotations are (probably) contiguous. That is to say, right after N1 ends, another sleep stage starts. If you allow the user to specify arbitrary tmin or tmax in the Epochs constructor, their epochs could contain two (or more) sleep stages instead of one.
I think adding a check inside the Epochs constructor that makes sure your epochs don't contain more than one annotation should be fine.
I would say that this is experiment specific. Even if I have annotations of
contiguous regions all with the same size, why should I not be able to get
epochs from onset-0.1 to duration+0.1?
That this might not make sense for most experiments. Maybe. But I don't see
why it should not be possible.
On Fri, Nov 9, 2018 at 5:28 PM Mainak Jas ***@***.***> wrote:
I'm concerned about the use case you shared in your code snippet above.
The duration is not 0 there and the annotations are (probably) contiguous.
That is to say, right after N1 ends, another sleep stage starts. If you
allow the user to specify arbitrary tmin or tmax in the Epochs constructor,
their epochs could contain two (or more) sleep stages instead of one.
I think adding a check inside the Epochs constructor that makes sure your
epochs don't contain more than one annotation should be fine.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5684 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGt-45aREyCiRBtbogeNB_cTzMnsbxi2ks5uta0WgaJpZM4YF_Gc>
.
If I'm trying to do a classification task between sleep stages, I don't want my data to be contaminated by other classes. I'm worried that people will unknowingly use the wrong tmax (e.g., by copy-paste from example) when they did not intend to.
Of course maybe people want to do onset - 0.1 to duration + 0.1 but I'm not aware of such use cases. Maybe there are valid reasons to do this too ...
Just a reminder that it won't be as easy with eeglab data: currently the eeglab event reader does more steps than just events, event_id = mne.events_from_annotations(raw) to be backward compatible (for example event names that contain digits are turned to integers).
No, I'll check, I'd be happy to be wrong on this. :)
What I meant is that before annotations one could just read the eeglab file and then use mne.find_events(), while currently you need to create a function that parses event names and pass it to events_from_annotations, right? But I'll check that later in hope that it is as easy as it was before. :)
def_event_id_func(trigger, event_id, event_id_func, dropped):
"""Mimic old behavior to be used with events_from_annotations."""ifevent_idisnotNoneandtriggerinevent_id:
returnevent_id[trigger]
ifevent_id_func=='strip_to_integer':
trigger_new="".join([xforxintriggerifx.isdigit()])
iftrigger_new.isdigit():
returnint(trigger_new)
else:
dropped.append(trigger)
returnNoneelifevent_id_funcisnotNone:
returnevent_id_func(trigger)
# ...# create event_ch from annotationsannot=read_annotations(input_fname)
self.set_annotations(annot)
_check_boundary(annot, event_id)
latencies=np.round(annot.onset*self.info['sfreq'])
_check_latencies(latencies)
dropped_desc= [] # use to collect dropped descriptionsevent_id_=partial(_event_id_func,
event_id=event_id,
event_id_func=event_id_func,
dropped=dropped_desc)
events, _=events_from_annotations(self, event_id=event_id_)
and then many additional checks. So currently it does not seem possible to drop what eeglab reader does internally and unify with the future default of events_from_annotations.
But sorry for littering this discussion - this is not specific to sleep data, but relates to whether eeglab file reading could be made easy with using events_from_annotations and still produce the same events as before. But this is a separate discussion.
@mmagnuski we are aiming to avoid having some custom handling of annotations across our readers. What was (is still) done by eeglab raw reader should be deprecated although it should still be simple to do with the new unified Annotations API. As I don't use eeglab I don't have a clear vision. What are your thoughts on this? Can you live with the new API?
btw @massich did we already deprecate all the stim channel generation for eeg readers as planned? it should be done before the release otherwise it will delay the transition by 6 months. Do we all agree on this? cc @cbrnr@jona-sassenhagen
I don't use EEGLAB data myself these days, so I might not be the best advocate. But remember it's a secondary format - it is for data recorded in another format, and preprocessed in EEGLAB. So it might not be a top-priority format.
@agramfort Let's continue this conversation in the issue regarding backwards compatibility of eeglab reading, ok? I didn't want to sidetrack the conversation here so much.
let me share here some thoughts of how working with EEG sleep data could be simplified once we have the annotations API in place. Given let's say 2 files (one raw data and one annotations) it should be as easy as doing:
import mne
raw = mne.io.read_raw_edf('data.edf')
annotations = mne.read_annotations('sleep_annots.edf')
raw.set_annotations(annotations)
events, event_id = mne.events_from_annotations(raw)
epochs = mne.Epochs(raw, events, event_id, tmin=0., tmax=30., baseline=None)
epochs['N1'] # to get all epochs of N1 type etc.
I am stuck, and I want to get out of it. May I request you to spare some time to clarify my doubts. If you clarify my doubts, It would be a very big support for my research work. Any time of your convenience is okay for me.
Activity
massich commentedon Nov 1, 2018
massich commentedon Nov 7, 2018
Is there any sleeping data already in MNE-python?
dengemann commentedon Nov 7, 2018
dengemann commentedon Nov 7, 2018
jona-sassenhagen commentedon Nov 7, 2018
API wise it looks good.
Slasnista commentedon Nov 8, 2018
Ok, I'll go over it and make you a proposal.
Just a question, can multiple process access to the same edf record at the same time ? It would be great to use it in a batch generator for deep learning.
agramfort commentedon Nov 8, 2018
jasmainak commentedon Nov 8, 2018
@agramfort I would argue that you shouldn't need:
since the annotations already contain the
duration. So specifyingtminandtmaxwill run into the danger of overshooting your duration of annotation.massich commentedon Nov 8, 2018
jasmainak commentedon Nov 8, 2018
So, if I do:
I will get an error?
massich commentedon Nov 8, 2018
agramfort commentedon Nov 9, 2018
@jasmainak I am not sure I get your concern here. Many formats use annotations to mark stim onsets like events. We just allow this with event and event_id. If the durations are not 0 or fixed for some annotations then we'll need to invent something new. But we'll need a good use case.
jasmainak commentedon Nov 9, 2018
I'm concerned about the use case you shared in your code snippet above. The duration is not 0 there and the annotations are (probably) contiguous. That is to say, right after N1 ends, another sleep stage starts. If you allow the user to specify arbitrary tmin or tmax in the Epochs constructor, their epochs could contain two (or more) sleep stages instead of one.
I think adding a check inside the Epochs constructor that makes sure your epochs don't contain more than one annotation should be fine.
massich commentedon Nov 9, 2018
jasmainak commentedon Nov 9, 2018
If I'm trying to do a classification task between sleep stages, I don't want my data to be contaminated by other classes. I'm worried that people will unknowingly use the wrong tmax (e.g., by copy-paste from example) when they did not intend to.
Of course maybe people want to do onset - 0.1 to duration + 0.1 but I'm not aware of such use cases. Maybe there are valid reasons to do this too ...
4 remaining items
Slasnista commentedon Nov 13, 2018
yes the data are on our dropbox and the script is called
check_mne_reader.pymassich commentedon Nov 13, 2018
The error was due to fact that
events_from_annotationswas called without specifyingevent_id. Therefor it wasNoneand all the events are selected.passing
event_idsolves the problemagramfort commentedon Nov 13, 2018
massich commentedon Nov 13, 2018
We should. @Slasnista said he would draft an example with public data. I'll try to integrate it to MNE
@bdyetton pointed us to some publicly available sleep data in #4494 (comment)
mmagnuski commentedon Nov 13, 2018
Just a reminder that it won't be as easy with eeglab data: currently the eeglab event reader does more steps than just
events, event_id = mne.events_from_annotations(raw)to be backward compatible (for example event names that contain digits are turned to integers).massich commentedon Nov 13, 2018
I think that this was addressed. Or available through
event_idas a callable. Do you have an example that is not working?mmagnuski commentedon Nov 13, 2018
No, I'll check, I'd be happy to be wrong on this. :)
What I meant is that before annotations one could just read the eeglab file and then use
mne.find_events(), while currently you need to create a function that parses event names and pass it toevents_from_annotations, right? But I'll check that later in hope that it is as easy as it was before. :)mmagnuski commentedon Nov 13, 2018
Currently the eeglab reader does this internally:
and then many additional checks. So currently it does not seem possible to drop what eeglab reader does internally and unify with the future default of
events_from_annotations.But sorry for littering this discussion - this is not specific to sleep data, but relates to whether eeglab file reading could be made easy with using
events_from_annotationsand still produce the same events as before. But this is a separate discussion.agramfort commentedon Nov 13, 2018
@mmagnuski we are aiming to avoid having some custom handling of annotations across our readers. What was (is still) done by eeglab raw reader should be deprecated although it should still be simple to do with the new unified Annotations API. As I don't use eeglab I don't have a clear vision. What are your thoughts on this? Can you live with the new API?
btw @massich did we already deprecate all the stim channel generation for eeg readers as planned? it should be done before the release otherwise it will delay the transition by 6 months. Do we all agree on this? cc @cbrnr @jona-sassenhagen
jona-sassenhagen commentedon Nov 13, 2018
I don't use EEGLAB data myself these days, so I might not be the best advocate. But remember it's a secondary format - it is for data recorded in another format, and preprocessed in EEGLAB. So it might not be a top-priority format.
That said, deprecation is fine with me.
mmagnuski commentedon Nov 13, 2018
@agramfort Let's continue this conversation in the issue regarding backwards compatibility of eeglab reading, ok? I didn't want to sidetrack the conversation here so much.
massich commentedon Nov 13, 2018
So this should warn?
bphanikrishna commentedon Jan 15, 2019
Myself KRISHNA B, I'm a student from India. My research is on EEG signals using a wireless sensor network to detect drowsiness of a person.
I have questions about the details of the procedure described for extracting wakeful state and drowsiness stage from freely available physionet sleep EEG data. That is available at:
https://physionet.org/physiobank/database/sleep-edfx/sleep-cassette/
I am stuck, and I want to get out of it. May I request you to spare some time to clarify my doubts. If you clarify my doubts, It would be a very big support for my research work. Any time of your convenience is okay for me.
agramfort commentedon Jan 15, 2019
closed by #5718