Skip to content

recipe_phase_adherence

recipe_phase_adherence ¤

Recipe-phase adherence: check each batch phase against a spec.

Batch processes execute a sequence of named phases (heat-up, hold, cool-down, ...). Each phase has a development-defined spec: an expected duration window, a hold-value window, a maximum ramp rate, sometimes a peak ceiling. This detector iterates the phase intervals in a batch and emits one event per phase carrying pass/fail plus which criterion failed.

The spec format is intentionally a plain dict so it can be authored by a process engineer (or loaded from YAML/JSON) without inventing a new schema class -- see :meth:evaluate for the recognized keys.

RecipePhaseAdherenceEvents ¤

RecipePhaseAdherenceEvents(
    dataframe: DataFrame,
    phase_uuid: str,
    value_uuid: str,
    spec: dict[str, dict[str, Any]],
    *,
    event_uuid: str = "dev:recipe_phase_adherence",
    value_column: str = "value_double",
    time_column: str = "systime"
)

Bases: Base

Evaluate batch recipe phases against a declarative spec.

The spec is a mapping {phase_name: criteria_dict}. Recognized criteria keys (all optional) per phase:

  • duration_seconds -- (min, max) seconds. duration_s is the deprecated spelling of the same criterion: it still works, with a DeprecationWarning, until the next major release (giving both for one phase raises ValueError); criteria_failed names the key the spec used.
  • hold_value -- (min, max) for the mean value during the phase.
  • ramp_rate_max -- maximum absolute slope (value-units per second) computed from the first to the last sample.
  • peak_value -- (min, max) for the phase max.
  • trough_value -- (min, max) for the phase min.

Missing criteria are not checked. A phase whose name is absent from the spec is reported with pass=True and an empty criteria_failed list (the phase was observed but not constrained).

evaluate ¤

evaluate(
    *,
    interval_end: str = "next_change",
    data_end: Timestamp | None = None
) -> pd.DataFrame

Evaluate every observed phase interval against the spec.

Parameters:

Name Type Description Default
interval_end str

How each phase interval is closed. "next_change" (default) closes a phase at the next phase change; value samples are taken from [start, end) (the sample at the transition belongs to the next phase), and the final phase is closed at data_end when given, otherwise at its own last sample. "last_sample" spans the first to the last phase-signal sample carrying the phase; on a change-encoded (is_delta) phase signal, which logs one row per transition, every phase is then zero-length.

'next_change'
data_end Timestamp | None

Optional bound for the final phase when interval_end="next_change" (e.g. the batch end).

None

Returns:

Name Type Description
DataFrame

Interval-shape DataFrame, one row per phase occurrence,

columns DataFrame

start, end, duration_seconds, uuid,

DataFrame

phase, mean_value, min_value, max_value,

DataFrame

observed_ramp_per_s, criteria_failed (list[str]),

DataFrame

pass.