Skip to content

Commit

Permalink
Divider in brainvision files. (#4354)
Browse files Browse the repository at this point in the history
* Divider in brainvision files.

* Fix.
  • Loading branch information
jaeilepp authored and larsoner committed Jun 27, 2017
1 parent f6791a4 commit 541bf85
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions mne/io/brainvision/brainvision.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,13 @@ def _read_vmrk_events(fname, event_id=None, response_trig_shift=0):

def _check_hdr_version(header):
"""Check the header version."""
tags = ['Brain Vision Data Exchange Header File Version 1.0',
'Brain Vision Data Exchange Header File Version 2.0']
if header not in tags:
raise ValueError("Currently only support %r, not %r"
"Contact MNE-Developers for support."
% (str(tags), header))
if header == 'Brain Vision Data Exchange Header File Version 1.0':
return 1
elif header == 'Brain Vision Data Exchange Header File Version 2.0':
return 2
else:
raise ValueError("Currently only support versions 1.0 and 2.0, not %r "
"Contact MNE-Developers for support." % header)


def _check_mrk_version(header):
Expand Down Expand Up @@ -490,6 +491,15 @@ def _get_vhdr_info(vhdr_fname, eog, misc, scale, montage):
lowpass = []
highpass = []

# for newer BV files, the unit is specified for every channel
# separated by a single space, while for older files, the unit is
# specified in the column headers
divider = '\s+'
if 'Resolution / Unit' in settings[idx]:
shift = 1 # shift for unit
else:
shift = 0

# extract filter units and convert s to Hz if necessary
# this cannot be done as post-processing as the inverse t-f
# relationship means that the min/max comparisons don't make sense
Expand All @@ -499,19 +509,16 @@ def _get_vhdr_info(vhdr_fname, eog, misc, scale, montage):
lp_s = '[s]' in header[lp_col]

for i, ch in enumerate(ch_names[:-1], 1):
line = re.split('\s\s+', settings[idx + i])
line = re.split(divider, settings[idx + i])
# double check alignment with channel by using the hw settings
# the actual divider is multiple spaces -- for newer BV
# files, the unit is specified for every channel separated
# by a single space, while for older files, the unit is
# specified in the column headers
if idx == idx_amp:
line_amp = line
else:
line_amp = re.split('\s\s+', settings[idx_amp + i])
line_amp = re.split(divider, settings[idx_amp + i])
assert ch in line_amp
highpass.append(line[hp_col])
lowpass.append(line[lp_col])

highpass.append(line[hp_col + shift])
lowpass.append(line[lp_col + shift])
if len(highpass) == 0:
pass
elif len(set(highpass)) == 1:
Expand Down

0 comments on commit 541bf85

Please sign in to comment.