reject=reject) random_state = np.random.RandomState(42) ############################################################################### # 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.
noise_cov=None, random_state=0) print ica # get epochs tmin, tmax, event_id = -0.2, 0.5, 1 # baseline = None baseline = (None, 0) reject = None events = mne.find_events(raw, stim_channel='STI 014') epochs = mne.Epochs(raw, events, event_id, tmin, tmax, proj=True, picks=picks, baseline=baseline, preload=True, reject=reject) # 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')
events = mne.find_events(raw, stim_channel='STI 014') epochs = mne.Epochs(raw, events, event_id, tmin, tmax, proj=False, picks=picks, baseline=baseline, preload=True, reject=reject) random_state = np.random.RandomState(42) ############################################################################### # 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
print ica # get epochs tmin, tmax, event_id = -0.2, 0.5, 1 # baseline = None baseline = (None, 0) reject = None events = mne.find_events(raw, stim_channel="STI 014") epochs = mne.Epochs( raw, events, event_id, tmin, tmax, proj=True, picks=picks, baseline=baseline, preload=True, reject=reject ) # 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")