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
Is there a way to pull out the annotations of an EDF file without having to read in the whole file?
Right now what I am doing is running the following commands:
foo = mne.io.read_raw_edf(file, stim_channel=auto,preload = True)
temp = mne.io.get_edf_events(foo)
As @teonbrooks has already commented, the whole file must be read in order to parse the annotations. These are stored in a special channel and not in an event table like e.g. in GDF files at the beginning or end of the file. Therefore, this issue should be closed because it cannot be implemented.
the whole file must be read in order to parse the annotations.
The single channel from the whole file must be loaded, yes. However, it is sometimes faster and almost always more memory efficient to read a single channel of data in MNE than it is to read the entire thing. So this still seems like a reasonable request. If preload is False then we can still do something internally similar to raw[annot_pick][0] to get the channel with lower overhead than preload=True.
I suppose so. I'd consider that a more of a workaround than a permanent solution, though. Forcing someone to have two copies of their raw instance, one that they had to construct with a exclude=np.setdiff1d(np.arange(len(raw.ch_names)), raw.ch_names.index('annotation_ch')) or so is a pretty clunky solution to what we should be able to solve internally.
True, but I'm still not sure if this is really necessary in the first place unless you throw some convincing numbers at me (e.g. a decent amount of reduced absolute memory usage and/or speed increase). I haven't come across a large EDF file where memory usage/load times was an issue.
@larsoner Sbang002 was an intern working with me but he finished up, hence the lack of reply.
Just to get back to you, our lab works with sleep records, and loading in 8 hrs+ worth of EEG to read of the sleep stages (encoded as edf annotations) is time-consuming and memory intensive. Loading annotations only would speed up our analysis by a large margin, however, I understand if this is a low priority fix.
@bdyetton I don't think is a low priority fix. It is actually on the top of my list. I'll be happy to help. And if you can share some data and we make an example out of it, it would be awesome.
plus, we will need code reviews when we tackle it.
Seems like there could be a bug with our loaders, I've started a discussion in #12386 (not specifically about reading annotations, but the EDF reader already seems to consume too much memory).
Activity
teonbrooks commentedon Aug 17, 2017
given the way the annotations are constructed, the file must be loaded in order to pull off the annotations.
agramfort commentedon Aug 17, 2017
cbrnr commentedon Nov 22, 2017
As @teonbrooks has already commented, the whole file must be read in order to parse the annotations. These are stored in a special channel and not in an event table like e.g. in GDF files at the beginning or end of the file. Therefore, this issue should be closed because it cannot be implemented.
larsoner commentedon Nov 22, 2017
The single channel from the whole file must be loaded, yes. However, it is sometimes faster and almost always more memory efficient to read a single channel of data in MNE than it is to read the entire thing. So this still seems like a reasonable request. If
preload is Falsethen we can still do something internally similar toraw[annot_pick][0]to get the channel with lower overhead thanpreload=True.cbrnr commentedon Nov 22, 2017
Can't we set the
excludeargument accordingly to only load the stim channel?larsoner commentedon Nov 22, 2017
I suppose so. I'd consider that a more of a workaround than a permanent solution, though. Forcing someone to have two copies of their
rawinstance, one that they had to construct with aexclude=np.setdiff1d(np.arange(len(raw.ch_names)), raw.ch_names.index('annotation_ch'))or so is a pretty clunky solution to what we should be able to solve internally.cbrnr commentedon Nov 22, 2017
True, but I'm still not sure if this is really necessary in the first place unless you throw some convincing numbers at me (e.g. a decent amount of reduced absolute memory usage and/or speed increase). I haven't come across a large EDF file where memory usage/load times was an issue.
larsoner commentedon Nov 22, 2017
I assumed that this issue was opened because it was problematic. Can you explain why
preload=Trueis bad for you @sbang002 ?bdyetton commentedon Sep 11, 2018
@larsoner Sbang002 was an intern working with me but he finished up, hence the lack of reply.
Just to get back to you, our lab works with sleep records, and loading in 8 hrs+ worth of EEG to read of the sleep stages (encoded as edf annotations) is time-consuming and memory intensive. Loading annotations only would speed up our analysis by a large margin, however, I understand if this is a low priority fix.
agramfort commentedon Sep 11, 2018
massich commentedon Sep 11, 2018
@bdyetton I don't think is a low priority fix. It is actually on the top of my list. I'll be happy to help. And if you can share some data and we make an example out of it, it would be awesome.
plus, we will need code reviews when we tackle it.
bdyetton commentedon Sep 12, 2018
Great, I'll gather up a few edf+ and edf++ files for you.
bdyetton commentedon Sep 17, 2018
Here ya go:
https://drive.google.com/open?id=186eklftvEB2FeLLxHPHUjZxe2iPvJ1f7
This a selection of EDF files from a bunch of open source sleep datasets, some are edf, others are edf+ and edf++.
agramfort commentedon Sep 18, 2018
massich commentedon Feb 13, 2019
@bdyetton have you checked #5718 #5699 and what this test is doing?
mne-python/mne/io/edf/tests/test_edf.py
Lines 273 to 278 in 1e53204
at this point
mne-python/mastershould be able to do what you need.I'm closing this issue, if there's anything that does not work feel free to reopen or open a new one.
abraar-raza commentedon Jan 25, 2024
Hi, I'm a bit confused about how this problem was solved? How would I read annotations without having to load the entire file in memory? Thanks!
cbrnr commentedon Jan 25, 2024
You can use
mne.read_annotations().abraar-raza commentedon Jan 25, 2024
Hey, thanks for replying! I did use this function but it still ends up loading the entire EDF file to RAM?
cbrnr commentedon Jan 25, 2024
Seems like there could be a bug with our loaders, I've started a discussion in #12386 (not specifically about reading annotations, but the EDF reader already seems to consume too much memory).