External Email - Use Caution
Colleagues,
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
plt.switch_backend('TkAgg')
plt.ion()
raw = mn.io.read_raw_edf("/Users/fishbacp/data.edf", preload=True)
Fs=raw.info['sfreq']
data,times=raw[:,:]
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
https://stackoverflow.com/questions/62921389/the-most-efficient-way-to-delete-columns-of-a-matrix-based-upon-lists-of-startin/62923354#62923354
.
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)))
data_new=data[:,saved_cols]
A big thank you to the individual who provided assistance.
Best,
Paul Fishback