Doing peak to peak rejection with a time step

Hello,

I am very new to MNE python and EEG data analysis, and I hoped someone could help me with a bit of my preprocessing pipeline that I cannot figure out how to do. I am trying to replicate the analysis used in a paper that mentions: “After first epoching the data from -1000 to 2000 ms relative to target onset, and performing a baseline correction using a 200 ms pre-target baseline interval, we rejected data that exceeded a peak-to-peak threshold of 70 μV (in 100 ms steps)”. So, I have figured out that I could make my epochs with something like the bit of code below. But I am missing the “in 100ms steps” here, and the peak to peak rejection is applied to the whole duration of the epochs, rejecting almost all of them. I see there is a rejection_tmin and rejection_tmax argument that could be useful here, but I do not see how to use it in a way to make a 100ms step.

tmin = -1
tmax = 2
baseline = (-0.2, 0)
reject = dict(eeg=70e-6)

epochs = mne.Epochs(raw, events, event_id, tmin, tmax, proj=True, baseline=baseline, reject=reject)

Best regards,
r.lamarque

  • MNE version: 1.4.2
  • operating system: Windows 11

You could solve this by working with a loop, creating epochs repeatedly with different reject_tmin and reject_tmax arguments, and seeing which epochs get rejected, and then concatenating that information for use with your final epochs.

Below some pseudocode (it will need adjustments, I did not run it, but it is showing you the concept):

tmin = -1
tmax = 2
baseline = (-0.2, 0)
reject = dict(eeg=70e-6)

epo_kwargs = dict(
    raw=raw,
    events=events,
    event_id=event_id,
    tmin=tmin,
    tmax=tmax,
    proj=True,
    baseline=baseline,
    reject=reject
)

step = 0.1
dropped = []
for t in range(tmin, tmax+step, step):
    epochs = mne.Epochs(reject_tmin=t, reject_tmax=t+step, **epo_kwargs)
    dropped.extend(list(epochs.drop_log))
    del epochs


del epo_kwargs["reject"]  # no rejection needed anymore
my_final_epochs = mne.Epochs(**epo_kwargs)

# Use information from the "dropped" variable that we built
to_drop = set(dropped)  # remove duplicates
my_final_epochs.drop(to_drop, reason="peak-to-peak")

Or you could build your own function using epochs.get_data() and numpy.ptp — NumPy v2.1 Manual