From 0ffdd2665e8193604b8d25b45ac2cd8bfe530d56 Mon Sep 17 00:00:00 2001 From: Chris Kerr Date: Sat, 10 Sep 2022 22:33:29 +0300 Subject: [PATCH] Improve MPT parsing for the new test data file --- galvani/BioLogic.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/galvani/BioLogic.py b/galvani/BioLogic.py index 88c91e1..cc54d17 100644 --- a/galvani/BioLogic.py +++ b/galvani/BioLogic.py @@ -26,10 +26,7 @@ def fieldname_to_dtype(fieldname): elif fieldname in ("ox/red", "error", "control changes", "Ns changes", "counter inc."): return (fieldname, np.bool_) - elif fieldname in ("time/s", "P/W", "(Q-Qo)/mA.h", "x", "control/V", - "control/V/mA", "(Q-Qo)/C", "dQ/C", "freq/Hz", - "|Ewe|/V", "|I|/A", "Phase(Z)/deg", "|Z|/Ohm", - "Re(Z)/Ohm", "-Im(Z)/Ohm"): + elif fieldname in ("x", "control/V/mA", "Temperature/°C", "Efficiency/%"): return (fieldname, np.float_) elif fieldname in ("cycle number", "I Range", "Ns", "half cycle"): return (fieldname, np.int_) @@ -37,8 +34,15 @@ def fieldname_to_dtype(fieldname): return ("dQ/mA.h", np.float_) elif fieldname in ("I/mA", "/mA"): return ("I/mA", np.float_) - elif fieldname in ("Ewe/V", "/V"): + elif fieldname in ("Ewe/V", "/V", "Ecell/V"): return ("Ewe/V", np.float_) + elif fieldname.endswith(("/s", "/Hz", "/deg", + "/W", "/mW", "/W.h", "/mW.h", + "/A", "/mA", "/A.h", "/mA.h", + "/V", "/mV", + "/F", "/mF", "/uF", + "/C", "/Ohm",)): + return (fieldname, np.float_) else: raise ValueError("Invalid column header: %s" % fieldname) @@ -62,7 +66,7 @@ def MPTfile(file_or_path, encoding='ascii'): mpt_file = file_or_path magic = next(mpt_file) - if magic != b'EC-Lab ASCII FILE\r\n': + if magic not in (b'EC-Lab ASCII FILE\r\n', b'BT-Lab ASCII FILE\r\n'): raise ValueError("Bad first line for EC-Lab file: '%s'" % magic) nb_headers_match = re.match(rb'Nb header lines : (\d+)\s*$',