Skip to content

Commit 293f35a

Browse files
authored
Merge pull request #1531 from apdavison/issue1530
Fix for #1530 [IgorIO and missing "xUnits"]
2 parents 332d69d + b34eae5 commit 293f35a

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

neo/io/igorproio.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,24 @@ def _wave_to_analogsignal(self, content, dirpath):
133133
header = content["wave_header"]
134134
name = str(header["bname"].decode("utf-8"))
135135
units = "".join([x.decode() for x in header["dataUnits"]])
136-
time_units = "".join([x.decode() for x in header["xUnits"]])
136+
if "xUnits" in header:
137+
# "xUnits" is used in Versions 1, 2, 3 of .pxp files
138+
time_units = "".join([x.decode() for x in header["xUnits"]])
139+
elif "dimUnits" in header:
140+
# Version 5 uses "dimUnits"
141+
# see https://github.com/AFM-analysis/igor2/blob/43fccf51714661fb96372e8119c59e17ce01f683/igor2/binarywave.py#L501
142+
_time_unit_structure = header["dimUnits"].ravel()
143+
# For the files we've seen so far, the first element of _time_unit_structure contains the units.
144+
# If someone has a file for which this assumption does not hold an Exception will be raised.
145+
if not all([element == b'' for element in _time_unit_structure[1:]]):
146+
raise Exception(
147+
"Neo cannot yet handle the units in this file. "
148+
"Please create a new issue in the Neo issue tracker at "
149+
"https://github.com/NeuralEnsemble/python-neo/issues/new/choose"
150+
)
151+
time_units = _time_unit_structure[0].decode()
152+
else:
153+
time_units = ""
137154
if len(time_units) == 0:
138155
time_units = "s"
139156
try:

0 commit comments

Comments
 (0)