Repository: mne-tools/mne-python

Issue:
check extension of brainvision file
I mistakenly tried:

raw = mne.io.read_raw_brainvision('test.vmrk')

instead of

raw = mne.io.read_raw_brainvision('test.vhdr')

and got this error, which is not super explicit:

--> 402         assert l == 'Brain Vision Data Exchange Header File Version 1.0'

to help here we should check file extension and use a properly exception (not this assert).

@teonlamont can you take care of that?

thanks heaps.



Discussion:
agramfort: Lgtm

Merge when Travis is happy

Thx for the quick fix

Patch:
diff --git a/mne/io/brainvision/brainvision.py b/mne/io/brainvision/brainvision.py
index 35fd057a2..81b41fa78 100644
--- a/mne/io/brainvision/brainvision.py
+++ b/mne/io/brainvision/brainvision.py
@@ -396,6 +396,10 @@ def _get_eeg_info(vhdr_fname, eog, misc):
     info['filename'] = vhdr_fname
     eeg_info = {}
 
+    ext = os.path.splitext(vhdr_fname)[-1]
+    if ext != '.vhdr':
+        raise IOError("The header file must be given to read the data, "
+                      "not the '%s' file." % ext)
     with open(vhdr_fname, 'r') as f:
         # extract the first section to resemble a cfg
         l = f.readline().strip()


Test patch:
diff --git a/mne/io/brainvision/tests/test_brainvision.py b/mne/io/brainvision/tests/test_brainvision.py
index 44eb09816..5131d978a 100644
--- a/mne/io/brainvision/tests/test_brainvision.py
+++ b/mne/io/brainvision/tests/test_brainvision.py
@@ -22,6 +22,7 @@ from mne.io import read_raw_brainvision
 FILE = inspect.getfile(inspect.currentframe())
 data_dir = op.join(op.dirname(op.abspath(FILE)), 'data')
 vhdr_path = op.join(data_dir, 'test.vhdr')
+vmrk_path = op.join(data_dir, 'test.vmrk')
 vhdr_highpass_path = op.join(data_dir, 'test_highpass.vhdr')
 montage = op.join(data_dir, 'test.hpts')
 eeg_bin = op.join(data_dir, 'test_bin_raw.fif')
@@ -42,6 +43,7 @@ def test_brainvision_data_filters():
 def test_brainvision_data():
     """Test reading raw Brain Vision files
     """
+    assert_raises(IOError, read_raw_brainvision, vmrk_path)
     assert_raises(TypeError, read_raw_brainvision, vhdr_path, montage,
                   preload=True, scale="0")
     raw_py = read_raw_brainvision(vhdr_path, montage, eog=eog, preload=True)