"fix_stim_artifacts" after "peak_finder"

Hi, thank you all very much for the support here!

I have MEG data contaminated with spiky artifacts from a neural stimulation device. I want to use “fix_stim_artifacts” to cut and interpolate these noisy spikes. I understand that I need to give the function the events to work on (“events = …”). I am working on a raw file (continuous data) and assume these events are the actual spikes. Am I correct? To find these “events,” I am using the EOG channel, as the spikes are seen there pretty clearly. I was able to detect all spikes from the EOG channel using “peak_finder” → I got a one-dimensional array of the indices of the spikes maximum.
Then, I generated my own event array (n_spikes * 3, where the two other columns contain zeros). I pass this events array to “fix_stim_artifacts”, but for some reason - I get the interpolation away from the actual spikes. Can you please explain what I am doing wrong? please see code below. Thank you!

CODE:

rr = mne.io.read_raw_fif(aa)
rr.copy().pick(‘BIO001’).plot()
xx = rr.copy().pick(‘BIO001’).get_data()
xx = np.squeeze(xx)
peak_locs, peak_mags = mne.preprocessing.peak_finder(xx)
Fs = rr.info[‘sfreq’]
t = np.arange(0, len(xx), 1)/Fs

#here, i am plotting a spike i found, to make sure it is detected
a = 281;
b = 281.6;
plt.plot(t,xx)
plt.xlim(a,b)
plt.plot(t[peak_locs],np.max(xx)*np.ones(np.size(peak_locs)),‘bo’)
plt.xlim(a,b)
plt.show()

here, I am making the “events array” for the spikes

ss = (len(peak_locs),3)
z1 = np.zeros(ss)
z1[:,0] = peak_locs

yo = mne.preprocessing.fix_stim_artifact(rr.copy().load_data(), events=z1, event_id=None, tmin=-0.05, tmax=0.05, mode=‘linear’, stim_channel=None, picks=“BIO001”)

here, I plot once again to see if the spike has been removed

yy = yo.copy().pick(‘BIO001’).get_data()
yy = np.squeeze(yy)
plt.plot(t,yy)
plt.xlim(a,b)
plt.plot(t[peak_locs],np.max(yy)*np.ones(np.size(peak_locs)),‘bo’)
plt.xlim(a,b)
plt.show()

  • MNE version: 1.6.0
  • operating system: Windows 10