Repository: mne-tools/mne-bids

Issue:
[mne.io.Raw] problem with undefined "_init_kwargs"
hello there, thanks for the cool work! 

I encountered the following problem with RawBrainVision objects, but it might hold true for other types of data (I didnt check).

feeding `mne_bids.write_raw_bids(..)` raw-objects created with minimal input aruments (e.g. `raw = mne.io.read_raw_brainvision(header_file, preload=False)` ) causes the function to crash in line 633: 
`raw_orig = reader[ext](**raw._init_kwargs)` 
since there are no _init_kwargs. the same would probably happen again in line 742: 
`if 'mrk' in raw._init_kwargs:`

even though this is rather a problem of mne.io I thought you should know. there might be an easy workaround.

cheers, Dominik  




Discussion:
What version of `mne` are you using and what version of `mne-bids` are you using? It seems like you might have a version mismatch since the `raw._init_kwargs` was introduced very recently in `mne`
mne_bids 0.1
mne 0.16

you're right, this issue was resolved by upgrading mne to 0.17.0

a try + warning message, or a check for the mne-version would be (a minor) improvement. i might do it the next days
Yeah agreed. We could probably add a check_version somewhere.

Thanks for the feedback!

On Wed 12 Dec 2018 at 13:50, dominikwelke <notifications@github.com> wrote:

> mne_bids 0.1
> mne 0.16
>
> you're right, this issue was resolved by upgrading mne to 0.17.0
> a try + warning message, or a check for the mne-version would be (a minor)
> improvement.
>
> —
> You are receiving this because you commented.
>
>
> Reply to this email directly, view it on GitHub
> <https://github.com/mne-tools/mne-bids/issues/151#issuecomment-446700045>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/APHiomjygXf0wW_BcYAq3pxp9ejb8aJkks5u4U_2gaJpZM4ZPc02>
> .
>
-- 
Sent from my iPhone

any news on this @dominikwelke ?
not really. but thanks for nudging me: i will start implementing a check_version :)

might be useful for solving other issues to come (one in the pipeline: the deprecation of mne.find_events - ill open another issue for this soon)
@jasmainak @sappelhoff what implementation would you go for:

1. a private function like `check_version(required_version)` that returns a bool wheter the requirement is met
2. a simple helper function that retuns the mne.__version__ as string or float to be used more generically case by case
3. something else

Resolving patch:
diff --git a/mne_bids/io.py b/mne_bids/io.py
--- a/mne_bids/io.py
+++ b/mne_bids/io.py
@@ -58,9 +58,9 @@ def _read_raw(raw_fname, electrode=None, hsp=None, hpi=None, config=None,
 
     # BTi systems
     elif ext == '.pdf' and os.path.isfile(raw_fname):
-            raw = io.read_raw_bti(raw_fname, config_fname=config,
-                                  head_shape_fname=hsp,
-                                  preload=False, verbose=verbose)
+        raw = io.read_raw_bti(raw_fname, config_fname=config,
+                              head_shape_fname=hsp,
+                              preload=False, verbose=verbose)
 
     elif ext in ['.fif', '.ds', '.vhdr', '.set']:
         raw = reader[ext](raw_fname)
diff --git a/mne_bids/mne_bids.py b/mne_bids/mne_bids.py
--- a/mne_bids/mne_bids.py
+++ b/mne_bids/mne_bids.py
@@ -22,6 +22,7 @@
 from mne.io.pick import channel_type
 from mne.io import BaseRaw
 from mne.channels.channels import _unit2human
+from mne.utils import check_version
 
 from datetime import datetime
 from warnings import warn
@@ -593,6 +594,10 @@ def write_raw_bids(raw, bids_basename, output_path, events_data=None,
     of the participant correctly.
 
     """
+    if not check_version('mne', '0.17'):
+        raise ValueError('Your version of MNE is too old. '
+                         'Please update to 0.17 or newer.')
+
     if not isinstance(raw, BaseRaw):
         raise ValueError('raw_file must be an instance of BaseRaw, '
                          'got %s' % type(raw))


Test patch:
diff --git a/mne_bids/tests/test_mne_bids.py b/mne_bids/tests/test_mne_bids.py
--- a/mne_bids/tests/test_mne_bids.py
+++ b/mne_bids/tests/test_mne_bids.py
@@ -350,6 +350,15 @@ def test_set():
     raw_fname = op.join(data_path, 'test_raw.set')
 
     raw = mne.io.read_raw_eeglab(raw_fname)
+
+    # embedded - test mne-version assertion
+    tmp_version = mne.__version__
+    mne.__version__ = '0.16'
+    with pytest.raises(ValueError, match='Your version of MNE is too old.'):
+        write_raw_bids(raw, bids_basename, output_path)
+    mne.__version__ = tmp_version
+
+    # proceed with the actual test for EEGLAB data
     write_raw_bids(raw, bids_basename, output_path, overwrite=False)
 
     with pytest.raises(FileExistsError, match="already exists"):