Skip to content

Commit 9745ba9

Browse files
committed
change string parsing
1 parent 8ec58f7 commit 9745ba9

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

neo/rawio/axonrawio.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414
and available here:
1515
http://www.mathworks.com/matlabcentral/fileexchange/22114-abf2load
1616
17+
18+
The StringsSection parsing (parse_axon_soup) now relies on an idea
19+
presented in pyABF MIT License Copyright (c) 2018 Scott W Harden
20+
written by Scott Harden. His unofficial documentation for the formats
21+
is here:
22+
https://swharden.com/pyabf/abf2-file-format/
23+
24+
1725
Information on abf 1 and 2 formats is available here:
1826
http://www.moleculardevices.com/pages/software/developer_info.html
1927
@@ -461,21 +469,19 @@ def parse_axon_soup(filename):
461469
# strings sections
462470
# hack for reading channels names and units
463471
# this section is not very detailed and so the code
464-
# not very robust. The idea is to remove the first
465-
# part by finding one of th following KEY
466-
# unfortunately the later part contains a the file
467-
# that can contain by accident also one of theses keys...
472+
# not very robust.
468473
f.seek(sections["StringsSection"]["uBlockIndex"] * BLOCKSIZE)
469474
big_string = f.read(sections["StringsSection"]["uBytes"])
470-
goodstart = -1
471-
for key in [b"AXENGN", b"clampex", b"Clampex", b"EDR3", b"CLAMPEX", b"axoscope", b"AxoScope", b"Clampfit"]:
472-
# goodstart = big_string.lower().find(key)
473-
goodstart = big_string.find(b"\x00" + key)
474-
if goodstart != -1:
475-
break
476-
assert goodstart != -1, "This file does not contain clampex, axoscope or clampfit in the header"
477-
big_string = big_string[goodstart + 1 :]
478-
strings = big_string.split(b"\x00")
475+
476+
# this idea comes from pyABF https://github.com/swharden/pyABF
477+
# previously we searched for clampex, Clampex etc, but this was
478+
# brittle. pyABF believes that looking for the \x00\x00 is more
479+
# robust. We find these values, replace mu->u, then split into
480+
# a set of strings
481+
indexed_string = big_string[big_string.rfind(b'\x00\x00'):]
482+
indexed_string = indexed_string.replace(b'\xb5', b'\x75')
483+
indexed_string = indexed_string.split(b'\x00')
484+
strings = indexed_string
479485

480486
# ADC sections
481487
header["listADCInfo"] = []

0 commit comments

Comments
 (0)