Skip to content

Commit

Permalink
Improve MPT parsing for the new test data file
Browse files Browse the repository at this point in the history
  • Loading branch information
chatcannon committed Sep 10, 2022
1 parent 54e5765 commit 0ffdd26
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions galvani/BioLogic.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,23 @@ 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_)
elif fieldname in ("dq/mA.h", "dQ/mA.h"):
return ("dQ/mA.h", np.float_)
elif fieldname in ("I/mA", "<I>/mA"):
return ("I/mA", np.float_)
elif fieldname in ("Ewe/V", "<Ewe>/V"):
elif fieldname in ("Ewe/V", "<Ewe>/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)

Expand All @@ -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*$',
Expand Down

0 comments on commit 0ffdd26

Please sign in to comment.