Skip to content

feat: renumber cycles for discharge-first full cells (cellpy#359 / Stage 5 S3) - #153

Merged
jepegit merged 3 commits into
mainfrom
cursor/359-discharge-first-cycles-061c
Oct 1, 2026
Merged

jepegit merged 3 commits into
mainfrom
cursor/359-discharge-first-cycles-061c

Conversation

@jepegit

@jepegit jepegit commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Stage 5 S3 — mirrors jepegit/cellpy#359 (labelled to core): full cells that start with a lone discharge get a cycler cycle counter that mis-pairs half-cycles ([D C D][C D]… or [D C][D C]…), so coulombic efficiency and curve extraction are wrong.

Changes

  • config.StepDirection (CHARGE / DISCHARGE) — the direction that opens a cycle. Kept separate from TestMode, which stays binary (polarity only).
  • summarizers.renumber_cycles(data, schema=None, opening=StepDirection.CHARGE, **step_table_kwargs) — opt-in post-processing step, exported top-level:
    • per test_id, a new cycle opens where an opening step follows the last non-neutral step of the other direction; the first step is never a boundary, so a leading lone discharge stays cycle 1; rest / IR / OCV steps attach to the current cycle;
    • raw cycle-cumulative capacity / energy columns are re-accumulated to the new boundaries via _reaccumulate_cumulative (body extracted from normalize_capacity_granularity, which now calls the same helper);
    • exact no-op (early return) when the counter already matches; otherwise the step table is rebuilt with make_step_table(**step_table_kwargs) and a stale summary is dropped;
    • ValueError for ustep step tables / duplicate (test_id, cycle, step) keys, NoDataFound without raw or steps.
  • Docs: standalone-use.md section, harmonized-raw.md cycle_num open question resolved, design note .issueflows/04-designs-and-guides/cycle-renumbering.md.
  • Default engine behaviour unchanged; golden / e2e fixtures untouched.

Tests

tests/test_renumber_cycles.py (14 tests): the three patterns from the issue against a plain-Python oracle, rest/CV attachment, anode mirror (opening=DISCHARGE), 0-based numbering preserved, energy columns, two test_ids renumbered independently, pandas in/out, summary drop, error paths, and the harmonized anode fixture ([D C]x17 [D]): byte-identical no-op with opening=DISCHARGE, regrouped as [D] + [C D]x17 with capacity conserved under opening=CHARGE.

Full suite: 303 passed; ruff check / ruff format --check clean.

[D] [C D] [C D]        -> [D] [C D] [C D]        opening=charge   (no-op)
[D C D] [C D] [C D]    -> [D] [C D] [C D] [C D]  opening=charge
[D C] [D C] [D C]      -> [D] [C D] [C D] [C]    opening=charge
[C D C] [D C]          -> [C] [D C] [D C]        opening=discharge

Notes

  • The cellpy/cellpy-core mirror issue could not be created from this environment (read-only token); the local tracking number 359 is provisional.
  • cellpy-side wiring (a cycle_mode variant mapping to TestMode.NORMAL + renumber_cycles) and the release note are follow-ups in jepegit/cellpy.
  • Changelog entry and version bump (minor) are left for /iflow-close.
Open in Web Open in Cursor 

cursoragent and others added 3 commits October 1, 2026 17:49
…ft plan

Co-authored-by: Jan Petter Maehlen <jepe@ife.no>
Opt-in post-processing step that renumbers cycle_num so every cycle opens
with a chosen StepDirection, re-accumulates the cycle-cumulative raw
capacity/energy columns to the new boundaries (shared helper extracted
from normalize_capacity_granularity), rebuilds the step table and drops a
stale summary. Mirrors jepegit/cellpy#359 (Stage 5 S3).

Co-authored-by: Jan Petter Maehlen <jepe@ife.no>
…n (#359)

Co-authored-by: Jan Petter Maehlen <jepe@ife.no>
@jepegit
jepegit marked this pull request as ready for review October 1, 2026 18:28
@jepegit
jepegit merged commit 0060898 into main Oct 1, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants