Skip to main content
Version: 0.0.98

ts_shape.events.engineering.startup_events

Classes
NameDescription
StartupDetectionEventsDetect equipment startup intervals based on threshold crossings or

StartupDetectionEvents​

classsource
StartupDetectionEvents(
dataframe: pd.DataFrame,
target_uuid: str,
*,
event_uuid: str = "eng:startup",
value_column: str = "value_double",
time_column: str = "systime"
) -> None

Bases: Base

Detect equipment startup intervals based on threshold crossings or sustained positive slope in a numeric metric (speed, temperature, etc.).

Schema assumptions (columns):

  • uuid, sequence_number, systime, plctime, is_delta
  • value_integer, value_string, value_double, value_bool, value_bytes
Functions
NameDescription
detect_startup_by_thresholdStartup begins at first crossing above threshold (or hysteresis enter)
detect_startup_by_slopeStartup intervals where per-second slope >= min_slope for at least
detect_startup_multi_signalDetect startups based on multiple signals with configurable AND/OR logic.
detect_startup_adaptiveDetect startups using adaptive thresholds calculated from historical baseline data.
assess_startup_qualityAssess the quality of detected startup events.
track_startup_phasesTrack progression through defined startup phases.
detect_failed_startupsDetect failed or aborted startup attempts.
Parameters
NameTypeDescriptionDefault
dataframeDataFrameLong-format timeseries frame (one row per sample, uuid identifies the signal).required
target_uuidstrUUID of the metric (speed, temperature, ...) startups are detected on; must be present in dataframe.required
event_uuidstrUUID stamped on emitted events.'eng:startup'
value_columnstrColumn holding the signal values.'value_double'
time_columnstrTimestamp column.'systime'

detect_startup_by_threshold​

methodsource
detect_startup_by_threshold(
*,
threshold: float,
hysteresis: tuple[float, float] | None = None,
min_above: str = "0s"
) -> pd.DataFrame

Startup begins at first crossing above threshold (or hysteresis enter) and is valid only if the metric stays above the (exit) threshold for at least min_above.

Parameters
NameTypeDescriptionDefault
thresholdfloatLevel in signal units; a startup starts where the signal rises to or above it. Reported in the threshold column.required
hysteresistuple[float, float] | NoneOptional (enter, exit) pair that replaces threshold: the rising edge is detected against enter and the dwell is checked against exit. None uses threshold for both.None
min_abovestrMinimum time the signal must stay at or above the exit level after the crossing (pandas offset string). It also sets end (start + min_above). Default "0s".'0s'
Returns
TypeDescription
DataFrameDataFrame with columns: start, end, duration_seconds, uuid,
DataFramesource_uuid, is_delta, method, threshold.

detect_startup_by_slope​

methodsource
detect_startup_by_slope(
*, min_slope: float, slope_window: str = "0s", min_duration: str = "0s"
) -> pd.DataFrame

Startup intervals where per-second slope >= min_slope for at least min_duration.

With the default slope_window="0s" the slope is the instantaneous slope between consecutive samples. With a positive slope_window the slope at each sample is taken over a trailing window: the change from the latest sample at or before t - slope_window to the current sample, divided by the actual elapsed seconds. Samples with no sample that far back get no slope. A longer window smooths noise.

The slope at a sample describes the step from its reference sample (the previous sample, or the one slope_window back) to it, so an interval starts at the reference sample of its first ramping sample -- the sample before the first fast step with the default slope_window -- and ends at its last ramping sample. A single fast step from t[i-1] to t[i] lasts t[i] - t[i-1].

Parameters
NameTypeDescriptionDefault
min_slopefloatMinimum slope in signal units per second.required
slope_windowstrTrailing window for the slope as a pandas offset string (default '0s': between consecutive samples).'0s'
min_durationstrMinimum duration (pandas offset string) of a contiguous run of samples at or above min_slope, measured from the run's start to its end.'0s'
Returns
TypeDescription
DataFrameDataFrame with columns: start, end, duration_seconds, uuid,
DataFramesource_uuid, is_delta, method, min_slope, avg_slope.

detect_startup_multi_signal​

methodsource
detect_startup_multi_signal(
signals: dict[str, dict[str, Any]],
logic: str = "all",
*,
time_tolerance: str = "30s"
) -> pd.DataFrame

Detect startups based on multiple signals with configurable AND/OR logic.

Parameters
NameTypeDescriptionDefault
signalsdict[str, dict[str, Any]]Dict mapping uuid to detection config. Each config should contain: - 'method': 'threshold' or 'slope' - For threshold: 'threshold', optional 'hysteresis', 'min_above' - For slope: 'min_slope', optional 'slope_window', 'min_duration'required
logicstr'all' (AND - all signals must detect) or 'any' (OR - at least one)'all'
time_tolerancestrMaximum time difference between signals for 'all' logic'30s'
Returns
TypeDescription
DataFrameDataFrame with columns: start, end, uuid, is_delta, method, signals_triggered, signal_details

detect_startup_adaptive​

methodsource
detect_startup_adaptive(
*,
baseline_window: str | None = None,
sensitivity: float = 2.0,
min_above: str = "10s",
lookback_periods: int = 5
) -> pd.DataFrame

Detect startups using adaptive thresholds calculated from historical baseline data.

The baseline (mean and std) is computed from samples before each point, so a rising value does not raise its own threshold.

Parameters
NameTypeDescriptionDefault
baseline_windowstr | NoneTime span of preceding samples for the baseline (e.g. '1h'). Default None uses the last lookback_periods samples instead. (This parameter used to default to '1h' but was ignored.)None
sensitivityfloatMultiplier for standard deviation (threshold = mean + sensitivity * std)2.0
min_abovestrMinimum time the value must stay above threshold'10s'
lookback_periodsintNumber of preceding samples for the baseline when baseline_window is None5
Returns
TypeDescription
DataFrameDataFrame with columns: start, end, duration_seconds, uuid,
DataFramesource_uuid, is_delta, method, adaptive_threshold, baseline_mean,
DataFramebaseline_std

assess_startup_quality​

methodsource
assess_startup_quality(
startup_events: pd.DataFrame,
*,
smoothness_window: int = 5,
anomaly_threshold: float = 3.0
) -> pd.DataFrame

Assess the quality of detected startup events.

Parameters
NameTypeDescriptionDefault
startup_eventsDataFrameDataFrame of detected startup events (must have 'start' and 'end' columns)required
smoothness_windowintWindow size for calculating smoothness metrics5
anomaly_thresholdfloatZ-score threshold for detecting anomalies3.0
Returns
TypeDescription
DataFrameDataFrame with quality metrics for each startup: - duration: Total duration of startup - smoothness_score: Inverse of derivative variance (higher = smoother) - anomaly_flags: Number of anomalous points detected - value_change: Total change in value during startup - avg_rate: Average rate of change - max_value: Maximum value reached - stability_score: 1 / (1 + CV) of the values in the final 20% of the startup (at least its last two samples); 1.0 is perfectly flat. NaN when the startup holds fewer than two samples; 0.0 when the final mean is 0 (CV undefined).

track_startup_phases​

methodsource
track_startup_phases(
phases: list[dict[str, Any]], *, min_phase_duration: str = "5s"
) -> pd.DataFrame

Track progression through defined startup phases.

Parameters
NameTypeDescriptionDefault
phaseslist[dict[str, Any]]List of phase definitions, each containing: - 'name': Phase name - 'condition': 'threshold', 'range', or 'slope' - For 'threshold': 'min_value' (value must be >= min_value) - For 'range': 'min_value' and 'max_value' (value in range) - For 'slope': 'min_slope' (slope must be >= min_slope)required
min_phase_durationstrMinimum time to stay in phase to be considered valid'5s'
Returns
TypeDescription
DataFrameDataFrame with phase transitions: - phase_name: Name of the phase - phase_number: Sequential phase number (0-indexed) - start: Phase start time - end: Phase end time - duration: Time spent in phase - next_phase: Name of the next phase (None for last phase) - completed: Whether full startup sequence completed

detect_failed_startups​

methodsource
detect_failed_startups(
*,
threshold: float,
min_rise_duration: str = "5s",
max_completion_time: str = "5min",
completion_threshold: float | None = None,
required_stability: str = "10s"
) -> pd.DataFrame

Detect failed or aborted startup attempts.

A failed startup is identified when:

  1. Value rises above threshold for at least min_rise_duration
  2. But fails to reach completion_threshold within max_completion_time
  3. Or drops back below threshold before achieving required_stability
Parameters
NameTypeDescriptionDefault
thresholdfloatInitial threshold that must be crossed to begin startuprequired
min_rise_durationstrMinimum time above threshold to consider it a startup attempt'5s'
max_completion_timestrMaximum time allowed to complete startup'5min'
completion_thresholdfloat | NoneTarget threshold for successful completion (default: 2x threshold)None
required_stabilitystrTime that must be maintained at completion level'10s'
Returns
TypeDescription
DataFrameDataFrame with columns: systime (= start, the startup attempt),
DataFrameuuid, source_uuid, start, end, is_delta, method, failure_reason,
DataFramemax_value_reached, time_to_failure