Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Divider in brainvision files. #4354

Merged
merged 2 commits into from
Jun 27, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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