Removing high amplitude epoch from EEG

  • MNE version: e.g. 0.24.0
  • EEG system: mBrainTrain smarting Mobi with 24 EEG electrodes and 2 miscellaneous ones (M1, M2)
  • operating system: Windows 10

Dear MNE community,

I’m cleaning my EEG data and found this chunk of data with exceptional high amplitude. How do I remove this epoch?

Thanks

Also, I tried using the annotate amplitude code which is producing a blank in this case and not helping the results:

annotations, bads = mne.preprocessing.annotate_amplitude(raw1, peak=100e-6, picks = 'eeg', bad_percent=5, min_duration=0.005)
Finding segments below or above PTP threshold.
bads
[]

Hi Bilal,

I had a similar experience … the reason is that the function only looks for peak-to-peak in consecutive samples as mentioned in the fine print. What you need is a function that finds peak-to-peak in a longer time window. Your best bet is to provide a rejection threshold during epoching. You can use get_rejection_threshold function in autoreject to make your life a little simpler.

However, if you cannot work with epoched data, you may find this function I wrote with a collaborator useful. This is a bit buggy, so please check carefully before using … I haven’t found the time to fix the bugs. If you do manage to fix the edge cases, do share the code!

Hope this helps,
Mainak

I think we should have a way to annotate using a rolling peak to peak estimator. You provide
the window length and then you double its length to build the annotations.

Alex

1 Like

Hi Mainak,

Thank you for the help!

I tried using the code you provided - it worked like a charm in my case (at least), not sure about other edge cases. Although one needs to chose hyper-parameters carefully. But I just have one more question, now that I have annotated the bad segments, how do I reject them?

I’m sorry if its a silly question. I don’t have much prior experience working with raw EEG data.

Thanks

could we get a PR for this feature? It seems very useful

A

Hi Alexandre,

Pardon my ignorance, could you explain what PR is?

Thanks

Segments annotated as anything starting with “BAD_” will be automatically ignored by MNE in all subsequent processing steps (filtering, epoching etc) so there’s nothing more you need to do!

PR means pull request — Alex was asking whether you could contribute the code you used to get those annotations to MNE-Python via a GitHub Pull Request :blush:

Best wishes,
Richard

Hi @richard,

Thank you for the explanation.

So, I understand that while the segment is marked as ‘BAD_’, mne won’t process that segment. But my question/problem is when I am extracting data from ‘raw’ into a numpy array that annotated data is also getting extracted.
So is there a way to either extract data without the annotated segment or to completely reject (or delete) the annotated segment?

Thanks

Yes, you can use the reject_by_annotation parameter of raw.get_data() to control this behavior.

Best wishes,
Richard

It’s on my todo but I will likely not get to it soon enough. If anyone else wants to take the initiative, please feel free to create a PR. A feature in autoreject to export the reject log as an annotation is also needed …

Mainak

Thanks everyone so much,

Just a last question on this: Is there a way to crop/trim/chuck out a particular segment, say from t=3 to t=5 seconds without using annotation?

Thanks again!

Hi Bilal,

You can manually create an annotation by directly using the Annotation class: https://mne.tools/stable/generated/mne.Annotations.html

The other alternative is to crop and concatenate which is likely to be more error-prone and laborious:

https://mne.tools/stable/generated/mne.io.Raw.html#mne.io.Raw.crop
https://mne.tools/stable/generated/mne.concatenate_raws.html

Hope that helps!
Mainak

Thanks a lot Mainak.