Skip to content

Commit a0acf9a

Browse files
authored
eclab.mpr: Add column conflict resolution scheme. (#227)
* Fix columns * Add new tests. * conflict_columns * docs changes. * typo
1 parent 465eeeb commit a0acf9a

19 files changed

+375
-10
lines changed

docs/source/version.6_2.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ Bug fixes in ``yadg-next`` include:
2323
- Added further ``Set I/C`` parameters. Thanks to `@Locki3 <https://github.com/Locki3>`_ for providing test files.
2424
- Fixed ``param format`` and ``data_column`` in CV files generated with EC-Lab version 11.50 using the :mod:`yadg.extractors.eclab.mpr` module. Thank you to J.N. Hausmann from Helmholtz-Zentrum Berlin für Materialien und Energie for providing the test files.
2525
- Fixed parsing of various kinds of Modulo Bat files in :mod:`yadg.extractors.eclab.mpr`. Thank you to `@JohannesBaller <https://github.com/JohannesBaller>`_ for providing test files.
26+
- Columns in :mod:`yadg.extractors.eclab.mpr` files may have different meanings based on which other columns are also present in the files, see `issue 225 <https://github.com/dgbowl/yadg/issues/225>`_. Added a (hopefully extensible) way to tackle such conflicts and clarified the warnings.

src/yadg/extractors/eclab/mpr.py

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@
199199
settings_dtypes,
200200
flag_columns,
201201
data_columns,
202+
conflict_columns,
202203
log_dtypes,
203204
extdev_dtypes,
204205
)
@@ -314,17 +315,57 @@ def parse_columns(column_ids: list[int]) -> tuple[list, list, list, dict]:
314315
names.append("flags")
315316
dtypes.append("|u1")
316317
units.append(None)
317-
elif id in data_columns:
318+
elif id in data_columns and id not in conflict_columns:
318319
dtype, name, unit = data_columns[id]
319320
if name in names:
320-
logger.warning("Duplicate column '%s' with unit '%s'.", name, unit)
321+
logger.error(
322+
"Column ID %d is a duplicate of '%s' with unit '%s'. "
323+
"This is most certainly an error, please submit a bug report.",
324+
id,
325+
name,
326+
unit,
327+
)
321328
name = f"duplicate {name}"
322329
names.append(name)
323330
dtypes.append(dtype)
324331
units.append(unit)
332+
elif id in conflict_columns:
333+
for cid, cvals in conflict_columns[id].items():
334+
if cid in column_ids:
335+
dtype, name, unit = cvals
336+
names.append(name)
337+
dtypes.append(dtype)
338+
units.append(unit)
339+
logger.warning(
340+
"Ambiguous column ID %d assigned as '%s' with unit '%s'. "
341+
"Please check this assignment manually.",
342+
id,
343+
name,
344+
unit,
345+
)
346+
break
347+
else:
348+
dtype, name, unit = data_columns[id]
349+
if name in names:
350+
logger.error(
351+
"Column ID %d is duplicate of '%s' with unit '%s'. "
352+
"This is most certainly an error, please submit a bug report.",
353+
id,
354+
name,
355+
unit,
356+
)
357+
name = f"duplicate {name}"
358+
names.append(name)
359+
dtypes.append(dtype)
360+
units.append(unit)
325361
else:
326362
name = f"unknown_{len(names)}"
327-
logger.warning("Unknown column ID %d was assigned into '%s'.", id, name)
363+
logger.error(
364+
"Unknown column ID %d encountered and assigned into '%s'. "
365+
"This is an error, please submit a bug report.",
366+
id,
367+
name,
368+
)
328369
names.append(name)
329370
dtypes.append("<f4")
330371
units.append(None)

src/yadg/extractors/eclab/mpr_columns.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,13 @@
110110
169: ("<f4", "Cs", "µF"),
111111
172: ("<f4", "Cp", "µF"),
112112
173: ("<f4", "Cp⁻²", "µF⁻²"),
113-
174: ("<f4", "<Ewe>", "V"),
113+
174: ("<f4", "<Ewe>", "V"), # This column may conflict with ID 77.
114114
178: ("<f4", "(Q-Qo)", "C"),
115115
179: ("<f4", "dQ", "C"),
116116
182: ("<f8", "step time", "s"),
117117
185: ("<f4", "<Ece>", "V"),
118118
211: ("<f8", "Q charge or discharge", "C"),
119+
215: ("<f4", "<Ece>", "V"),
119120
217: ("<f4", "THD Ewe", "%"),
120121
241: ("<f4", "|E1|", "V"),
121122
242: ("<f4", "|E2|", "V"),
@@ -128,6 +129,7 @@
128129
326: ("<f4", "P", "W"),
129130
331: ("<f4", "Re(Z1)", "Ω"),
130131
332: ("<f4", "Re(Z2)", "Ω"),
132+
352: ("<f4", "|Ece|", "Ω"),
131133
361: ("<f4", "-Im(Z1)", "Ω"),
132134
362: ("<f4", "-Im(Z2)", "Ω"),
133135
368: ("<f8", "Energy we", "W·h"),
@@ -181,6 +183,13 @@
181183
981: ("<u4", "z cycle", None), # 981 % 512 = 469, also z cycle
182184
}
183185

186+
# Conflict resolution map. If both the outer and inner column ID are present,
187+
# the meaning of the outer column ID is set to the entry below.
188+
conflict_columns = {
189+
174: {
190+
77: ("<f4", "Phase(Zwe-ce)", "deg"),
191+
},
192+
}
184193

185194
# Relates the offset in log data to the corresponding dtype and name.
186195
# NOTE: The safety limits are maybe at 0x200?

src/yadg/extractors/eclab/mpt.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ def process_data(
245245
units = dict()
246246
columns = list()
247247
for n in names:
248+
if n.strip() == "":
249+
continue
248250
c, u = column_units[n.strip()]
249251
if c in columns:
250252
logger.warning("Duplicate column '%s' with unit '%s'.", c, u)

src/yadg/extractors/eclab/mpt_columns.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"<Ece>/V": ("<Ece>", "V"),
1414
"<Ewe>/V": ("<Ewe>", "V"),
1515
"<Ewe/V>": ("<Ewe>", "V"),
16+
"<Ewe-Ece>/V": ("<Ewe-Ece>", "V"),
1617
"<I>/mA": ("<I>", "mA"),
1718
"|C|/nF": ("|C|", "nF"),
1819
"|Conductivity|/mS/cm": ("|Conductivity|", "mS/cm"),

src/yadg/extractors/eclab/techniques.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1697,7 +1697,7 @@ def dev_derived(
16971697
elif unit in {"deg"}:
16981698
# VMP-3: using accuracy: 1 degree
16991699
return 1.0
1700-
elif unit in {"Ω", "S", "W"}:
1700+
elif unit in {"Ω", "S", "W", "Ω⁻¹"}:
17011701
# [Ω] = [V]/[A];
17021702
# [S] = [A]/[V];
17031703
# [W] = [A]*[V];

tests/test_x_eclab.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ def compare_params(left, right):
6969
("ocv", "en_US"),
7070
("ocv.issue_149", "de_DE"),
7171
("peis", "en_US"),
72+
("peis.issue_225.no_ece", "en_US"),
73+
("peis.issue_225.with_ece", "en_US"),
74+
("peis.issue_225.ewe_ece", "en_US"),
7275
("wait", "en_US"),
7376
("vsp_ocv_wo", "en_US"),
7477
("vsp_ocv_with", "en_US"),
@@ -88,7 +91,7 @@ def test_eclab_consistency(froot, locale, datadir):
8891
try:
8992
xr.testing.assert_allclose(aret[key], bret[key])
9093
except AssertionError as e:
91-
e.args = (e.args[0] + f"Error happened on key: {key!r}\n",)
94+
e.args = (e.args[0] + f"\nError happened on key: {key!r}\n",)
9295
raise e
9396
compare_params(aret, bret)
9497

@@ -111,7 +114,7 @@ def test_eclab_consistency_extract_mpr_bytes(froot, locale, datadir):
111114
try:
112115
xr.testing.assert_equal(aret[key], bret[key])
113116
except AssertionError as e:
114-
e.args = (e.args[0] + f"Error happened on key: {key!r}\n",)
117+
e.args = (e.args[0] + f"\nError happened on key: {key!r}\n",)
115118
raise e
116119
compare_params(aret, bret)
117120

@@ -149,7 +152,7 @@ def test_eclab_consistency_partial_1(froot, locale, datadir):
149152
try:
150153
xr.testing.assert_allclose(aret[key], bret[key])
151154
except AssertionError as e:
152-
e.args = (e.args[0] + f"Error happened on key: {key!r}\n",)
155+
e.args = (e.args[0] + f"\nError happened on key: {key!r}\n",)
153156
raise e
154157
compare_params(aret, bret)
155158

@@ -176,7 +179,7 @@ def test_eclab_consistency_partial_2(froot, locale, datadir):
176179
try:
177180
xr.testing.assert_allclose(aret[key], bret[key])
178181
except AssertionError as e:
179-
e.args = (e.args[0] + f"Error happened on key: {key!r}\n",)
182+
e.args = (e.args[0] + f"\nError happened on key: {key!r}\n",)
180183
raise e
181184
compare_params(aret, bret)
182185

@@ -217,5 +220,5 @@ def test_eclab_mpt_old(afile, bfile, datadir):
217220
if key in {"Efficiency", "Efficiency_std_err"}:
218221
pass
219222
else:
220-
e.args = (e.args[0] + f"Error happened on key: {key!r}\n",)
223+
e.args = (e.args[0] + f"\nError happened on key: {key!r}\n",)
221224
raise e
19.2 KB
Binary file not shown.
20 KB
Binary file not shown.

0 commit comments

Comments
 (0)