From 2e7437c7ca8e9dc3dc013482d5d94599b763c84c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=B3=E8=87=B4=E8=AB=AD=28Chihyu=20Chen=235570=29?= Date: Wed, 11 May 2022 17:07:45 +0800 Subject: [PATCH 1/4] Add Column 438 'Unknown' to parser --- galvani/BioLogic.py | 1 + 1 file changed, 1 insertion(+) diff --git a/galvani/BioLogic.py b/galvani/BioLogic.py index 8c7c047..88c91e1 100644 --- a/galvani/BioLogic.py +++ b/galvani/BioLogic.py @@ -209,6 +209,7 @@ VMPdata_colID_dtype_map = { 433: ('-Im(Zwe-ce)/Ohm', '/V', ' Date: Sat, 10 Sep 2022 22:01:44 +0300 Subject: [PATCH 2/4] Add test data provided by yuyuchen0821 --- tests/test_BioLogic.py | 1 + tests/testdata/020-formation_CB5.mpr | 3 +++ tests/testdata/020-formation_CB5.mpr.license | 2 ++ tests/testdata/020-formation_CB5.mpt | 3 +++ tests/testdata/020-formation_CB5.mpt.license | 2 ++ 5 files changed, 11 insertions(+) create mode 100644 tests/testdata/020-formation_CB5.mpr create mode 100644 tests/testdata/020-formation_CB5.mpr.license create mode 100644 tests/testdata/020-formation_CB5.mpt create mode 100644 tests/testdata/020-formation_CB5.mpt.license diff --git a/tests/test_BioLogic.py b/tests/test_BioLogic.py index a739f5f..3eeef1e 100644 --- a/tests/test_BioLogic.py +++ b/tests/test_BioLogic.py @@ -186,6 +186,7 @@ def assert_MPR_matches_MPT(mpr, mpt, comments): # bio_logic5 and bio_logic6 are special cases 'CV_C01', '121_CA_455nm_6V_30min_C01', + '020-formation_CB5', ]) def test_MPR_matches_MPT(testdata_dir, basename): """Check the MPR parser against the MPT parser. diff --git a/tests/testdata/020-formation_CB5.mpr b/tests/testdata/020-formation_CB5.mpr new file mode 100644 index 0000000..84528ea --- /dev/null +++ b/tests/testdata/020-formation_CB5.mpr @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:586836288e1144454c277ecd6adfc384bfe1614ed141900c5f004b26a8b54d64 +size 157216 diff --git a/tests/testdata/020-formation_CB5.mpr.license b/tests/testdata/020-formation_CB5.mpr.license new file mode 100644 index 0000000..148639d --- /dev/null +++ b/tests/testdata/020-formation_CB5.mpr.license @@ -0,0 +1,2 @@ +SPDX-FileCopyrightText Chihyu Chen +SPDX-License-Identifier CC-BY-4.0 diff --git a/tests/testdata/020-formation_CB5.mpt b/tests/testdata/020-formation_CB5.mpt new file mode 100644 index 0000000..88bfdaf --- /dev/null +++ b/tests/testdata/020-formation_CB5.mpt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c323f95a3f5f1465d07ef8654a86df1de65e3a5dc3af11e7fb27d187f2ffe43e +size 681331 diff --git a/tests/testdata/020-formation_CB5.mpt.license b/tests/testdata/020-formation_CB5.mpt.license new file mode 100644 index 0000000..148639d --- /dev/null +++ b/tests/testdata/020-formation_CB5.mpt.license @@ -0,0 +1,2 @@ +SPDX-FileCopyrightText Chihyu Chen +SPDX-License-Identifier CC-BY-4.0 From 0ffdd2665e8193604b8d25b45ac2cd8bfe530d56 Mon Sep 17 00:00:00 2001 From: Chris Kerr Date: Sat, 10 Sep 2022 22:33:29 +0300 Subject: [PATCH 3/4] 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*$', From e1ff99a5598c0053343b697a92b04ab2639273c0 Mon Sep 17 00:00:00 2001 From: Chris Kerr Date: Sat, 10 Sep 2022 22:33:55 +0300 Subject: [PATCH 4/4] Update test precision for the new data files --- tests/test_BioLogic.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_BioLogic.py b/tests/test_BioLogic.py index 3eeef1e..ad7be6f 100644 --- a/tests/test_BioLogic.py +++ b/tests/test_BioLogic.py @@ -165,7 +165,7 @@ def assert_MPR_matches_MPT(mpr, mpt, comments): mpt["Ewe/V"], decimal=6) # 32 bit float precision - assert_field_matches("dQ/mA.h", decimal=17) # 64 bit float precision + assert_field_matches("dQ/mA.h", decimal=16) # 64 bit float precision assert_field_matches("P/W", decimal=10) # 32 bit float precision for 1.xxE-5 assert_field_matches("I/mA", decimal=6) # 32 bit float precision @@ -173,7 +173,7 @@ def assert_MPR_matches_MPT(mpr, mpt, comments): assert_field_matches("(Q-Qo)/C", decimal=6) # 32 bit float precision try: - assert timestamp_from_comments(comments) == mpr.timestamp + assert timestamp_from_comments(comments) == mpr.timestamp.replace(microsecond=0) except AttributeError: pass @@ -197,7 +197,7 @@ def test_MPR_matches_MPT(testdata_dir, basename): binpath = os.path.join(testdata_dir, basename + '.mpr') txtpath = os.path.join(testdata_dir, basename + '.mpt') mpr = MPRfile(binpath) - mpt, comments = MPTfile(txtpath) + mpt, comments = MPTfile(txtpath, encoding='latin1') assert_MPR_matches_MPT(mpr, mpt, comments)