Skip to content

Commit

Permalink
ENH - support older files where the Unit is not specified in the chan…
Browse files Browse the repository at this point in the history
…nel info
  • Loading branch information
robertoostenveld committed Sep 12, 2024
1 parent b03074b commit 98f59cd
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions brainvision.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def write(filename, vhdr, vmrk, eeg):
nchans = int(vhdr['Common Infos']['NumberOfChannels'])
for ch in range(nchans):
info = vhdr['Channel Infos']['Ch%d' % (ch+1)]
(name, ref, resolution, unit) = info.split(',')
parts = info.split(',') + ['µV'] # older files might not have the Unit field, default is µV
(name, ref, resolution, unit) = parts[0:4]
resolution = '1'
vhdr['Channel Infos']['Ch%d' % (ch+1)] = ','.join((name, ref, resolution, unit))
# write the header file
Expand Down Expand Up @@ -143,7 +144,8 @@ def read_eeg(filename, vhdr):
# apply the calibration to get the actual values
for ch in range(nchans):
info = vhdr['Channel Infos']['Ch%d' % (ch+1)]
(name, ref, resolution, unit) = info.split(',')
parts = info.split(',') + ['µV'] # older files might not have the Unit field, default is µV
(name, ref, resolution, unit) = parts[0:4]
eeg[ch] = eeg[ch] * float(resolution)
return eeg

Expand Down

0 comments on commit 98f59cd

Please # to comment.