Issue with raw.add_channels()

,

MNE version: e.g. 1.4.2
Operating system: CentOS Linux 7 (Core)

Hi, I’m using PREP to preprocess some EEG data. I’m trying to add the EOG channels back to the EEG data post-PREP, but add_channels() doesn’t seem to be working

prep = PrepPipeline(
    raw,
    prep_params,
    raw.get_montage(),
    ransac = False,
    random_state = int(sub)
    )
prep = prep.fit()
raw_prep = prep.raw_eeg # retrieve eeg data from prep
raw_non_eeg = prep.raw_non_eeg # retrieve the eog channels
raw_prep = raw_prep.add_channels([raw_non_eeg], force_update_info=True) # combine eeg and eog channels

If I print out the information for raw, the output shows there are 62 EEG, 2 EOG, 1 Stimulus channels. When I print out the information for raw_non_eeg, I’m told there are 2 EOG, 1 Stimulus. When I print out the information for raw_prep, I only have 62 EEG channels, there are no EOG channels. It seems that add_channels() isn’t combining the raw data objects properly. Does anyone have any advice?

Short of a better solution, in case anyone runs into the same issue, I managed to solve the problem the naive way. I extracted the data and info from the Prep object and created a new Raw object and it seems to work. You might have to edit the raw_info object to make sure the channels are in the correct order (code not shown). Open to other suggestions though!

prep_eeg = prep.raw_eeg.get_data() # get data for EEG channels from PREP
prep_non_eeg = prep.raw_non_eeg.get_data() # get data for non-EEG channels from PREP
raw_data = np.concatenate((prep_eeg, prep_non_eeg)) # combine the two
raw_info = raw.info # copy info from original raw data object
raw = mne.io.RawArray(raw_data, raw_info) # replace original raw object

Hello,

I’m not sure what might be going wrong here. Your code snippet looks OK. For comparison, this is working on my side:

from mne.datasets import sample
from mne.io import read_raw_fif


directory = sample.data_path() / "MEG" / "sample"
raw = read_raw_fif(directory / "sample_audvis_raw.fif", preload=False)
raw_eog = raw.copy().pick("eog").load_data()
raw_eeg = raw.pick("eeg").load_data()
assert "eeg" not in raw_eog
assert "eog" not in raw_eeg
raw_eeg.add_channels([raw_eog], force_update_info=True)
assert "eog" in raw_eeg

Mathieu