From 318e4ef832ca8942fe59ce3ad2a97fc2de0dd651 Mon Sep 17 00:00:00 2001 From: Andrew Davison Date: Tue, 27 Aug 2024 15:45:26 +0200 Subject: [PATCH 1/2] Fix for #1530 "xUnits" is only used in Versions 1, 2, 3 of .pxp files; Version 5 uses "dimUnits" - see https://github.com/AFM-analysis/igor2/blob/43fccf51714661fb96372e8119c59e17ce01f683/igor2/binarywave.py#L501 --- neo/io/igorproio.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/neo/io/igorproio.py b/neo/io/igorproio.py index 48ccf6516..e87dc72b0 100644 --- a/neo/io/igorproio.py +++ b/neo/io/igorproio.py @@ -133,7 +133,12 @@ def _wave_to_analogsignal(self, content, dirpath): header = content["wave_header"] name = str(header["bname"].decode("utf-8")) units = "".join([x.decode() for x in header["dataUnits"]]) - time_units = "".join([x.decode() for x in header["xUnits"]]) + if "xUnits" in header: + time_units = "".join([x.decode() for x in header["xUnits"]]) + elif "dimUnits" in header: + time_units = header["dimUnits"].ravel()[0].decode() + else: + time_units = "" if len(time_units) == 0: time_units = "s" try: From 016d6eefe85fef4529dd7854799919de067b5086 Mon Sep 17 00:00:00 2001 From: Andrew Davison Date: Fri, 11 Oct 2024 15:32:39 +0200 Subject: [PATCH 2/2] Add more explanation, and some checks, for how we find the time units in the header of .pxp files [IgorIO] --- neo/io/igorproio.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/neo/io/igorproio.py b/neo/io/igorproio.py index e87dc72b0..f084496bd 100644 --- a/neo/io/igorproio.py +++ b/neo/io/igorproio.py @@ -134,9 +134,21 @@ def _wave_to_analogsignal(self, content, dirpath): name = str(header["bname"].decode("utf-8")) units = "".join([x.decode() for x in header["dataUnits"]]) if "xUnits" in header: + # "xUnits" is used in Versions 1, 2, 3 of .pxp files time_units = "".join([x.decode() for x in header["xUnits"]]) elif "dimUnits" in header: - time_units = header["dimUnits"].ravel()[0].decode() + # Version 5 uses "dimUnits" + # see https://github.com/AFM-analysis/igor2/blob/43fccf51714661fb96372e8119c59e17ce01f683/igor2/binarywave.py#L501 + _time_unit_structure = header["dimUnits"].ravel() + # For the files we've seen so far, the first element of _time_unit_structure contains the units. + # If someone has a file for which this assumption does not hold an Exception will be raised. + if not all([element == b'' for element in _time_unit_structure[1:]]): + raise Exception( + "Neo cannot yet handle the units in this file. " + "Please create a new issue in the Neo issue tracker at " + "https://github.com/NeuralEnsemble/python-neo/issues/new/choose" + ) + time_units = _time_unit_structure[0].decode() else: time_units = "" if len(time_units) == 0: