mirror of
https://github.com/echemdata/galvani.git
synced 2025-12-14 09:15:34 +00:00
Added the test data files sent by Matthias Richter (see #1)
Had to make a few changes to ensure that they open correctly
This commit is contained in:
24
BioLogic.py
24
BioLogic.py
@@ -9,7 +9,7 @@ import csv
|
|||||||
from os import SEEK_SET, SEEK_CUR
|
from os import SEEK_SET, SEEK_CUR
|
||||||
import time
|
import time
|
||||||
from datetime import date, datetime, timedelta
|
from datetime import date, datetime, timedelta
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict, defaultdict
|
||||||
from warnings import warn
|
from warnings import warn
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@@ -35,7 +35,9 @@ def fieldname_to_dtype(fieldname):
|
|||||||
"|Ewe|/V", "|I|/A", "Phase(Z)/deg", "|Z|/Ohm",
|
"|Ewe|/V", "|I|/A", "Phase(Z)/deg", "|Z|/Ohm",
|
||||||
"Re(Z)/Ohm", "-Im(Z)/Ohm"):
|
"Re(Z)/Ohm", "-Im(Z)/Ohm"):
|
||||||
return (fieldname, np.float_)
|
return (fieldname, np.float_)
|
||||||
elif fieldname in ("cycle number", "I Range"):
|
# N.B. I'm not sure what 'Ns' is as in the only file I have with that
|
||||||
|
# header it never has any value other than '0'
|
||||||
|
elif fieldname in ("cycle number", "I Range", "Ns"):
|
||||||
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_)
|
||||||
@@ -47,6 +49,12 @@ def fieldname_to_dtype(fieldname):
|
|||||||
raise ValueError("Invalid column header: %s" % fieldname)
|
raise ValueError("Invalid column header: %s" % fieldname)
|
||||||
|
|
||||||
|
|
||||||
|
def comma_converter(float_string):
|
||||||
|
"""Convert numbers to floats whether the decimal point is '.' or ','"""
|
||||||
|
trans_table = bytes.maketrans(b',', b'.')
|
||||||
|
return float(float_string.translate(trans_table))
|
||||||
|
|
||||||
|
|
||||||
def MPTfile(file_or_path):
|
def MPTfile(file_or_path):
|
||||||
"""Opens .mpt files as numpy record arrays
|
"""Opens .mpt files as numpy record arrays
|
||||||
|
|
||||||
@@ -75,7 +83,11 @@ def MPTfile(file_or_path):
|
|||||||
fieldnames = str3(next(mpt_file)).strip().split('\t')
|
fieldnames = str3(next(mpt_file)).strip().split('\t')
|
||||||
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)
|
## Must be able to parse files where commas are used for decimal points
|
||||||
|
converter_dict = dict(((i, comma_converter)
|
||||||
|
for i in range(len(fieldnames))))
|
||||||
|
mpt_array = np.loadtxt(mpt_file, dtype=record_type,
|
||||||
|
converters=converter_dict)
|
||||||
|
|
||||||
return mpt_array, comments
|
return mpt_array, comments
|
||||||
|
|
||||||
@@ -320,10 +332,16 @@ class MPRfile:
|
|||||||
dtype='<f8', count=1)
|
dtype='<f8', count=1)
|
||||||
ole_timestamp2 = np.fromstring(log_module['data'][469:],
|
ole_timestamp2 = np.fromstring(log_module['data'][469:],
|
||||||
dtype='<f8', count=1)
|
dtype='<f8', count=1)
|
||||||
|
ole_timestamp3 = np.fromstring(log_module['data'][473:],
|
||||||
|
dtype='<f8', count=1)
|
||||||
if ole_timestamp1 > 40000 and ole_timestamp1 < 50000:
|
if ole_timestamp1 > 40000 and ole_timestamp1 < 50000:
|
||||||
ole_timestamp = ole_timestamp1
|
ole_timestamp = ole_timestamp1
|
||||||
elif ole_timestamp2 > 40000 and ole_timestamp2 < 50000:
|
elif ole_timestamp2 > 40000 and ole_timestamp2 < 50000:
|
||||||
ole_timestamp = ole_timestamp2
|
ole_timestamp = ole_timestamp2
|
||||||
|
elif ole_timestamp3 > 40000 and ole_timestamp3 < 50000:
|
||||||
|
ole_timestamp = ole_timestamp3
|
||||||
|
else:
|
||||||
|
raise ValueError("Could not find timestamp in the LOG module")
|
||||||
|
|
||||||
ole_base = datetime(1899, 12, 30, tzinfo=None)
|
ole_base = datetime(1899, 12, 30, tzinfo=None)
|
||||||
ole_timedelta = timedelta(days=ole_timestamp[0])
|
ole_timedelta = timedelta(days=ole_timestamp[0])
|
||||||
|
|||||||
@@ -18,4 +18,8 @@ http://files.figshare.com/1778944/bio_logic6.mpt
|
|||||||
http://files.figshare.com/1778945/bio_logic1.mpt
|
http://files.figshare.com/1778945/bio_logic1.mpt
|
||||||
http://files.figshare.com/1778946/bio_logic3.mpr
|
http://files.figshare.com/1778946/bio_logic3.mpr
|
||||||
http://files.figshare.com/1780444/bio_logic4.mpr
|
http://files.figshare.com/1780444/bio_logic4.mpr
|
||||||
|
http://files.figshare.com/1780529/121_CA_455nm_6V_30min_C01.mpr
|
||||||
|
http://files.figshare.com/1780530/121_CA_455nm_6V_30min_C01.mpt
|
||||||
|
http://files.figshare.com/1780526/CV_C01.mpr
|
||||||
|
http://files.figshare.com/1780527/CV_C01.mpt
|
||||||
END_FILELIST
|
END_FILELIST
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ def assert_MPR_matches_MPT(mpr, mpt, comments):
|
|||||||
|
|
||||||
assert_array_almost_equal(mpr.data["time/s"],
|
assert_array_almost_equal(mpr.data["time/s"],
|
||||||
mpt["time/s"],
|
mpt["time/s"],
|
||||||
decimal=4) # 5 digits in CSV
|
decimal=2) # 2 digits in CSV
|
||||||
|
|
||||||
assert_field_matches("control/V/mA", decimal=6)
|
assert_field_matches("control/V/mA", decimal=6)
|
||||||
assert_field_matches("control/V", decimal=6)
|
assert_field_matches("control/V", decimal=6)
|
||||||
@@ -178,3 +178,18 @@ def test_MPR6_matches_MPT6():
|
|||||||
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)
|
||||||
|
|
||||||
|
|
||||||
|
## Tests for issue #1 -- new dtypes ##
|
||||||
|
|
||||||
|
|
||||||
|
def test_CV_C01():
|
||||||
|
mpr = MPRfile(os.path.join(testdata_dir, 'CV_C01.mpr'))
|
||||||
|
mpt, comments = MPTfile(os.path.join(testdata_dir, 'CV_C01.mpt'))
|
||||||
|
assert_MPR_matches_MPT(mpr, mpt, comments)
|
||||||
|
|
||||||
|
|
||||||
|
def test_CA_455nm():
|
||||||
|
mpr = MPRfile(os.path.join(testdata_dir, '121-CA-455nm-6V_30min_C01.mpr'))
|
||||||
|
mpt, comments = MPTfile(os.path.join(testdata_dir, '121-CA-455nm-6V_30min_C01.mpt'))
|
||||||
|
assert_MPR_matches_MPT(mpr, mpt, comments)
|
||||||
|
|||||||
Reference in New Issue
Block a user