mirror of
https://github.com/echemdata/galvani.git
synced 2025-12-14 01:15:34 +00:00
added tests for v11.50
This commit is contained in:
@@ -48,6 +48,13 @@ def fieldname_to_dtype(fieldname):
|
|||||||
"|Z|/Ohm",
|
"|Z|/Ohm",
|
||||||
"Re(Z)/Ohm",
|
"Re(Z)/Ohm",
|
||||||
"-Im(Z)/Ohm",
|
"-Im(Z)/Ohm",
|
||||||
|
"Re(M)",
|
||||||
|
"Im(M)",
|
||||||
|
"|M|",
|
||||||
|
"Re(Permittivity)",
|
||||||
|
"Im(Permittivity)",
|
||||||
|
"|Permittivity|",
|
||||||
|
"Tan(Delta)",
|
||||||
):
|
):
|
||||||
return (fieldname, np.float_)
|
return (fieldname, np.float_)
|
||||||
elif fieldname in (
|
elif fieldname in (
|
||||||
@@ -60,13 +67,13 @@ def fieldname_to_dtype(fieldname):
|
|||||||
"Capacity/mA.h",
|
"Capacity/mA.h",
|
||||||
):
|
):
|
||||||
return (fieldname, np.float_)
|
return (fieldname, np.float_)
|
||||||
elif fieldname in ("cycle number", "I Range", "Ns", "half cycle"):
|
elif fieldname in ("cycle number", "I Range", "Ns", "half cycle", "z cycle"):
|
||||||
return (fieldname, np.int_)
|
return (fieldname, np.int_)
|
||||||
elif fieldname in ("dq/mA.h", "dQ/mA.h"):
|
elif fieldname in ("dq/mA.h", "dQ/mA.h"):
|
||||||
return ("dQ/mA.h", np.float_)
|
return ("dQ/mA.h", np.float_)
|
||||||
elif fieldname in ("I/mA", "<I>/mA"):
|
elif fieldname in ("I/mA", "<I>/mA"):
|
||||||
return ("I/mA", np.float_)
|
return ("I/mA", np.float_)
|
||||||
elif fieldname in ("Ewe/V", "<Ewe>/V", "Ecell/V"):
|
elif fieldname in ("Ewe/V", "<Ewe>/V", "Ecell/V", "<Ewe/V>"):
|
||||||
return ("Ewe/V", np.float_)
|
return ("Ewe/V", np.float_)
|
||||||
elif fieldname.endswith(
|
elif fieldname.endswith(
|
||||||
(
|
(
|
||||||
@@ -87,8 +94,13 @@ def fieldname_to_dtype(fieldname):
|
|||||||
"/mF",
|
"/mF",
|
||||||
"/uF",
|
"/uF",
|
||||||
"/µF",
|
"/µF",
|
||||||
|
"/nF",
|
||||||
"/C",
|
"/C",
|
||||||
"/Ohm",
|
"/Ohm",
|
||||||
|
"/Ohm-1",
|
||||||
|
"/Ohm.cm",
|
||||||
|
"/mS/cm",
|
||||||
|
"/%",
|
||||||
)
|
)
|
||||||
):
|
):
|
||||||
return (fieldname, np.float_)
|
return (fieldname, np.float_)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import re
|
|||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from numpy.testing import assert_array_almost_equal, assert_array_equal
|
from numpy.testing import assert_array_almost_equal, assert_array_equal, assert_allclose
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from galvani import BioLogic, MPTfile, MPRfile
|
from galvani import BioLogic, MPTfile, MPRfile
|
||||||
@@ -209,6 +209,89 @@ def assert_MPR_matches_MPT(mpr, mpt, comments):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def assert_MPR_matches_MPT_v2(mpr, mpt, comments):
|
||||||
|
"""
|
||||||
|
Asserts that the fields in the MPR.data ar the same as in the MPT. Modified from assert_MPR_matches_MPT.
|
||||||
|
Automatically converts dtype from MPT data to dtype from MPR data before comparing the columns.
|
||||||
|
Speficicity for EIS_indicators : these fields are valid only at f<100kHz so their values are replaced
|
||||||
|
by -1 or 0 at high frequency in the MPT file, this is not the case in the MPR.data.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
mpr : MPRfile
|
||||||
|
Data extracted with the MPRfile class.
|
||||||
|
mpt : np.array
|
||||||
|
Data extracted with MPTfile method.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
None.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def assert_field_matches(fieldname):
|
||||||
|
EIS_quality_indicators = [
|
||||||
|
"THD Ewe/%",
|
||||||
|
"NSD Ewe/%",
|
||||||
|
"NSR Ewe/%",
|
||||||
|
"|Ewe h2|/V",
|
||||||
|
"|Ewe h3|/V",
|
||||||
|
"|Ewe h4|/V",
|
||||||
|
"|Ewe h5|/V",
|
||||||
|
"|Ewe h6|/V",
|
||||||
|
"|Ewe h7|/V",
|
||||||
|
"THD I/%",
|
||||||
|
"NSD I/%",
|
||||||
|
"NSR I/%",
|
||||||
|
"|I h2|/A",
|
||||||
|
"|I h3|/A",
|
||||||
|
"|I h4|/A",
|
||||||
|
"|I h5|/A",
|
||||||
|
"|I h6|/A",
|
||||||
|
"|I h7|/A",
|
||||||
|
]
|
||||||
|
|
||||||
|
if fieldname in EIS_quality_indicators: # EIS quality indicators only valid for f < 100kHz
|
||||||
|
index_inf_100k = np.where(mpr.data["freq/Hz"] < 100000)[0]
|
||||||
|
assert_allclose(
|
||||||
|
mpr.data[index_inf_100k][fieldname],
|
||||||
|
mpt[index_inf_100k][fieldname].astype(mpr.data[fieldname].dtype),
|
||||||
|
)
|
||||||
|
elif fieldname == "<Ewe>/V":
|
||||||
|
assert_allclose(
|
||||||
|
mpr.data[fieldname],
|
||||||
|
mpt["Ewe/V"].astype(mpr.data[fieldname].dtype),
|
||||||
|
)
|
||||||
|
elif fieldname == "<I>/mA":
|
||||||
|
assert_allclose(
|
||||||
|
mpr.data[fieldname],
|
||||||
|
mpt["I/mA"].astype(mpr.data[fieldname].dtype),
|
||||||
|
)
|
||||||
|
elif fieldname == "dq/mA.h":
|
||||||
|
assert_allclose(
|
||||||
|
mpr.data[fieldname],
|
||||||
|
mpt["dQ/mA.h"].astype(mpr.data[fieldname].dtype),
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
assert_allclose(
|
||||||
|
mpr.data[fieldname],
|
||||||
|
mpt[fieldname].astype(mpr.data[fieldname].dtype),
|
||||||
|
)
|
||||||
|
|
||||||
|
def assert_field_exact(fieldname):
|
||||||
|
if fieldname in mpr.dtype.fields:
|
||||||
|
assert_array_equal(mpr.data[fieldname], mpt[fieldname])
|
||||||
|
|
||||||
|
for key in mpr.flags_dict.keys():
|
||||||
|
assert_array_equal(mpr.get_flag(key), mpt[key])
|
||||||
|
|
||||||
|
for d in mpr.dtype.descr[1:]:
|
||||||
|
assert_field_matches(d[0])
|
||||||
|
|
||||||
|
try:
|
||||||
|
assert timestamp_from_comments(comments) == mpr.timestamp.replace(microsecond=0)
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"basename",
|
"basename",
|
||||||
@@ -252,3 +335,19 @@ def test_MPR6_matches_MPT6(testdata_dir):
|
|||||||
mpt, comments = MPTfile(os.path.join(testdata_dir, "bio_logic6.mpt"))
|
mpt, comments = MPTfile(os.path.join(testdata_dir, "bio_logic6.mpt"))
|
||||||
mpr.data = mpr.data[:958] # .mpt file is incomplete
|
mpr.data = mpr.data[:958] # .mpt file is incomplete
|
||||||
assert_MPR_matches_MPT(mpr, mpt, comments)
|
assert_MPR_matches_MPT(mpr, mpt, comments)
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"basename_v1150",
|
||||||
|
["v1150_CA", "v1150_CP", "v1150_GCPL", "v1150_GEIS", "v1150_MB", "v1150_OCV", "v1150_PEIS"],
|
||||||
|
)
|
||||||
|
def test_MPR_matches_MPT_v1150(testdata_dir, basename_v1150):
|
||||||
|
"""Check the MPR parser against the MPT parser.
|
||||||
|
|
||||||
|
Load a binary .mpr file and a text .mpt file which should contain
|
||||||
|
exactly the same data. Check that the loaded data actually match.
|
||||||
|
"""
|
||||||
|
binpath = os.path.join(testdata_dir, "v1150", basename_v1150 + ".mpr")
|
||||||
|
txtpath = os.path.join(testdata_dir, "v1150", basename_v1150 + ".mpt")
|
||||||
|
mpr = MPRfile(binpath)
|
||||||
|
mpt, comments = MPTfile(txtpath, encoding="latin1")
|
||||||
|
assert_MPR_matches_MPT_v2(mpr, mpt, comments)
|
||||||
|
|||||||
BIN
tests/testdata/v1150/v1150_CA.mpr
LFS
vendored
Normal file
BIN
tests/testdata/v1150/v1150_CA.mpr
LFS
vendored
Normal file
Binary file not shown.
BIN
tests/testdata/v1150/v1150_CA.mpt
LFS
vendored
Normal file
BIN
tests/testdata/v1150/v1150_CA.mpt
LFS
vendored
Normal file
Binary file not shown.
BIN
tests/testdata/v1150/v1150_CP.mpr
LFS
vendored
Normal file
BIN
tests/testdata/v1150/v1150_CP.mpr
LFS
vendored
Normal file
Binary file not shown.
BIN
tests/testdata/v1150/v1150_CP.mpt
LFS
vendored
Normal file
BIN
tests/testdata/v1150/v1150_CP.mpt
LFS
vendored
Normal file
Binary file not shown.
BIN
tests/testdata/v1150/v1150_GCPL.mpr
LFS
vendored
Normal file
BIN
tests/testdata/v1150/v1150_GCPL.mpr
LFS
vendored
Normal file
Binary file not shown.
BIN
tests/testdata/v1150/v1150_GCPL.mpt
LFS
vendored
Normal file
BIN
tests/testdata/v1150/v1150_GCPL.mpt
LFS
vendored
Normal file
Binary file not shown.
BIN
tests/testdata/v1150/v1150_GEIS.mpr
LFS
vendored
Normal file
BIN
tests/testdata/v1150/v1150_GEIS.mpr
LFS
vendored
Normal file
Binary file not shown.
BIN
tests/testdata/v1150/v1150_GEIS.mpt
LFS
vendored
Normal file
BIN
tests/testdata/v1150/v1150_GEIS.mpt
LFS
vendored
Normal file
Binary file not shown.
BIN
tests/testdata/v1150/v1150_MB.mpr
LFS
vendored
Normal file
BIN
tests/testdata/v1150/v1150_MB.mpr
LFS
vendored
Normal file
Binary file not shown.
BIN
tests/testdata/v1150/v1150_MB.mpt
LFS
vendored
Normal file
BIN
tests/testdata/v1150/v1150_MB.mpt
LFS
vendored
Normal file
Binary file not shown.
BIN
tests/testdata/v1150/v1150_OCV.mpr
LFS
vendored
Normal file
BIN
tests/testdata/v1150/v1150_OCV.mpr
LFS
vendored
Normal file
Binary file not shown.
BIN
tests/testdata/v1150/v1150_OCV.mpt
LFS
vendored
Normal file
BIN
tests/testdata/v1150/v1150_OCV.mpt
LFS
vendored
Normal file
Binary file not shown.
BIN
tests/testdata/v1150/v1150_PEIS.mpr
LFS
vendored
Normal file
BIN
tests/testdata/v1150/v1150_PEIS.mpr
LFS
vendored
Normal file
Binary file not shown.
BIN
tests/testdata/v1150/v1150_PEIS.mpt
LFS
vendored
Normal file
BIN
tests/testdata/v1150/v1150_PEIS.mpt
LFS
vendored
Normal file
Binary file not shown.
Reference in New Issue
Block a user