Skip to content

Commit eaa6903

Browse files
authored
Merge pull request #1560 from PeterNSteinmetz/BrainvisionHeaderParse
Improved brainvision header parsing.
2 parents 4f9cc85 + 08ca180 commit eaa6903

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

neo/rawio/brainvisionrawio.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,22 @@ def _parse_header(self):
9292
channel_desc = channel_infos[f"Ch{c+1}"]
9393
except KeyError:
9494
channel_desc = channel_infos[f"ch{c + 1}"]
95-
name, ref, res, units = channel_desc.split(",")
96-
units = units.replace("µ", "u")
95+
# split up channel description, handling default values
96+
cds = channel_desc.split(",")
97+
name = cds[0]
98+
if len(cds) >= 2:
99+
ref = cds[1]
100+
else:
101+
ref = ""
102+
if len(cds) >= 3:
103+
res = cds[2]
104+
else:
105+
res = "1.0"
106+
if len(cds) == 4:
107+
units = cds[3]
108+
else:
109+
units = "u"
110+
units = units.replace("µ", "u") # Brainvision spec for specific unicode
97111
chan_id = str(c + 1)
98112
if sig_dtype == np.int16 or sig_dtype == np.int32:
99113
gain = float(res)

neo/test/rawiotest/test_brainvisionrawio.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class TestBrainVisionRawIO(
2020
"brainvision/File_brainvision_3_float32.vhdr",
2121
"brainvision/File_brainvision_3_int16.vhdr",
2222
"brainvision/File_brainvision_3_int32.vhdr",
23+
"brainvision/File_brainvision_4_float32.vhdr",
2324
]
2425

2526
entities_to_download = ["brainvision"]

0 commit comments

Comments
 (0)