jepegit / cellpy

extract and tweak data from electrochemical tests of cells
MIT License
88 stars 30 forks source link

Weight mean-values in steps-table based on time and capacity #314

Open morrowrasmus opened 4 months ago

morrowrasmus commented 4 months ago

Is your feature request related to a problem? Please describe. My current understanding of the make_step_table()-method is that the mean values are simple, arithmetic means. This is fine when all datapoints are equally spaced, but since cyclers typically record data at either a $\Delta V$ or $\Delta t$ threshold, this is seldom the case. A simple arithmetic mean will give too much weight to closely spaced datapoints. As an example, the mean potential of a discharge cycle with an intial steep slope followed by gradually decreasing potential would have a higher data point density in the beginning of the discharge, and the arithmetic mean would overestimate the mean potential of the discharge step.

This will have an impact on the standard deviation calculations as well.

Describe the solution you'd like The current implementation is:

by = [shdr.cycle, shdr.step, shdr.sub_step]

gf = df.groupby(by=by)

df_steps = gf.agg(["mean", "std", "min", "max", "first", "last", delta]).rename(
    columns={"amin": "min", "amax": "max", "mean": "avr"}
)

Here "mean" should either be replaced with, or there should be added a couple of custom functions (like delta in the above example) that calculates the time-weighted and the capacity-weighted means.

"std" would also need to be modified.

jepegit commented 4 months ago

@morrowrasmus; if you could start on this, that would be great. I can check how changing the step-table influences loading older cellpy files (could potentially be some conflicts) and update the necessary part if needed.