@@ -115,7 +115,11 @@ def add_flag_cat(self, kind, bad_ch_names, *args):
115115 logger .debug (f"NEW BAD CHANNELS { bad_ch_names } " )
116116 if isinstance (bad_ch_names , xr .DataArray ):
117117 bad_ch_names = bad_ch_names .values
118- self [kind ] = bad_ch_names
118+ if kind in self :
119+ self [kind ] = list (np .unique (np .concatenate ((self [kind ], bad_ch_names ))))
120+ else :
121+ self [kind ] = bad_ch_names
122+
119123
120124 def get_flagged (self ):
121125 """Return a list of channels flagged by the lossless pipeline."""
@@ -138,9 +142,12 @@ def rereference(self, inst, **kwargs):
138142 """
139143 # Concatenate and remove duplicates
140144 bad_chs = list (
141- set (self .ll .find_outlier_chs (inst ) + self .get_flagged () + inst .info ["bads" ])
145+ set (self .ll .find_outlier_chs (inst , picks = "eeg" ) +
146+ self .get_flagged () +
147+ inst .info ["bads" ])
142148 )
143- ref_chans = [ch for ch in inst .copy ().pick ("eeg" ).ch_names if ch not in bad_chs ]
149+ ref_chans = [ch for ch in inst .copy ().pick ("eeg" ).ch_names
150+ if ch not in bad_chs ]
144151 inst .set_eeg_reference (ref_channels = ref_chans , ** kwargs )
145152
146153 def save_tsv (self , fname ):
@@ -223,7 +230,10 @@ def add_flag_cat(self, kind, bad_epoch_inds, epochs):
223230 The :class:`mne.Epochs` object created from the Raw object that is
224231 being assessed by the LosslessPipeline.
225232 """
226- self [kind ] = bad_epoch_inds
233+ if kind in self :
234+ self [kind ] = list (np .unique (np .concatenate ((self [kind ], bad_epoch_inds ))))
235+ else :
236+ self [kind ] = bad_epoch_inds
227237 self .ll .add_pylossless_annotations (bad_epoch_inds , kind , epochs )
228238
229239 def load_from_raw (self , raw , events , config ):
0 commit comments