Repository: mne-tools/mne-python

Issue:
Brain Vision: Assertion error with channel names containing spaces
Hi,
I have plenty of Brain Vision files with channel names containing spaces:
```
Channels
--------
#     Name      Phys. Chn.    Resolution / Unit   Low Cutoff [s]   High Cutoff [Hz]   Notch [Hz]    Series Res. [kOhm] Gradient         Offset
1     ECoG 1      1                 10 µV             DC              250              Off                0                 
2     ECoG 2      2                 10 µV             DC              250              Off                0      
```

and when I try to read them, I get following Assertion Error:
```
File "...\lib\site-packages\mne\io\brainvision\brainvision.py", line 637, in _get_vhdr_info
    assert ch in line_amp

AssertionError
```
because the channel name "ECoG 1" is splited into "ECoG" and "1" in the line 636
```line_amp = re.split(divider, settings[idx_amp + i])```
and then the channel name is not found in the resulting list.
It works, when I change the line 611 from
```divider = r'\s+'```
to 
```divider = r'\s\s+'```
and remove all the shift related code for the highpass and lowpass search but this will of course break in case of names with multiple white spaces or probably also very long channel names.




Discussion:
do you have time to send us a PR to address these issues?


Resolving patch:
diff --git a/mne/io/brainvision/brainvision.py b/mne/io/brainvision/brainvision.py
--- a/mne/io/brainvision/brainvision.py
+++ b/mne/io/brainvision/brainvision.py
@@ -619,16 +619,21 @@ def _get_vhdr_info(vhdr_fname, eog, misc, scale):
         lp_s = '[s]' in header[lp_col]
 
         for i, ch in enumerate(ch_names, 1):
-            line = re.split(divider, settings[idx + i])
             # double check alignment with channel by using the hw settings
             if idx == idx_amp:
-                line_amp = line
+                line_amp = settings[idx + i]
             else:
-                line_amp = re.split(divider, settings[idx_amp + i])
-            assert ch in line_amp
+                line_amp = settings[idx_amp + i]
+            assert line_amp.find(ch) > -1
+
+            # Correct shift for channel names with spaces
+            # Header already gives 1 therefore has to be subtracted
+            ch_name_parts = re.split(divider, ch)
+            real_shift = shift + len(ch_name_parts) - 1
 
-            highpass.append(line[hp_col + shift])
-            lowpass.append(line[lp_col + shift])
+            line = re.split(divider, settings[idx + i])
+            highpass.append(line[hp_col + real_shift])
+            lowpass.append(line[lp_col + real_shift])
         if len(highpass) == 0:
             pass
         elif len(set(highpass)) == 1:


Test patch:
diff --git a/mne/io/brainvision/tests/data/test_mixed_lowpass.vhdr b/mne/io/brainvision/tests/data/test_mixed_lowpass.vhdr
--- a/mne/io/brainvision/tests/data/test_mixed_lowpass.vhdr
+++ b/mne/io/brainvision/tests/data/test_mixed_lowpass.vhdr
@@ -47,7 +47,7 @@ Ch24=CP2,,0.5,µV
 Ch25=FC5,,0.5,µV
 Ch26=FC6,,0.5,µV
 Ch27=CP5,,0.5,µV
-Ch28=CP6,,0.5,µV
+Ch28=CP 6,,0.5,µV
 Ch29=HL,,0.5,µV
 Ch30=HR,,0.5,µV
 Ch31=Vb,,0.5,µV
@@ -91,7 +91,7 @@ Channels
 25    FC5         25               0.5 µV             10              250              Off                0
 26    FC6         26               0.5 µV             10              250              Off                0
 27    CP5         27               0.5 µV             10              250              Off                0
-28    CP6         28               0.5 µV             10              250              Off                0
+28    CP 6        28               0.5 µV             10              250              Off                0
 29    HL          29               0.5 µV             10              250              Off                0
 30    HR          30               0.5 µV             10              250              Off                0
 31    Vb          31               0.5 µV             10              250              Off                0