ica.apply for MEG and EEG

Dear mne python users,

I am trying to take out eog artifacts using mne python artifact
correction with ICA. I do ICA on raw data that has both EEG and MEG
data. I first pick MEG ch., do ICA on them (ica.fit where 'picks' has
meg only) and find components to reject. Then I want to apply ICA
solution to the MEG part of data and move onto EEG.

I am doing it like so:

raw_meg_iced=ica.apply(raw, exclude=some_components) #some_components =
artifact components

picks_eeg=mne.pick_types(raw_meg_iced.info, meg=False, eeg=True,
eog=False, stim=False, exclude='bads')

ica.fit(raw_meg_iced, picks=picks_eeg) # and so on ...

I was wondering if I am doing the right thing by doing ica.apply on the
whole raw object? Presumably, since I identify components from meg data
first, I want to apply ica to meg data only? But ica.apply doesn't have
'picks' function. The two functions that perform signal reconstruction
(_apply_raw and _pick_sources) seem to reconstruct the data from the pca
components derived from what was ica-ed - i.e the meg data in the first
instance. Yet the resulting raw_meg_icaed object still has original EEG
data and I can pick and ICA it subsequently. I can't figure out how it
knows to keep it in. Clearly I am missing something here.

Thanks a lot for your help,
Ana

Hi Ana,

ICA should be smart enough to figure out which channels it applies to.
The important thing is that you fit it twice, cone for MEG and once for EEG.
The workflow then is to apply them sequentially to your raw object.
I am not sure if we have an example that shows this.
We'll check that and add it if it doesn't exist.
Thanks for bringing this up!

Denis

Hi Denis,

Thanks for replying. Yes, I couldn't find an example of MEG and EEG
sequential ICA workflow on the website and it would be very useful.

Do I conclude correctly then, from what you said, that my approach (the
lines of code I forwarded) is correct? I guess I can save some space by
not creating a new object (raw_meg_iced=ica.apply(raw,
exclude=some_components)) and continue EEG ica directly on raw as you
suggest. But both should do the same thing.

Thanks again,
Ana

Yes, that is correct. But I'd suggest that you just fit twice on the same
object and keep the apply step separated. It's conceptually cleaner and
does not force you to save ica'd data to disk. I'd rather save 2 ICA
solutions to disk and load + apply them sequentially (order doe not even
matter in this case).
I'll open an issue on github to track this gap in our docs.

Cheers,
Denis