[Mne_analysis] Updating raw data matrix based upon visual annotations

Paul Fishback fishbacp at mail.gvsu.edu
Wed Jul 15 17:00:30 EDT 2020
Search archives:

        External Email - Use Caution        


My work is primarily done outside MNE, with the exception of reading in EDF
data and performing basic filtering. Yesterday I submitted a question to
the moderator and received a very helpful answer, which I was encouraged to
share with others.

The problem is essentially as follows:

Suppose I read in my EDF into a raw structure and visually annotate the
data plot. Once I perform the annotations, is there a way to obtain the
revised data matrix which is the original one with the annotations removed.
Here's a synopsis of how to do so, where all work was done on a MAC with
OSX 10.15.4, using IDLE and Python 3.7.

import mne as mn
import matplotlib.pyplot as plt

raw = mn.io.read_raw_edf("/Users/fishbacp/data.edf", preload=True)

raw.plot(block=True)   #At this stage we annotate our data visually. Once
the plot window is closed, all annotation data is saved in raw.annotations.

starts=[int(t*Fs) for t in raw.annotations.onset]      #The annotation
start times converted to indices using the sampling frequencies
lengths=[int(t*Fs) for t in raw.annotations.duration]     #The annotation
durations converted to indices.

#Now remove from data those columns determined by the starts and lengths
just computed. There are various means of doing so as discussed at

Here's one way, where the result is stored in data_new:

cols = list(range(data.shape[1]))
remove = []
for i, s in enumerate(starts):
    remove += range(s, s+lengths[i])
saved_cols = list(set(cols).difference(set(remove)))

A big thank you to the individual who provided assistance.


Paul Fishback
Professor of Mathematics, Grand Valley State University
Department of Mathematics (MAK C-2-408)
Grand Valley State University
1 Campus Dr.
Allendale, MI 49401
fishbacp at mail.gvsu.edu
616.331.3120 (fax)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20200715/eaced9d0/attachment.html 

More information about the Mne_analysis mailing list