From 33c3daac81d63ac2a48896cd76d9d50d56a2fba6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Richard=20H=C3=B6chenberger?=
 <richard.hoechenberger@gmail.com>
Date: Thu, 26 Mar 2020 18:27:43 +0100
Subject: [PATCH] TESTS, PKG: Remove DeprecationWarnings (#377)

* TESTS, PKG: Remove DeprecationWarnings

`nibabel` threw `DeprecationWarnings`  in calls to
`1w.get_data()`: the `get_data()` method has been
deprecated since release 3.0 (December 2019), and one
should use `get_fdata()` instead, see e.g.
https://git.fmrib.ox.ac.uk/samh/profumo/commit/82cde929f04a581c2c6984d7fa280a37868d082b

`get_fdata()` was introduced in `nibabel` 2.2 (October 2017),
therefore I felt incouraged to simply switch `mne-bids` to
`get_fdata()` without adding a fallback to `get_data()`, and
bumping the min. required `nibabel` version to 2.2.

* TESTS: Update doc env
---
 README.rst                   |  2 +-
 doc/environment.yml          |  2 +-
 environment.yml              |  2 +-
 mne_bids/tests/test_write.py | 12 ++++++------
 mne_bids/write.py            |  2 +-
 setup.cfg                    |  1 -
 6 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/README.rst b/README.rst
index 0fbccbbe8..f34ad2857 100644
--- a/README.rst
+++ b/README.rst
@@ -77,7 +77,7 @@ Dependencies
 * numpy (>=1.14)
 * scipy (>=0.18.1)
 * mne (>=0.19.1)
-* nibabel (optional)
+* nibabel (>=2.2, optional)
 * pybv (optional)
 
 Installation
diff --git a/doc/environment.yml b/doc/environment.yml
index 990125a76..7826c2ba2 100644
--- a/doc/environment.yml
+++ b/doc/environment.yml
@@ -13,7 +13,7 @@ dependencies:
 - pip:
   - mne_bids>=0.3,<0.4
   - mne>=0.19.1
-  - nibabel
+  - nibabel>=2.2
   - pybv
   - nilearn
   - flake8
diff --git a/environment.yml b/environment.yml
index 1a8675887..6b7a7fa02 100644
--- a/environment.yml
+++ b/environment.yml
@@ -12,7 +12,7 @@ dependencies:
 - matplotlib
 - pip:
   - mne>=0.19.1
-  - nibabel
+  - nibabel>=2.2
   - pybv
   - nilearn
   - flake8
diff --git a/mne_bids/tests/test_write.py b/mne_bids/tests/test_write.py
index 3133b2cd7..9c9a8bf9a 100644
--- a/mne_bids/tests/test_write.py
+++ b/mne_bids/tests/test_write.py
@@ -943,14 +943,14 @@ def test_write_anat(_bids_validate):
                           session_id, raw=raw, trans=trans_fname,
                           verbose=True, deface=True, overwrite=True)
     t1w = nib.load(op.join(anat_dir, 'sub-01_ses-01_T1w.nii.gz'))
-    vox_sum = t1w.get_data().sum()
+    vox_sum = t1w.get_fdata().sum()
 
     anat_dir2 = write_anat(bids_root, subject_id, t1w_mgh,
                            session_id, raw=raw, trans=trans_fname,
                            verbose=True, deface=dict(inset=25.),
                            overwrite=True)
     t1w2 = nib.load(op.join(anat_dir2, 'sub-01_ses-01_T1w.nii.gz'))
-    vox_sum2 = t1w2.get_data().sum()
+    vox_sum2 = t1w2.get_fdata().sum()
 
     assert vox_sum > vox_sum2
 
@@ -959,7 +959,7 @@ def test_write_anat(_bids_validate):
                            verbose=True, deface=dict(theta=25),
                            overwrite=True)
     t1w3 = nib.load(op.join(anat_dir3, 'sub-01_ses-01_T1w.nii.gz'))
-    vox_sum3 = t1w3.get_data().sum()
+    vox_sum3 = t1w3.get_fdata().sum()
 
     assert vox_sum > vox_sum3
 
@@ -1016,7 +1016,7 @@ def test_write_anat(_bids_validate):
     _bids_validate(bids_root)
 
     t1w1 = nib.load(op.join(anat_dir, 'sub-01_ses-01_acq-01_T1w.nii.gz'))
-    vox1 = t1w1.get_data()
+    vox1 = t1w1.get_fdata()
 
     # test mri landmarks
     anat_dir = write_anat(bids_root, subject_id, t1w_mgh, session_id,
@@ -1026,7 +1026,7 @@ def test_write_anat(_bids_validate):
     _bids_validate(bids_root)
 
     t1w2 = nib.load(op.join(anat_dir, 'sub-01_ses-01_acq-01_T1w.nii.gz'))
-    vox2 = t1w2.get_data()
+    vox2 = t1w2.get_fdata()
 
     # because of significant rounding errors the voxels are fairly different
     # but the deface works in all three cases and was checked
@@ -1056,7 +1056,7 @@ def test_write_anat(_bids_validate):
     _bids_validate(bids_root)
 
     t1w3 = nib.load(op.join(anat_dir, 'sub-01_ses-01_acq-01_T1w.nii.gz'))
-    vox3 = t1w3.get_data()
+    vox3 = t1w3.get_fdata()
 
     assert abs(vox1 - vox3).sum() / abs(vox1).sum() < 0.2
 
diff --git a/mne_bids/write.py b/mne_bids/write.py
index c5d90a44d..50b997877 100644
--- a/mne_bids/write.py
+++ b/mne_bids/write.py
@@ -671,7 +671,7 @@ def _deface(t1w, mri_landmarks, deface):
                          'degrees. Got %s' % theta)
 
     # x: L/R L+, y: S/I I+, z: A/P A+
-    t1w_data = t1w.get_data().copy()
+    t1w_data = t1w.get_fdata().copy()
     idxs_vox = np.meshgrid(np.arange(t1w_data.shape[0]),
                            np.arange(t1w_data.shape[1]),
                            np.arange(t1w_data.shape[2]),
diff --git a/setup.cfg b/setup.cfg
index 78ac3aeea..f0c2cd69a 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -10,7 +10,6 @@ filterwarnings =
     error
     ignore::RuntimeWarning
     ignore::UserWarning
-    ignore::DeprecationWarning
     ignore::ImportWarning
 
 [pydocstyle]