Skip to main content
Version: Next

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.
Classes
NameDescription
GoldenBatchDeviationEventsQuantify deviation of a new batch from a golden reference batch.

GoldenBatchDeviationEvents​

classsource
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.

Functions
NameDescription
compareCompare a single new batch to the stored golden reference.
phase_breakdownPer-phase deviation of a batch against the golden reference.
Parameters
NameTypeDescriptionDefault
dataframeDataFrameLong-format frame of the golden reference batch (formerly reference_df).required
signal_uuidstrThe signal compared between batches.required
event_uuidstrUUID assigned to generated events.'dev:golden_batch_deviation'
value_columnstrColumn holding the signal value.'value_double'
time_columnstrTimestamp column.'systime'
n_resampleintPoints of the normalized batch-time grid both traces are resampled to (at least 4).256
Raises
TypeDescription
ValueErrorIf n_resample is below 4 or the reference has no samples of signal_uuid.

compare​

methodsource
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.

Parameters
NameTypeDescriptionDefault
batch_dfDataFrameLong-form DataFrame containing the candidate batch's signal. The configured signal_uuid is used to extract the trace.required
modestr"pointwise", "area", or "dtw".'pointwise'
dtw_band_fracfloatSakoe-Chiba band width as a fraction of the resampled grid length. Only used for mode="dtw".0.1
Returns
TypeDescription
DataFrameInterval-shape DataFrame with one row, columns: start,
DataFrameend, duration_seconds, uuid, mode,
DataFramedeviation_score, max_abs_residual,
DataFramebatch_time_at_max.

phase_breakdown​

methodsource
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.

Parameters
NameTypeDescriptionDefault
batch_dfDataFrameLong-form signal DataFrame for the candidate batch.required
phase_dfDataFrameLong-form DataFrame containing the phase-tracking signal, where value_string (or the configured value column) carries the phase name.required
phase_uuidstrUUID of the phase signal in phase_df.required
Returns
TypeDescription
DataFrameSummary DataFrame: start, end, duration_seconds,
DataFramephase, deviation_score, max_abs_residual.