Skip to content

Commit

Permalink
Merge c5479b6 into 6f77638
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdoc committed May 9, 2016
2 parents 6f77638 + c5479b6 commit fa4a24b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
20 changes: 13 additions & 7 deletions nipy/labs/viz_tools/activation_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def plot_map(map, affine, cut_coords=None, anat=None, anat_affine=None,
threshold=None, annotate=True, draw_cross=True,
do3d=False, threshold_3d=None,
view_3d=(38.5, 70.5, 300, (-2.7, -12, 9.1)),
black_bg=False, **kwargs):
black_bg=False, **imshow_kwargs):
""" Plot three cuts of a given activation map (Frontal, Axial, and Lateral)
Parameters
Expand Down Expand Up @@ -116,7 +116,7 @@ def plot_map(map, affine, cut_coords=None, anat=None, anat_affine=None,
you whish to save figures with a black background, you
will need to pass "facecolor='k', edgecolor='k'" to pylab's
savefig.
kwargs: extra keyword arguments, optional
imshow_kwargs: extra keyword arguments, optional
Extra keyword arguments passed to pylab.imshow
Notes
Expand Down Expand Up @@ -230,12 +230,13 @@ def plot_map(map, affine, cut_coords=None, anat=None, anat_affine=None,
_plot_anat(slicer, anat, anat_affine, title=title,
annotate=annotate, draw_cross=draw_cross)

slicer.plot_map(map, affine, **kwargs)
slicer.plot_map(map, affine, **imshow_kwargs)
return slicer


def _plot_anat(slicer, anat, anat_affine, title=None,
annotate=True, draw_cross=True, dim=False, cmap=pl.cm.gray):
annotate=True, draw_cross=True, dim=False, cmap=pl.cm.gray,
**imshow_kwargs):
""" Internal function used to plot anatomy
"""
canonical_anat = False
Expand Down Expand Up @@ -274,7 +275,8 @@ def _plot_anat(slicer, anat, anat_affine, title=None,
else:
vmin = vmean - (1+dim)*ptp
slicer.plot_map(anat, anat_affine, cmap=cmap,
vmin=vmin, vmax=vmax)
vmin=vmin, vmax=vmax,
**imshow_kwargs)

if annotate:
slicer.annotate()
Expand All @@ -296,7 +298,8 @@ def _plot_anat(slicer, anat, anat_affine, title=None,

def plot_anat(anat=None, anat_affine=None, cut_coords=None, slicer='ortho',
figure=None, axes=None, title=None, annotate=True,
draw_cross=True, black_bg=False, dim=False, cmap=pl.cm.gray):
draw_cross=True, black_bg=False, dim=False, cmap=pl.cm.gray,
**imshow_kwargs):
""" Plot three cuts of an anatomical image (Frontal, Axial, and Lateral)
Parameters
Expand Down Expand Up @@ -344,6 +347,8 @@ def plot_anat(anat=None, anat_affine=None, cut_coords=None, slicer='ortho',
savefig.
cmap: matplotlib colormap, optional
The colormap for the anat
imshow_kwargs: extra keyword arguments, optional
Extra keyword arguments passed to pylab.imshow
Notes
-----
Expand All @@ -356,7 +361,8 @@ def plot_anat(anat=None, anat_affine=None, cut_coords=None, slicer='ortho',
black_bg=black_bg)

_plot_anat(slicer, anat, anat_affine, title=title,
annotate=annotate, draw_cross=draw_cross, dim=dim, cmap=cmap)
annotate=annotate, draw_cross=draw_cross, dim=dim, cmap=cmap,
**imshow_kwargs)
return slicer


Expand Down
18 changes: 18 additions & 0 deletions nipy/labs/viz_tools/test/test_activation_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import numpy as np

from nose import SkipTest
from nipy.testing.decorators import skipif
try:
import matplotlib as mp
# Make really sure that we don't try to open an Xserver connection.
Expand All @@ -15,6 +16,11 @@
except ImportError:
raise SkipTest('Could not import matplotlib')

try:
from mock import patch
except ImportError:
patch = None

from ..activation_maps import demo_plot_map, plot_anat, plot_map
from ..anat_cache import mni_sform, _AnatCache

Expand Down Expand Up @@ -53,6 +59,18 @@ def test_plot_anat():
plot_map(np.ma.masked_equal(data, 0), mni_sform, slicer='x')
plot_map(data, mni_sform, slicer='y')

@skipif(not patch, 'Cannot import patch from mock')
def test_plot_anat_kwargs():
data = np.zeros((20, 20, 20))
data[3:-3, 3:-3, 3:-3] = 1
kwargs = {'interpolation': 'nearest'}
with patch('nipy.labs.viz_tools.activation_maps._plot_anat') \
as mock_plot_anat:
ortho_slicer = plot_anat(data, mni_sform, dim=True, **kwargs)
kwargs_passed = mock_plot_anat.call_args[-1]
assert('interpolation' in kwargs_passed)
assert(kwargs_passed['interpolation'] == 'nearest')


def test_anat_cache():
# A smoke test, that can work only if the templates are installed
Expand Down

0 comments on commit fa4a24b

Please sign in to comment.