diff --git a/src/yadg/extractors/eclab/mpr.py b/src/yadg/extractors/eclab/mpr.py index a296039b..cb3dc982 100644 --- a/src/yadg/extractors/eclab/mpr.py +++ b/src/yadg/extractors/eclab/mpr.py @@ -298,14 +298,18 @@ def process_settings(data: bytes, minver: str) -> tuple[dict, list]: params = [] for pardict in pardicts: for k, v in pardict.items(): - # MPR quirk: I_range off by one - if k == "I_range": + # MPR quirk: I Range off by one + if k == "I Range": v += 1 pardict[k] = param_from_key(k, v, to_str=True) # Handle NaNs and +/-Inf in params here if np.isnan(v) or np.isinf(v): pardict[k] = str(v) params.append(pardict) + if len(params) > 0: + params = {k: [d[k] for d in params] for k in params[0]} + else: + params = {} return settings, params @@ -420,7 +424,7 @@ def process_data( elif unit is None: intv = int(value) if name == "I Range": - vals[name] = param_from_key("I_range", intv) + vals[name] = param_from_key("I Range", intv) else: vals[name] = intv if flaglist: @@ -441,7 +445,7 @@ def process_data( Irstr = Iranges[Ns] if "I Range" in vals: Irstr = vals["I Range"] - Irange = param_from_key("I_range", Irstr, to_str=False) + Irange = param_from_key("I Range", Irstr, to_str=False) # I Range can be None if it's set to "Auto", "PAC" or other such string. if Irange is None: @@ -569,20 +573,17 @@ def process_modules(contents: bytes) -> tuple[dict, list, list, dict, dict]: module_data = module[mhd.itemsize :] if name == "VMP Set": settings, params = process_settings(module_data, minver) - Eranges = [] - Iranges = [] - ctrls = [] - for el in params: - E_range_max = el.get("E_range_max", float("inf")) - E_range_min = el.get("E_range_min", float("-inf")) - Eranges.append(E_range_max - E_range_min) - Iranges.append(el.get("I_range", "Auto")) - if "set_I/C" in el: - ctrls.append(el["set_I/C"]) - elif "apply_I/C" in el: - ctrls.append(el["apply_I/C"]) - else: - ctrls.append(None) + + E_range_max = params.get("E range max (V)", [float("inf")]) + E_range_min = params.get("E range min (V)", [float("-inf")]) + Eranges = [a - b for a, b in zip(E_range_max, E_range_min)] + Iranges = params.get("I Range", ["Auto"]) + if "Set I/C" in params: + ctrls = params.get("Set I/C") + elif "Apply I/C" in params: + ctrls = params.get("Apply I/C") + else: + ctrls = [None] * len(Iranges) elif name == "VMP data": ds = process_data(module_data, version, Eranges, Iranges, ctrls) elif name == "VMP LOG": diff --git a/src/yadg/extractors/eclab/mpt.py b/src/yadg/extractors/eclab/mpt.py index 4574a318..3d3f2aca 100644 --- a/src/yadg/extractors/eclab/mpt.py +++ b/src/yadg/extractors/eclab/mpt.py @@ -262,7 +262,7 @@ def process_data( if units.get(name) is None: ival = int(parse_decimal(value, locale=locale)) if name == "I Range": - vals[name] = param_from_key("I_range", ival) + vals[name] = param_from_key("I Range", ival) else: vals[name] = ival else: @@ -280,7 +280,7 @@ def process_data( Irstr = Iranges[Ns] if isinstance(Iranges, list) else Iranges if "I Range" in vals: Irstr = vals["I Range"] - Irange = param_from_key("I_range", Irstr, to_str=False) + Irange = param_from_key("I Range", Irstr, to_str=False) # I Range can be None if it's set to "Auto", "PAC" or other such string. if Irange is None: diff --git a/src/yadg/extractors/eclab/techniques.py b/src/yadg/extractors/eclab/techniques.py index b5137463..39bd2935 100644 --- a/src/yadg/extractors/eclab/techniques.py +++ b/src/yadg/extractors/eclab/techniques.py @@ -39,31 +39,31 @@ ( np.dtype( [ - ("Ei", "", 2),), +} + +vs_map = ( + ("Eoc", 0), + ("Emeas", 2), + ("Ei", 3), + ("Ref", 4), +) + param_map = { - "I_range": ( + "I Range": ( ("10 mA", 1, 1e-2), ("100 µA", 2, 1e-4), ("1 µA", 3, 1e-6), @@ -1356,18 +1415,33 @@ ("16 A", 193, 16.0), ("Auto", None, None), ), - "Is_unit": ( - ("A", 0), # guess - ("mA", 1), - ("µA", 2), - ("nA", 3), # guess - ("pA", 4), # guess - ), - "set_I/C": ( + "unit dI": unit_map["I"], + "unit dIp": unit_map["I"], + "unit dq": unit_map["Q"], + "unit dQ": unit_map["Q"], + "unit dQM": unit_map["Q"], + "unit dQp": unit_map["Q"], + "unit f": unit_map["f"], + "unit fi": unit_map["f"], + "unit ff": unit_map["f"], + "unit Ia": unit_map["I"], + "unit Im": unit_map["I"], + "unit Imax": unit_map["I"], + "unit Imin": unit_map["I"], + "unit Is": unit_map["I"], + "unit Is vs.": unit_map["vs."], + "E (V) vs.": vs_map, + "E1 (V) vs.": vs_map, + "E2 (V) vs.": vs_map, + "Ef (V) vs.": vs_map, + "Ei (V) vs.": vs_map, + "EL (V) vs.": vs_map, + "Es (V) vs.": vs_map, + "Set I/C": ( ("I", 0), - ("C", 1), # guess + ("C", 1), ), - "apply_I/C": ( + "Apply I/C": ( ("I", 0), ("C", 1), ), diff --git a/tests/test_extract.py b/tests/test_extract.py index 2529e1c7..57b0b16c 100644 --- a/tests/test_extract.py +++ b/tests/test_extract.py @@ -26,6 +26,6 @@ def test_yadg_extractors_extract_with_metadata(filetype, infile, datadir): ret = extract( filetype=filetype, path=infile, locale="en_GB", timezone="Europe/Berlin" ) - # ret.to_netcdf(f"C:/Users/Kraus/Code/yadg/tests/test_extract/{outfile}", engine="h5netcdf") + ret.to_netcdf(f"{outfile}.tmp", engine="h5netcdf") ref = datatree.open_datatree(outfile, engine="h5netcdf") compare_datatrees(ret, ref, thislevel=True, descend=True) diff --git a/tests/test_extract/cp.mpr.nc b/tests/test_extract/cp.mpr.nc index 178ae023..f216c309 100644 Binary files a/tests/test_extract/cp.mpr.nc and b/tests/test_extract/cp.mpr.nc differ diff --git a/tests/test_x_eclab.py b/tests/test_x_eclab.py index 2377afe5..8c03d02d 100644 --- a/tests/test_x_eclab.py +++ b/tests/test_x_eclab.py @@ -18,6 +18,15 @@ def check_file(fname, kwargs, func): return ret +def compare_params(left, right): + lpar = left.attrs["original_metadata"].get("params", {}) + rpar = right.attrs["original_metadata"].get("params", {}) + for k in rpar: + if k.endswith("vs.") or k.startswith("unit") or k == "I Range": + assert k in lpar, f"Param {k!r} not found in mpt file: {lpar.keys()}" + assert lpar[k] == rpar[k], f"Inconsistent param {k!r}: {lpar[k]}, {rpar[k]}" + + @pytest.mark.parametrize( "froot, locale", [ @@ -64,6 +73,7 @@ def test_eclab_consistency(froot, locale, datadir): except AssertionError as e: e.args = (e.args[0] + f"Error happened on key: {key!r}\n",) raise e + compare_params(aret, bret) @pytest.mark.parametrize( @@ -101,6 +111,7 @@ def test_eclab_consistency_partial_1(froot, locale, datadir): except AssertionError as e: e.args = (e.args[0] + f"Error happened on key: {key!r}\n",) raise e + compare_params(aret, bret) @pytest.mark.parametrize( @@ -126,6 +137,7 @@ def test_eclab_consistency_partial_2(froot, locale, datadir): except AssertionError as e: e.args = (e.args[0] + f"Error happened on key: {key!r}\n",) raise e + compare_params(aret, bret) @pytest.mark.parametrize( diff --git a/tests/test_x_eclab/ca.issue_134.mpr.pkl b/tests/test_x_eclab/ca.issue_134.mpr.pkl index 80568680..ba3ee232 100644 Binary files a/tests/test_x_eclab/ca.issue_134.mpr.pkl and b/tests/test_x_eclab/ca.issue_134.mpr.pkl differ diff --git a/tests/test_x_eclab/ca.issue_149.mpr.pkl b/tests/test_x_eclab/ca.issue_149.mpr.pkl index afbe00e2..0fe8c9cb 100644 Binary files a/tests/test_x_eclab/ca.issue_149.mpr.pkl and b/tests/test_x_eclab/ca.issue_149.mpr.pkl differ diff --git a/tests/test_x_eclab/ca.mpr.pkl b/tests/test_x_eclab/ca.mpr.pkl index 683bb451..c507d448 100644 Binary files a/tests/test_x_eclab/ca.mpr.pkl and b/tests/test_x_eclab/ca.mpr.pkl differ diff --git a/tests/test_x_eclab/coc.issue_185.mpr.pkl b/tests/test_x_eclab/coc.issue_185.mpr.pkl index 4d1d7168..e470b8f7 100644 Binary files a/tests/test_x_eclab/coc.issue_185.mpr.pkl and b/tests/test_x_eclab/coc.issue_185.mpr.pkl differ diff --git a/tests/test_x_eclab/cov.issue_185.mpr.pkl b/tests/test_x_eclab/cov.issue_185.mpr.pkl index 4093fb6f..e38abed7 100644 Binary files a/tests/test_x_eclab/cov.issue_185.mpr.pkl and b/tests/test_x_eclab/cov.issue_185.mpr.pkl differ diff --git a/tests/test_x_eclab/cp.issue_149.mpr.pkl b/tests/test_x_eclab/cp.issue_149.mpr.pkl index 187660a2..66ab6236 100644 Binary files a/tests/test_x_eclab/cp.issue_149.mpr.pkl and b/tests/test_x_eclab/cp.issue_149.mpr.pkl differ diff --git a/tests/test_x_eclab/cp.issue_61.mpr.pkl b/tests/test_x_eclab/cp.issue_61.mpr.pkl index c90d7782..e10a9b75 100644 Binary files a/tests/test_x_eclab/cp.issue_61.mpr.pkl and b/tests/test_x_eclab/cp.issue_61.mpr.pkl differ diff --git a/tests/test_x_eclab/cp.mpr.pkl b/tests/test_x_eclab/cp.mpr.pkl index 92baa945..673bbe20 100644 Binary files a/tests/test_x_eclab/cp.mpr.pkl and b/tests/test_x_eclab/cp.mpr.pkl differ diff --git a/tests/test_x_eclab/cv.issue_149.mpr.pkl b/tests/test_x_eclab/cv.issue_149.mpr.pkl index c807b0c2..aea94093 100644 Binary files a/tests/test_x_eclab/cv.issue_149.mpr.pkl and b/tests/test_x_eclab/cv.issue_149.mpr.pkl differ diff --git a/tests/test_x_eclab/cv.mpr.pkl b/tests/test_x_eclab/cv.mpr.pkl index 73ca6f8b..058ab25a 100644 Binary files a/tests/test_x_eclab/cv.mpr.pkl and b/tests/test_x_eclab/cv.mpr.pkl differ diff --git a/tests/test_x_eclab/cva.issue_135.mpr.pkl b/tests/test_x_eclab/cva.issue_135.mpr.pkl index 9cbcf7de..cb4615ee 100644 Binary files a/tests/test_x_eclab/cva.issue_135.mpr.pkl and b/tests/test_x_eclab/cva.issue_135.mpr.pkl differ diff --git a/tests/test_x_eclab/gcpl.issue_149.mpr.pkl b/tests/test_x_eclab/gcpl.issue_149.mpr.pkl index 61b8ebff..49307f8d 100644 Binary files a/tests/test_x_eclab/gcpl.issue_149.mpr.pkl and b/tests/test_x_eclab/gcpl.issue_149.mpr.pkl differ diff --git a/tests/test_x_eclab/gcpl.mpr.pkl b/tests/test_x_eclab/gcpl.mpr.pkl index c23f771b..a118eb6c 100644 Binary files a/tests/test_x_eclab/gcpl.mpr.pkl and b/tests/test_x_eclab/gcpl.mpr.pkl differ diff --git a/tests/test_x_eclab/gcpl.pr_182.1.mpr.pkl b/tests/test_x_eclab/gcpl.pr_182.1.mpr.pkl index 33b82c57..8e22ea49 100644 Binary files a/tests/test_x_eclab/gcpl.pr_182.1.mpr.pkl and b/tests/test_x_eclab/gcpl.pr_182.1.mpr.pkl differ diff --git a/tests/test_x_eclab/gcpl.pr_182.2.mpr.pkl b/tests/test_x_eclab/gcpl.pr_182.2.mpr.pkl index ef672145..bef3c589 100644 Binary files a/tests/test_x_eclab/gcpl.pr_182.2.mpr.pkl and b/tests/test_x_eclab/gcpl.pr_182.2.mpr.pkl differ diff --git a/tests/test_x_eclab/geis.issue_149.mpr.pkl b/tests/test_x_eclab/geis.issue_149.mpr.pkl index 022cd27b..8f8c808a 100644 Binary files a/tests/test_x_eclab/geis.issue_149.mpr.pkl and b/tests/test_x_eclab/geis.issue_149.mpr.pkl differ diff --git a/tests/test_x_eclab/geis.mpr.pkl b/tests/test_x_eclab/geis.mpr.pkl index b5dcdae4..246f38bd 100644 Binary files a/tests/test_x_eclab/geis.mpr.pkl and b/tests/test_x_eclab/geis.mpr.pkl differ diff --git a/tests/test_x_eclab/lsv.mpr.pkl b/tests/test_x_eclab/lsv.mpr.pkl index 650dcab3..2aea06f0 100644 Binary files a/tests/test_x_eclab/lsv.mpr.pkl and b/tests/test_x_eclab/lsv.mpr.pkl differ diff --git a/tests/test_x_eclab/mb.issue_149.mpr.pkl b/tests/test_x_eclab/mb.issue_149.mpr.pkl index 2c591b7a..11a58e67 100644 Binary files a/tests/test_x_eclab/mb.issue_149.mpr.pkl and b/tests/test_x_eclab/mb.issue_149.mpr.pkl differ diff --git a/tests/test_x_eclab/mb.issue_95.mpr.pkl b/tests/test_x_eclab/mb.issue_95.mpr.pkl index a2131d95..cea0666b 100644 Binary files a/tests/test_x_eclab/mb.issue_95.mpr.pkl and b/tests/test_x_eclab/mb.issue_95.mpr.pkl differ diff --git a/tests/test_x_eclab/mb.mpr.pkl b/tests/test_x_eclab/mb.mpr.pkl index 3c54dc2e..4626f2b3 100644 Binary files a/tests/test_x_eclab/mb.mpr.pkl and b/tests/test_x_eclab/mb.mpr.pkl differ diff --git a/tests/test_x_eclab/mp.issue_183.mpr.pkl b/tests/test_x_eclab/mp.issue_183.mpr.pkl index 945973a5..017ff4fc 100644 Binary files a/tests/test_x_eclab/mp.issue_183.mpr.pkl and b/tests/test_x_eclab/mp.issue_183.mpr.pkl differ diff --git a/tests/test_x_eclab/ocv.issue_149.mpr.pkl b/tests/test_x_eclab/ocv.issue_149.mpr.pkl index df4a8a11..ac15b959 100644 Binary files a/tests/test_x_eclab/ocv.issue_149.mpr.pkl and b/tests/test_x_eclab/ocv.issue_149.mpr.pkl differ diff --git a/tests/test_x_eclab/ocv.mpr.pkl b/tests/test_x_eclab/ocv.mpr.pkl index 302fe03c..07b57edf 100644 Binary files a/tests/test_x_eclab/ocv.mpr.pkl and b/tests/test_x_eclab/ocv.mpr.pkl differ diff --git a/tests/test_x_eclab/peis.issue_149.mpr.pkl b/tests/test_x_eclab/peis.issue_149.mpr.pkl index 430c0a4a..45087c23 100644 Binary files a/tests/test_x_eclab/peis.issue_149.mpr.pkl and b/tests/test_x_eclab/peis.issue_149.mpr.pkl differ diff --git a/tests/test_x_eclab/peis.mpr.pkl b/tests/test_x_eclab/peis.mpr.pkl index c0b3da1f..ff85d616 100644 Binary files a/tests/test_x_eclab/peis.mpr.pkl and b/tests/test_x_eclab/peis.mpr.pkl differ diff --git a/tests/test_x_eclab/vsp_ocv_with.mpr.pkl b/tests/test_x_eclab/vsp_ocv_with.mpr.pkl index 816a1830..f5bae7ff 100644 Binary files a/tests/test_x_eclab/vsp_ocv_with.mpr.pkl and b/tests/test_x_eclab/vsp_ocv_with.mpr.pkl differ diff --git a/tests/test_x_eclab/vsp_ocv_wo.mpr.pkl b/tests/test_x_eclab/vsp_ocv_wo.mpr.pkl index 74055e29..b3b35ac0 100644 Binary files a/tests/test_x_eclab/vsp_ocv_wo.mpr.pkl and b/tests/test_x_eclab/vsp_ocv_wo.mpr.pkl differ diff --git a/tests/test_x_eclab/vsp_peis_with.mpr.pkl b/tests/test_x_eclab/vsp_peis_with.mpr.pkl index d496cc3d..bfb327d4 100644 Binary files a/tests/test_x_eclab/vsp_peis_with.mpr.pkl and b/tests/test_x_eclab/vsp_peis_with.mpr.pkl differ diff --git a/tests/test_x_eclab/wait.mpr.pkl b/tests/test_x_eclab/wait.mpr.pkl index a7a8b5ff..e9ae97c9 100644 Binary files a/tests/test_x_eclab/wait.mpr.pkl and b/tests/test_x_eclab/wait.mpr.pkl differ diff --git a/tests/test_x_eclab/zir.mpr.pkl b/tests/test_x_eclab/zir.mpr.pkl index 5d26c301..69bdba1c 100644 Binary files a/tests/test_x_eclab/zir.mpr.pkl and b/tests/test_x_eclab/zir.mpr.pkl differ diff --git a/tests/test_yadg/cp.mpr.nc b/tests/test_yadg/cp.mpr.nc index 93b3eb29..b2b1195d 100644 Binary files a/tests/test_yadg/cp.mpr.nc and b/tests/test_yadg/cp.mpr.nc differ