Skip to content

Commit

Permalink
fixed BinaryFormat in the example, also added to validation
Browse files Browse the repository at this point in the history
  • Loading branch information
robertoostenveld committed Sep 12, 2024
1 parent 1169413 commit b03074b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ The following example constructs data from scratch and writes it to disk. Upon w
import numpy as np
import brainvision

vhdr = {'Common Infos': {'Codepage': 'UTF-8', 'DataFile': 'output.eeg', 'MarkerFile': 'output.vmrk', 'DataFormat': 'BINARY', 'DataOrientation': 'MULTIPLEXED', 'NumberOfChannels': '1', 'SamplingInterval': '1000'}, 'Binary Infos': {'BinaryFormat': 'FLOAT_32'}, 'Channel Infos': {'Ch1': '1,,0.5,µV'}}
vhdr = {'Common Infos': {'Codepage': 'UTF-8', 'DataFile': 'output.eeg', 'MarkerFile': 'output.vmrk', 'DataFormat': 'BINARY', 'DataOrientation': 'MULTIPLEXED', 'NumberOfChannels': '1', 'SamplingInterval': '1000'}, 'Binary Infos': {'BinaryFormat': 'IEEE_FLOAT_32'}, 'Channel Infos': {'Ch1': '1,,0.5,µV'}}

vmrk = {'Common Infos': {'Codepage': 'UTF-8', 'DataFile': 'output.eeg'}, 'Marker Infos': {'Mk1': 'New Segment,,1,1,0'}}

Expand Down
9 changes: 9 additions & 0 deletions brainvision.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ def validate(vhdr, vmrk, eeg):
for ch in range(nchans):
if not 'Ch%d' % (ch+1) in vhdr['Channel Infos']:
raise ValueError('%s section is missing in Channel Infos' % section)
# check consistency of certain values
if not vhdr['Common Infos']['Codepage'] == 'UTF-8':
raise ValueError('Unsupported codepage')
if not vhdr['Common Infos']['DataFormat'] == 'BINARY':
raise ValueError('Unsupported data format')
if not vhdr['Common Infos']['DataOrientation'] == 'MULTIPLEXED':
raise ValueError('Unsupported data orientation')
if not vhdr['Binary Infos']['BinaryFormat'] in ['INT_16', 'INT_32', 'IEEE_FLOAT_32']:
raise ValueError('Unsupported binary format')
# check consistency between header and data
nchans = int(vhdr['Common Infos']['NumberOfChannels'])
if nchans != eeg.shape[0]:
Expand Down

0 comments on commit b03074b

Please # to comment.