SSP artifacts correction excluding annotated bad epochs

Hello everyone,

I am trying to use SSP to correct the slow drift below 0.5 Hz. Ideally the epochs annotated as “bad” should be excluded from SSP procedure. Does anyone have an idea how to make the SSP “annotation aware”?

Best,
Meng

  • MNE version: e.g. 1.6.0
  • operating system: e.g. Ubuntu 22.04.3
sub_id='C08'
os.chdir("/home/user/Desktop/MEEG/"+sub_id)
#% read raw fif file,delete bad channels
fname=sub_id+'_P1'
raw=mne.io.read_raw_fif(fname+'.fif',preload=True)
# raw.plot() # check bad EEG ch´annels´
raw=eeg_montage(raw=raw)
# if there is a txt file listing all bad channels, run this part. Or else, do bad channels first and coyp them to the txt file
chs_drop=[]
with open('bad_ch_meeg.txt','r') as f:
ch_bad=f.readlines()
for ch in ch_bad:
chs_drop.append(ch.strip('\n'))
raw.drop_channels(chs_drop)
new_annotations = mne.read_annotations('/home/user/Desktop/MEEG/C08/C08_p1_raw-annot.fif')
raw.set_annotations(new_annotations)
#%% ssp correction for the slow drift
rawlow = copy.deepcopy(raw)
rawlow.filter(l_freq=None,h_freq=0.5)
art_proj = mne.compute_proj_raw(rawlow,n_grad=6,n_eeg=0)
mne.viz.plot_projs_topomap(art_proj, info=[rawlow.info](http://rawlow.info/))
raw.add_proj(art_proj).