# 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. ecg_source_idx = np.argsort(np.abs(ecg_scores))[-1] # get sources as epochs object and inspect some trial some_trial = 10 title = 'Source most similar to ECG' ica.plot_sources_epochs(epochs[some_trial], ecg_source_idx, title=title) # As we have an EOG channel, we can use it to detect the source. eog_scores = ica.find_sources_epochs(epochs, target='EOG 061', score_func='pearsonr')
# 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. ecg_source_idx = np.argsort(np.abs(ecg_scores))[-1] # get sources as epochs object and inspect some trial some_trial = 10 title = 'Source most similar to ECG' ica.plot_sources_epochs(epochs[some_trial], ecg_source_idx, title=title) # As we have an EOG channel, we can use it to detect the source. eog_scores = ica.find_sources_epochs(epochs, target='EOG 061', score_func='pearsonr') # get maximum correlation index for EOG eog_source_idx = np.abs(eog_scores).argmax()
# fit sources from epochs or from raw (both works for epochs) ica.decompose_epochs(epochs) # plot components for one epoch of interest # A distinct cardiac component should be visible ica.plot_sources_epochs(epochs, epoch_idx=13, n_components=25) ############################################################################### # Automatically find the ECG component using correlation with ECG signal # 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_scores = ica.find_sources_epochs(epochs, target="MEG 1531", score_func="pearsonr") # get maximum correlation index for ECG ecg_source_idx = np.abs(ecg_scores).argmax() print "#%i -- ICA component resembling the ECG" % ecg_source_idx ############################################################################### # 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_epochs(epochs, target="EOG 061", score_func="pearsonr") # get maximum correlation index for EOG eog_source_idx = np.abs(eog_scores).argmax()
# fit sources from epochs or from raw (both works for epochs) ica.decompose_epochs(epochs) # plot components for one epoch of interest # A distinct cardiac component should be visible ica.plot_sources_epochs(epochs, epoch_idx=13, n_components=25) ############################################################################### # Automatically find the ECG component using correlation with ECG signal # 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_scores = ica.find_sources_epochs(epochs, target='MEG 1531', score_func='pearsonr') # get maximum correlation index for ECG ecg_source_idx = np.abs(ecg_scores).argmax() print '#%i -- ICA component resembling the ECG' % ecg_source_idx ############################################################################### # 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_epochs(epochs, target='EOG 061', score_func='pearsonr') # get maximum correlation index for EOG
# 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=0) ica.decompose_epochs(epochs) print ica ############################################################################### # 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_scores = ica.find_sources_epochs(epochs, target='MEG 1531', score_func='pearsonr') # get maximum correlation index for ECG ecg_source_idx = np.abs(ecg_scores).argmax() # get sources from concatenated epochs sources = ica.get_sources_epochs(epochs, concatenate=True) # plot first epoch times = epochs.times first_trial = np.arange(len(times)) pl.figure() pl.title('Source most correlated with the ECG channel') pl.plot(times, sources[ecg_source_idx, first_trial].T, color='r') pl.xlabel('Time (s)')