mirror of
https://github.com/echemdata/galvani.git
synced 2025-12-14 17:15:36 +00:00
Added column IDs from step voltammetry
This commit is contained in:
27
BioLogic.py
27
BioLogic.py
@@ -24,8 +24,10 @@ def fieldname_to_dtype(fieldname):
|
|||||||
"counter inc."):
|
"counter inc."):
|
||||||
return (fieldname, np.bool_)
|
return (fieldname, np.bool_)
|
||||||
elif fieldname in ("time/s", "Ewe/V", "P/W", "(Q-Qo)/mA.h", "x",
|
elif fieldname in ("time/s", "Ewe/V", "P/W", "(Q-Qo)/mA.h", "x",
|
||||||
"control/V", "control/V/mA"):
|
"control/V", "control/V/mA", "(Q-Qo)/C"):
|
||||||
return (fieldname, np.float_)
|
return (fieldname, np.float_)
|
||||||
|
elif fieldname in ("cycle number",):
|
||||||
|
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"):
|
||||||
@@ -60,23 +62,6 @@ def MPTfile(file_or_path):
|
|||||||
comments = [next(mpt_file) for i in range(nb_headers - 3)]
|
comments = [next(mpt_file) for i in range(nb_headers - 3)]
|
||||||
|
|
||||||
fieldnames = next(mpt_file).decode('ascii').strip().split('\t')
|
fieldnames = next(mpt_file).decode('ascii').strip().split('\t')
|
||||||
|
|
||||||
expected_fieldnames = (
|
|
||||||
["mode", "ox/red", "error", "control changes", "Ns changes",
|
|
||||||
"counter inc.", "time/s", "control/V/mA", "Ewe/V", "dq/mA.h",
|
|
||||||
"P/W", "<I>/mA", "(Q-Qo)/mA.h", "x"],
|
|
||||||
['mode', 'ox/red', 'error', 'control changes', 'Ns changes',
|
|
||||||
'counter inc.', 'time/s', 'control/V', 'Ewe/V', 'dq/mA.h',
|
|
||||||
'<I>/mA', '(Q-Qo)/mA.h', 'x'],
|
|
||||||
["mode", "ox/red", "error", "control changes", "Ns changes",
|
|
||||||
"counter inc.", "time/s", "control/V", "Ewe/V", "I/mA",
|
|
||||||
"dQ/mA.h", "P/W"],
|
|
||||||
["mode", "ox/red", "error", "control changes", "Ns changes",
|
|
||||||
"counter inc.", "time/s", "control/V", "Ewe/V", "<I>/mA",
|
|
||||||
"dQ/mA.h", "P/W"])
|
|
||||||
if fieldnames not in expected_fieldnames:
|
|
||||||
warn("Unrecognised headers for MPT file format %s" % fieldnames)
|
|
||||||
|
|
||||||
record_type = np.dtype(list(map(fieldname_to_dtype, fieldnames)))
|
record_type = np.dtype(list(map(fieldname_to_dtype, fieldnames)))
|
||||||
|
|
||||||
mpt_array = np.loadtxt(mpt_file, dtype=record_type)
|
mpt_array = np.loadtxt(mpt_file, dtype=record_type)
|
||||||
@@ -155,10 +140,16 @@ def VMPdata_dtype_from_colIDs(colIDs):
|
|||||||
dtype_dict['dQ/mA.h'] = '<f8'
|
dtype_dict['dQ/mA.h'] = '<f8'
|
||||||
elif colID == 8:
|
elif colID == 8:
|
||||||
dtype_dict['I/mA'] = '<f4'
|
dtype_dict['I/mA'] = '<f4'
|
||||||
|
elif colID == 11:
|
||||||
|
dtype_dict['I/mA'] = '<f8'
|
||||||
elif colID == 19:
|
elif colID == 19:
|
||||||
dtype_dict['control/V'] = '<f4'
|
dtype_dict['control/V'] = '<f4'
|
||||||
|
elif colID == 24:
|
||||||
|
dtype_dict['cycle number'] = '<f8'
|
||||||
elif colID == 70:
|
elif colID == 70:
|
||||||
dtype_dict['P/W'] = '<f4'
|
dtype_dict['P/W'] = '<f4'
|
||||||
|
elif colID == 434:
|
||||||
|
dtype_dict['(Q-Qo)/C'] = '<f4'
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError("column type %d not implemented" % colID)
|
raise NotImplementedError("column type %d not implemented" % colID)
|
||||||
return np.dtype(list(dtype_dict.items()))
|
return np.dtype(list(dtype_dict.items()))
|
||||||
|
|||||||
@@ -77,6 +77,13 @@ def test_open_MPR5():
|
|||||||
eq_(mpr.enddate, date(2013, 1, 28))
|
eq_(mpr.enddate, date(2013, 1, 28))
|
||||||
|
|
||||||
|
|
||||||
|
def test_open_MPR6():
|
||||||
|
mpr = MPRfile(os.path.join(testdata_dir, 'bio-logic6.mpr'))
|
||||||
|
## Check the dates as a basic test that it has been read properly
|
||||||
|
eq_(mpr.startdate, date(2012, 9, 11))
|
||||||
|
## no end date because no VMP LOG module
|
||||||
|
|
||||||
|
|
||||||
@raises(ValueError)
|
@raises(ValueError)
|
||||||
def test_open_MPR_fails_for_bad_file():
|
def test_open_MPR_fails_for_bad_file():
|
||||||
mpr1 = MPRfile(os.path.join(testdata_dir, 'arbin1.res'))
|
mpr1 = MPRfile(os.path.join(testdata_dir, 'arbin1.res'))
|
||||||
@@ -90,6 +97,10 @@ def assert_MPR_matches_MPT(mpr, mpt):
|
|||||||
mpt[fieldname],
|
mpt[fieldname],
|
||||||
decimal=decimal)
|
decimal=decimal)
|
||||||
|
|
||||||
|
def assert_field_exact(fieldname):
|
||||||
|
if fieldname in mpr.dtype.fields:
|
||||||
|
assert_array_equal(mpr.data[fieldname], mpt[fieldname])
|
||||||
|
|
||||||
assert_array_equal(mpr.data["flags"] & 0x03, mpt["mode"])
|
assert_array_equal(mpr.data["flags"] & 0x03, mpt["mode"])
|
||||||
assert_array_equal(np.array(mpr.data["flags"] & 0x04, dtype=np.bool_),
|
assert_array_equal(np.array(mpr.data["flags"] & 0x04, dtype=np.bool_),
|
||||||
mpt["ox/red"])
|
mpt["ox/red"])
|
||||||
@@ -97,8 +108,9 @@ def assert_MPR_matches_MPT(mpr, mpt):
|
|||||||
mpt["error"])
|
mpt["error"])
|
||||||
assert_array_equal(np.array(mpr.data["flags"] & 0x10, dtype=np.bool_),
|
assert_array_equal(np.array(mpr.data["flags"] & 0x10, dtype=np.bool_),
|
||||||
mpt["control changes"])
|
mpt["control changes"])
|
||||||
assert_array_equal(np.array(mpr.data["flags"] & 0x20, dtype=np.bool_),
|
if "Ns changes" in mpt.dtype.fields:
|
||||||
mpt["Ns changes"])
|
assert_array_equal(np.array(mpr.data["flags"] & 0x20, dtype=np.bool_),
|
||||||
|
mpt["Ns changes"])
|
||||||
## Nothing uses the 0x40 bit of the flags
|
## Nothing uses the 0x40 bit of the flags
|
||||||
assert_array_equal(np.array(mpr.data["flags"] & 0x80, dtype=np.bool_),
|
assert_array_equal(np.array(mpr.data["flags"] & 0x80, dtype=np.bool_),
|
||||||
mpt["counter inc."])
|
mpt["counter inc."])
|
||||||
@@ -114,13 +126,13 @@ def assert_MPR_matches_MPT(mpr, mpt):
|
|||||||
mpt["Ewe/V"],
|
mpt["Ewe/V"],
|
||||||
decimal=6) # 32 bit float precision
|
decimal=6) # 32 bit float precision
|
||||||
|
|
||||||
assert_array_almost_equal(mpr.data["dQ/mA.h"],
|
assert_field_matches("dQ/mA.h", decimal=17) # 64 bit float precision
|
||||||
mpt["dQ/mA.h"],
|
|
||||||
decimal=17) # 64 bit float precision
|
|
||||||
|
|
||||||
assert_field_matches("P/W", decimal=10) # 32 bit float precision for 1.xxE-5
|
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
|
assert_field_matches("I/mA", decimal=6) # 32 bit float precision
|
||||||
|
|
||||||
|
assert_field_exact("cycle number")
|
||||||
|
assert_field_matches("(Q-Qo)/C", decimal=6) # 32 bit float precision
|
||||||
|
|
||||||
|
|
||||||
def test_MPR1_matches_MPT1():
|
def test_MPR1_matches_MPT1():
|
||||||
mpr1 = MPRfile(os.path.join(testdata_dir, 'bio-logic1.mpr'))
|
mpr1 = MPRfile(os.path.join(testdata_dir, 'bio-logic1.mpr'))
|
||||||
@@ -149,3 +161,10 @@ def test_MPR5_matches_MPT5():
|
|||||||
open(os.path.join(testdata_dir, 'bio-logic5.mpt'),
|
open(os.path.join(testdata_dir, 'bio-logic5.mpt'),
|
||||||
mode='rb')))
|
mode='rb')))
|
||||||
assert_MPR_matches_MPT(mpr, mpt)
|
assert_MPR_matches_MPT(mpr, mpt)
|
||||||
|
|
||||||
|
|
||||||
|
def test_MPR6_matches_MPT6():
|
||||||
|
mpr = MPRfile(os.path.join(testdata_dir, 'bio-logic6.mpr'))
|
||||||
|
mpt, comments = MPTfile(os.path.join(testdata_dir, 'bio-logic6.mpt'))
|
||||||
|
mpr.data = mpr.data[:958] # .mpt file is incomplete
|
||||||
|
assert_MPR_matches_MPT(mpr, mpt)
|
||||||
|
|||||||
Reference in New Issue
Block a user