From 5ad9066adfba5517dfb9847180b78a3ab3847fa6 Mon Sep 17 00:00:00 2001 From: KamalakerDadi Date: Tue, 3 Jul 2018 15:44:37 +0200 Subject: [PATCH 1/4] MAINT: temp work-around for conda install 1.11.2 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9efc43c123..ecb4d5de0b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 From 79720bd08b882a2904efab4dedd9d7c2069e8a30 Mon Sep 17 00:00:00 2001 From: KamalakerDadi Date: Wed, 4 Jul 2018 21:44:14 +0200 Subject: [PATCH 2/4] FIX: find_cut_slices returning the repetion of values --- nilearn/plotting/find_cuts.py | 16 ++++++++++++++- nilearn/plotting/tests/test_find_cuts.py | 26 +++++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/nilearn/plotting/find_cuts.py b/nilearn/plotting/find_cuts.py index de51de7003..227fa5c84b 100644 --- a/nilearn/plotting/find_cuts.py +++ b/nilearn/plotting/find_cuts.py @@ -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 ################################################################################ @@ -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 @@ -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] diff --git a/nilearn/plotting/tests/test_find_cuts.py b/nilearn/plotting/tests/test_find_cuts.py index 7f9f63622d..71544fe391 100644 --- a/nilearn/plotting/tests/test_find_cuts.py +++ b/nilearn/plotting/tests/test_find_cuts.py @@ -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) @@ -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)) From 8c5340e6beb7af09b799ce6d5729d0dcab9fc851 Mon Sep 17 00:00:00 2001 From: Jerome Dockes Date: Tue, 10 Jul 2018 13:56:12 +0200 Subject: [PATCH 3/4] fix visibledeprecationwarning issue --- nilearn/_utils/exceptions.py | 7 +++++++ nilearn/datasets/func.py | 3 ++- nilearn/plotting/img_plotting.py | 3 ++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/nilearn/_utils/exceptions.py b/nilearn/_utils/exceptions.py index 74b20d7ea5..bb1a182d9d 100644 --- a/nilearn/_utils/exceptions.py +++ b/nilearn/_utils/exceptions.py @@ -1,3 +1,10 @@ +try: + from numpy import VisibleDeprecationWarning +except ImportError: + class VisibleDeprecationWarning(DeprecationWarning): + pass + + AuthorizedException = ( BufferError, ArithmeticError, diff --git a/nilearn/datasets/func.py b/nilearn/datasets/func.py index c5db149035..b3dd0cb6e2 100644 --- a/nilearn/datasets/func.py +++ b/nilearn/datasets/func.py @@ -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. " @@ -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: diff --git a/nilearn/plotting/img_plotting.py b/nilearn/plotting/img_plotting.py index a68c761696..df9592f366 100644 --- a/nilearn/plotting/img_plotting.py +++ b/nilearn/plotting/img_plotting.py @@ -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 @@ -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, From 9986825909b4aa0509d2e528eb6642f182195bf1 Mon Sep 17 00:00:00 2001 From: Jerome Dockes Date: Tue, 10 Jul 2018 14:01:01 +0200 Subject: [PATCH 4/4] VisibleDeprecationWarning(UserWarning) --- nilearn/_utils/exceptions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nilearn/_utils/exceptions.py b/nilearn/_utils/exceptions.py index bb1a182d9d..ab47a7b1f0 100644 --- a/nilearn/_utils/exceptions.py +++ b/nilearn/_utils/exceptions.py @@ -1,7 +1,7 @@ try: from numpy import VisibleDeprecationWarning except ImportError: - class VisibleDeprecationWarning(DeprecationWarning): + class VisibleDeprecationWarning(UserWarning): pass