Repository: mne-tools/mne-bids

Issue:
raw_to_bids: reading non-FIF files is broken
### Problem
In both the development version (latest Git commit) and release version (0.4) of mne-bids, running the `raw_to_bids` CLI tool on an EEG data file in the EDF format raises an exception:

```
mne_bids raw_to_bids --subject_id sub001 --task tracelab --raw edfs/demi_01\ Data.edf --bids_root bids

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/mne_bids/commands/mne_bids_raw_to_bids.py", line 81, in <module>
    run()
  File "/usr/local/lib/python3.7/site-packages/mne_bids/commands/mne_bids_raw_to_bids.py", line 74, in run
    allow_maxshield=opt.allow_maxshield)
  File "/usr/local/lib/python3.7/site-packages/mne_bids/read.py", line 63, in _read_raw
    raw = reader[ext](raw_fpath, preload=True, **kwargs)
TypeError: read_raw_edf() got an unexpected keyword argument 'allow_maxshield'

```

### Cause
Looking at the current mne-python and mne-bids source code, the source of the bug becomes clear:

Basically, this line in the CLI tool calls the mne-bids `_read_raw` function with `allow_maxshield` as a keyword argument: https://github.com/mne-tools/mne-bids/blob/11464cdc85940175e4752c99ff40fd8bff38668d/mne_bids/commands/mne_bids_raw_to_bids.py#L74

Then, for files with the .edf extension, that keyword argument gets passed to the .edf reader function in mne's `io` module:
https://github.com/mne-tools/mne-bids/blob/11464cdc85940175e4752c99ff40fd8bff38668d/mne_bids/read.py#L60

However, the mne `read_raw_edf` function [has no `allow_maxshield` argument](https://github.com/mne-tools/mne-python/blob/171917801f6d197d31af82fda7350d3553d8300f/mne/io/edf/edf.py#L1114), so it throws an exception:
```python
def read_raw_edf(input_fname, eog=None, misc=None,
                 stim_channel='auto', exclude=(), preload=False, verbose=None):
```

Looking through the MNE source, it looks like the *only* reader function for which `allow_maxshield` is a valid argument is the `.fif` reader, meaning that unless I'm misunderstanding something, the `raw_to_bids` CLI tool should be broken for all formats except `.fif`.

### Solution?
It seems like the simplest fix would be to assign the `allow_maxshield` value from the kwargs dict to some variable early in the `_read_raw` function, remove that key/value pair from the kwargs, and then use the assigned value only in the call to `read_raw_fif`.

Also, thanks for all the efforts creating and maintaining this package! Eager to start adopting BIDS for all my EEG work.


Discussion:
@hoechenberger maybe you can have a look?
... or maybe @a-hurst wants to give this a try in a PR on their own? :-)

the reasoning about whats causing the error and the potential solution sound good to me so far.

Resolving patch:
diff --git a/mne_bids/read.py b/mne_bids/read.py
--- a/mne_bids/read.py
+++ b/mne_bids/read.py
@@ -30,8 +30,8 @@
                             _estimate_line_freq, _infer_kind)
 
 
-def _read_raw(raw_fpath, electrode=None, hsp=None, hpi=None, config=None,
-              verbose=None, **kwargs):
+def _read_raw(raw_fpath, electrode=None, hsp=None, hpi=None,
+              allow_maxshield=False, config=None, verbose=None, **kwargs):
     """Read a raw file into MNE, making inferences based on extension."""
     _, ext = _parse_ext(raw_fpath)
 
@@ -48,17 +48,11 @@ def _read_raw(raw_fpath, electrode=None, hsp=None, hpi=None, config=None,
                               **kwargs)
 
     elif ext == '.fif':
-        raw = reader[ext](raw_fpath, **kwargs)
+        raw = reader[ext](raw_fpath, allow_maxshield, **kwargs)
 
-    elif ext in ['.ds', '.vhdr', '.set']:
+    elif ext in ['.ds', '.vhdr', '.set', '.edf', '.bdf']:
         raw = reader[ext](raw_fpath, **kwargs)
 
-    # EDF (european data format) or BDF (biosemi) format
-    # TODO: integrate with lines above once MNE can read
-    # annotations with preload=False
-    elif ext in ['.edf', '.bdf']:
-        raw = reader[ext](raw_fpath, preload=True, **kwargs)
-
     # MEF and NWB are allowed, but not yet implemented
     elif ext in ['.mef', '.nwb']:
         raise ValueError('Got "{}" as extension. This is an allowed extension '


Test patch:
diff --git a/mne_bids/commands/tests/test_cli.py b/mne_bids/commands/tests/test_cli.py
--- a/mne_bids/commands/tests/test_cli.py
+++ b/mne_bids/commands/tests/test_cli.py
@@ -51,6 +51,13 @@ def test_raw_to_bids(tmpdir):
                      raw_fname, '--bids_root', output_path)):
         mne_bids_raw_to_bids.run()
 
+    # Test EDF files as well
+    edf_data_path = op.join(base_path, 'edf', 'tests', 'data')
+    edf_fname = op.join(edf_data_path, 'test.edf')
+    with ArgvSetter(('--subject_id', subject_id, '--task', task, '--raw',
+                     edf_fname, '--bids_root', output_path)):
+        mne_bids_raw_to_bids.run()
+
     # Too few input args
     with pytest.raises(SystemExit):
         with ArgvSetter(('--subject_id', subject_id)):