Esempio n. 1
0
def test_plot_glass_brain():
    img = _generate_img()

    # test plot_glass_brain with colorbar
    plot_glass_brain(img, colorbar=True)

    # test plot_glass_brain with negative values
    plot_glass_brain(img, colorbar=True, plot_abs=False)
Esempio n. 2
0
def test_plot_glass_brain_colorbar_having_nans(testdata_3d):
    img = testdata_3d['img']
    data = get_data(img)

    data[6, 5, 2] = np.inf
    img = nibabel.Nifti1Image(data, np.eye(4))
    plot_glass_brain(img, colorbar=True)
    plt.close()
Esempio n. 3
0
def test_plot_glass_brain():
    mp.use('template', warn=False)
    import matplotlib.pyplot as plt
    plt.switch_backend('template')
    img = _generate_img()

    # test plot_glass_brain with colorbar
    plot_glass_brain(img, colorbar=True)
Esempio n. 4
0
def test_plot_glass_brain():
    img = _generate_img()

    # test plot_glass_brain with colorbar
    plot_glass_brain(img, colorbar=True)

    # test plot_glass_brain with negative values
    plot_glass_brain(img, colorbar=True, plot_abs=False)
Esempio n. 5
0
def test_plot_glass_brain_colorbar_having_nans():
    img = _generate_img()
    data = img.get_data()

    data[6, 5, 2] = np.inf
    img = nibabel.Nifti1Image(data, np.eye(4))
    plot_glass_brain(img, colorbar=True)
    plt.close()
Esempio n. 6
0
def test_plot_glass_brain():
    mp.use('template', warn=False)
    import matplotlib.pyplot as plt
    plt.switch_backend('template')
    img = _generate_img()

    # test plot_glass_brain with colorbar
    plot_glass_brain(img, colorbar=True)
Esempio n. 7
0
def test_plot_glass_brain_with_completely_masked_img():
    # Smoke test for PR #1888 with display modes having 'l'
    data = np.zeros((10, 20, 30))
    affine = np.eye(4)

    img = nibabel.Nifti1Image(data, affine)
    plot_glass_brain(img, display_mode='lzry')
    plot_glass_brain(img, display_mode='lr')
    plt.close()
Esempio n. 8
0
def test_plot_glass_brain():
    img = _generate_img()

    # test plot_glass_brain with colorbar
    plot_glass_brain(img, colorbar=True)

    # test plot_glass_brain with negative values
    plot_glass_brain(img, colorbar=True, plot_abs=False)

    # Save execution time and memory
    plt.close()
Esempio n. 9
0
def test_plotting_functions_with_cmaps():
    img = load_mni152_template()
    cmaps = ['Paired', 'Set1', 'Set2', 'Set3']
    for cmap in cmaps:
        plot_roi(img, cmap=cmap, colorbar=True)
        plot_stat_map(img, cmap=cmap, colorbar=True)
        plot_glass_brain(img, cmap=cmap, colorbar=True)

    if LooseVersion(matplotlib.__version__) >= LooseVersion('2.0.0'):
        plot_stat_map(img, cmap='viridis', colorbar=True)

    plt.close()
Esempio n. 10
0
def test_plot_stat_map_with_nans(testdata_3d):
    img = testdata_3d['img']
    data = get_data(img)

    data[6, 5, 1] = np.nan
    data[1, 5, 2] = np.nan
    data[1, 3, 2] = np.nan
    data[6, 5, 2] = np.inf

    img = nibabel.Nifti1Image(data, mni_affine)
    plot_epi(img)
    plot_stat_map(img)
    plot_glass_brain(img)
Esempio n. 11
0
def test_plot_stat_map_with_nans():
    img = _generate_img()
    data = img.get_data()

    data[6, 5, 1] = np.nan
    data[1, 5, 2] = np.nan
    data[1, 3, 2] = np.nan
    data[6, 5, 2] = np.inf

    img = nibabel.Nifti1Image(data, mni_affine)
    plot_epi(img)
    plot_stat_map(img)
    plot_glass_brain(img)
Esempio n. 12
0
def test_plotting_functions_with_cmaps():
    img = load_mni152_template()
    # some cmaps such as 'viridis' (the new default in 2.0), 'magma', 'plasma',
    # and 'inferno' are not supported for older matplotlib version from < 1.5
    cmaps = ['Paired', 'Set1', 'Set2', 'Set3']
    for cmap in cmaps:
        plot_roi(img, cmap=cmap, colorbar=True)
        plot_stat_map(img, cmap=cmap, colorbar=True)
        plot_glass_brain(img, cmap=cmap, colorbar=True)

    if LooseVersion(matplotlib.__version__) >= LooseVersion('2.0.0'):
        plot_stat_map(img, cmap='viridis', colorbar=True)

    plt.close()
Esempio n. 13
0
def test_plotting_functions_with_cmaps():
    img = load_mni152_template()
    # some cmaps such as 'viridis' (the new default in 2.0), 'magma', 'plasma',
    # and 'inferno' are not supported for older matplotlib version from < 1.5
    cmaps = ['Paired', 'Set1', 'Set2', 'Set3']
    for cmap in cmaps:
        plot_roi(img, cmap=cmap, colorbar=True)
        plot_stat_map(img, cmap=cmap, colorbar=True)
        plot_glass_brain(img, cmap=cmap, colorbar=True)

    if LooseVersion(matplotlib.__version__) >= LooseVersion('2.0.0'):
        plot_stat_map(img, cmap='viridis', colorbar=True)

    plt.close()
Esempio n. 14
0
def test_plot_glass_brain_threshold_for_uint8(testdata_3d):
    # mask was applied in [-threshold, threshold] which is problematic
    # for uint8 data. See https://github.com/nilearn/nilearn/issues/611
    # for more details
    data = 10 * np.ones((10, 10, 10), dtype='uint8')
    # Having a zero minimum value is important to reproduce
    # https://github.com/nilearn/nilearn/issues/762
    data[0, 0] = 0
    affine = np.eye(4)
    img = nibabel.Nifti1Image(data, affine)
    threshold = np.array(5, dtype='uint8')
    display = plot_glass_brain(img,
                               threshold=threshold,
                               display_mode='z',
                               colorbar=True)
    # Next two lines retrieve the numpy array from the plot
    ax = list(display.axes.values())[0].ax
    plotted_array = ax.images[0].get_array()
    # Make sure that there is one value masked
    assert plotted_array.mask.sum() == 1
    # Make sure that the value masked is in the corner. Note that the
    # axis orientation seem to be flipped, hence (0, 0) -> (-1, 0)
    assert plotted_array.mask[-1, 0]

    # Save execution time and memory
    plt.close()
Esempio n. 15
0
def test_add_markers_using_plot_glass_brain():
    fig = plot_glass_brain(None)
    coords = [(-34, -39, -9)]
    fig.add_markers(coords)
    fig.close()

    # Add a single marker in right hemishpere such that no marker
    # should appear in the left hemisphere when plotting
    display = plotting.plot_glass_brain(None, display_mode='lyrz')
    display.add_markers([[20, 20, 20]])
    # Check that Axe 'l' has no marker
    assert display.axes['l'].ax.collections[0].get_offsets().data.shape == (0, 2)
    # Check that all other Axes have one marker
    for d in 'ryz':
        assert display.axes[d].ax.collections[0].get_offsets().data.shape == (1, 2)

    # Add two markers in left hemisphere such that no marker
    # should appear in the right hemisphere when plotting
    display = plotting.plot_glass_brain(None, display_mode='lyrz')
    display.add_markers([[-20, 20, 20], [-10, 10, 10]],
                        marker_color=['r', 'b'])
    # Check that Axe 'r' has no marker
    assert display.axes['r'].ax.collections[0].get_offsets().data.shape == (0, 2)
    # Check that all other Axes have two markers
    for d in 'lyz':
        assert display.axes[d].ax.collections[0].get_offsets().data.shape == (2, 2)
Esempio n. 16
0
def test_plot_noncurrent_axes():
    """Regression test for Issue #450"""

    maps_img = nibabel.Nifti1Image(np.random.random((10, 10, 10)), np.eye(4))
    fh1 = plt.figure()
    fh2 = plt.figure()
    ax1 = fh1.add_subplot(1, 1, 1)

    assert_equal(plt.gcf(), fh2, "fh2  was the last plot created.")

    # Since we gave ax1, the figure should be plotted in fh1.
    # Before #451, it was plotted in fh2.
    slicer = plot_glass_brain(maps_img, axes=ax1, title='test')
    for ax_name, niax in slicer.axes.items():
        ax_fh = niax.ax.get_figure()
        assert_equal(ax_fh, fh1, 'New axis %s should be in fh1.' % ax_name)
Esempio n. 17
0
def test_plot_noncurrent_axes():
    """Regression test for Issue #450"""

    maps_img = nibabel.Nifti1Image(np.random.random((10, 10, 10)), np.eye(4))
    fh1 = plt.figure()
    fh2 = plt.figure()
    ax1 = fh1.add_subplot(1, 1, 1)

    assert_equal(plt.gcf(), fh2, "fh2  was the last plot created.")

    # Since we gave ax1, the figure should be plotted in fh1.
    # Before #451, it was plotted in fh2.
    slicer = plot_glass_brain(maps_img, axes=ax1, title='test')
    for ax_name, niax in slicer.axes.items():
        ax_fh = niax.ax.get_figure()
        assert_equal(ax_fh, fh1, 'New axis %s should be in fh1.' % ax_name)
Esempio n. 18
0
def test_plot_noncurrent_axes():
    """Regression test for Issue #450"""
    rng = np.random.RandomState(42)
    maps_img = nibabel.Nifti1Image(rng.random_sample((10, 10, 10)), np.eye(4))
    fh1 = plt.figure()
    fh2 = plt.figure()
    ax1 = fh1.add_subplot(1, 1, 1)

    assert plt.gcf() == fh2, "fh2  was the last plot created."

    # Since we gave ax1, the figure should be plotted in fh1.
    # Before #451, it was plotted in fh2.
    slicer = plot_glass_brain(maps_img, axes=ax1, title='test')
    for ax_name, niax in slicer.axes.items():
        ax_fh = niax.ax.get_figure()
        assert ax_fh == fh1, 'New axis %s should be in fh1.' % ax_name

    # Save execution time and memory
    plt.close()
Esempio n. 19
0
def test_plot_glass_brain_threshold_for_uint8():
    # mask was applied in [-threshold, threshold] which is problematic
    # for uint8 data. See https://github.com/nilearn/nilearn/issues/611
    # for more details
    data = 10 * np.ones((10, 10, 10), dtype="uint8")
    # Having a zero minimum value is important to reproduce
    # https://github.com/nilearn/nilearn/issues/762
    data[0, 0] = 0
    affine = np.eye(4)
    img = nibabel.Nifti1Image(data, affine)
    threshold = np.array(5, dtype="uint8")
    display = plot_glass_brain(img, threshold=threshold, display_mode="z", colorbar=True)
    # Next two lines retrieve the numpy array from the plot
    ax = list(display.axes.values())[0].ax
    plotted_array = ax.images[0].get_array()
    # Make sure that there is one value masked
    assert_equal(plotted_array.mask.sum(), 1)
    # Make sure that the value masked is in the corner. Note that the
    # axis orientation seem to be flipped, hence (0, 0) -> (-1, 0)
    assert_true(plotted_array.mask[-1, 0])
def test_plot_glass_brain():
    img = _generate_img()

    # test plot_glass_brain with colorbar
    plot_glass_brain(img, colorbar=True)

    # test plot_glass_brain with negative values
    plot_glass_brain(img, colorbar=True, plot_abs=False)

    # Save execution time and memory
    plt.close()
    # smoke-test for hemispheric glass brain
    filename = tempfile.mktemp(suffix='.png')
    plot_glass_brain(img, output_file=filename, display_mode='lzry')
    plt.close()
Esempio n. 21
0
def test_plot_glass_brain():
    img = _generate_img()

    # test plot_glass_brain with colorbar
    plot_glass_brain(img, colorbar=True)

    # test plot_glass_brain with negative values
    plot_glass_brain(img, colorbar=True, plot_abs=False)

    # Save execution time and memory
    plt.close()
    # smoke-test for hemispheric glass brain
    filename = tempfile.mktemp(suffix='.png')
    plot_glass_brain(img, output_file=filename, display_mode='lzry')
    plt.close()
Esempio n. 22
0
def test_plot_glass_brain(testdata_3d):
    img = testdata_3d['img']

    # test plot_glass_brain with colorbar
    plot_glass_brain(img, colorbar=True, resampling_interpolation='nearest')

    # test plot_glass_brain with negative values
    plot_glass_brain(img, colorbar=True, plot_abs=False,
                     resampling_interpolation='nearest')

    # Save execution time and memory
    plt.close()
    # smoke-test for hemispheric glass brain
    filename = tempfile.mktemp(suffix='.png')
    plot_glass_brain(img, output_file=filename, display_mode='lzry')
    plt.close()
Esempio n. 23
0
def test_plot_glass_brain():
    img = _generate_img()

    # test plot_glass_brain with colorbar
    plot_glass_brain(img, colorbar=True)
Esempio n. 24
0
"""The goal of this script is to align the glass brain SVGs on top of the
anatomy. This is only useful for internal purposes especially when the
SVG is modified.
"""

from nilearn import plotting
from nilearn.plotting import img_plotting, glass_brain, show

# plotting anat for coarse alignment
bg_img, _, _, _ = img_plotting._load_anat()
display = img_plotting.plot_glass_brain(bg_img,
                                        threshold=0,
                                        black_bg=True,
                                        title='anat',
                                        alpha=1)
display = img_plotting.plot_glass_brain(bg_img,
                                        threshold=0,
                                        title='anat',
                                        alpha=1)

# plotting slices for finer alignment
# e.g. parieto-occipital sulcus


def add_brain_schematics(display):
    for axes in display.axes.values():
        kwargs = {'alpha': 0.5, 'linewidth': 1, 'edgecolor': 'orange'}
        object_bounds = glass_brain.plot_brain_schematics(
            axes.ax, axes.direction, **kwargs)
        axes.add_object_bounds(object_bounds)
Esempio n. 25
0
def test_add_markers_using_plot_glass_brain():
    fig = plot_glass_brain(None)
    coords = [(-34, -39, -9)]
    fig.add_markers(coords)
    fig.close()
Esempio n. 26
0
#!/usr/bin/env python
"""The goal of this script is to align the glass brain SVGs on top of the
anatomy. This is only useful for internal purposes especially when the
SVG is modified.
"""

from nilearn import plotting
from nilearn.plotting import img_plotting, glass_brain, show

if __name__ == '__main__':
    # plotting anat for coarse alignment
    bg_img, _, _, _ = img_plotting._load_anat()
    display = img_plotting.plot_glass_brain(bg_img,
                                            threshold=0,
                                            black_bg=True,
                                            title='anat',
                                            alpha=1)
    display = img_plotting.plot_glass_brain(bg_img,
                                            threshold=0,
                                            black_bg=True,
                                            title='anat',
                                            alpha=1,
                                            display_mode='ortho')
    display = img_plotting.plot_glass_brain(bg_img,
                                            threshold=0,
                                            title='anat',
                                            alpha=1)

    # checking hemispheres plotting
    display = img_plotting.plot_glass_brain(bg_img,
                                            threshold=0,
Esempio n. 27
0
"""The goal of this script is to align the glass brain SVGs on top of the
anatomy. This is only useful for internal purposes especially when the
SVG is modified.
"""

from nilearn import plotting
from nilearn.plotting import img_plotting, glass_brain, show


# plotting anat for coarse alignment
bg_img, _, _, _ = img_plotting._load_anat()
display = img_plotting.plot_glass_brain(bg_img, threshold=0, black_bg=True,
                                        title='anat', alpha=1)
display = img_plotting.plot_glass_brain(bg_img, threshold=0,
                                        title='anat', alpha=1)


# plotting slices for finer alignment
# e.g. parieto-occipital sulcus

def add_brain_schematics(display):
    for axes in display.axes.values():
        kwargs = {'alpha': 0.5, 'linewidth': 1, 'edgecolor': 'orange'}
        object_bounds = glass_brain.plot_brain_schematics(axes.ax,
                                                          axes.direction,
                                                          **kwargs)
        axes.add_object_bounds(object_bounds)


# side
display = plotting.plot_anat(display_mode='x', cut_coords=[-2])
Esempio n. 28
0
def test_plot_glass_brain():
    img = _generate_img()

    # test plot_glass_brain with colorbar
    plot_glass_brain(img, colorbar=True)
Esempio n. 29
0
#!/usr/bin/env python
"""The goal of this script is to align the glass brain SVGs on top of the
anatomy. This is only useful for internal purposes especially when the
SVG is modified.
"""

from nilearn import plotting
from nilearn.plotting import img_plotting, glass_brain, show

if __name__ == '__main__':
    # plotting anat for coarse alignment
    bg_img, _, _, _ = img_plotting._load_anat()
    display = img_plotting.plot_glass_brain(bg_img, threshold=0, black_bg=True,
                                            title='anat', alpha=1)
    display = img_plotting.plot_glass_brain(bg_img, threshold=0, black_bg=True,
                                            title='anat', alpha=1,
                                            display_mode='ortho')
    display = img_plotting.plot_glass_brain(bg_img, threshold=0,
                                            title='anat', alpha=1)

    # checking hemispheres plotting
    display = img_plotting.plot_glass_brain(bg_img, threshold=0, black_bg=True,
                                            title='anat', alpha=1,
                                            display_mode='lyrz')

    # plotting slices for finer alignment
    # e.g. parieto-occipital sulcus


    def add_brain_schematics(display):
        for axes in display.axes.values():
Esempio n. 30
0
def test_plot_glass_brain_display_modes_without_img():
    # Smoke test for work around from PR #1888
    fig = plot_glass_brain(None, display_mode='lr')
    fig = plot_glass_brain(None, display_mode='lzry')
    fig.close()