plt.show() # now the affected channel affected_idx = raw.ch_names.index('MEG 1531') plt.figure() plt.plot(times, data[affected_idx], color='r') plt.plot(times, data_clean[affected_idx], color='k') plt.xlim(100, 106) plt.show() ############################################################################### # Validation: check ECG components extracted # Export ICA as Raw object for subsequent processing steps in ICA space. ica_raw = ica.sources_as_raw(raw, start=100., stop=160., picks=None) from mne.preprocessing import find_ecg_events # find ECG events event_id = 999 events, _, _ = find_ecg_events(raw, ch_name='MEG 1531', event_id=event_id, l_freq=8, h_freq=16) # pick components, create epochs and evoked in ICA space ica_picks = np.arange(ica.n_components_) ica_raw.info['bads'] = [] # selected components are exported as bad channels
pl.title('Affected channel MEG 1531 before cleaning.') y0, y1 = pl.ylim() # plot the component that correlates most with the ECG pl.figure() pl.plot(times, data_clean[affected_idx]) pl.title('Affected channel MEG 1531 after cleaning.') pl.ylim(y0, y1) pl.show() ############################################################################### # Export ICA as raw for subsequent processing steps in ICA space. from mne.layouts import make_grid_layout ica_raw = ica.sources_as_raw(raw, start=start, stop=stop, picks=None) print ica_raw.ch_names ica_lout = make_grid_layout(ica_raw.info) # Uncomment the following two lines to save sources and layout. # ica_raw.save('ica_raw.fif') # ica_lout.save(os.path.join(os.environ['HOME'], '.mne/lout/ica.lout')) ################################################################################ # To save an ICA session you can say: # ica.save('my_ica.fif') # # You can later restore the session by saying: # >>> from mne.preprocessing import read_ica
plt.title('Affected channel MEG 1531 before cleaning.') y0, y1 = plt.ylim() # plot the component that correlates most with the ECG plt.figure() plt.plot(times, data_clean[affected_idx], color='k') plt.title('Affected channel MEG 1531 after cleaning.') plt.ylim(y0, y1) plt.show() ############################################################################### # Export ICA as raw for subsequent processing steps in ICA space. from mne.layouts import make_grid_layout ica_raw = ica.sources_as_raw(raw, start=100., stop=160., picks=None) print ica_raw.ch_names[:5] # just a few ica_lout = make_grid_layout(ica_raw.info) # Uncomment the following two lines to save sources and layout. # ica_raw.save('ica_raw.fif') # ica_lout.save(os.path.join(os.environ['HOME'], '.mne/lout/ica.lout')) ############################################################################### # To save an ICA session you can say: # ica.save('my_ica.fif') # # You can later restore the session by saying: # >>> from mne.preprocessing import read_ica