Added column IDs from step voltammetry

This commit is contained in:
Chris Kerr
2013-12-11 13:14:19 +00:00
parent 00e6670b4a
commit de84f9dd40
2 changed files with 35 additions and 25 deletions

View File

@@ -24,8 +24,10 @@ def fieldname_to_dtype(fieldname):
"counter inc."):
return (fieldname, np.bool_)
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_)
elif fieldname in ("cycle number",):
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"):
@@ -60,23 +62,6 @@ def MPTfile(file_or_path):
comments = [next(mpt_file) for i in range(nb_headers - 3)]
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)))
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'
elif colID == 8:
dtype_dict['I/mA'] = '<f4'
elif colID == 11:
dtype_dict['I/mA'] = '<f8'
elif colID == 19:
dtype_dict['control/V'] = '<f4'
elif colID == 24:
dtype_dict['cycle number'] = '<f8'
elif colID == 70:
dtype_dict['P/W'] = '<f4'
elif colID == 434:
dtype_dict['(Q-Qo)/C'] = '<f4'
else:
raise NotImplementedError("column type %d not implemented" % colID)
return np.dtype(list(dtype_dict.items()))

View File

@@ -77,19 +77,30 @@ def test_open_MPR5():
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)
def test_open_MPR_fails_for_bad_file():
mpr1 = MPRfile(os.path.join(testdata_dir, 'arbin1.res'))
def assert_MPR_matches_MPT(mpr, mpt):
def assert_field_matches(fieldname, decimal):
if fieldname in mpr.dtype.fields:
assert_array_almost_equal(mpr.data[fieldname],
mpt[fieldname],
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(np.array(mpr.data["flags"] & 0x04, dtype=np.bool_),
mpt["ox/red"])
@@ -97,8 +108,9 @@ def assert_MPR_matches_MPT(mpr, mpt):
mpt["error"])
assert_array_equal(np.array(mpr.data["flags"] & 0x10, dtype=np.bool_),
mpt["control changes"])
assert_array_equal(np.array(mpr.data["flags"] & 0x20, dtype=np.bool_),
mpt["Ns changes"])
if "Ns changes" in mpt.dtype.fields:
assert_array_equal(np.array(mpr.data["flags"] & 0x20, dtype=np.bool_),
mpt["Ns changes"])
## Nothing uses the 0x40 bit of the flags
assert_array_equal(np.array(mpr.data["flags"] & 0x80, dtype=np.bool_),
mpt["counter inc."])
@@ -114,12 +126,12 @@ def assert_MPR_matches_MPT(mpr, mpt):
mpt["Ewe/V"],
decimal=6) # 32 bit float precision
assert_array_almost_equal(mpr.data["dQ/mA.h"],
mpt["dQ/mA.h"],
decimal=17) # 64 bit float precision
assert_field_matches("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("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():
@@ -149,3 +161,10 @@ def test_MPR5_matches_MPT5():
open(os.path.join(testdata_dir, 'bio-logic5.mpt'),
mode='rb')))
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)