def test_plot_surf_roi():
    # Axes3DSubplot has no attribute 'plot_trisurf' for older versions of
    # matplotlib
    if LooseVersion(matplotlib.__version__) <= LooseVersion('1.3.1'):
        raise SkipTest
    mesh = _generate_surf()
    rng = np.random.RandomState(0)
    roi1 = rng.randint(0, mesh[0].shape[0], size=5)
    roi2 = rng.randint(0, mesh[0].shape[0], size=10)
    parcellation = rng.rand(mesh[0].shape[0])

    # plot roi
    plot_surf_roi(mesh, roi_map=roi1)

    # plot parcellation
    plot_surf_roi(mesh, roi_map=parcellation)

    # plot roi list
    plot_surf_roi(mesh, roi_map=[roi1, roi2])

    # plot to axes
    plot_surf_roi(mesh, roi_map=roi1, ax=None, figure=plt.gcf())

    # plot to axes
    with tempfile.NamedTemporaryFile() as tmp_file:
        plot_surf_roi(mesh,
                      roi_map=roi1,
                      ax=plt.gca(),
                      figure=None,
                      output_file=tmp_file.name)

    # Save execution time and memory
    plt.close()
Example #2
0
def test_plot_surf_roi():
    # Axes3DSubplot has no attribute 'plot_trisurf' for older versions of
    # matplotlib
    if LooseVersion(matplotlib.__version__) <= LooseVersion('1.3.1'):
        raise SkipTest
    mesh = _generate_surf()
    rng = np.random.RandomState(0)
    roi1 = rng.randint(0, mesh[0].shape[0], size=5)
    roi2 = rng.randint(0, mesh[0].shape[0], size=10)
    parcellation = rng.rand(mesh[0].shape[0])

    # plot roi
    plot_surf_roi(mesh, roi_map=roi1)

    # plot parcellation
    plot_surf_roi(mesh, roi_map=parcellation)

    # plot roi list
    plot_surf_roi(mesh, roi_map=[roi1, roi2])

    # plot to axes
    plot_surf_roi(mesh, roi_map=roi1, ax=None, figure=plt.gcf())

    # plot to axes
    with tempfile.NamedTemporaryFile() as tmp_file:
        plot_surf_roi(mesh, roi_map=roi1, ax=plt.gca(), figure=None,
                      output_file=tmp_file.name)

    # Save execution time and memory
    plt.close()
Example #3
0
def test_plot_surf_roi_error():
    mesh = generate_surf()
    rng = np.random.RandomState(0)
    roi_idx = rng.randint(0, mesh[0].shape[0], size=5)
    with pytest.raises(
            ValueError,
            match='roi_map does not have the same number of vertices'):
        plot_surf_roi(mesh, roi_map=roi_idx)
Example #4
0
def test_plot_surf_roi_error(engine):
    if not PLOTLY_INSTALLED and engine == "plotly":
        pytest.skip('Plotly is not installed; required for this test.')
    mesh = generate_surf()
    rng = np.random.RandomState(42)
    roi_idx = rng.randint(0, mesh[0].shape[0], size=5)
    with pytest.raises(
            ValueError,
            match='roi_map does not have the same number of vertices'):
        plot_surf_roi(mesh, roi_map=roi_idx, engine=engine)
Example #5
0
def test_plot_surf_roi(engine):
    if not PLOTLY_INSTALLED and engine == "plotly":
        pytest.skip('Plotly is not installed; required for this test.')
    mesh, roi_map, parcellation = _generate_data_test_surf_roi()
    # plot roi
    plot_surf_roi(mesh, roi_map=roi_map, engine=engine)
    plot_surf_roi(mesh, roi_map=roi_map, colorbar=True, engine=engine)
    # plot parcellation
    plot_surf_roi(mesh, roi_map=parcellation, engine=engine)
    plot_surf_roi(mesh, roi_map=parcellation, colorbar=True, engine=engine)
    plot_surf_roi(mesh,
                  roi_map=parcellation,
                  colorbar=True,
                  cbar_tick_fomat="%f",
                  engine=engine)
    plt.close()
Example #6
0
def test_plot_surf_roi():
    mesh = _generate_surf()
    rng = np.random.RandomState(0)
    roi1 = rng.randint(0, mesh[0].shape[0], size=5)
    roi2 = rng.randint(0, mesh[0].shape[0], size=10)
    parcellation = rng.rand(mesh[0].shape[0])

    # plot roi
    plot_surf_roi(mesh, roi_map=roi1)
    plot_surf_roi(mesh, roi_map=roi1, colorbar=True)

    # plot parcellation
    plot_surf_roi(mesh, roi_map=parcellation)
    plot_surf_roi(mesh, roi_map=parcellation, colorbar=True)

    # plot roi list
    plot_surf_roi(mesh, roi_map=[roi1, roi2])
    plot_surf_roi(mesh, roi_map=[roi1, roi2], colorbar=True)

    # plot to axes
    plot_surf_roi(mesh, roi_map=roi1, ax=None, figure=plt.gcf())

    # plot to axes
    with tempfile.NamedTemporaryFile() as tmp_file:
        plot_surf_roi(mesh, roi_map=roi1, ax=plt.gca(), figure=None,
                      output_file=tmp_file.name)
    with tempfile.NamedTemporaryFile() as tmp_file:
        plot_surf_roi(mesh, roi_map=roi1, ax=plt.gca(), figure=None,
                      output_file=tmp_file.name, colorbar=True)

    # Save execution time and memory
    plt.close()
def test_plot_surf_roi():
    mesh = generate_surf()
    rng = np.random.RandomState(0)
    roi_idx = rng.randint(0, mesh[0].shape[0], size=10)
    roi_map = np.zeros(mesh[0].shape[0])
    roi_map[roi_idx] = 1
    parcellation = rng.rand(mesh[0].shape[0])

    # plot roi
    plot_surf_roi(mesh, roi_map=roi_map)
    plot_surf_roi(mesh, roi_map=roi_map, colorbar=True)
    # change vmin, vmax
    img = plot_surf_roi(mesh,
                        roi_map=roi_map,
                        vmin=1.2,
                        vmax=8.9,
                        colorbar=True)
    cbar = img.axes[-1]
    cbar_vmin = float(cbar.get_yticklabels()[0].get_text())
    cbar_vmax = float(cbar.get_yticklabels()[-1].get_text())
    assert cbar_vmin == 1.2
    assert cbar_vmax == 8.9

    # plot parcellation
    plot_surf_roi(mesh, roi_map=parcellation)
    plot_surf_roi(mesh, roi_map=parcellation, colorbar=True)

    # plot to axes
    plot_surf_roi(mesh, roi_map=roi_map, ax=None, figure=plt.gcf())

    # plot to axes
    with tempfile.NamedTemporaryFile() as tmp_file:
        plot_surf_roi(mesh,
                      roi_map=roi_map,
                      ax=plt.gca(),
                      figure=None,
                      output_file=tmp_file.name)
    with tempfile.NamedTemporaryFile() as tmp_file:
        plot_surf_roi(mesh,
                      roi_map=roi_map,
                      ax=plt.gca(),
                      figure=None,
                      output_file=tmp_file.name,
                      colorbar=True)

    # Save execution time and memory
    plt.close()
Example #8
0
def test_plot_surf_roi():
    mesh = _generate_surf()
    rng = np.random.RandomState(0)
    roi_idx = rng.randint(0, mesh[0].shape[0], size=10)
    roi_map = np.zeros(mesh[0].shape[0])
    roi_map[roi_idx] = 1
    parcellation = rng.rand(mesh[0].shape[0])

    # plot roi
    plot_surf_roi(mesh, roi_map=roi_map)
    plot_surf_roi(mesh, roi_map=roi_map, colorbar=True)

    # plot parcellation
    plot_surf_roi(mesh, roi_map=parcellation)
    plot_surf_roi(mesh, roi_map=parcellation, colorbar=True)

    # plot to axes
    plot_surf_roi(mesh, roi_map=roi_map, ax=None, figure=plt.gcf())

    # plot to axes
    with tempfile.NamedTemporaryFile() as tmp_file:
        plot_surf_roi(mesh,
                      roi_map=roi_map,
                      ax=plt.gca(),
                      figure=None,
                      output_file=tmp_file.name)
    with tempfile.NamedTemporaryFile() as tmp_file:
        plot_surf_roi(mesh,
                      roi_map=roi_map,
                      ax=plt.gca(),
                      figure=None,
                      output_file=tmp_file.name,
                      colorbar=True)

    # Save execution time and memory
    plt.close()
def test_plot_surf_roi():
    mesh = generate_surf()
    rng = np.random.RandomState(42)
    roi_idx = rng.randint(0, mesh[0].shape[0], size=10)
    roi_map = np.zeros(mesh[0].shape[0])
    roi_map[roi_idx] = 1
    parcellation = rng.uniform(size=mesh[0].shape[0])

    # plot roi
    plot_surf_roi(mesh, roi_map=roi_map)
    plot_surf_roi(mesh, roi_map=roi_map, colorbar=True)
    # change vmin, vmax
    img = plot_surf_roi(mesh,
                        roi_map=roi_map,
                        vmin=1.2,
                        vmax=8.9,
                        colorbar=True)
    img.canvas.draw()
    cbar = img.axes[-1]
    cbar_vmin = float(cbar.get_yticklabels()[0].get_text())
    cbar_vmax = float(cbar.get_yticklabels()[-1].get_text())
    assert cbar_vmin == 1.0
    assert cbar_vmax == 8.0
    img2 = plot_surf_roi(mesh,
                         roi_map=roi_map,
                         vmin=1.2,
                         vmax=8.9,
                         colorbar=True,
                         cbar_tick_format="%.2g")
    img2.canvas.draw()
    cbar = img2.axes[-1]
    cbar_vmin = float(cbar.get_yticklabels()[0].get_text())
    cbar_vmax = float(cbar.get_yticklabels()[-1].get_text())
    assert cbar_vmin == 1.2
    assert cbar_vmax == 8.9

    # plot parcellation
    plot_surf_roi(mesh, roi_map=parcellation)
    plot_surf_roi(mesh, roi_map=parcellation, colorbar=True)
    plot_surf_roi(mesh,
                  roi_map=parcellation,
                  colorbar=True,
                  cbar_tick_fomat="%f")

    # plot to axes
    plot_surf_roi(mesh, roi_map=roi_map, ax=None, figure=plt.gcf())

    # plot to axes
    with tempfile.NamedTemporaryFile() as tmp_file:
        plot_surf_roi(mesh,
                      roi_map=roi_map,
                      ax=plt.gca(),
                      figure=None,
                      output_file=tmp_file.name)
    with tempfile.NamedTemporaryFile() as tmp_file:
        plot_surf_roi(mesh,
                      roi_map=roi_map,
                      ax=plt.gca(),
                      figure=None,
                      output_file=tmp_file.name,
                      colorbar=True)

    # Test nans handling
    parcellation[::2] = np.nan
    img = plot_surf_roi(mesh, roi_map=parcellation)
    # Check that the resulting plot facecolors contain no transparent faces
    # (last column equals zero) even though the texture contains nan values
    assert (mesh[1].shape[0] == (
        (img._axstack.as_list()[0].collections[0]._facecolors[:,
                                                              3]) != 0).sum())
    # Save execution time and memory
    plt.close()
Example #10
0
def test_plot_surf_roi_matplotlib_specific():
    mesh, roi_map, parcellation = _generate_data_test_surf_roi()
    # change vmin, vmax
    img = plot_surf_roi(mesh,
                        roi_map=roi_map,
                        vmin=1.2,
                        vmax=8.9,
                        colorbar=True,
                        engine='matplotlib')
    img.canvas.draw()
    cbar = img.axes[-1]
    cbar_vmin = float(cbar.get_yticklabels()[0].get_text())
    cbar_vmax = float(cbar.get_yticklabels()[-1].get_text())
    assert cbar_vmin == 1.0
    assert cbar_vmax == 8.0
    img2 = plot_surf_roi(mesh,
                         roi_map=roi_map,
                         vmin=1.2,
                         vmax=8.9,
                         colorbar=True,
                         cbar_tick_format="%.2g",
                         engine='matplotlib')
    img2.canvas.draw()
    cbar = img2.axes[-1]
    cbar_vmin = float(cbar.get_yticklabels()[0].get_text())
    cbar_vmax = float(cbar.get_yticklabels()[-1].get_text())
    assert cbar_vmin == 1.2
    assert cbar_vmax == 8.9
    # plot to axes
    plot_surf_roi(mesh,
                  roi_map=roi_map,
                  ax=None,
                  figure=plt.gcf(),
                  engine='matplotlib')

    # plot to axes
    with tempfile.NamedTemporaryFile() as tmp_file:
        plot_surf_roi(mesh,
                      roi_map=roi_map,
                      ax=plt.gca(),
                      figure=None,
                      output_file=tmp_file.name,
                      engine='matplotlib')
    with tempfile.NamedTemporaryFile() as tmp_file:
        plot_surf_roi(mesh,
                      roi_map=roi_map,
                      ax=plt.gca(),
                      figure=None,
                      output_file=tmp_file.name,
                      colorbar=True,
                      engine='matplotlib')

    # Test nans handling
    parcellation[::2] = np.nan
    img = plot_surf_roi(mesh, roi_map=parcellation, engine='matplotlib')
    # Check that the resulting plot facecolors contain no transparent faces
    # (last column equals zero) even though the texture contains nan values
    assert (mesh[1].shape[0] == (
        (img._axstack.as_list()[0].collections[0]._facecolors[:,
                                                              3]) != 0).sum())
    # Save execution time and memory
    plt.close()