Skip to content

Stage 1.13: units — convert_value, calculate_scaler, validate_units #115

Description

@jepegit

Part of Stage 1 — behavior-preserving construction (see the Stage-1 tracking issue). Stage 0: jepegit/cellpy#439. Plan documents live in the shared workspace: cellpy-workspace/architecture-plan/ (the architecture-plan repo; formerly architecture-plan/) (alongside the cellpy and cellpy-core repos). Everything in Stage 1 lands on master with the full suite green; nothing flips user-visible behavior.

Goal

Three additive helpers in cellpycore.units (behind the existing units extra):

  • convert_value(value, physical_property, from_units=None, to_units=None) -> float —
    port of cellpy's to_cellpy_unit generalized (accepts number / pint-quantity string /
    (value, unit) tuple; defaults from raw→cellpy units).
  • calculate_scaler(from_unit, to_unit) -> float — port of unit_scaler_from_raw
    (Q(1, a).to(b).m).
  • validate_units(units) -> CellpyUnits — every label pint-parsable, warn on unknown
    keys; the loader-boundary validator (note the "C" Celsius-vs-Coulomb pitfall —
    decide degC handling here).

Why

cellpy Stage 1.6 deletes its duplicated converter bodies and needs these to wrap;
the loader port later calls validate_units on every configuration. Additions cross the
repos core-first (release + re-pin) per the merge-order rule.

Links (workspace)

  • architecture-plan/unit-handling-cellpy2-plan.md (Phase 2–3, §3 gap table, §7 risk 5)
  • architecture-plan/cellpy2-release-and-branching-plan.md (§3 merge order)

Acceptance

  • Unit tests incl. quantity-string and tuple inputs, bad-label failures, temperature
    handling documented; pint-optional guard still green (helpers raise only when called).
  • Tagged release cut so cellpy can re-pin (release-procedure.md).

Metadata

Metadata

Assignees

No one assigned

    Labels

    cellpy2-stage1cellpy 2 Stage 1: behavior-preserving constructionyoloAllow the agents to run in YOLO-mode

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions