@@ -184,6 +184,12 @@ def merge(epoch_S1: mne.Epochs, epoch_S2: mne.Epochs) -> mne.Epochs:
184184
185185 merges = []
186186
187+ # Verify both epochs have same filter settings
188+ if (epoch_S1 .info ['highpass' ] != epoch_S2 .info ['highpass' ] or
189+ epoch_S1 .info ['lowpass' ] != epoch_S2 .info ['lowpass' ]):
190+ import warnings
191+ warnings .warn ("Filter settings differ between participants. Using S1 settings." )
192+
187193 # checking wether data have the same size
188194 assert (len (epoch_S1 ) == len (epoch_S2 )
189195 ), "Epochs from S1 and S2 should have the same size!"
@@ -210,10 +216,23 @@ def merge(epoch_S1: mne.Epochs, epoch_S2: mne.Epochs) -> mne.Epochs:
210216
211217 merged = np .array (merges )
212218 ch_names_merged = ch_names1 + ch_names2
213- info = mne .create_info (ch_names_merged , sfreq , ch_types = 'eeg' ,
214- verbose = None )
219+
220+ # Create info object with filter information preserved
221+ info = mne .create_info (ch_names_merged , sfreq , ch_types = 'eeg' , verbose = None )
222+
223+ # Also preserve other relevant metadata
224+ if 'description' in epoch_S1 .info :
225+ info ['description' ] = epoch_S1 .info ['description' ]
226+ elif 'description' in epoch_S2 .info :
227+ info ['description' ] = epoch_S2 .info ['description' ]
228+
215229 ep_hyper = mne .EpochsArray (merged , info )
216230
231+ # Preserve filter information from source epochs
232+ with ep_hyper .info ._unlock ():
233+ ep_hyper .info ['highpass' ] = epoch_S1 .info ['highpass' ]
234+ ep_hyper .info ['lowpass' ] = epoch_S1 .info ['lowpass' ]
235+
217236 # setting channels type
218237 EOG_ch = []
219238 for ch in epoch_S1 .info ['chs' ]:
@@ -222,14 +241,10 @@ def merge(epoch_S1: mne.Epochs, epoch_S2: mne.Epochs) -> mne.Epochs:
222241
223242 for ch in ep_hyper .info ['chs' ]:
224243 if ch ['ch_name' ].split ('_' )[0 ] in EOG_ch :
225- # print('emg')
226244 ch ['kind' ] = FIFF .FIFFV_EOG_CH
227245 else :
228246 ch ['kind' ] = FIFF .FIFFV_EEG_CH
229247
230- # info about task
231- ep_hyper .info ['description' ] = epoch_S1 [0 ].info ['description' ]
232-
233248 return ep_hyper
234249
235250
0 commit comments