Skip to main content
Version: 0.0.98

ts_shape.events.engineering.disturbance_recovery

Classes
NameDescription
DisturbanceRecoveryEventsEngineering: Disturbance / Upset Detection and Recovery

DisturbanceRecoveryEvents​

classsource
DisturbanceRecoveryEvents(
dataframe: pd.DataFrame,
signal_uuid: str,
*,
setpoint_uuid: str | None = None,
event_uuid: str = "eng:disturbance_recovery",
value_column: str = "value_double",
time_column: str = "systime"
) -> None

Bases: Base

Engineering: Disturbance / Upset Detection and Recovery

Detect external upsets hitting a process signal and measure how the process recovered. Works with a rolling baseline or an optional setpoint.

Methods:

  • detect_disturbances: Intervals where signal deviates from baseline.
  • recovery_time: How long until signal returns to normal after each upset.
  • disturbance_frequency: Count disturbances per shift/day.
  • before_after_comparison: Did the upset permanently change the process?
Functions
NameDescription
detect_disturbancesDetect intervals where signal deviates significantly from baseline.
recovery_timeMeasure recovery time after each disturbance.
disturbance_frequencyCount disturbances per time window.
before_after_comparisonCompare process statistics before vs after each disturbance.
Parameters
NameTypeDescriptionDefault
dataframeDataFrameLong-format timeseries frame (one row per sample, uuid identifies the signal).required
signal_uuidstrUUID of the process signal to monitor.required
setpoint_uuidstr | NoneUUID of a setpoint signal used as the baseline. None (default) uses a rolling baseline.None
event_uuidstrUUID stamped on emitted events.'eng:disturbance_recovery'
value_columnstrColumn holding the signal values.'value_double'
time_columnstrTimestamp column.'systime'

detect_disturbances​

methodsource
detect_disturbances(
baseline_window: str = "10min",
n_sigma: float = 3.0,
min_duration: str = "30s",
) -> pd.DataFrame

Detect intervals where signal deviates significantly from baseline.

Parameters
NameTypeDescriptionDefault
baseline_windowstrWindow for rolling baseline computation.'10min'
n_sigmafloatDeviation threshold in multiples of rolling std.3.0
min_durationstrMinimum disturbance duration.'30s'
Returns
TypeDescription
DataFrameDataFrame with columns: start, end, duration_seconds, uuid,
DataFramesource_uuid, is_delta, peak_deviation, mean_deviation, direction,
DataFramedisturbance_type.

recovery_time​

methodsource
recovery_time(
baseline_window: str = "10min",
n_sigma: float = 3.0,
recovery_pct: float = 0.95,
max_recovery: str = "1h",
) -> pd.DataFrame

Measure recovery time after each disturbance.

Parameters
NameTypeDescriptionDefault
baseline_windowstrWindow for the rolling baseline and rolling std (pandas offset string). Ignored for the baseline when a setpoint_uuid was given; the setpoint is used instead.'10min'
n_sigmafloatDeviation threshold in multiples of the rolling std.3.0
recovery_pctfloatSignal must return to within (1 - recovery_pct) of peak deviation to be considered recovered.0.95
max_recoverystrMaximum time to look for recovery.'1h'
Returns
TypeDescription
DataFrameDataFrame with columns: start, end, duration_seconds (of the
DataFramedisturbance), uuid, source_uuid, recovery_time_seconds, recovered,
DataFramepre_disturbance_mean, post_recovery_mean, residual_offset.

disturbance_frequency​

methodsource
disturbance_frequency(
window: str = "8h", baseline_window: str = "10min", n_sigma: float = 3.0
) -> pd.DataFrame

Count disturbances per time window.

Parameters
NameTypeDescriptionDefault
windowstrCounting window as a pandas offset string (e.g. '8h' per shift, '1D' per day).'8h'
baseline_windowstrWindow for the rolling baseline and rolling std used by :meth:detect_disturbances.'10min'
n_sigmafloatDeviation threshold in multiples of the rolling std.3.0
Returns
TypeDescription
DataFrameDataFrame with columns: start, end, duration_seconds,
DataFramedisturbance_count, total_disturbance_seconds, pct_time_disturbed,
DataFrameavg_recovery_seconds. end is start + window.
DataFrameCanonical twin columns: time_disturbed_pct (after
DataFramepct_time_disturbed); each holds the same values as the deprecated column
DataFrameright before it, which is removed in the next major release.

before_after_comparison​

methodsource
before_after_comparison(
baseline_window: str = "10min",
n_sigma: float = 3.0,
comparison_window: str = "5min",
) -> pd.DataFrame

Compare process statistics before vs after each disturbance.

Parameters
NameTypeDescriptionDefault
baseline_windowstrWindow for the rolling baseline and rolling std used by :meth:detect_disturbances.'10min'
n_sigmafloatDeviation threshold in multiples of the rolling std.3.0
comparison_windowstrLength of the span compared just before the disturbance start and just after its end. Disturbances with fewer than two samples on either side are skipped.'5min'
Returns
TypeDescription
DataFrameDataFrame with columns: start, end, duration_seconds, uuid,
DataFramesource_uuid, pre_mean, post_mean, pre_std, post_std, mean_shift,
DataFramevariance_ratio, variance_factor (post_std / pre_std; NaN when
DataFramepre_std is 0, never inf). start / end are the
DataFramedisturbance bounds.
DataFrameCanonical twin columns: variance_factor (after
DataFramevariance_ratio, which is not a 0-1 fraction); it holds the
DataFramesame values as the deprecated column right before it, which is
DataFrameremoved in the next major release.