ecg_scores = ica.find_sources_raw(raw, target=ecg, score_func=score_func) # get maximum correlation index for ECG ecg_source_idx = np.abs(ecg_scores).argmax() title = 'ICA source matching ECG' ica.plot_sources_raw(raw, ecg_source_idx, title=title, stop=3.0) # let us have a look which other components resemble the ECG. # We can do this by reordering the plot by our scores using order # and generating sort indices for the sources: ecg_order = np.abs(ecg_scores).argsort()[::-1] # ascending order ica.plot_sources_raw(raw, ecg_order[:15], start=start_plot, stop=stop_plot) ica.plot_topomap(ecg_order[:15], colorbar=False) ecg_inds = np.abs(ecg_scores).argsort()[-3:] # take the first 3 components ica.exclude.extend(ecg_inds) ############################################################################### # Automatically find the EOG component using correlation with EOG signal. # As we have an EOG channel, we can use it to detect the source. eog_scores = ica.find_sources_raw(raw, target='EOG 061', score_func=score_func) # get maximum correlation index for EOG eog_source_idx = np.abs(eog_scores).argmax()
# As we have an EOG channel, we can use it to detect the source. eog_scores = ica.find_sources_raw(raw, target='EOG 061', score_func=corr) # get maximum correlation index for EOG eog_source_idx = np.abs(eog_scores).argmax() # plot the component that correlates most with the EOG title = 'ICA source matching EOG' ica.plot_sources_raw(raw, eog_source_idx, title=title, stop=3.0) # plot spatial sensitivities of EOG and ECG ICA components title = 'Spatial patterns of ICA components for ECG+EOG (Magnetometers)' source_idx = range(15) ica.plot_topomap([ecg_source_idx, eog_source_idx], ch_type='mag') plt.suptitle(title, fontsize=12) ############################################################################### # Show MEG data before and after ICA cleaning. # We now add the eog artifacts to the ica.exclusion list ica.exclude += [eog_source_idx] # Restore sensor space data raw_ica = ica.pick_sources_raw(raw, include=None) start_compare, stop_compare = raw.time_as_index([100, 106]) data, times = raw[picks, start_compare:stop_compare] data_clean, _ = raw_ica[picks, start_compare:stop_compare]
# for more background information visit the plot_ica_from_raw.py example # fit sources from epochs or from raw (both works for epochs) ica = ICA(n_components=0.90, n_pca_components=64, max_pca_components=100, noise_cov=None, random_state=random_state) ica.decompose_epochs(epochs, decim=2) print(ica) # plot spatial sensitivities of a few ICA components title = 'Spatial patterns of ICA components (Magnetometers)' source_idx = range(35, 50) ica.plot_topomap(source_idx, ch_type='mag') plt.suptitle(title, fontsize=12) ############################################################################### # Automatically find ECG and EOG component using correlation coefficient. # As we don't have an ECG channel we use one that correlates a lot with heart # beats: 'MEG 1531'. We can directly pass the name to the find_sources method. # In our example, the find_sources method returns and array of correlation # scores for each ICA source. ecg_ch_name = 'MEG 1531' ecg_scores = ica.find_sources_epochs(epochs, target=ecg_ch_name, score_func='pearsonr') # get the source most correlated with the ECG.
############################################################################### # Setup ICA seed decompose data, then access and plot sources. # for more background information visit the plot_ica_from_raw.py example # fit sources from epochs or from raw (both works for epochs) ica = ICA(n_components=0.90, n_pca_components=64, max_pca_components=100, noise_cov=None, random_state=random_state) ica.decompose_epochs(epochs, decim=2) print(ica) # plot spatial sensitivities of a few ICA components title = 'Spatial patterns of ICA components (Magnetometers)' source_idx = range(35, 50) ica.plot_topomap(source_idx, ch_type='mag') plt.suptitle(title, fontsize=12) ############################################################################### # Automatically find ECG and EOG component using correlation coefficient. # As we don't have an ECG channel we use one that correlates a lot with heart # beats: 'MEG 1531'. We can directly pass the name to the find_sources method. # In our example, the find_sources method returns and array of correlation # scores for each ICA source. ecg_ch_name = 'MEG 1531' ecg_scores = ica.find_sources_epochs(epochs, target=ecg_ch_name, score_func='pearsonr') # get the source most correlated with the ECG.