In [1]:

    import mne
    from importlib import reload

In [2]:

    from mne.preprocessing import read_ica_eeglab
    reload(mne.preprocessing)

    raw = mne.io.read_raw_eeglab('sub-009_ses-P3_task-P3_eeg.set')
    raw.set_channel_types(mapping={'HEOG_left':'eog','HEOG_right':'eog','VEOG_lower':'eog'})

    raw.set_montage('standard_1020',match_case=False)
    badChannels = [11 ,27]
    raw.info['bads'].extend([raw.ch_names[i] for i in badChannels])  # add a list of channels

    ica = mne.preprocessing.read_ica_eeglab('sub-009_ses-P3_task-P3_ica.set')
    #ica.plot_components(0)

    Reading sub-009_ses-P3_task-P3_eeg.fdt
    <ipython-input-2-c97320ce2d67>:4: RuntimeWarning: Data file name in EEG.data (sub-009_task-P3_eeg.fdt) is incorrect, the file name must have changed on disk, using the correct file name (sub-009_ses-P3_task-P3_eeg.fdt).
      raw = mne.io.read_raw_eeglab('sub-009_ses-P3_task-P3_eeg.set')

In [3]:

    print(raw)
    print(ica)

    <RawEEGLAB | sub-009_ses-P3_task-P3_eeg.fdt, 33 x 361472 (353.0 s), ~48 kB, data not loaded>
    <ICA | epochs decomposition, fit (imported_eeglab):  samples, 28 components>

In [4]:

    #ica.set_montage('standard_1020',match_case=False) <-- doesnt work because function does not exist

    #ica.info = raw.info # <-- alex mentioned we shouldnt do that either.
    ica.plot_components(1) # <-- we get an error here because ICA is 28x28 matrix, but raw has shape 30 because the two channels were not yet removed (thus their indices go from 0-29, with 11 and 27 removed, but we cant indice a 28 matrix on position 29))

    ---------------------------------------------------------------------------
    RuntimeError                              Traceback (most recent call last)
    <ipython-input-4-92466e059971> in <module>
          2
          3 #ica.info = raw.info # <-- alex mentioned we shouldnt do that either.
    ----> 4 ica.plot_components(1) # <-- we get an error here because ICA is 28x28 matrix, but raw has shape 30 because the two channels were not yet removed (thus their indices go from 0-29, with 11 and 27 removed, but we cant indice a 28 matrix on position 29))

    /netpool/work/ccs-srv-001/users/ehinger/projects/course_eeg_WS2020/local/venv/lib/python3.8/site-packages/mne/preprocessing/ica.py in plot_components(self, picks, ch_type, res, vmin, vmax, cmap, sensors, colorbar, title, show, outlines, contours, image_interp, inst, plot_std, topomap_args, image_args, psd_args, reject, sphere)
       1802                         image_args=None, psd_args=None, reject='auto',
       1803                         sphere=None):
    -> 1804         return plot_ica_components(self, picks=picks, ch_type=ch_type,
       1805                                    res=res, vmin=vmin,
       1806                                    vmax=vmax, cmap=cmap, sensors=sensors,

    /netpool/work/ccs-srv-001/users/ehinger/projects/course_eeg_WS2020/local/venv/lib/python3.8/site-packages/mne/viz/topomap.py in plot_ica_components(ica, picks, ch_type, res, vmin, vmax, cmap, sensors, colorbar, title, show, outlines, contours, image_interp, inst, plot_std, topomap_args, image_args, psd_args, reject, sphere)
       1129
       1130     if ica.info is None:
    -> 1131         raise RuntimeError('The ICA\'s measurement info is missing. Please '
       1132                            'fit the ICA or add the corresponding info object.')
       1133

    RuntimeError: The ICA's measurement info is missing. Please fit the ICA or add the corresponding info object.

In [5]:

    # After setting ica.info = info in mne/preprocessing/ica.py
    # or after running this code:
    # assuming ica is subset of raw
    ch_raw = raw.info['ch_names']
    ch_ica = ica.ch_names

    ix = [k for k,c in enumerate(ch_raw) if c in ch_ica and not c in raw.info['bads']]

    info = raw.info.copy()
    mne.io.pick.pick_info(info, ix, copy=False)
    ica.info = info
    ica.info.set_montage('standard_1020',match_case=False)
    ica._update_ica_names()

    ica.plot_components(0)

Out[5]: