Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into add_fsaverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromedockes committed Jul 10, 2018
2 parents 2cd7be2 + d5368d8 commit 318b91a
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ matrix:
SCIKIT_LEARN_VERSION="0.15"
# Fake Ubuntu Xenial (Travis doesn't support Xenial yet)
- env: DISTRIB="conda" PYTHON_VERSION="2.7"
NUMPY_VERSION="1.11" SCIPY_VERSION="0.17"
NUMPY_VERSION="1.11.2" SCIPY_VERSION="0.17"
SCIKIT_LEARN_VERSION="0.17"
NIBABEL_VERSION="2.0.2"
# Python 3.4 with intermediary versions
Expand Down
7 changes: 7 additions & 0 deletions nilearn/_utils/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
try:
from numpy import VisibleDeprecationWarning
except ImportError:
class VisibleDeprecationWarning(UserWarning):
pass


AuthorizedException = (
BufferError,
ArithmeticError,
Expand Down
3 changes: 2 additions & 1 deletion nilearn/datasets/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from .._utils import check_niimg
from .._utils.compat import BytesIO, _basestring, _urllib
from .._utils.numpy_conversions import csv_to_array
from .._utils.exceptions import VisibleDeprecationWarning


@deprecated("fetch_haxby_simple will be removed in future releases. "
Expand Down Expand Up @@ -151,7 +152,7 @@ def fetch_haxby(data_dir=None, n_subjects=None, subjects=(2,),
warn_str = ("The parameter 'n_subjects' is deprecated from 0.2.6 and "
"will be removed in nilearn next release. Use parameter "
"'subjects' instead.")
warnings.warn(warn_str, np.VisibleDeprecationWarning, stacklevel=2)
warnings.warn(warn_str, VisibleDeprecationWarning, stacklevel=2)
subjects = n_subjects

if isinstance(subjects, numbers.Number) and subjects > 6:
Expand Down
16 changes: 15 additions & 1 deletion nilearn/plotting/find_cuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from .._utils.numpy_conversions import as_ndarray
from .._utils import check_niimg_3d
from .._utils.niimg import _safe_get_data
from ..image.resampling import get_mask_bounds, coord_transform
from ..image.resampling import get_mask_bounds, coord_transform, reorder_img
from ..image.image import _smooth_array

################################################################################
Expand Down Expand Up @@ -216,6 +216,12 @@ def find_cut_slices(img, direction='z', n_cuts=7, spacing='auto'):
separated by a distance of at least 'spacing'. If n_cuts is very
large and all the activated regions are covered, cuts with a spacing
less than 'spacing' will be returned.
Warning
-------
If a non-diagonal img is given. This function automatically reorders
img to get it back to diagonal. This is to avoid finding same cuts in
the slices.
"""

# misc
Expand All @@ -226,6 +232,14 @@ def find_cut_slices(img, direction='z', n_cuts=7, spacing='auto'):
axis = 'xyz'.index(direction)
img = check_niimg_3d(img)
affine = img.affine
if not np.alltrue(np.diag(affine)[:3]):
warnings.warn('A non-diagonal affine is found in the given '
'image. Reordering the image to get diagonal affine '
'for finding cuts in the slices.', stacklevel=2)
# resample is set to avoid issues with an image having a non-diagonal
# affine and rotation.
img = reorder_img(img, resample='nearest')
affine = img.affine
orig_data = np.abs(_safe_get_data(img))
this_shape = orig_data.shape[axis]

Expand Down
3 changes: 2 additions & 1 deletion nilearn/plotting/img_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from .._utils.fixes.matplotlib_backports import (cbar_outline_get_xy,
cbar_outline_set_xy)
from .._utils.ndimage import get_border_data
from .._utils.exceptions import VisibleDeprecationWarning
from ..datasets import load_mni152_template
from ..image import iter_img
from .displays import get_slicer, get_projector
Expand Down Expand Up @@ -807,7 +808,7 @@ def plot_prob_atlas(maps_img, bg_img=MNI152TEMPLATE, view_type='auto',
bg_img = anat_img
warn_str = ("anat_img is deprecated and will be removed in 0.5. "
"Use `bg_img` instead.")
warnings.warn(warn_str, np.VisibleDeprecationWarning, stacklevel=2)
warnings.warn(warn_str, VisibleDeprecationWarning, stacklevel=2)

display = plot_anat(bg_img, cut_coords=cut_coords,
display_mode=display_mode,
Expand Down
26 changes: 25 additions & 1 deletion nilearn/plotting/tests/test_find_cuts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from nose.tools import assert_equal, assert_true
from nose.tools import assert_equal, assert_true, assert_not_equal
import nibabel
from nilearn.plotting.find_cuts import (find_xyz_cut_coords, find_cut_slices,
_transform_cut_coords)
Expand Down Expand Up @@ -88,6 +88,30 @@ def test_find_cut_slices():
cuts = find_cut_slices(img, direction=direction,
n_cuts=n_cuts, spacing=2)

# non-diagonal affines
affine = np.array([[-1., 0., 0., 123.46980286],
[0., 0., 1., -94.11079407],
[0., -1., 0., 160.694],
[0., 0., 0., 1.]])
img = nibabel.Nifti1Image(data, affine)
cuts = find_cut_slices(img, direction='z')
assert_not_equal(np.diff(cuts).min(), 0.)
affine = np.array([[-2., 0., 0., 123.46980286],
[0., 0., 2., -94.11079407],
[0., -2., 0., 160.694],
[0., 0., 0., 1.]])
img = nibabel.Nifti1Image(data, affine)
cuts = find_cut_slices(img, direction='z')
assert_not_equal(np.diff(cuts).min(), 0.)
# Rotate it slightly
angle = np.pi / 180 * 15
rotation_matrix = np.array([[np.cos(angle), -np.sin(angle)],
[np.sin(angle), np.cos(angle)]])
affine[:2, :2] = rotation_matrix * 2.0
img = nibabel.Nifti1Image(data, affine)
cuts = find_cut_slices(img, direction='z')
assert_not_equal(np.diff(cuts).min(), 0.)


def test_validity_of_ncuts_error_in_find_cut_slices():
data = np.zeros((50, 50, 50))
Expand Down

0 comments on commit 318b91a

Please sign in to comment.