예제 #1
0
def test_plot_ica_components():
    """Test plotting of ICA solutions."""
    import matplotlib.pyplot as plt
    res = 8
    fast_test = {"res": res, "contours": 0, "sensors": False}
    raw = _get_raw()
    ica = ICA(noise_cov=read_cov(cov_fname),
              n_components=2,
              max_pca_components=3,
              n_pca_components=3)
    ica_picks = _get_picks(raw)
    with warnings.catch_warnings(record=True):
        ica.fit(raw, picks=ica_picks)
    warnings.simplefilter('always', UserWarning)
    with warnings.catch_warnings(record=True):
        for components in [0, [0], [0, 1], [0, 1] * 2, None]:
            ica.plot_components(components,
                                image_interp='bilinear',
                                colorbar=True,
                                **fast_test)
        plt.close('all')

        # test interactive mode (passing 'inst' arg)
        ica.plot_components([0, 1], image_interp='bilinear', inst=raw, res=16)
        fig = plt.gcf()

        # test title click
        # ----------------
        lbl = fig.axes[1].get_label()
        ica_idx = int(lbl[-3:])
        titles = [ax.title for ax in fig.axes]
        title_pos_midpoint = (titles[1].get_window_extent().extents.reshape(
            (2, 2)).mean(axis=0))
        # first click adds to exclude
        _fake_click(fig, fig.axes[1], title_pos_midpoint, xform='pix')
        assert ica_idx in ica.exclude
        # clicking again removes from exclude
        _fake_click(fig, fig.axes[1], title_pos_midpoint, xform='pix')
        assert ica_idx not in ica.exclude

        # test topo click
        # ---------------
        _fake_click(fig, fig.axes[1], (0., 0.), xform='data')

        c_fig = plt.gcf()
        labels = [ax.get_label() for ax in c_fig.axes]

        for l in ['topomap', 'image', 'erp', 'spectrum', 'variance']:
            assert_true(l in labels)

        topomap_ax = c_fig.axes[labels.index('topomap')]
        title = topomap_ax.get_title()
        assert_true(lbl == title)

    ica.info = None
    assert_raises(ValueError, ica.plot_components, 1)
    assert_raises(RuntimeError, ica.plot_components, 1, ch_type='mag')
    plt.close('all')
예제 #2
0
def test_plot_ica_topomap():
    """Test plotting of ICA solutions
    """
    ica = ICA(noise_cov=read_cov(cov_fname), n_components=2,
              max_pca_components=3, n_pca_components=3)
    ica.decompose_raw(raw, picks=ica_picks)
    for components in [0, [0], [0, 1], [0, 1] * 7]:
        ica.plot_topomap(components)
    ica.info = None
    assert_raises(RuntimeError, ica.plot_topomap, 1)
예제 #3
0
def test_plot_ica_components():
    """Test plotting of ICA solutions."""
    res = 8
    fast_test = {"res": res, "contours": 0, "sensors": False}
    raw = _get_raw()
    ica = ICA(noise_cov=read_cov(cov_fname), n_components=2)
    ica_picks = _get_picks(raw)
    with pytest.warns(RuntimeWarning, match='projection'):
        ica.fit(raw, picks=ica_picks)

    for components in [0, [0], [0, 1], [0, 1] * 2, None]:
        ica.plot_components(components, image_interp='bilinear',
                            colorbar=True, **fast_test)
    plt.close('all')

    # test interactive mode (passing 'inst' arg)
    with catch_logging() as log:
        ica.plot_components([0, 1], image_interp='bilinear', inst=raw, res=16,
                            verbose='debug', ch_type='grad')
    log = log.getvalue()
    assert 'grad data' in log
    assert 'Interpolation mode local to mean' in log
    fig = plt.gcf()

    # test title click
    # ----------------
    lbl = fig.axes[1].get_label()
    ica_idx = int(lbl[-3:])
    titles = [ax.title for ax in fig.axes]
    title_pos_midpoint = (titles[1].get_window_extent().extents
                          .reshape((2, 2)).mean(axis=0))
    # first click adds to exclude
    _fake_click(fig, fig.axes[1], title_pos_midpoint, xform='pix')
    assert ica_idx in ica.exclude
    # clicking again removes from exclude
    _fake_click(fig, fig.axes[1], title_pos_midpoint, xform='pix')
    assert ica_idx not in ica.exclude

    # test topo click
    # ---------------
    _fake_click(fig, fig.axes[1], (0., 0.), xform='data')

    c_fig = plt.gcf()
    labels = [ax.get_label() for ax in c_fig.axes]

    for label in ['topomap', 'image', 'erp', 'spectrum', 'variance']:
        assert label in labels

    topomap_ax = c_fig.axes[labels.index('topomap')]
    title = topomap_ax.get_title()
    assert (lbl == title)

    ica.info = None
    with pytest.raises(RuntimeError, match='fit the ICA'):
        ica.plot_components(1, ch_type='mag')
예제 #4
0
def test_plot_ica_components():
    """Test plotting of ICA solutions."""
    import matplotlib.pyplot as plt
    res = 8
    fast_test = {"res": res, "contours": 0, "sensors": False}
    raw = _get_raw()
    ica = ICA(noise_cov=read_cov(cov_fname), n_components=2,
              max_pca_components=3, n_pca_components=3)
    ica_picks = _get_picks(raw)
    with warnings.catch_warnings(record=True):
        ica.fit(raw, picks=ica_picks)
    warnings.simplefilter('always', UserWarning)
    with warnings.catch_warnings(record=True):
        for components in [0, [0], [0, 1], [0, 1] * 2, None]:
            ica.plot_components(components, image_interp='bilinear',
                                colorbar=True, **fast_test)
        plt.close('all')

        # test interactive mode (passing 'inst' arg)
        ica.plot_components([0, 1], image_interp='bilinear', inst=raw, res=16)
        fig = plt.gcf()

        # test title click
        # ----------------
        lbl = fig.axes[1].get_label()
        ica_idx = int(lbl[-3:])
        titles = [ax.title for ax in fig.axes]
        title_pos_midpoint = (titles[1].get_window_extent().extents
                              .reshape((2, 2)).mean(axis=0))
        # first click adds to exclude
        _fake_click(fig, fig.axes[1], title_pos_midpoint, xform='pix')
        assert ica_idx in ica.exclude
        # clicking again removes from exclude
        _fake_click(fig, fig.axes[1], title_pos_midpoint, xform='pix')
        assert ica_idx not in ica.exclude

        # test topo click
        # ---------------
        _fake_click(fig, fig.axes[1], (0., 0.), xform='data')

        c_fig = plt.gcf()
        labels = [ax.get_label() for ax in c_fig.axes]

        for l in ['topomap', 'image', 'erp', 'spectrum', 'variance']:
            assert_true(l in labels)

        topomap_ax = c_fig.axes[labels.index('topomap')]
        title = topomap_ax.get_title()
        assert_true(lbl == title)

    ica.info = None
    assert_raises(ValueError, ica.plot_components, 1)
    assert_raises(RuntimeError, ica.plot_components, 1, ch_type='mag')
    plt.close('all')
예제 #5
0
def test_plot_ica_topomap():
    """Test plotting of ICA solutions
    """
    raw = _get_raw()
    ica = ICA(noise_cov=read_cov(cov_fname), n_components=2,
              max_pca_components=3, n_pca_components=3)
    ica_picks = fiff.pick_types(raw.info, meg=True, eeg=False, stim=False,
                                ecg=False, eog=False, exclude='bads')
    ica.decompose_raw(raw, picks=ica_picks)
    for components in [0, [0], [0, 1], [0, 1] * 7]:
        ica.plot_topomap(components)
    ica.info = None
    assert_raises(RuntimeError, ica.plot_topomap, 1)
    plt.close('all')
예제 #6
0
파일: test_viz.py 프로젝트: rgoj/mne-python
def test_plot_ica_topomap():
    """Test plotting of ICA solutions
    """
    raw = _get_raw()
    ica = ICA(noise_cov=read_cov(cov_fname), n_components=2, max_pca_components=3, n_pca_components=3)
    ica_picks = pick_types(raw.info, meg=True, eeg=False, stim=False, ecg=False, eog=False, exclude="bads")
    ica.decompose_raw(raw, picks=ica_picks)
    warnings.simplefilter("always", UserWarning)
    with warnings.catch_warnings(record=True):
        for components in [0, [0], [0, 1], [0, 1] * 7]:
            ica.plot_topomap(components)
    ica.info = None
    assert_raises(RuntimeError, ica.plot_topomap, 1)
    plt.close("all")
예제 #7
0
def test_plot_ica_components():
    """Test plotting of ICA solutions
    """
    raw = _get_raw()
    ica = ICA(noise_cov=read_cov(cov_fname), n_components=2,
              max_pca_components=3, n_pca_components=3)
    ica_picks = _get_picks(raw)
    ica.fit(raw, picks=ica_picks)
    warnings.simplefilter('always', UserWarning)
    with warnings.catch_warnings(record=True):
        for components in [0, [0], [0, 1], [0, 1] * 2, None]:
            ica.plot_components(components, image_interp='bilinear', res=16)
    ica.info = None
    assert_raises(RuntimeError, ica.plot_components, 1)
    plt.close('all')
예제 #8
0
def plot_components(A, raw, picks, **kwargs):
    p, q = A.shape
    ica = ICA_(n_components=q, method='fastica', random_state=0,
               fit_params=dict(max_iter=1))
    ica.info = pick_info(raw.info, picks)
    if ica.info['comps']:
        ica.info['comps'] = []
    ica.ch_names = ica.info['ch_names']
    ica.mixing_matrix_ = A
    ica.pca_components_ = np.eye(p)
    ica.pca_mean_ = None
    ica.unmixing_matrix_ = np.linalg.pinv(A)
    ica.n_components_ = p
    ica._update_ica_names()
    ica.plot_components(**kwargs)
예제 #9
0
def test_plot_ica_components():
    """Test plotting of ICA solutions."""
    import matplotlib.pyplot as plt
    res = 8
    fast_test = {"res": res, "contours": 0, "sensors": False}
    raw = _get_raw()
    ica = ICA(noise_cov=read_cov(cov_fname),
              n_components=2,
              max_pca_components=3,
              n_pca_components=3)
    ica_picks = _get_picks(raw)
    with warnings.catch_warnings(record=True):
        ica.fit(raw, picks=ica_picks)
    warnings.simplefilter('always', UserWarning)
    with warnings.catch_warnings(record=True):
        for components in [0, [0], [0, 1], [0, 1] * 2, None]:
            ica.plot_components(components,
                                image_interp='bilinear',
                                colorbar=True,
                                **fast_test)

        # test interactive mode (passing 'inst' arg)
        plt.close('all')
        ica.plot_components([0, 1], image_interp='bilinear', inst=raw, res=16)

        fig = plt.gcf()
        ax = [a for a in fig.get_children() if isinstance(a, plt.Axes)]
        lbl = ax[1].get_label()
        _fake_click(fig, ax[1], (0., 0.), xform='data')

        c_fig = plt.gcf()
        ax = [a for a in c_fig.get_children() if isinstance(a, plt.Axes)]
        labels = [a.get_label() for a in ax]

        for l in ['topomap', 'image', 'erp', 'spectrum', 'variance']:
            assert_true(l in labels)

        topomap_ax = ax[labels.index('topomap')]
        title = topomap_ax.get_title()
        assert_true(lbl == title)

    ica.info = None
    assert_raises(ValueError, ica.plot_components, 1)
    assert_raises(RuntimeError, ica.plot_components, 1, ch_type='mag')
    plt.close('all')
예제 #10
0
def transfer_to_mne(A, raw, picks):
    '''
    Hack to use the MNE ICA class providing the estimated mixing matrix A.
    '''
    p, q = A.shape
    ica = ICA_(n_components=q, method='fastica', random_state=0,
               fit_params=dict(max_iter=1))
    ica.info = pick_info(raw.info, picks)
    if ica.info['comps']:
        ica.info['comps'] = []
    ica.ch_names = ica.info['ch_names']
    ica.mixing_matrix_ = A
    ica.pca_components_ = np.eye(p)
    ica.pca_mean_ = None
    ica.unmixing_matrix_ = np.linalg.pinv(A)
    ica.n_components_ = p
    ica._update_ica_names()
    return ica
예제 #11
0
def test_plot_ica_components():
    """Test plotting of ICA solutions."""
    import matplotlib.pyplot as plt
    res = 8
    fast_test = {"res": res, "contours": 0, "sensors": False}
    raw = _get_raw()
    ica = ICA(noise_cov=read_cov(cov_fname), n_components=2,
              max_pca_components=3, n_pca_components=3)
    ica_picks = _get_picks(raw)
    with warnings.catch_warnings(record=True):
        ica.fit(raw, picks=ica_picks)
    warnings.simplefilter('always', UserWarning)
    with warnings.catch_warnings(record=True):
        for components in [0, [0], [0, 1], [0, 1] * 2, None]:
            ica.plot_components(components, image_interp='bilinear',
                                colorbar=True, **fast_test)

        # test interactive mode (passing 'inst' arg)
        plt.close('all')
        ica.plot_components([0, 1], image_interp='bilinear', inst=raw, res=16)

        fig = plt.gcf()
        ax = [a for a in fig.get_children() if isinstance(a, plt.Axes)]
        lbl = ax[1].get_label()
        _fake_click(fig, ax[1], (0., 0.), xform='data')

        c_fig = plt.gcf()
        ax = [a for a in c_fig.get_children() if isinstance(a, plt.Axes)]
        labels = [a.get_label() for a in ax]

        for l in ['topomap', 'image', 'erp', 'spectrum', 'variance']:
            assert_true(l in labels)

        topomap_ax = ax[labels.index('topomap')]
        title = topomap_ax.get_title()
        assert_true(lbl == title)

    ica.info = None
    assert_raises(ValueError, ica.plot_components, 1)
    assert_raises(RuntimeError, ica.plot_components, 1, ch_type='mag')
    plt.close('all')
예제 #12
0
def test_plot_ica_topomap():
    """Test plotting of ICA solutions
    """
    raw = _get_raw()
    ica = ICA(noise_cov=read_cov(cov_fname),
              n_components=2,
              max_pca_components=3,
              n_pca_components=3)
    ica_picks = fiff.pick_types(raw.info,
                                meg=True,
                                eeg=False,
                                stim=False,
                                ecg=False,
                                eog=False,
                                exclude='bads')
    ica.decompose_raw(raw, picks=ica_picks)
    for components in [0, [0], [0, 1], [0, 1] * 7]:
        ica.plot_topomap(components)
    ica.info = None
    assert_raises(RuntimeError, ica.plot_topomap, 1)
    plt.close('all')
예제 #13
0
def test_plot_ica_components():
    """Test plotting of ICA solutions."""
    import matplotlib.pyplot as plt

    raw = _get_raw()
    ica = ICA(noise_cov=read_cov(cov_fname), n_components=2, max_pca_components=3, n_pca_components=3)
    ica_picks = _get_picks(raw)
    with warnings.catch_warnings(record=True):
        ica.fit(raw, picks=ica_picks)
    warnings.simplefilter("always", UserWarning)
    with warnings.catch_warnings(record=True):
        for components in [0, [0], [0, 1], [0, 1] * 2, None]:
            ica.plot_components(components, image_interp="bilinear", res=16, colorbar=True)

        # test interactive mode (passing 'inst' arg)
        plt.close("all")
        ica.plot_components([0, 1], image_interp="bilinear", res=16, inst=raw)

        fig = plt.gcf()
        ax = [a for a in fig.get_children() if isinstance(a, plt.Axes)]
        lbl = ax[1].get_label()
        _fake_click(fig, ax[1], (0.0, 0.0), xform="data")

        c_fig = plt.gcf()
        ax = [a for a in c_fig.get_children() if isinstance(a, plt.Axes)]
        labels = [a.get_label() for a in ax]

        for l in ["topomap", "image", "erp", "spectrum", "variance"]:
            assert_true(l in labels)

        topomap_ax = ax[labels.index("topomap")]
        title = topomap_ax.get_title()
        assert_true(lbl == title)

    ica.info = None
    assert_raises(ValueError, ica.plot_components, 1)
    assert_raises(RuntimeError, ica.plot_components, 1, ch_type="mag")
    plt.close("all")
예제 #14
0
def test_plot_ica_topomap():
    """Test plotting of ICA solutions
    """
    raw = _get_raw()
    ica = ICA(noise_cov=read_cov(cov_fname),
              n_components=2,
              max_pca_components=3,
              n_pca_components=3)
    ica_picks = pick_types(raw.info,
                           meg=True,
                           eeg=False,
                           stim=False,
                           ecg=False,
                           eog=False,
                           exclude='bads')
    ica.decompose_raw(raw, picks=ica_picks)
    warnings.simplefilter('always', UserWarning)
    with warnings.catch_warnings(record=True):
        for components in [0, [0], [0, 1], [0, 1] * 7]:
            ica.plot_topomap(components)
    ica.info = None
    assert_raises(RuntimeError, ica.plot_topomap, 1)
    plt.close('all')