Skip to content

ENH: Annotations.sort #5854

Closed
Closed

Description

@larsoner

Sort annotations based on onset. Should return self for consistency.

Activity

  1. added this to the 0.18 milestone on Jan 22, 2019
  2. massich commented on Jan 23, 2019

    @massich
    Contributor

    If we have a sorting method, we should used in places like this (there are more):

    mne-python/mne/viz/utils.py

    Lines 1913 to 1914 in e96d706

    ann_order = raw.annotations.onset.argsort(axis=0)
    descriptions = raw.annotations.description[ann_order]

    The other option it would be to actually keep annotations always sorted by onset, and use numpy.searchsorted in append and _combine_annotations

  3. mmagnuski commented on Jan 24, 2019

    @mmagnuski
    Member

    I'd be +1 for always sorting, but I'm also ok with annotations.sort().

  4. agramfort commented on Jan 25, 2019

    @agramfort
    SponsorMember
  5. larsoner commented on Jan 25, 2019

    @larsoner
    MemberAuthor

    If we do this, then we should make sure there is extend in addition to append. I automate annotation of infant data, marking segments of fast movement as bad. There can be thousands of tiny segments like this per file, and so calling sort over and over again will incur a worsening penalty as the number grows. (Though using searchsorted with assume_sorted=True might be reasonable.)

    We could also add a sort=True kwarg but this seems less clean than just always sorting and adding an extend method, if we don't have it.

  6. cbrnr commented on Jan 25, 2019

    @cbrnr
    Contributor

    +1 for always sorting and adding an extend method. As tie breakers I suggest that we use description and then duration.

  7. larsoner commented on Jan 29, 2019

    @larsoner
    MemberAuthor

    It looks like append already has extend-like behavior, so we can just update the docstring.

  8. self-assigned this
    on Feb 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions