当前位置: 首页>>代码示例>>Python>>正文


Python ICA.plot_sources方法代码示例

本文整理汇总了Python中mne.preprocessing.ICA.plot_sources方法的典型用法代码示例。如果您正苦于以下问题:Python ICA.plot_sources方法的具体用法?Python ICA.plot_sources怎么用?Python ICA.plot_sources使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mne.preprocessing.ICA的用法示例。


在下文中一共展示了ICA.plot_sources方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_plot_instance_components

# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import plot_sources [as 别名]
def test_plot_instance_components():
    """Test plotting of components as instances of raw and epochs."""
    import matplotlib.pyplot as plt
    raw = _get_raw()
    picks = _get_picks(raw)
    ica = ICA(noise_cov=read_cov(cov_fname), n_components=2,
              max_pca_components=3, n_pca_components=3)
    with pytest.warns(RuntimeWarning, match='projection'):
        ica.fit(raw, picks=picks)
    fig = ica.plot_sources(raw, exclude=[0], title='Components')
    for key in ['down', 'up', 'right', 'left', 'o', '-', '+', '=', 'pageup',
                'pagedown', 'home', 'end', 'f11', 'b']:
        fig.canvas.key_press_event(key)
    ax = fig.get_axes()[0]
    line = ax.lines[0]
    _fake_click(fig, ax, [line.get_xdata()[0], line.get_ydata()[0]],
                'data')
    _fake_click(fig, ax, [-0.1, 0.9])  # click on y-label
    fig.canvas.key_press_event('escape')
    plt.close('all')
    epochs = _get_epochs()
    fig = ica.plot_sources(epochs, exclude=[0], title='Components')
    for key in ['down', 'up', 'right', 'left', 'o', '-', '+', '=', 'pageup',
                'pagedown', 'home', 'end', 'f11', 'b']:
        fig.canvas.key_press_event(key)
    # Test a click
    ax = fig.get_axes()[0]
    line = ax.lines[0]
    _fake_click(fig, ax, [line.get_xdata()[0], line.get_ydata()[0]], 'data')
    _fake_click(fig, ax, [-0.1, 0.9])  # click on y-label
    fig.canvas.key_press_event('escape')
    plt.close('all')
开发者ID:SherazKhan,项目名称:mne-python,代码行数:34,代码来源:test_ica.py

示例2: test_plot_instance_components

# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import plot_sources [as 别名]
def test_plot_instance_components():
    """Test plotting of components as instances of raw and epochs."""
    import matplotlib.pyplot as plt
    raw = _get_raw()
    picks = _get_picks(raw)
    ica = ICA(noise_cov=read_cov(cov_fname), n_components=2,
              max_pca_components=3, n_pca_components=3)
    with warnings.catch_warnings(record=True):  # bad proj
        ica.fit(raw, picks=picks)
    fig = ica.plot_sources(raw, exclude=[0], title='Components')
    fig.canvas.key_press_event('down')
    fig.canvas.key_press_event('up')
    fig.canvas.key_press_event('right')
    fig.canvas.key_press_event('left')
    fig.canvas.key_press_event('o')
    fig.canvas.key_press_event('-')
    fig.canvas.key_press_event('+')
    fig.canvas.key_press_event('=')
    fig.canvas.key_press_event('pageup')
    fig.canvas.key_press_event('pagedown')
    fig.canvas.key_press_event('home')
    fig.canvas.key_press_event('end')
    fig.canvas.key_press_event('f11')
    ax = fig.get_axes()[0]
    line = ax.lines[0]
    _fake_click(fig, ax, [line.get_xdata()[0], line.get_ydata()[0]], 'data')
    _fake_click(fig, ax, [-0.1, 0.9])  # click on y-label
    fig.canvas.key_press_event('escape')
    plt.close('all')
    epochs = _get_epochs()
    fig = ica.plot_sources(epochs, exclude=[0], title='Components')
    fig.canvas.key_press_event('down')
    fig.canvas.key_press_event('up')
    fig.canvas.key_press_event('right')
    fig.canvas.key_press_event('left')
    fig.canvas.key_press_event('o')
    fig.canvas.key_press_event('-')
    fig.canvas.key_press_event('+')
    fig.canvas.key_press_event('=')
    fig.canvas.key_press_event('pageup')
    fig.canvas.key_press_event('pagedown')
    fig.canvas.key_press_event('home')
    fig.canvas.key_press_event('end')
    fig.canvas.key_press_event('f11')
    # Test a click
    ax = fig.get_axes()[0]
    line = ax.lines[0]
    _fake_click(fig, ax, [line.get_xdata()[0], line.get_ydata()[0]], 'data')
    _fake_click(fig, ax, [-0.1, 0.9])  # click on y-label
    fig.canvas.key_press_event('escape')
    plt.close('all')
开发者ID:jmontoyam,项目名称:mne-python,代码行数:53,代码来源:test_ica.py

示例3: test_plot_instance_components

# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import plot_sources [as 别名]
def test_plot_instance_components():
    """Test plotting of components as instances of raw and epochs."""
    import matplotlib.pyplot as plt

    raw = _get_raw()
    picks = _get_picks(raw)
    ica = ICA(noise_cov=read_cov(cov_fname), n_components=2, max_pca_components=3, n_pca_components=3)
    with warnings.catch_warnings(record=True):  # bad proj
        ica.fit(raw, picks=picks)
    fig = ica.plot_sources(raw, exclude=[0], title="Components")
    fig.canvas.key_press_event("down")
    fig.canvas.key_press_event("up")
    fig.canvas.key_press_event("right")
    fig.canvas.key_press_event("left")
    fig.canvas.key_press_event("o")
    fig.canvas.key_press_event("-")
    fig.canvas.key_press_event("+")
    fig.canvas.key_press_event("=")
    fig.canvas.key_press_event("pageup")
    fig.canvas.key_press_event("pagedown")
    fig.canvas.key_press_event("home")
    fig.canvas.key_press_event("end")
    fig.canvas.key_press_event("f11")
    ax = fig.get_axes()[0]
    line = ax.lines[0]
    _fake_click(fig, ax, [line.get_xdata()[0], line.get_ydata()[0]], "data")
    _fake_click(fig, ax, [-0.1, 0.9])  # click on y-label
    fig.canvas.key_press_event("escape")
    plt.close("all")
    epochs = _get_epochs()
    fig = ica.plot_sources(epochs, exclude=[0], title="Components")
    fig.canvas.key_press_event("down")
    fig.canvas.key_press_event("up")
    fig.canvas.key_press_event("right")
    fig.canvas.key_press_event("left")
    fig.canvas.key_press_event("o")
    fig.canvas.key_press_event("-")
    fig.canvas.key_press_event("+")
    fig.canvas.key_press_event("=")
    fig.canvas.key_press_event("pageup")
    fig.canvas.key_press_event("pagedown")
    fig.canvas.key_press_event("home")
    fig.canvas.key_press_event("end")
    fig.canvas.key_press_event("f11")
    # Test a click
    ax = fig.get_axes()[0]
    line = ax.lines[0]
    _fake_click(fig, ax, [line.get_xdata()[0], line.get_ydata()[0]], "data")
    _fake_click(fig, ax, [-0.1, 0.9])  # click on y-label
    fig.canvas.key_press_event("escape")
    plt.close("all")
开发者ID:nwilming,项目名称:mne-python,代码行数:53,代码来源:test_ica.py

示例4: test_plot_ica_sources

# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import plot_sources [as 别名]
def test_plot_ica_sources():
    """Test plotting of ICA panel
    """
    import matplotlib.pyplot as plt
    raw = io.Raw(raw_fname, preload=True)
    raw.crop(0, 1, copy=False)
    picks = _get_picks(raw)
    epochs = _get_epochs()
    raw.pick_channels([raw.ch_names[k] for k in picks])
    ica_picks = pick_types(raw.info, meg=True, eeg=False, stim=False,
                           ecg=False, eog=False, exclude='bads')
    ica = ICA(n_components=2, max_pca_components=3, n_pca_components=3)
    ica.fit(raw, picks=ica_picks)
    raw.info['bads'] = ['MEG 0113']
    assert_raises(RuntimeError, ica.plot_sources, inst=raw)
    ica.plot_sources(epochs)
    epochs.info['bads'] = ['MEG 0113']
    assert_raises(RuntimeError, ica.plot_sources, inst=epochs)
    epochs.info['bads'] = []
    with warnings.catch_warnings(record=True):  # no labeled objects mpl
        ica.plot_sources(epochs.average())
    assert_raises(ValueError, ica.plot_sources, 'meeow')
    plt.close('all')
开发者ID:Lem97,项目名称:mne-python,代码行数:25,代码来源:test_ica.py

示例5: test_plot_ica_sources

# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import plot_sources [as 别名]
def test_plot_ica_sources():
    """Test plotting of ICA panel
    """
    import matplotlib.pyplot as plt
    raw = io.Raw(raw_fname, preload=False)
    raw.crop(0, 1, copy=False)
    raw.preload_data()
    picks = _get_picks(raw)
    epochs = _get_epochs()
    raw.pick_channels([raw.ch_names[k] for k in picks])
    ica_picks = pick_types(raw.info, meg=True, eeg=False, stim=False,
                           ecg=False, eog=False, exclude='bads')
    ica = ICA(n_components=2, max_pca_components=3, n_pca_components=3)
    ica.fit(raw, picks=ica_picks)
    raw.info['bads'] = ['MEG 0113']
    assert_raises(RuntimeError, ica.plot_sources, inst=raw)
    ica.plot_sources(epochs)
    epochs.info['bads'] = ['MEG 0113']
    assert_raises(RuntimeError, ica.plot_sources, inst=epochs)
    epochs.info['bads'] = []
    with warnings.catch_warnings(record=True):  # no labeled objects mpl
        ica.plot_sources(epochs.average())
        evoked = epochs.average()
        fig = ica.plot_sources(evoked)
        # Test a click
        ax = fig.get_axes()[0]
        line = ax.lines[0]
        _fake_click(fig, ax,
                    [line.get_xdata()[0], line.get_ydata()[0]], 'data')
        _fake_click(fig, ax,
                    [ax.get_xlim()[0], ax.get_ylim()[1]], 'data')
        # plot with bad channels excluded
        ica.plot_sources(evoked, exclude=[0])
        ica.exclude = [0]
        ica.plot_sources(evoked)  # does the same thing
    assert_raises(ValueError, ica.plot_sources, 'meeow')
    plt.close('all')
开发者ID:Odingod,项目名称:mne-python,代码行数:39,代码来源:test_ica.py

示例6: test_plot_ica_sources

# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import plot_sources [as 别名]
def test_plot_ica_sources():
    """Test plotting of ICA panel
    """
    raw = io.Raw(raw_fname, preload=True)
    picks = _get_picks(raw)
    epochs = _get_epochs()
    picks = np.round(np.linspace(0, len(picks) + 1, n_chan)).astype(int)
    raw.pick_channels([raw.ch_names[k] for k in picks])
    ica_picks = pick_types(raw.info, meg=True, eeg=False, stim=False, ecg=False, eog=False, exclude="bads")
    ica = ICA(n_components=2, max_pca_components=3, n_pca_components=3)
    ica.fit(raw, picks=ica_picks)
    ica.plot_sources(raw)
    ica.plot_sources(epochs)
    ica.plot_sources(epochs.average())
    assert_raises(ValueError, ica.plot_sources, "meeow")
    plt.close("all")
开发者ID:rgoj,项目名称:mne-python,代码行数:18,代码来源:test_viz.py

示例7: artifacts

# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import plot_sources [as 别名]
    ##########################################################################
    # 2) identify bad components by analyzing latent sources.

    title = "Sources related to %s artifacts (red)"

    # generate ECG epochs use detection via phase statistics

    ecg_epochs = create_ecg_epochs(raw, tmin=-0.5, tmax=0.5, picks=picks)

    ecg_inds, scores = ica.find_bads_ecg(ecg_epochs, method="ctps")
    ica.plot_scores(scores, exclude=ecg_inds, title=title % "ecg")

    if ecg_inds:
        show_picks = np.abs(scores).argsort()[::-1][:5]

        ica.plot_sources(raw, show_picks, exclude=ecg_inds, title=title % "ecg")
        ica.plot_components(ecg_inds, title=title % "ecg", colorbar=True)

    ecg_inds = ecg_inds[:n_max_ecg]
    ica.exclude += ecg_inds

    # detect EOG by correlation

    eog_inds, scores = ica.find_bads_eog(raw)
    ica.plot_scores(scores, exclude=eog_inds, title=title % "eog")

    if eog_inds:
        show_picks = np.abs(scores).argsort()[::-1][:5]

        #        ica.plot_sources(raw, show_picks, exclude=eog_inds,
        #                         title="Sources related to EOG artifacts (red)")
开发者ID:MadsJensen,项目名称:Hyp_MEG_MNE_2,代码行数:33,代码来源:filter_ICA.py

示例8: create_eog_epochs

# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import plot_sources [as 别名]
                       stim=False, exclude='bads')

ica.fit(raw, picks=picks, decim=3, reject=dict(mag=4e-12, grad=4000e-13))

# create EOG epochs to improve detection by correlation
picks = mne.pick_types(raw.info, meg=True, eog=True)
eog_epochs = create_eog_epochs(raw, picks=picks)

eog_inds, scores = ica.find_bads_eog(eog_epochs)  # inds sorted!

ica.plot_scores(scores, exclude=eog_inds)  # inspect metrics used

show_picks = np.abs(scores).argsort()[::-1][:5]  # indices of top five scores

# detected artifacts drawn in red (via exclude)
ica.plot_sources(raw, show_picks, exclude=eog_inds, start=0., stop=3.0)
ica.plot_components(eog_inds, colorbar=False)  # show component sensitivites

ica.exclude += eog_inds[:1]  # mark first for exclusion

###############################################################################
# 3) check detection and visualize artifact rejection

# estimate average artifact
eog_evoked = eog_epochs.average()
ica.plot_sources(eog_evoked)  # latent EOG sources + selction
ica.plot_overlay(eog_evoked)  # overlay raw and clean EOG artifacts

# check the amplitudes do not change
ica.plot_overlay(raw)  # EOG artifacts remain
开发者ID:katcharewich,项目名称:mne-python,代码行数:32,代码来源:plot_ica_from_raw.py

示例9: ica_method

# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import plot_sources [as 别名]
def ica_method(raw, picks, plot='n', save ='n'):
    
    
    ###############################################################################
    # 1) Fit ICA model using the FastICA algorithm
    # Other available choices are `infomax` or `extended-infomax`
    # We pass a float value between 0 and 1 to select n_components based on the
    # percentage of variance explained by the PCA components.
    
    ica = ICA(n_components=0.95, method='fastica')
    
    picks = mne.pick_types(raw.info, meg=False, eeg=True, eog=False,
                           stim=False, exclude='bads')
    
    ica.fit(raw, picks=picks, decim=3)
    
    # maximum number of components to reject
    n_max_eog =  1  # here we don't expect horizontal EOG components
    
    ###############################################################################
    # 2) identify bad components by analyzing latent sources.
    
    
    # detect EOG by correlation
    
    eog_inds, scores = ica.find_bads_eog(raw, threshold=2.5)    
    show_picks = np.abs(scores).argsort()[::-1][:5]
    eog_inds = eog_inds[:n_max_eog]
    ica.exclude += eog_inds
    
    ###############################################################################
    # 3) Assess component selection and unmixing quality
    eog_evoked = create_eog_epochs(raw, tmin=-.5, tmax=.5, picks=picks).average()
    
    if plot=='y':
        
        title = 'Sources related to %s artifacts (red)'
        ica.plot_scores(scores, exclude=eog_inds, title=title % 'eog', labels='eog')
        if save=='y':
            pylab.savefig('2.png')

        ica.plot_sources(raw, show_picks, exclude=eog_inds, title=title % 'eog')
        if save=='y':
            pylab.savefig('3.png')

        ica.plot_components(eog_inds, title=title % 'eog', colorbar=True)
        if save=='y':

            pylab.savefig('4.png')

        ica.plot_overlay(raw)  # EOG artifacts remain
        if save=='y':

            pylab.savefig('5.png')

        ica.plot_sources(eog_evoked, exclude=eog_inds)  # plot EOG sources + selection
        if save=='y':

            pylab.savefig('6.png')

        ica.plot_overlay(eog_evoked, exclude=eog_inds)  # plot EOG cleaning
        if save=='y':
            pylab.savefig('7.png')


    ica.apply(raw, exclude=eog_inds)    
    eeg_only_after=raw.pick_types(meg=False, eeg=True)    
    

    return eeg_only_after
    
开发者ID:RenatoBMLR,项目名称:ProjectSigma205,代码行数:72,代码来源:ValidationICA.py

示例10: create_eog_epochs

# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import plot_sources [as 别名]
##########################################################################
# 2) identify bad components by analyzing latent sources.

# DETECT EOG BY CORRELATION
# HORIZONTAL EOG
title = "ICA: %s for %s"
picks = mne.pick_types(raw.info, meg=True, eeg=False, eog=False, emg=False,
                       bio=True, stim=False, exclude='bads')
eog_epochs = create_eog_epochs(raw, ch_name="EOG001")  
eog_average = eog_epochs.average()
# channel name
eog_inds, scores = ica.find_bads_eog(raw)

# ica.plot_components()
ica.plot_sources(raw)

 # %%
# eog_inds = [10]
# ica.exclude += eog_inds

fig = ica.plot_scores(scores, exclude=eog_inds,
                      title=title % ('eog', subject))
fig.savefig(save_folder + "pics/%s_%s_eog_scores.png" % (subject,
                                                         condition))
                                                         

fig = ica.plot_sources(eog_average, exclude=None)
fig.savefig(save_folder + "pics/%s_%s_eog_source.png" % (subject,
                                                         condition))
开发者ID:MadsJensen,项目名称:RP_scripts,代码行数:31,代码来源:ICA_interactive.py

示例11: ICA

# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import plot_sources [as 别名]
    #ica = ICA(n_components=n_components, max_pca_components=None,max_iter=256, noise_cov=baseline_cov)
    ica = ICA(n_components=n_components, max_pca_components=None,max_iter=256)
    ica.fit(epochs, picks=picks, decim = 5, reject=ica_reject)

    eog_inds, scores = ica.find_bads_eog(epochs, ch_name='EOG001,EOG003')
    allscores = np.vstack((scores[0], scores[1]))
    mscores = np.max(np.abs(allscores), axis=0)
    # now scores is 
    show_picks = mscores.argsort()[::-1][:5]
    eog_inds = list(show_picks[:n_max_eog])
    ica.exclude += eog_inds

    fig = ica.plot_scores(scores, exclude=eog_inds, title=title % 'eog')
    fig.savefig(img_folder + '/ica_eog_scores.png')

    fig = ica.plot_sources(epochs, show_picks, exclude=eog_inds, title=title % 'eog')
    fig.savefig(img_folder + '/ica_eog_sources.png')
    fig = ica.plot_components(show_picks, title=title % 'eog', colorbar=True)
    fig.set_size_inches(12.,8.)
    fig.savefig(img_folder + '/ica_eog_components.png')

    # Now exclude what we find
    # epochs_ica = ica.apply(epochs, copy=True)
    #evo_ica = epochs_ica.average()
    evo= epochs.average()

    #megp = pick_types(epochs.info, meg=True, eog=False)
    #eogp = pick_types(epochs.info, meg=False, eog=True)
    #fig = ica.plot_overlay(evo, picks=megp)  # 
    fig = ica.plot_overlay(evo)  # 
    fig.savefig(img_folder + '/ica_evo_overlay_meg.png')
开发者ID:cjayb,项目名称:VSC-MEG-analysis,代码行数:33,代码来源:plot_ica_from_epochs_example.py

示例12: create_eog_epochs

# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import plot_sources [as 别名]
    title = "ICA: %s for %s"

    eog_epochs = create_eog_epochs(raw, ch_name="EOG002")  # TODO: check EOG
    eog_average = eog_epochs.average()
    # channel name
    eog_inds, scores = ica.find_bads_eog(raw)

    eog_inds = eog_inds[:n_max_eog]
    ica.exclude += eog_inds

    if eog_inds:
        fig = ica.plot_scores(
            scores, exclude=eog_inds, title=title % ('eog', subject))
        fig.savefig(ica_folder + "plots/%s_%s_eog_scores_2.png" % (subject,
                                                                   condition))
        fig = ica.plot_sources(eog_average, exclude=eog_inds)
        fig.savefig(ica_folder + "plots/%s_%s_eog_source_2.png" % (subject,
                                                                   condition))

        fig = ica.plot_components(
            eog_inds, title=title % ('eog', subject), colorbar=True)
        fig.savefig(ica_folder + "plots/%s_%s_eog_component_2.png" % (
            subject, condition))
        fig = ica.plot_overlay(eog_average, exclude=eog_inds, show=False)
        fig.savefig(ica_folder + "plots/%s_%s_eog_excluded_2.png" % (
            subject, condition))

    del eog_epochs, eog_average

    # ECG
    ecg_epochs = create_ecg_epochs(raw, tmin=-.5, tmax=.5)
开发者ID:MadsJensen,项目名称:RP_scripts,代码行数:33,代码来源:filter_ICA.py

示例13: create_ecg_epochs

# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import plot_sources [as 别名]
# UNLESS picks=None
picks=None
ecg_epochs = create_ecg_epochs(raw, ch_name='ECG002', tmin=-.5, tmax=.5, picks=picks, verbose=True)

# This will work with the above, but uses MASSIVE RAM
# Not sure the ECG quality is good enough for the QRS-detector
ecg_inds, scores = ica.find_bads_ecg(ecg_epochs, method='ctps', ch_name='ECG002')
# This creates a synthetic ECG from magnetometers, probably better...
ecg_inds, scores = ica.find_bads_ecg(ecg_epochs, method='ctps', ch_name='ECG002')

fig = ica.plot_scores(scores, exclude=ecg_inds, title=title % 'ecg')
fig.savefig(img_folder + '/ica_ecg_scores.png')

show_picks = np.abs(scores).argsort()[::-1][:5]

fig = ica.plot_sources(raw, show_picks, exclude=ecg_inds, title=title % 'ecg')
fig.savefig(img_folder + '/ica_ecg_sources.png')
fig = ica.plot_components(ecg_inds, title=title % 'ecg', colorbar=True)
fig.set_size_inches(12.,8.)
fig.savefig(img_folder + '/ica_ecg_components.png')

ecg_inds = ecg_inds[:n_max_ecg]
ica.exclude += ecg_inds

# detect EOG by correlation
# First do both together
eog_inds, scores = ica.find_bads_eog(raw, ch_name='EOG001,EOG003')
allscores = np.vstack((scores[0], scores[1]))
mscores = np.max(np.abs(allscores), axis=0)
# now scores is 
show_picks = mscores.argsort()[::-1][:5]
开发者ID:cjayb,项目名称:VSC-MEG-analysis,代码行数:33,代码来源:plot_ica_from_raw_example.py

示例14: compute_ica

# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import plot_sources [as 别名]
def compute_ica(subject):
    """Function will compute ICA on raw and apply the ICA.

    params:
    subject : str
        the subject id to be loaded
    """
    raw = Raw(save_folder + "%s_filtered_data_mc_raw_tsss.fif" % subject,
              preload=True)

    # ICA Part
    ica = ICA(n_components=0.95, method='fastica', max_iter=256)

    picks = mne.pick_types(raw.info, meg=True, eeg=True,
                           stim=False, exclude='bads')

    ica.fit(raw, picks=picks, decim=decim, reject=reject)

    # maximum number of components to reject
    n_max_ecg, n_max_eog = 3, 1

    ##########################################################################
    # 2) identify bad components by analyzing latent sources.
    title = 'Sources related to %s artifacts (red) for sub: %s'

    # generate ECG epochs use detection via phase statistics
    ecg_epochs = create_ecg_epochs(raw, ch_name="ECG002",
                                   tmin=-.5, tmax=.5, picks=picks)
    n_ecg_epochs_found = len(ecg_epochs.events)
    sel_ecg_epochs = np.arange(0, n_ecg_epochs_found, 10)
    ecg_epochs = ecg_epochs[sel_ecg_epochs]

    ecg_inds, scores = ica.find_bads_ecg(ecg_epochs, method='ctps')
    fig = ica.plot_scores(scores, exclude=ecg_inds,
                          title=title % ('ecg', subject))
    fig.savefig(save_folder + "pics/%s_ecg_scores.png" % subject)

    if ecg_inds:
        show_picks = np.abs(scores).argsort()[::-1][:5]

        fig = ica.plot_sources(raw, show_picks, exclude=ecg_inds,
                               title=title % ('ecg', subject), show=False)
        fig.savefig(save_folder + "pics/%s_ecg_sources.png" % subject)
        fig = ica.plot_components(ecg_inds, title=title % ('ecg', subject),
                                  colorbar=True)
        fig.savefig(save_folder + "pics/%s_ecg_component.png" % subject)

        ecg_inds = ecg_inds[:n_max_ecg]
        ica.exclude += ecg_inds

    # estimate average artifact
    ecg_evoked = ecg_epochs.average()
    del ecg_epochs

    # plot ECG sources + selection
    fig = ica.plot_sources(ecg_evoked, exclude=ecg_inds)
    fig.savefig(save_folder + "pics/%s_ecg_sources_ave.png" % subject)

    # plot ECG cleaning
    ica.plot_overlay(ecg_evoked, exclude=ecg_inds)
    fig.savefig(save_folder + "pics/%s_ecg_sources_clean_ave.png" % subject)

    # DETECT EOG BY CORRELATION
    # HORIZONTAL EOG
    eog_epochs = create_eog_epochs(raw, ch_name="EOG001")
    eog_inds, scores = ica.find_bads_eog(raw)
    fig = ica.plot_scores(scores, exclude=eog_inds,
                          title=title % ('eog', subject))
    fig.savefig(save_folder + "pics/%s_eog_scores.png" % subject)

    fig = ica.plot_components(eog_inds, title=title % ('eog', subject),
                              colorbar=True)
    fig.savefig(save_folder + "pics/%s_eog_component.png" % subject)

    eog_inds = eog_inds[:n_max_eog]
    ica.exclude += eog_inds

    del eog_epochs

    ##########################################################################
    # Apply the solution to Raw, Epochs or Evoked like this:
    raw_ica = ica.apply(raw, copy=False)
    ica.save(save_folder + "%s-ica.fif" % subject)  # save ICA componenets
    # Save raw with ICA removed
    raw_ica.save(save_folder + "%s_filtered_ica_mc_raw_tsss.fif" % subject,
                 overwrite=True)
    plt.close("all")
开发者ID:MadsJensen,项目名称:malthe_alpha_project,代码行数:89,代码来源:filter_ICA.py

示例15: test_plot_ica_sources

# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import plot_sources [as 别名]
def test_plot_ica_sources():
    """Test plotting of ICA panel."""
    import matplotlib.pyplot as plt

    raw = read_raw_fif(raw_fname).crop(0, 1).load_data()
    picks = _get_picks(raw)
    epochs = _get_epochs()
    raw.pick_channels([raw.ch_names[k] for k in picks])
    ica_picks = pick_types(raw.info, meg=True, eeg=False, stim=False, ecg=False, eog=False, exclude="bads")
    ica = ICA(n_components=2, max_pca_components=3, n_pca_components=3)
    ica.fit(raw, picks=ica_picks)
    ica.exclude = [1]
    fig = ica.plot_sources(raw)
    fig.canvas.key_press_event("escape")
    # Sadly close_event isn't called on Agg backend and the test always passes.
    assert_array_equal(ica.exclude, [1])

    raw.info["bads"] = ["MEG 0113"]
    assert_raises(RuntimeError, ica.plot_sources, inst=raw)
    ica.plot_sources(epochs)
    epochs.info["bads"] = ["MEG 0113"]
    assert_raises(RuntimeError, ica.plot_sources, inst=epochs)
    epochs.info["bads"] = []
    with warnings.catch_warnings(record=True):  # no labeled objects mpl
        ica.plot_sources(epochs.average())
        evoked = epochs.average()
        fig = ica.plot_sources(evoked)
        # Test a click
        ax = fig.get_axes()[0]
        line = ax.lines[0]
        _fake_click(fig, ax, [line.get_xdata()[0], line.get_ydata()[0]], "data")
        _fake_click(fig, ax, [ax.get_xlim()[0], ax.get_ylim()[1]], "data")
        # plot with bad channels excluded
        ica.plot_sources(evoked, exclude=[0])
        ica.exclude = [0]
        ica.plot_sources(evoked)  # does the same thing
        ica.labels_ = dict(eog=[0])
        ica.labels_["eog/0/crazy-channel"] = [0]
        ica.plot_sources(evoked)  # now with labels
    assert_raises(ValueError, ica.plot_sources, "meeow")
    plt.close("all")
开发者ID:nwilming,项目名称:mne-python,代码行数:43,代码来源:test_ica.py


注:本文中的mne.preprocessing.ICA.plot_sources方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。