Skip to content

plot_events throws ValueError if event_id contains additional entries #6905

Closed

Description

@AKMeunier

mne.viz.plot_events(events, event_id=event_id) produces

ValueError: 17 from event_id is not present in events.

Is it possible to make this only a warning and let the code run through? In my experiments the stimuli are letters and not all letters are present in every session, and it is very tiresome creating a specific filtered event dict for every session.

Activity

  1. agramfort commented on Oct 3, 2019

    @agramfort
    SponsorMember
  2. larsoner commented on Oct 3, 2019

    @larsoner
    Member

    It would be good to replicate the Epochs(..., on_missing=...) API here

  3. rderollepot commented on Jul 17, 2020

    @rderollepot
    Contributor

    Any news on this issue ?

    If not, I can try to work on it as I am confronted with this problem too.

  4. larsoner commented on Jul 17, 2020

    @larsoner
    Member

    Nobody has worked on it as far as I know @rderollepot, feel free to give it a shot!

  5. added this to the 0.21 milestone on Jul 17, 2020
  6. rderollepot commented on Jul 17, 2020

    @rderollepot
    Contributor

    Ok I will give it a try !

  7. rderollepot commented on Jul 17, 2020

    @rderollepot
    Contributor

    If you don't mind I'd like to discuss the problem a little further, but I'd like to precise I'm very new to MNE and I'm using it to treat fNIRS data (working with @swy7ch), so I might be missing a big part of the iceberg 😉

    First of all, in this part of the code, event_id is optional and its purpose is to add a legend to the plot if provided by the user (according to the function docstring).

    The following piece of code (pointed out by the present issue) throw an error if you try to give a description in the legend to events that are not present in the dataset.

            for this_event in unique_events_id:
                if this_event not in unique_events:
                    raise ValueError('%s from event_id is not present in events.'
                                     % this_event)
    

    It seems to me that it should clearly not throw an error because here, event_id just contains more information than required for this optional functionality. I wonder if this should even be a warning ? If we throw a warning, the purpose seems to be:

    Hey, are you sure your dataset is good, you don't seem to have all the events you want to describe ?

    But is it the purpose of this optional functionality, in a plot function ? I'm not sure, and my preference goes to just skipping the unnecessary information. We would need however to filter unique_events_id so it only contains event IDs present in the dataset to avoid having blank lines on the plot.


    It seems to me that the piece of code coming just after is also problematic (should I open another issue ?):

            for this_event in unique_events:
                if this_event not in unique_events_id:
                    warn('event %s missing from event_id will be ignored'
                         % this_event)
    

    It is realized here that information is missing to completely update the legend and it is decided to ignore events that would have no entries in it. Thus, adding this optional parameters change what the plot contains, and it looks like an issue, isn't it ?

    We could follow @larsoner suggestion and replicate the Epochs(..., on_missing=...) API to solve it, but I'm not sure what to do if the user select warning/ignore ? Partially update the legend, so we have legend entries following event_label = '%s (%s)' % (event_id_rev[ev], count) and others following event_label = 'N=%d' % (count,) ?

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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions