# BrainVision files

**URL:** <https://mne.discourse.group/t/brainvision-files/942>\
**Category:** Mailing List Archive (read-only)\
**Tags:** list-archive\
**Created:** [January 5, 2016, 9:17am UTC](https://mne.discourse.group/t/brainvision-files/942 "2016-01-05T09:17:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [January 5, 2016, 9:17am UTC](https://mne.discourse.group/t/brainvision-files/942/1 "2016-01-05T09:17:59Z")

</div>

Dear colleagues,

I'm just starting to use MNE-python, and I face a problem opening  
BrainVisionAnalyer files. When calling the  
"mne.io.read\_raw\_brainvision", I get the following error (full traceback  
at the end):

--\> 462 params, settings = settings.split('[Comment]')  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;463 cfg = configparser.ConfigParser()  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;464 if hasattr(cfg, 'read\_file'): # newer API

ValueError: need more than 1 value to unpack

It appears that 'read\_raw\_brainvision' is searching for a "section"  
untitled "Comment" in the header (vhdr) file. I have been using  
BrainVision files quite a lot (actually, I would like to get rid of it  
by using mne-python...), and I never encountered such a "Comment" field  
in my vhdr files. However, I always worked with data \*\*exported\*\* from  
BrainVision, not acquired with it. So I guess the "Comment" field the  
parser is searching might come from the files created by  
BrainVisionRecorder. But since I do not have any such file, I cannot check.

I do have python code that, I believe, open all variants of files  
\*\*exported\*\* from BrainVisionAnalyser (be they ASCII or binary, 16, 32  
... bits etc...). The code outputs a dictionary for the header (vhdr)  
file, a numpy.array for the data, and a list of events for the  
markers/events/triggers. Although I guess it should also open files  
created by BrainVisionRecorder, I cannot be sure.

So, if someone could provide me with a small file that is currently  
openable by "mne.io.read\_raw\_brainvision", I would be happy to check  
whether my code also open it. And, if you find it useful, I would be  
more than happy to share the code and adapt it to mne-python (with a bit  
of help from you, probably ...)

&nbsp;&nbsp;&nbsp;All the best,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;B.

full traceback:  
In [4]: mne.io.read\_raw\_brainvision('COUBA\_EMG\_PC\_CompLeft.vhdr')  
Extracting eeg Parameters from COUBA\_EMG\_PC\_CompLeft.vhdr...

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [January 5, 2016, 12:32pm UTC](https://mne.discourse.group/t/brainvision-files/942/2 "2016-01-05T12:32:41Z")

</div>

hi Boris,

our test data are in:

[https://github.com/mne-tools/mne-python/tree/master/mne/io/brainvision/tests/data](https://github.com/mne-tools/mne-python/tree/master/mne/io/brainvision/tests/data)

don't hesitate to share a file so we can patch the reader to fix the issue.

Best,  
Alex

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [January 5, 2016, 4:56pm UTC](https://mne.discourse.group/t/brainvision-files/942/3 "2016-01-05T16:56:59Z")

</div>

Hi again,

Trying to find the issue, I realized that my installed version of mne  
was pretty old (0.8.6), and that this issue has already been fixed (at  
least it is in the dev version...). I apologize for that...

But I found another issue:

If I read correctly, it looks like line 201 of \_read\_vmrk\_events assumes  
that response triggers name must contain an integer, probably  
considering that the names are "Rxxx", with "xxx" being integers.  
However, this is not a requirement of the file format and, especially  
after some preprocessing, the triggers names may have been changed to  
pure text (for example 'LeftResp'). In this case, the code does not seem  
to work, since 'trigger' is None, and line 206 issues an error:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;trigger += response\_trig\_shift  
TypeError: unsupported operand type(s) for +=: 'NoneType' and 'int'

Am I reading the code correctly?  
&nbsp;&nbsp;  
&nbsp;&nbsp;Thanks in advance,  
&nbsp;&nbsp;&nbsp;&nbsp;B.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [January 5, 2016, 9:10pm UTC](https://mne.discourse.group/t/brainvision-files/942/4 "2016-01-05T21:10:14Z")

</div>

Jona and Teon. Any thought on this?

thanks  
Alex

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [January 5, 2016, 9:13pm UTC](https://mne.discourse.group/t/brainvision-files/942/5 "2016-01-05T21:13:42Z")

</div>

Teon has recently added extended BV support:  
[https://github.com/mne-tools/mne-python/pull/2634/files](https://github.com/mne-tools/mne-python/pull/2634/files)

Now with the most up-to-date version,  
&nbsp;&nbsp;event\_id : dict | None  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The id of the event to consider. If None (default),  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;only stimulus events are added to the stimulus channel. If dict,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;the keys will be mapped to trigger values on the stimulus channel  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;in addition to the stimulus events. Keys are case-sensitive.  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Example: {'SyncStatus': 1; 'Pulse Artifact': 3}.

Does that help?

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [January 5, 2016, 9:23pm UTC](https://mne.discourse.group/t/brainvision-files/942/6 "2016-01-05T21:23:48Z")

</div>

Hi Jona,

Thanks for looking at it.

> Teon has recently added extended BV support:  
> [[MRG] ENH Add support for Brainvision V2.0 by teonbrooks · Pull Request #2634 · mne-tools/mne-python · GitHub](https://github.com/mne-tools/mne-python/pull/2634/files)
> 
> Now with the most up-to-date version,
> 
> &nbsp;&nbsp;&nbsp;event\_id :dict | None  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Theid of the event to consider. If None (default),  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;only stimulus events are added to the stimulus channel. Ifdict,  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;the keys will be mapped to trigger values on the stimulus channel  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;in addition to the stimulus events. Keys are case-sensitive.  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Example: {'SyncStatus':1;'Pulse Artifact':3}.
> 
> Does that help?

Not really, since this still assumes that the trigger values are  
integers, and we translate those integers into strings (or whatever).  
But if the triggers are already strings, then the code fails.

A workaround could be to check whether "trigger" is an int, and if not,  
return keep the description (mdesc) of the event. Code around line 206  
would read:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if mtype.lower().startswith('response'):  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if response\_trig\_shift is not None:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if isinstance(trigger, int):  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;trigger += response\_trig\_shift  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;trigger = mdesc

This small modification helps reading files with marker descriptions  
such as "Resp\_Left" for example. But I'm not sure whether that would  
introduce other issues elsewhere...

&nbsp;&nbsp;hope this helps...  
&nbsp;&nbsp;&nbsp;&nbsp;B.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [January 5, 2016, 9:30pm UTC](https://mne.discourse.group/t/brainvision-files/942/7 "2016-01-05T21:30:31Z")

</div>

Hi Boris,

If I understand this correctly, you're saying that you want to preserve the  
string information?

In MNE, the default is to have events represented as int and these are  
later referred to by strings in a dict. The event\_id that is mentioned in  
the raw reader would be the same one you could use in your epochs  
constructor. This will allow you refer to the events as strings again.  
Since the underlying data representation are numpy.array of floats, this is  
the best approach to maintain max cross-talk to other packages.

If I missed the mark, could you share an example file with me, and try  
expressing again what you want the reader to do.

HTH,
