Skip to content

DOC: time of events and first_samp #5201

Closed

Description

@pdeman

hi,

how can i plot the events on top of the eeg versus time plot ?
i found the events/versus sample using find events. but when i divide versus the sampling rate i don't have at all the same values in time than the eeg. there must be an offset.
I'ld like to plot some eeg data with the "events" on top of it.

regards

Activity

  1. agramfort commented on May 12, 2018

    @agramfort
    SponsorMember
  2. jona-sassenhagen commented on May 12, 2018

    @jona-sassenhagen
    Contributor

    but don't resample raw after finding the evens otherwise they won't match.

    To be precise, we recommend

    raw, events = raw.resample(new_sfreq, events=events)

  3. pdeman commented on May 12, 2018

    @pdeman
    Author

    Thanks but in this particular case I don't plot using mne.
    I would need to find the time for raws recording and time for events in the same unit.

  4. agramfort commented on May 13, 2018

    @agramfort
    SponsorMember
  5. pdeman commented on May 13, 2018

    @pdeman
    Author

    ok thanks

  6. larsoner commented on May 13, 2018

    @larsoner
    Member

    At some point we should add a tutorial that discusses:

    1. find_events, with event masking
    2. events column values
    3. raw.first_samp, what it is, how it changes with .crop, how to get event times relative to the start of the instance
    4. Annotations and orig_time

    I'll re-open and re-title this issue so we do this at some point.

  7. changed the title [-]plot events on top of eeg[/-] [+]DOC: time of events and first_samp[/+] on May 13, 2018
  8. added this to the 0.17 milestone on May 13, 2018
  9. larsoner commented on Oct 4, 2018

    @larsoner
    Member

    @massich you have been working on these things quite a bit recently, could you make a plot_timing.py tutorial or something similar to cover these topics in the next two weeks to make it into 0.17?

  10. massich commented on Oct 4, 2018

    @massich
    Contributor

    yes

  11. larsoner commented on Nov 5, 2018

    @larsoner
    Member

    Moving to 0.18, not a blocker

  12. modified the milestones: 0.17, 0.18 on Nov 5, 2018
  13. massich commented on Nov 9, 2018

    @massich
    Contributor

    Regarding the events and masking, there are several things I don't understand.

    See this:

    import os.path as op
    import numpy as np
    
    import mne
    
    # load the data
    data_path = mne.datasets.sample.data_path()
    fname = op.join(data_path, 'MEG', 'sample', 'sample_audvis_raw.fif')
    raw = mne.io.read_raw_fif(fname)
    
    events = mne.find_events(raw)
    
    [print('{0:3d} --> {0:{fill}8b}'.format(id, fill='0')) for id in np.unique(events[:,2])]
      1 --> 00000001
      2 --> 00000010
      3 --> 00000011
      4 --> 00000100
      5 --> 00000101
     32 --> 00100000

    If the events, are binary mapped events then 3 should not be visual/left but both audios. (but I guess, that this depends on the vendor and this vendor they are not independent bits).

    Then if I do this, this works.

    events = mne.find_events(raw, mask=258)

    So far so good.

    But this breaks:

    In [32]: %paste
    import os.path as op
    import numpy as np
    
    import mne
    
    # load the data
    data_path = mne.datasets.sample.data_path()
    fname = op.join(data_path, 'MEG', 'sample', 'sample_audvis_raw.fif')
    raw = mne.io.read_raw_fif(fname)
    
    event_id = {'Auditory/Left': 1, 'Auditory/Right': 2,
                'Visual/Left': 3, 'Visual/Right': 4,
                'smiley': 5, 'button': 32}
    color = {1: 'green', 2: 'yellow', 3: 'red', 4: 'c', 5: 'black', 32: 'blue'}
    
    mne.viz.plot_events(mne.find_events(raw,mask=3), raw.info['sfreq'], raw.first_samp, color=color, event_id=event_id)
    ## -- End pasted text --
    Traceback (most recent call last):
      File "<ipython-input-32-2c850fa9ff7f>", line 16, in <module>
        mne.viz.plot_events(mne.find_events(raw,mask=3), raw.info['sfreq'], raw.first_samp, color=color, event_id=event_id)
      File "/home/sik/code/mne-python/mne/viz/misc.py", line 504, in plot_events
        % this_event)
    ValueError: 4 from event_id is not present in events.
  14. massich commented on Nov 9, 2018

    @massich
    Contributor

    @larsoner are all these the things you were referring when you were talking about event columns and masking? in points 1 and 2?

  15. larsoner commented on Nov 9, 2018

    @larsoner
    Member

    They seem related yes. mask is a binary mask (behavior dependent on what mask_type is) and the resulting events[:, 2] are the detected event numbers.

    The error you hit is because you supplied an event_id that is not in the events that you supplied. In theory we should have an option to handle this the same way we do with on_missing in Epochs.

  16. agramfort commented on Nov 9, 2018

    @agramfort
    SponsorMember
  17. removed this from the 0.18 milestone on May 13, 2019
  18. larsoner commented on May 13, 2019

    @larsoner
    Member

    @drammock can you see if this is taken care of yet, and if not, add to the documentation todo?

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

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions