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:
- 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;
- 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); - fault patterns: the residuals of the anomalous cycles are clustered
(hierarchical, average linkage); a cluster of at least
:data:
PATTERN_MIN_CYCLEScycles is a recurring fault shape, named after its signal, direction and phase, and linked to the cycles' classes and the time they lost.
Classes
| Name | Description |
|---|---|
CurveSignatureEvents | Golden curves, per-cycle deviations and recurring fault shapes. |
CurveSignatureEvents
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
| Name | Description |
|---|---|
curve_golden | The golden curve of every variant and analog signal. |
curve_cycle_scores | How far every cycle's curve leaves the golden curve. |
curve_patterns | The recurring fault shapes, ranked by the time they cost. |
evaluation_window | Whether each variant and signal can be trusted, and why not. |
summary | Headline numbers (JSON-able). |
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
dataframe | DataFrame | Long-format signals of one PLC. | required |
cycle_profile | CycleProfileEvents | None | A computed cycle profile of the same signals to reuse; None (default) builds one. | None |
signal_uuids | list[str] | None | Signals to use (default: all). | None |
n_sigma | float | A cycle whose deviation score is this many robust sigmas above the median score (and at least twice it) is anomalous. | 3.0 |
min_cycles | int | A variant and signal with fewer normal cycles is not evaluable. | 30 |
max_signals | int | At most this many analog signals (the most sampled). | 20 |
time_column | str | Timestamp column. | 'systime' |
uuid_column | str | Signal column. | 'uuid' |
event_uuid | str | uuid of the cycle score records. | 'prod:curve_signature' |
**cycle_options | Any | Options of the cycle profile built when cycle_profile is None. | {} |
curve_golden
curve_golden() -> pd.DataFrame
The golden curve of every variant and analog signal.
Returns
| Type | Description |
|---|---|
DataFrame | One row per variant, signal and grid point: variant, |
DataFrame | signal, offset_seconds (from the cycle start), phase |
DataFrame | (segment of the standard view), p10, median, p90. |
curve_cycle_scores
curve_cycle_scores() -> pd.DataFrame
How far every cycle's curve leaves the golden curve.
Returns
| Type | Description |
|---|---|
DataFrame | Point events at the cycle end: systime, uuid, |
DataFrame | source_uuid (the signal), cycle_uuid, variant, |
DataFrame | cycle_class, duration_seconds, deviation_score (mean |
DataFrame | |
DataFrame | percentile), is_anomaly, |
DataFrame | deviating_phase, direction, pattern_id (-1 |
DataFrame | when the cycle belongs to no recurring pattern) and |
DataFrame | after_restart (part of a warm-up: a run of off-band cycles |
DataFrame | beginning right after a pause or variant change; left out of the |
DataFrame | patterns). |
curve_patterns
curve_patterns() -> pd.DataFrame
The recurring fault shapes, ranked by the time they cost.
Returns
| Type | Description |
|---|---|
DataFrame | One row per pattern: pattern_id, pattern (``" |
DataFrame | ), variant`` (the variants it was |
DataFrame | seen in; patterns are clustered per signal over all variants), |
DataFrame | signal, |
DataFrame | cycle_count, long_share_ratio (share of its cycles that |
DataFrame | are long), lost_seconds (cycle time beyond the variant's |
DataFrame | median, summed), median_deviation_score and |
DataFrame | potential_rank. Warm-up cycles (after_restart) are not |
DataFrame | clustered. |
evaluation_window
evaluation_window() -> pd.DataFrame
Whether each variant and signal can be trusted, and why not.
Returns
| Type | Description |
|---|---|
DataFrame | One row per variant and analog signal (scope = |
DataFrame | ``" |
DataFrame | evaluable, reason (below_resolution with fewer than |
DataFrame | data:CURVE_MIN_SAMPLES readings per cycle), variant and |
DataFrame | signal; one all row without analog signals or cycles. |
summary
summary() -> dict[str, Any]
Headline numbers (JSON-able).
Returns
| Type | Description |
|---|---|
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. |