ts_shape.events.development.golden_batch
Golden-batch deviation: compare new batch trajectories to a reference.
In batch process development a golden batch is a canonical run whose trajectory delivered the target product. Comparing later batches to that trajectory -- per timestep, per phase, or as a whole-trajectory shape distance -- is a workhorse diagnostic in pharma, food, and specialty chemicals.
This detector supports three comparison modes:
pointwise-- resample both batches to a common normalized batch time and report the maximum signed residual.area-- numerical integral of the absolute residual using the trapezoid rule. Captures cumulative deviation.dtw-- pure-numpy dynamic time warping distance with a Sakoe -Chiba band. Captures trajectory shape even when batches run at different paces. No external DTW library required.
| Name | Description |
|---|---|
GoldenBatchDeviationEvents | Quantify deviation of a new batch from a golden reference batch. |
GoldenBatchDeviationEvents
GoldenBatchDeviationEvents(
dataframe: pd.DataFrame,
signal_uuid: str,
*,
event_uuid: str = "dev:golden_batch_deviation",
value_column: str = "value_double",
time_column: str = "systime",
n_resample: int = 256
) -> None
Bases: Base
Quantify deviation of a new batch from a golden reference batch.
| Name | Description |
|---|---|
compare | Compare a single new batch to the stored golden reference. |
phase_breakdown | Per-phase deviation of a batch against the golden reference. |
| Name | Type | Description | Default |
|---|---|---|---|
dataframe | DataFrame | Long-format frame of the golden reference batch (formerly reference_df). | required |
signal_uuid | str | The signal compared between batches. | required |
event_uuid | str | UUID assigned to generated events. | 'dev:golden_batch_deviation' |
value_column | str | Column holding the signal value. | 'value_double' |
time_column | str | Timestamp column. | 'systime' |
n_resample | int | Points of the normalized batch-time grid both traces are resampled to (at least 4). | 256 |
| Type | Description |
|---|---|
ValueError | If n_resample is below 4 or the reference has no samples of signal_uuid. |
compare
compare(
batch_df: pd.DataFrame,
*,
mode: str = "pointwise",
dtw_band_frac: float = 0.1
) -> pd.DataFrame
Compare a single new batch to the stored golden reference.
| Name | Type | Description | Default |
|---|---|---|---|
batch_df | DataFrame | Long-form DataFrame containing the candidate batch's signal. The configured signal_uuid is used to extract the trace. | required |
mode | str | "pointwise", "area", or "dtw". | 'pointwise' |
dtw_band_frac | float | Sakoe-Chiba band width as a fraction of the resampled grid length. Only used for mode="dtw". | 0.1 |
| Type | Description |
|---|---|
DataFrame | Interval-shape DataFrame with one row, columns: start, |
DataFrame | end, duration_seconds, uuid, mode, |
DataFrame | deviation_score, max_abs_residual, |
DataFrame | batch_time_at_max. |
phase_breakdown
phase_breakdown(
batch_df: pd.DataFrame, phase_df: pd.DataFrame, *, phase_uuid: str
) -> pd.DataFrame
Per-phase deviation of a batch against the golden reference.
The reference batch is sliced into phases by the same boundaries
applied to the candidate batch, expressed in normalized batch time
(the same 0..1 axis compare uses): a phase spanning the fraction
[a, b] of the candidate batch (first to last candidate sample)
is compared against the fraction [a, b] of the golden batch.
Both slices are resampled to n_resample points. This assumes the
phase sequence and relative phase lengths are consistent across
runs, which is true for recipes that are executed phase-by-phase
under recipe control.
| Name | Type | Description | Default |
|---|---|---|---|
batch_df | DataFrame | Long-form signal DataFrame for the candidate batch. | required |
phase_df | DataFrame | Long-form DataFrame containing the phase-tracking signal, where value_string (or the configured value column) carries the phase name. | required |
phase_uuid | str | UUID of the phase signal in phase_df. | required |
| Type | Description |
|---|---|
DataFrame | Summary DataFrame: start, end, duration_seconds, |
DataFrame | phase, deviation_score, max_abs_residual. |