Skip to content

Extracting EDF+ annotations  #4494

Closed
Closed

Description

@sbang002

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)

Activity

  1. teonbrooks commented on Aug 17, 2017

    @teonbrooks
    Member

    given the way the annotations are constructed, the file must be loaded in order to pull off the annotations.

  2. agramfort commented on Aug 17, 2017

    @agramfort
    SponsorMember
  3. cbrnr commented on Nov 22, 2017

    @cbrnr
    Contributor

    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.

  4. larsoner commented on Nov 22, 2017

    @larsoner
    Member

    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.

  5. cbrnr commented on Nov 22, 2017

    @cbrnr
    Contributor

    Can't we set the exclude argument accordingly to only load the stim channel?

  6. larsoner commented on Nov 22, 2017

    @larsoner
    Member

    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.

  7. cbrnr commented on Nov 22, 2017

    @cbrnr
    Contributor

    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.

  8. larsoner commented on Nov 22, 2017

    @larsoner
    Member

    I assumed that this issue was opened because it was problematic. Can you explain why preload=True is bad for you @sbang002 ?

  9. bdyetton commented on Sep 11, 2018

    @bdyetton

    @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.

  10. agramfort commented on Sep 11, 2018

    @agramfort
    SponsorMember
  11. massich commented on Sep 11, 2018

    @massich
    Contributor

    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.

  12. bdyetton commented on Sep 12, 2018

    @bdyetton

    Great, I'll gather up a few edf+ and edf++ files for you.

  13. bdyetton commented on Sep 17, 2018

    @bdyetton

    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++.

  14. agramfort commented on Sep 18, 2018

    @agramfort
    SponsorMember
  15. massich commented on Feb 13, 2019

    @massich
    Contributor

    @bdyetton have you checked #5718 #5699 and what this test is doing?

    @testing.requires_testing_data
    @pytest.mark.parametrize('fname', [test_generator_edf, test_generator_bdf])
    def test_read_annotations(fname, recwarn):
    """Test IO of annotations from edf and bdf files via regexp."""
    annot = read_annotations(fname)
    assert len(annot.onset) == 2

    at this point mne-python/master should 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.

  16. abraar-raza commented on Jan 25, 2024

    @abraar-raza

    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!

  17. cbrnr commented on Jan 25, 2024

    @cbrnr
    Contributor
  18. abraar-raza commented on Jan 25, 2024

    @abraar-raza

    You can use mne.read_annotations().

    Hey, thanks for replying! I did use this function but it still ends up loading the entire EDF file to RAM?

  19. cbrnr commented on Jan 25, 2024

    @cbrnr
    Contributor

    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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions