Repository: nilearn/nilearn

Issue:
restore localizers interface
it seems @GaelVaroquaux 's comment on #2097 

https://github.com/nilearn/nilearn/pull/2097/files#r328283557

was not addressed and we overlooked this when merging the PR.
`fetch_localizer_button_task` and `fetch_localizer_calculation_task` should be restored to their previous interface before the release

@kchawla-pi 


Discussion:
Okay. This is high priority. I'll start on this right away.

> Okay. This is high priority. I'll start on this right away.

thanks!

Thank for caching i! A big save!
Kshitij

------------------------------------------------------------
"Those who never wander might be lost."

Working to be kind, aware, equanimous, and skilled at python.


On Wed, Oct 16, 2019 at 11:51 AM jeromedockes <notifications@github.com>
wrote:

>
> > Okay. This is high priority. I'll start on this right away.
>
> thanks!
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/nilearn/nilearn/issues/2181?email_source=notifications&email_token=AB6SXRAA3OSWKZIZCW3CXPLQO3PZ7A5CNFSM4JBH5AK2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBL4K4Y#issuecomment-542623091>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AB6SXRDXLJP2EYXZHFDN43DQO3PZ7ANCNFSM4JBH5AKQ>
> .
>


Resolving patch:
diff --git a/examples/01_plotting/plot_dim_plotting.py b/examples/01_plotting/plot_dim_plotting.py
--- a/examples/01_plotting/plot_dim_plotting.py
+++ b/examples/01_plotting/plot_dim_plotting.py
@@ -21,9 +21,9 @@
 
 localizer_dataset = datasets.fetch_localizer_button_task()
 # Contrast map of motor task
-localizer_tmap_filename = localizer_dataset.tmaps[0]
+localizer_tmap_filename = localizer_dataset.tmap
 # Subject specific anatomical image
-localizer_anat_filename = localizer_dataset.anats[0]
+localizer_anat_filename = localizer_dataset.anat
 ###########################################################################
 # Plotting with enhancement of background image with dim=-.5
 # --------------------------------------------------------------------------
diff --git a/nilearn/datasets/func.py b/nilearn/datasets/func.py
--- a/nilearn/datasets/func.py
+++ b/nilearn/datasets/func.py
@@ -1073,7 +1073,7 @@ def fetch_localizer_calculation_task(n_subjects=1, data_dir=None, url=None,
     return data
 
 
-def fetch_localizer_button_task(n_subjects=None, data_dir=None, url=None,
+def fetch_localizer_button_task(data_dir=None, url=None,
                                 verbose=1):
     """Fetch left vs right button press contrast maps from the localizer.
 
@@ -1116,18 +1116,14 @@ def fetch_localizer_button_task(n_subjects=None, data_dir=None, url=None,
     nilearn.datasets.fetch_localizer_contrasts
 
     """
-    if n_subjects is None:
-        n_subjects = [2]
     data = fetch_localizer_contrasts(["left vs right button press"],
-                                     n_subjects=n_subjects,
+                                     n_subjects=[2],
                                      get_tmaps=True, get_masks=False,
                                      get_anats=True, data_dir=data_dir,
                                      url=url, resume=True, verbose=verbose)
-    # TODO: remove -> only here for compatibility
-    if len(data["tmaps"]) == 1:
-        setattr(data, "tmap", data["tmaps"][0])
-    if len(data["anats"]) == 1:
-        setattr(data, "anat", data["anats"][0])
+    # Additional keys for backward compatibility
+    data['tmap'] = data['tmaps'][0]
+    data['anat'] = data['anats'][0]
     return data
 
 


Test patch:
diff --git a/nilearn/datasets/tests/test_func.py b/nilearn/datasets/tests/test_func.py
--- a/nilearn/datasets/tests/test_func.py
+++ b/nilearn/datasets/tests/test_func.py
@@ -281,12 +281,23 @@ def test_fetch_localizer_calculation_task():
 @with_setup(tst.setup_tmpdata, tst.teardown_tmpdata)
 @with_setup(setup_localizer, teardown_localizer)
 def test_fetch_localizer_button_task():
-    # 2 subjects
-    dataset = func.fetch_localizer_button_task(
-        data_dir=tst.tmpdir,
-        verbose=1)
-    assert_true(isinstance(dataset.tmaps[0], _basestring))
-    assert_true(isinstance(dataset.anats[0], _basestring))
+    local_url = "file://" + tst.datadir
+
+    # Disabled: cannot be tested without actually fetching covariates CSV file
+    # Only one subject
+    dataset = func.fetch_localizer_button_task(data_dir=tst.tmpdir,
+                                               url=local_url,
+                                               verbose=1)
+
+    assert_true(isinstance(dataset.tmaps, list))
+    assert_true(isinstance(dataset.anats, list))
+
+    assert len(dataset.tmaps) == 1
+    assert len(dataset.anats) == 1
+
+    assert_true(isinstance(dataset.tmap, str))
+    assert_true(isinstance(dataset.anat, str))
+
     assert_not_equal(dataset.description, '')