Skip to main content
Version: Next

ts_shape.events.engineering.control_loop_health

Classes
NameDescription
ControlLoopHealthEventsEngineering: Control Loop Health

ControlLoopHealthEvents​

classsource
ControlLoopHealthEvents(
dataframe: pd.DataFrame,
setpoint_uuid: str,
actual_uuid: str,
*,
output_uuid: str | None = None,
event_uuid: str = "eng:control_loop_health",
value_column: str = "value_double",
time_column: str = "systime"
) -> None

Bases: Base

Engineering: Control Loop Health

Continuously assess PID/control loop health from setpoint + actual pairs, independent of setpoint changes. Computes error integrals, detects oscillation in the error signal, and checks for valve saturation.

Methods:

  • error_integrals: Per-window IAE, ISE, ITAE, bias.
  • detect_oscillation: Sustained oscillation in the error signal.
  • output_saturation: Valve pegged at limits.
  • loop_health_summary: Shift-level report card.
Functions
NameDescription
error_integralsPer-window error integrals for control loop performance.
detect_oscillationDetect sustained oscillation in the error signal.
output_saturationDetect when controller output is pegged at limits.
loop_health_summaryShift-level report card combining all loop health metrics.
Parameters
NameTypeDescriptionDefault
dataframeDataFrameLong-format timeseries frame (one row per sample, uuid identifies the signal).required
setpoint_uuidstrUUID of the setpoint signal.required
actual_uuidstrUUID of the actual (process value) signal.required
output_uuidstr | NoneUUID of the controller output signal, used by :meth:output_saturation. None (default) when there is none.None
event_uuidstrUUID stamped on emitted events.'eng:control_loop_health'
value_columnstrNumeric column holding the signal values.'value_double'
time_columnstrTimestamp column.'systime'

error_integrals​

methodsource
error_integrals(
window: str = "1h", *, max_gap: str | None = None
) -> pd.DataFrame

Per-window error integrals for control loop performance.

The error e = PV - SP is piecewise constant between samples and integrated over time; a step that crosses a window boundary is split at the boundary, so every second between the first and the last sample is booked to the window it falls in (none is lost at window edges, and a window with no sample of its own still receives the time a held error covers in it).

  • IAE = integral |e| dt, ISE = integral e**2 dt.
  • ITAE = integral (t - window_start) * |e| dt: time is measured from the start of the window, and the integral is exact for the piecewise-constant error.
Parameters
NameTypeDescriptionDefault
windowstrResample window (e.g. '1h', '8h').'1h'
max_gapstr | NoneDefault None gives each error the time since the previous sample (the step (t[i-1], t[i]] carries e[i]), with no gap cap. When set, each error is held until the next sample (zero-order hold, the step [t[i], t[i+1]) carries e[i]) and any step longer than max_gap contributes nothing, so a communication gap is not integrated as one huge error. In both modes no time is integrated before the first or after the last sample.None
Returns
TypeDescription
DataFrameDataFrame with columns: start, end, duration_seconds, iae, ise,
DataFrameitae, bias, sample_count. end is start + window.
DataFramebias is the mean error of the samples in the window (NaN for
DataFramea window without samples) and sample_count their number.
DataFrameWindows that receive no integrated time are omitted.

detect_oscillation​

methodsource
detect_oscillation(
window: str = "5min", min_crossings: int = 4
) -> pd.DataFrame

Detect sustained oscillation in the error signal.

A zero-crossing is a change of the error's sign; a sample with zero (or NaN) error carries the last non-zero sign, so 1, 0, -1 is one crossing and touching zero (1, 0, 1) is none. A crossing is timed at the sample where the carried sign changes, and estimated_period_seconds is twice the mean time between consecutive crossings (0 with fewer than two).

Parameters
NameTypeDescriptionDefault
windowstrAnalysis window size.'5min'
min_crossingsintMinimum zero-crossings to flag oscillation.4
Returns
TypeDescription
DataFrameDataFrame with columns: start, end, duration_seconds, uuid,
DataFramesource_uuid (setpoint and actual uuids, comma-joined), is_delta,
DataFramecrossing_count, estimated_period_seconds, amplitude,
DataFramedamping_direction.

output_saturation​

methodsource
output_saturation(
upper_limit: float = 100.0, lower_limit: float = 0.0, window: str = "1h"
) -> pd.DataFrame

Detect when controller output is pegged at limits.

Requires output_uuid in constructor.

Parameters
NameTypeDescriptionDefault
upper_limitfloatUpper output limit, in the output signal's units. Samples within 1% of the upper_limit - lower_limit range of it count as saturated high. Default 100.0.100.0
lower_limitfloatLower output limit, in the output signal's units. Samples within 1% of the range of it count as saturated low. Default 0.0.0.0
windowstrResample window as a pandas offset string (e.g. '1h').'1h'

Shares and run lengths are measured in time, not samples: each output sample is held until the next one (zero-order hold, the module's interval_end="next_change" convention), steps are split at the window boundaries, and the time after the last sample is not observed (the last sample opens no step). A single saturated sample therefore counts for the time until the next sample.

Returns
TypeDescription
DataFrameDataFrame with columns: start, end, duration_seconds, uuid,
DataFramesource_uuid (the output uuid), pct_time_at_high, pct_time_at_low,
DataFramepct_time_saturated, longest_saturation_seconds. One row per
DataFramewindow that holds observed time; end is start +
DataFramewindow. The percentages are shares of the observed (held)
DataFrametime in the window; longest_saturation_seconds is the
DataFramelongest stretch of consecutive saturated time inside the window
DataFrame(a run that crosses a window boundary is cut there).
DataFrameCanonical twin columns: time_at_high_pct (after pct_time_at_high),
DataFrametime_at_low_pct (after pct_time_at_low), time_saturated_pct
DataFrame(after pct_time_saturated); each holds the same values as the deprecated
DataFramecolumn right before it, which is removed in the next major release.

loop_health_summary​

methodsource
loop_health_summary(
window: str = "8h", oscillation_window: str = "5min", min_crossings: int = 4
) -> pd.DataFrame

Shift-level report card combining all loop health metrics.

Oscillation is detected with :meth:detect_oscillation on short analysis windows of oscillation_window (not on the report window: a whole shift would almost always contain enough zero-crossings). oscillation_count is the number of merged oscillation episodes that start inside each report window.

Parameters
NameTypeDescriptionDefault
windowstrReport window as a pandas offset string (e.g. '8h' for a shift). Used for the error integrals, the saturation share and to bucket the oscillation episodes.'8h'
oscillation_windowstrAnalysis window passed to :meth:detect_oscillation (default '5min').'5min'
min_crossingsintMinimum zero-crossings per oscillation_window to flag oscillation, passed to :meth:detect_oscillation.4
Returns
TypeDescription
DataFrameDataFrame with columns: start, end, duration_seconds, iae, bias,
DataFrameoscillation_count, pct_saturated, health_grade. end is
DataFramestart + window.
DataFrameCanonical twin columns: saturated_pct (after pct_saturated); each
DataFrameholds the same values as the deprecated column right before it, which is
DataFrameremoved in the next major release.