Repository: nilearn/nilearn

Issue:
replace img.get_data() by img.get_fdata()
This is to comply with Nibabel Deprecation warning.



Discussion:
do you mean `nilearn.image.get_data`? see #2172 
there are only a few uses of `get_data` that were introduced after #2172 , actually it would be good to fix these before the release so the release works with new versions of nibabel
we just need to replace `img.get_data()` with `nilearn.image.get_data(img)` in these places:

```
glm/tests/test_first_level.py
79:            fixed_fx_contrast.get_data(),
80:            fixed_fx_dic['effect_size'].get_data())
82:            fixed_fx_variance.get_data(),
83:            fixed_fx_dic['effect_variance'].get_data())
85:            fixed_fx_stat.get_data(), fixed_fx_dic['stat'].get_data())
94:            fixed_fx_contrast.get_data(),
95:            fixed_fx_dic['effect_size'].get_data())
97:            fixed_fx_variance.get_data(),
98:            fixed_fx_dic['effect_variance'].get_data())
100:            fixed_fx_stat.get_data(), fixed_fx_dic['stat'].get_data())
215:    assert_almost_equal(z1.get_data() + z2.get_data(),
216:                        2 * z_joint.get_data())

glm/tests/test_thresholding.py
117:    vals = th_map.get_data()
122:    vals = th_map.get_data()
127:    vals = th_map.get_data()
134:    vals = th_map.get_data()
146:    vals = th_map.get_data()

plotting/surf_plotting.py
802:        sm = _colorbar_from_array(stat_map.get_data(), vmax, threshold, kwargs,

plotting/img_plotting.py
686:    roi_data = roi_img.get_data()
```
Thx. I can do that unless you're on it.

I see @NicolasGensollen assigned this to himself, but if he didn't get started I can do it
On 12/11/2020 11:57, jeromedockes wrote:
>
> I see @NicolasGensollen <https://github.com/NicolasGensollen> assigned 
> this to himself, but if he didn't get started I can do it
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub 
> <https://github.com/nilearn/nilearn/issues/2593#issuecomment-726004538>, 
> or unsubscribe 
> <https://github.com/notifications/unsubscribe-auth/AABZHVRRX3S66TG3EXWU6R3SPO5R3ANCNFSM4TTARUWQ>.
>
I'm on it now. B



Resolving patch:
diff --git a/nilearn/plotting/img_plotting.py b/nilearn/plotting/img_plotting.py
--- a/nilearn/plotting/img_plotting.py
+++ b/nilearn/plotting/img_plotting.py
@@ -683,7 +683,7 @@ def _plot_roi_contours(display, roi_img, cmap, alpha, linewidths):
         Contours displayed on the background image.
     """
     roi_img = _utils.check_niimg_3d(roi_img)
-    roi_data = roi_img.get_data()
+    roi_data = get_data(roi_img)
     labels = np.unique(roi_data)
     cmap = plt.cm.get_cmap(cmap)
     color_list = cmap(np.linspace(0, 1, len(labels)))
diff --git a/nilearn/plotting/surf_plotting.py b/nilearn/plotting/surf_plotting.py
--- a/nilearn/plotting/surf_plotting.py
+++ b/nilearn/plotting/surf_plotting.py
@@ -9,6 +9,7 @@
 from matplotlib.cm import ScalarMappable, get_cmap
 from matplotlib.colors import Normalize, LinearSegmentedColormap
 from mpl_toolkits.mplot3d import Axes3D
+from nilearn import image
 from nilearn.plotting.img_plotting import (_get_colorbar_and_data_ranges,
                                            _crop_colorbar)
 from nilearn.surface import (load_surf_data,
@@ -799,7 +800,8 @@ def plot_img_on_surf(stat_map, surf_mesh='fsaverage5', mask_img=None,
         ax.dist = 6
 
     if colorbar:
-        sm = _colorbar_from_array(stat_map.get_data(), vmax, threshold, kwargs,
+        sm = _colorbar_from_array(image.get_data(stat_map),
+                                  vmax, threshold, kwargs,
                                   cmap=get_cmap(cmap))
 
         cbar_ax = fig.add_subplot(32, 1, 32)


Test patch:
diff --git a/nilearn/glm/tests/test_first_level.py b/nilearn/glm/tests/test_first_level.py
--- a/nilearn/glm/tests/test_first_level.py
+++ b/nilearn/glm/tests/test_first_level.py
@@ -76,13 +76,13 @@ def test_explicit_fixed_effects():
         ) = compute_fixed_effects(contrasts, variance, mask)
 
         assert_almost_equal(
-            fixed_fx_contrast.get_data(),
-            fixed_fx_dic['effect_size'].get_data())
+            get_data(fixed_fx_contrast),
+            get_data(fixed_fx_dic['effect_size']))
         assert_almost_equal(
-            fixed_fx_variance.get_data(),
-            fixed_fx_dic['effect_variance'].get_data())
+            get_data(fixed_fx_variance),
+            get_data(fixed_fx_dic['effect_variance']))
         assert_almost_equal(
-            fixed_fx_stat.get_data(), fixed_fx_dic['stat'].get_data())
+            get_data(fixed_fx_stat), get_data(fixed_fx_dic['stat']))
 
         # test without mask variable
         (
@@ -91,13 +91,13 @@ def test_explicit_fixed_effects():
             fixed_fx_stat,
         ) = compute_fixed_effects(contrasts, variance)
         assert_almost_equal(
-            fixed_fx_contrast.get_data(),
-            fixed_fx_dic['effect_size'].get_data())
+            get_data(fixed_fx_contrast),
+            get_data(fixed_fx_dic['effect_size']))
         assert_almost_equal(
-            fixed_fx_variance.get_data(),
-            fixed_fx_dic['effect_variance'].get_data())
+            get_data(fixed_fx_variance),
+            get_data(fixed_fx_dic['effect_variance']))
         assert_almost_equal(
-            fixed_fx_stat.get_data(), fixed_fx_dic['stat'].get_data())
+            get_data(fixed_fx_stat), get_data(fixed_fx_dic['stat']))
 
         # ensure that using unbalanced effects size and variance images
         # raises an error
@@ -212,8 +212,8 @@ def test_high_level_glm_different_design_matrices():
         fmri_data[1], design_matrices=design_matrices[1])
     z2 = model2.compute_contrast(np.eye(rk + 1)[:1],
                                  output_type='effect_size')
-    assert_almost_equal(z1.get_data() + z2.get_data(),
-                        2 * z_joint.get_data())
+    assert_almost_equal(get_data(z1) + get_data(z2),
+                        2 * get_data(z_joint))
 
 
 def test_run_glm():
diff --git a/nilearn/glm/tests/test_thresholding.py b/nilearn/glm/tests/test_thresholding.py
--- a/nilearn/glm/tests/test_thresholding.py
+++ b/nilearn/glm/tests/test_thresholding.py
@@ -114,24 +114,24 @@ def test_all_resolution_inference():
 
     # test 1: standard case
     th_map = cluster_level_inference(stat_img, threshold=3, alpha=.05)
-    vals = th_map.get_data()
+    vals = get_data(th_map)
     assert np.sum(vals > 0) == 8
 
     # test 2: high threshold
     th_map = cluster_level_inference(stat_img, threshold=6, alpha=.05)
-    vals = th_map.get_data()
+    vals = get_data(th_map)
     assert np.sum(vals > 0) == 0
 
     # test 3: list of thresholds
     th_map = cluster_level_inference(stat_img, threshold=[3, 6], alpha=.05)
-    vals = th_map.get_data()
+    vals = get_data(th_map)
     assert np.sum(vals > 0) == 8
 
     # test 4: one single voxel
     data[3, 6, 7] = 10
     stat_img_ = nib.Nifti1Image(data, np.eye(4))
     th_map = cluster_level_inference(stat_img_, threshold=7, alpha=.05)
-    vals = th_map.get_data()
+    vals = get_data(th_map)
     assert np.sum(vals > 0) == 1
 
     # test 5: aberrant alpha
@@ -143,7 +143,7 @@ def test_all_resolution_inference():
     # test 6 with mask_img
     th_map = cluster_level_inference(stat_img, mask_img=mask_img,
                                      threshold=3, alpha=.05)
-    vals = th_map.get_data()
+    vals = get_data(th_map)
     assert np.sum(vals > 0) == 8
 
     # test 7 verbose mode