Skip to content

Add metadata to Annotations #13199

Closed
Closed

Description

@PierreGtch

Describe the new feature or enhancement

The raw.annotations attribute holds information regarding the events happening in a row file.
However, this information is limited: we only have the onset, a string description and the duration of the events. For some tasks, other information could be useful to have; for example: response time, stimulation parameters, etc.

Moreover, the BIDS format supports arbitrary annotations of the events, but only the onset, description and duration can be saved in the mne.Annotations objects.

The mne.Epochs support arbitrary event information through the metadata attribute, but in the standard processing raw->epochs, the user has to handle the metadata on the side, then include it to the epochs.

Describe your proposed implementation

I propose to add a metadata attribute to the mne.Annotations class, with type None | pd.DataFrame.
When creating epochs, this new field should automatically populate the epochs.metadata attribute.

Describe possible alternatives

Possible alternative when doing a standard processing raw->epochs is to:

  • load the raw objects
  • load the additional event information on the side (metadata)
  • create the epochs
  • filter and reorder the metadata rows such they match the created epochs
  • set the epochs.metadata attribute

Additional context

This issue is related to mne-tools/mne-bids#1389

@drammock what do you think?

CC @matthiasdold

Activity

  1. sappelhoff commented on Apr 10, 2025

    @sappelhoff
    Member
  2. agramfort commented on Apr 19, 2025

    @agramfort
    SponsorMember

    @PierreGtch do you know about epochs metadata ? https://mne.tools/stable/auto_tutorials/epochs/30_epochs_metadata.html

    one challenge is to make sure the object can be serialized in fif for saving.

  3. PierreGtch commented on Apr 19, 2025

    @PierreGtch
    ContributorAuthor

    @agramfort Yes that's the whole point!
    When you create epochs, you have to somehow align your additional information columns with the epochs and manually set the epochs' metadata.
    This could be handled automatically if the annotations had a metadata attribute :)

  4. agramfort commented on Apr 22, 2025

    @agramfort
    SponsorMember
  5. PierreGtch commented on Apr 22, 2025

    @PierreGtch
    ContributorAuthor

    Thanks for your input!
    Option1 could streamline the code I think
    But I started something like option2 in #13213. However, I made the dependency to pandas optional using lazy imports only when the metadata is provided. My implementation is similar to what we have for the epochs' metadata attribute. I also updated the CSV and txt readers and savers to handle the metadata

  6. bruAristimunha commented on Feb 6, 2026

    @bruAristimunha
    Contributor

    I think Pierre has completed this issue, no?

  7. larsoner commented on Feb 9, 2026

    @larsoner
    Member

    Yeah looks like it was taken care of in #13228

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions