Skip to main content
Version: Next

ts_shape.events.profiling.curves

Mapping-free curve signatures: recurring fault shapes of analog curves.

:class:CurveSignatureEvents reads every analog signal of one PLC over each cycle of its cycle profile and learns, per product variant:

  1. the golden curve: per point of a fixed grid over the variant's best demonstrated cycle (P10), the median of the normal cycles and their P10..P90 band;
  2. per cycle, its deviation: the residual against the golden curve in robust units (median absolute deviation per point), its mean as the deviation_score, the phase of the cycle where it deviates most (the segment of the standard view, from → to) and the direction (high / low);
  3. fault patterns: the residuals of the anomalous cycles are clustered (hierarchical, average linkage); a cluster of at least :data:PATTERN_MIN_CYCLES cycles is a recurring fault shape, named after its signal, direction and phase, and linked to the cycles' classes and the time they lost.
Classes
NameDescription
CurveSignatureEventsGolden curves, per-cycle deviations and recurring fault shapes.

CurveSignatureEvents​

classsource
CurveSignatureEvents(
dataframe: pd.DataFrame,
*,
cycle_profile: CycleProfileEvents | None = None,
signal_uuids: list[str] | None = None,
n_sigma: float = 3.0,
min_cycles: int = 30,
max_signals: int = 20,
time_column: str = "systime",
uuid_column: str = "uuid",
event_uuid: str = "prod:curve_signature",
**cycle_options: Any
) -> None

Bases: _UnitProfiler

Golden curves, per-cycle deviations and recurring fault shapes.

Example
>>> import ts_shape
>>> frame, truth = ts_shape.make_plc_cycles(
... n_cycles=400, seed=5, curve_faults={"spike_in_hold": 0.05})
>>> curves = ts_shape.CurveSignatureEvents(frame)
>>> "plc:pressure" in set(curves.curve_golden()["signal"])
True
Functions
NameDescription
curve_goldenThe golden curve of every variant and analog signal.
curve_cycle_scoresHow far every cycle's curve leaves the golden curve.
curve_patternsThe recurring fault shapes, ranked by the time they cost.
evaluation_windowWhether each variant and signal can be trusted, and why not.
summaryHeadline numbers (JSON-able).
Parameters
NameTypeDescriptionDefault
dataframeDataFrameLong-format signals of one PLC.required
cycle_profileCycleProfileEvents | NoneA computed cycle profile of the same signals to reuse; None (default) builds one.None
signal_uuidslist[str] | NoneSignals to use (default: all).None
n_sigmafloatA cycle whose deviation score is this many robust sigmas above the median score (and at least twice it) is anomalous.3.0
min_cyclesintA variant and signal with fewer normal cycles is not evaluable.30
max_signalsintAt most this many analog signals (the most sampled).20
time_columnstrTimestamp column.'systime'
uuid_columnstrSignal column.'uuid'
event_uuidstruuid of the cycle score records.'prod:curve_signature'
**cycle_optionsAnyOptions of the cycle profile built when cycle_profile is None.{}

curve_golden​

methodsource
curve_golden() -> pd.DataFrame

The golden curve of every variant and analog signal.

Returns
TypeDescription
DataFrameOne row per variant, signal and grid point: variant,
DataFramesignal, offset_seconds (from the cycle start), phase
DataFrame(segment of the standard view), p10, median, p90.

curve_cycle_scores​

methodsource
curve_cycle_scores() -> pd.DataFrame

How far every cycle's curve leaves the golden curve.

Returns
TypeDescription
DataFramePoint events at the cycle end: systime, uuid,
DataFramesource_uuid (the signal), cycle_uuid, variant,
DataFramecycle_class, duration_seconds, deviation_score (mean
DataFrame
DataFramepercentile), is_anomaly,
DataFramedeviating_phase, direction, pattern_id (-1
DataFramewhen the cycle belongs to no recurring pattern) and
DataFrameafter_restart (part of a warm-up: a run of off-band cycles
DataFramebeginning right after a pause or variant change; left out of the
DataFramepatterns).

curve_patterns​

methodsource
curve_patterns() -> pd.DataFrame

The recurring fault shapes, ranked by the time they cost.

Returns
TypeDescription
DataFrameOne row per pattern: pattern_id, pattern (``":
DataFrame in "), variant`` (the variants it was
DataFrameseen in; patterns are clustered per signal over all variants),
DataFramesignal,
DataFramecycle_count, long_share_ratio (share of its cycles that
DataFrameare long), lost_seconds (cycle time beyond the variant's
DataFramemedian, summed), median_deviation_score and
DataFramepotential_rank. Warm-up cycles (after_restart) are not
DataFrameclustered.

evaluation_window​

methodsource
evaluation_window() -> pd.DataFrame

Whether each variant and signal can be trusted, and why not.

Returns
TypeDescription
DataFrameOne row per variant and analog signal (scope =
DataFrame``"
DataFrameevaluable, reason (below_resolution with fewer than
DataFramedata:CURVE_MIN_SAMPLES readings per cycle), variant and
DataFramesignal; one all row without analog signals or cycles.

summary​

methodsource
summary() -> dict[str, Any]

Headline numbers (JSON-able).

Returns
TypeDescription
dict[str, Any]evaluable (any variant and signal), reason,
dict[str, Any]anomalous_cycle_count (in-run cycles off the band),
dict[str, Any]warmup_cycle_count (off the band right after a restart),
dict[str, Any]pattern_count and top_pattern.