Repository: mne-tools/mne-bids

Issue:
[MRG] Add fetch function for eeg_matchingpennies dataset
Instead of adding a matchingpennies fetcher to the mne-study-template, I thought it could be a nice addition to mne-bids.

We can then easily import it at mne-study-template and make it run.

Merge checklist
---------------

Maintainer, please confirm the following before merging:

- [ ] All comments resolved
- [ ] This is not your own PR
- [x] All CIs are happy
- [x] PR title starts with [MRG]
- [x] [whats_new.rst](https://github.com/mne-tools/mne-bids/blob/master/doc/whats_new.rst) is updated
- ~PR description includes phrase "closes <#issue-number>"~
- [x] Commit history does not contain any merge commits



Discussion:
Travis is not happy

what happened to the datalad route? Why did you abandon it?
> what happened to the datalad route? Why did you abandon it?

No, not abandoned, but it's a rabbit hole, whereas I know that I can make this work in 1 to 2 hours.

re: datalad, I got some help, but it would take much more time to get it done:

https://github.com/templateflow/datalad-osf/issues/1#issuecomment-517743290

re: Travis: yep, I'll get it sorted out
hmm ... I'm not against merging this. But I want to understand why we can't merge the mne-study-template with just one dataset from datalad? Not even one dataset works with CircleCI? What is the pain point? Maybe @larsoner can help?
I agree to move on fast but I am scared of unclear scope of project. Could we consider putting this directly in mne or maybe better have a generic fetcher for neuro vault data in mne ?
https://nilearn.github.io/modules/generated/nilearn.datasets.fetch_neurovault.html
arggh, I am sorry @sappelhoff for misguiding you on this one.

I agree with @agramfort. I am still trying to understand why the `datalad` route doesn't work. I fear we are dodging the bullet, the elephant in the room, call it whatever ... which is to make scripts that work with BIDS datasets.

# [Codecov](https://codecov.io/gh/mne-tools/mne-bids/pull/249?src=pr&el=h1) Report
> Merging [#249](https://codecov.io/gh/mne-tools/mne-bids/pull/249?src=pr&el=desc) into [master](https://codecov.io/gh/mne-tools/mne-bids/commit/50e43b1d63813e3bd238c9316362423aff71c5c8?src=pr&el=desc) will **increase** coverage by `0.1%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/mne-tools/mne-bids/pull/249/graphs/tree.svg?width=650&token=x8vQyTMM9Y&height=150&src=pr)](https://codecov.io/gh/mne-tools/mne-bids/pull/249?src=pr&el=tree)

```diff
@@            Coverage Diff            @@
##           master     #249     +/-   ##
=========================================
+ Coverage   98.41%   98.51%   +0.1%     
=========================================
  Files          15       15             
  Lines        1573     1621     +48     
=========================================
+ Hits         1548     1597     +49     
+ Misses         25       24      -1
```


| [Impacted Files](https://codecov.io/gh/mne-tools/mne-bids/pull/249?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [mne\_bids/tests/test\_datasets.py](https://codecov.io/gh/mne-tools/mne-bids/pull/249/diff?src=pr&el=tree#diff-bW5lX2JpZHMvdGVzdHMvdGVzdF9kYXRhc2V0cy5weQ==) | `100% <100%> (ø)` | :arrow_up: |
| [mne\_bids/datasets.py](https://codecov.io/gh/mne-tools/mne-bids/pull/249/diff?src=pr&el=tree#diff-bW5lX2JpZHMvZGF0YXNldHMucHk=) | `100% <100%> (+3.44%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/mne-tools/mne-bids/pull/249?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/mne-tools/mne-bids/pull/249?src=pr&el=footer). Last update [50e43b1...eee17e6](https://codecov.io/gh/mne-tools/mne-bids/pull/249?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

### Ohh lots of points here. Let me address them all one by one

---

> But I want to understand why we can't merge the mne-study-template with just one dataset from datalad?

We could, and that's what I was trying to do with `ds000117`, but we need to fix MNE-Python first, see:

>  Not even one dataset works with CircleCI?

CircleCI is not the problem, but datalad needs git-annex repositories as input, and not all datasets are accessible as such (e.g., matchingpennies). I have tried to do this, see my attempts:

- turn eeg_matchingpennies into git-annex: https://github.com/templateflow/datalad-osf/issues/1
- find some more git-annex datasets that are not where they should be: https://github.com/OpenNeuroOrg/datalad-service/issues/81#issuecomment-515992625

> Could we consider putting this directly in mne

Yes, we could. I thought that with mne-bids we can move faster :-) and we already had a `mne_bids.datasets` module that I could enhance ... and mne-study-template is not suited, because it's not supposed to be a library with lots of modules

>  or maybe better have a generic fetcher for neuro vault data in mne ?

as far as I saw it, NeuroVault is for MRI and PET data
![image](https://user-images.githubusercontent.com/9084751/62395846-c0145280-b571-11e9-93cd-3c8032b9dd84.png)

> arggh, I am sorry @sappelhoff for misguiding you on this one.

no worries :)

> I agree with @agramfort. I am still trying to understand why the datalad route doesn't work.

 ... I hope I could shed some light into it with my points above. It's not rocket science, but I have no clue about git-annex, so datalad is very new and cryptic to me. Then what I thought would work nicely (`datalad_osf`) turned out to be buggy.

But we do have an example on how one could "manually" turn eeg_matchingpennies into a datalad usable git annex dataset:

https://github.com/templateflow/datalad-osf/issues/1#issuecomment-517743290

Thanks to yarikoptic and kyleam (I don't tag them because it'd be confusing for them).

>  I fear we are dodging the bullet, the elephant in the room, call it whatever ... which is to make scripts that work with BIDS datasets.

Let's stay positive: We're not moving very fast, but we're moving :-) and we're fixing lots of stuff along the way.

So kind of **"move slow and fix things"**, rather than Facebook's motto :smile: 
okay seems like we've figured out datalad now. Okay to close @sappelhoff ?
> okay seems like we've figured out datalad now. Okay to close @sappelhoff ?

I think this is a nice fetcher that can be useful in the future (e.g., for a "read_raw_bids" example.) ... eeg_matchingpennies is also a very straight forward eeg example in general

I think we should merge it

Not sure I agree. I think it would be nicer to do a general fetcher for `openneuro` / BIDS formatted /git-annexed datasets. You will avoid code duplication that way.

But I won't insist. What is @agramfort thoughts on this?
I agree that the fetcher should be made generic. Currently with the datalad
fix the
fetcher does not bring much to mne-bids. If you want to make it an
mne.datasets
and add an analysis example to MNE you're very welcome.

I would be in favor of deprecating the mne_bids.datasets module. The other
datasets there are here for historical reasons.

>

> I would be in favor of deprecating the mne_bids.datasets module. The other
datasets there are here for historical reasons.

yes, although we currently need the ds000117 fetcher for two examples

and the brainvision test data fetcher for an example and for two tests

It would be possible to replace the `datasets` module in mne-bids with "datalad" --> and make datalad an optional dependency (mainly for devs)

> you want to make it an mne.datasets and add an analysis example to MNE you're very welcome.

would I be able to include the code in MNE-Python "as is"? ... because I don't think that "making it generic" works (see https://github.com/mne-tools/mne-bids/pull/249#discussion_r310633463 )
> it would be nicer to do a general fetcher for openneuro / BIDS formatted /git-annexed datasets

yes @jasmainak, I agree, see the upper part of my comment https://github.com/mne-tools/mne-bids/pull/249#issuecomment-518259192
I moved the eeg_matchingpennies fetcher to the WIKI of the git-annex repo for now: https://github.com/sappelhoff/eeg_matchingpennies/wiki/eeg_matchingpennies.py

I think that @agramfort is right and we should deprecate the `datasets.py` module in MNE-BIDS. 

Instead, we can introduce the AWS dependency: https://github.com/boto/boto3 and use it as Mainak has shown here: https://github.com/mne-tools/mne-bids/pull/249#discussion_r310762011

opinions @jasmainak @agramfort ?
I support this plan!

On Wed 7 Aug 2019 at 11:18, Stefan Appelhoff <notifications@github.com>
wrote:

> I moved the eeg_matchingpennies fetcher to the WIKI of the git-annex repo
> for now:
> https://github.com/sappelhoff/eeg_matchingpennies/wiki/eeg_matchingpennies.py
>
> I think that @agramfort <https://github.com/agramfort> is right and we
> should deprecate the datasets.py module in MNE-BIDS.
>
> Instead, we can introduce the AWS dependency:
> https://github.com/boto/boto3 and use it as Mainak has shown here: #249
> (comment)
> <https://github.com/mne-tools/mne-bids/pull/249#discussion_r310762011>
>
> opinions @jasmainak <https://github.com/jasmainak> @agramfort
> <https://github.com/agramfort> ?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/mne-tools/mne-bids/pull/249?email_source=notifications&email_token=ADY6FIRX34AVWHJJIJYXGRDQDLRUZA5CNFSM4II7LM62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3YYERQ#issuecomment-519144006>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ADY6FIVXX5562GEMPCHMDYLQDLRUZANCNFSM4II7LM6Q>
> .
>
-- 
Sent from my iPhone

+1

>


Resolving patch:
diff --git a/examples/rename_brainvision_files.py b/examples/rename_brainvision_files.py
--- a/examples/rename_brainvision_files.py
+++ b/examples/rename_brainvision_files.py
@@ -30,36 +30,42 @@
 
 ###############################################################################
 # We are importing everything we need for this example:
-import os
+import os.path as op
 
 from numpy.testing import assert_array_equal
-from mne.io import read_raw_brainvision
+import mne
 
-from mne_bids.datasets import fetch_brainvision_testing_data
 from mne_bids.copyfiles import copyfile_brainvision
 
 ###############################################################################
 # Step 1: Download some example data
 # ----------------------------------
 # To demonstrate the MNE-BIDS functions, we need some testing data. Here, we
-# will use data that is shipped with MNE-Python. Feel free to use your own
-# BrainVision data.
-examples_dir = fetch_brainvision_testing_data()
+# will use the MNE-Python testing data. Feel free to use your own BrainVision
+# data.
+#
+# .. warning:: This will download 1.6 GB of data!
+
+data_path = mne.datasets.testing.data_path()
+examples_dir = op.join(data_path, 'Brainvision')
 
 ###############################################################################
 # Step 2: Rename the recording
 # ----------------------------------
-# Above, at the top of the example, we imported ``copyfile_brainvision`` from
+# Above, at the top of the example, we imported
+# :func:`mne_bids.utils.copyfile_brainvision` from
 # the MNE-BIDS ``utils.py`` module. This function takes two arguments as
 # input: First, the path to the existing .vhdr file. And second, the path to
 # the future .vhdr file.
 #
-# ``copyfile_brainvision`` will then create three new files (.vhdr, .vmrk, and
-# .eeg) with the new names as provided with the second argument.
+# :func:`mne_bids.utils.copyfile_brainvision` will then create three new files
+# (.vhdr, .vmrk, and .eeg) with the new names as provided with the second
+# argument.
 #
-# Here, we rename test.vhdr to test_renamed.vhdr:
-vhdr_file = os.path.join(examples_dir, 'test.vhdr')
-vhdr_file_renamed = os.path.join(examples_dir, 'test_renamed.vhdr')
+# Here, we rename a test file name:
+
+vhdr_file = op.join(examples_dir, 'test_NO.vhdr')
+vhdr_file_renamed = op.join(examples_dir, 'test_renamed.vhdr')
 copyfile_brainvision(vhdr_file, vhdr_file_renamed)
 
 ###############################################################################
@@ -67,8 +73,8 @@
 # --------------------------------------------------------------
 # Finally, let's use MNE-Python to read in both, the original BrainVision data
 # as well as the renamed data. They should be the same.
-raw = read_raw_brainvision(vhdr_file)
-raw_renamed = read_raw_brainvision(vhdr_file_renamed)
+raw = mne.io.read_raw_brainvision(vhdr_file)
+raw_renamed = mne.io.read_raw_brainvision(vhdr_file_renamed)
 
 assert_array_equal(raw.get_data(), raw_renamed.get_data())
 


Test patch:
diff --git a/cli/tests/test_cli.py b/cli/tests/test_cli.py
--- a/cli/tests/test_cli.py
+++ b/cli/tests/test_cli.py
@@ -6,14 +6,13 @@
 from os import path as op
 
 import pytest
+import mne
 from mne.datasets import testing
-from mne.utils import _TempDir, run_tests_if_main, ArgvSetter
-
-from mne_bids.datasets import fetch_brainvision_testing_data
+from mne.utils import run_tests_if_main, ArgvSetter
 
 from cli import mne_bids_raw_to_bids, mne_bids_cp
 
-
+base_path = op.join(op.dirname(mne.__file__), 'io')
 subject_id = '01'
 task = 'testing'
 
@@ -29,9 +28,9 @@ def check_usage(module, force_help=False):
         assert 'Usage: ' in out.stdout.getvalue()
 
 
-def test_raw_to_bids():
+def test_raw_to_bids(tmpdir):
     """Test mne_bids raw_to_bids."""
-    output_path = _TempDir()
+    output_path = str(tmpdir)
     data_path = testing.data_path()
     raw_fname = op.join(data_path, 'MEG', 'sample',
                         'sample_audvis_trunc_raw.fif')
@@ -49,10 +48,10 @@ def test_raw_to_bids():
             mne_bids_cp.run()
 
 
-def test_cp():
+def test_cp(tmpdir):
     """Test mne_bids cp."""
-    output_path = _TempDir()
-    data_path = fetch_brainvision_testing_data()
+    output_path = str(tmpdir)
+    data_path = op.join(base_path, 'brainvision', 'tests', 'data')
     raw_fname = op.join(data_path, 'test.vhdr')
     outname = op.join(output_path, 'test2.vhdr')