ts_shape.events.profiling.control_loops
Mapping-free control-loop profiler: find the loops, rank their health.
:class:ControlLoopProfileEvents needs no machine cycle and no names. It
reads the numeric signals of one controller and:
- finds setpoints: signals that hold their value for minutes between steps (judged on their own readings, so polled and on-change logging both work);
- pairs each setpoint with the continuous signal that follows its steps (moves in the step's direction by a good part of it) and tracks it the rest of the time; the pairing is one-to-one, best score first;
- finds the output (optional): the continuous signal that moves at once
(within
KICK_SAMPLESgrid samples) and consistently with the setpoint steps -- the controller's reaction; a signal that reacts at once is never taken for the process value, which reacts only after its dead time; - measures every loop with
:class:
~ts_shape.events.engineering.setpoint_events.SetpointChangeEvents(settling, rise, overshoot, oscillation per step) and :class:~ts_shape.events.engineering.control_loop_health.ControlLoopHealthEvents(IAE, output saturation); - diagnoses
oscillating(overshoot and repeated crossings, or a settling loop that overshoots by 30 % and more),sluggish(most steps do not settle in time) orok, and ranks the loops by a health score (mean percentile rank of the badness metrics).
A loop with fewer than min_steps steps gets steady-state metrics only
(too_few_units).
Classes
| Name | Description |
|---|---|
ControlLoopProfileEvents | Find the control loops among the signals and rank their health. |
ControlLoopProfileEvents
ControlLoopProfileEvents(
dataframe: pd.DataFrame,
*,
signal_uuids: list[str] | None = None,
min_steps: int = 5,
settle_pct: float = 0.1,
time_column: str = "systime",
uuid_column: str = "uuid",
value_column: str = "value_double",
event_uuid: str = "eng:control_loop_profile"
) -> None
Bases: _ProfilerBase
Find the control loops among the signals and rank their health.
Example
>>> import ts_shape
>>> frame, truth = ts_shape.make_control_loops(seed=1)
>>> loops = ts_shape.ControlLoopProfileEvents(frame).loop_register()
>>> dict(zip(loops["setpoint_uuid"], loops["diagnosis"]))["plc:tic102_sp"]
'oscillating'
Functions
| Name | Description |
|---|---|
loop_pairs | The control loops found among the signals. |
loop_steps | Response metrics of every setpoint step of every loop. |
loop_register | Health of every loop, worst first. |
evaluation_window | Whether each loop's metrics can be trusted, and why not. |
summary | Headline numbers (JSON-able). |
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
dataframe | DataFrame | Long-format signals of one controller or PLC. | required |
signal_uuids | list[str] | None | Signals to use (default: all numeric ones). | None |
min_steps | int | Setpoint steps a loop needs for step metrics. | 5 |
settle_pct | float | Settling band as a share of each step. | 0.1 |
time_column | str | Timestamp column. | 'systime' |
uuid_column | str | Signal column. | 'uuid' |
value_column | str | Numeric value column. | 'value_double' |
event_uuid | str | uuid of the step records. | 'eng:control_loop_profile' |
loop_pairs
loop_pairs() -> pd.DataFrame
The control loops found among the signals.
Returns
| Type | Description |
|---|---|
DataFrame | One row per loop: setpoint_uuid, actual_uuid, |
DataFrame | output_uuid (None when no output reacts), step_count, |
DataFrame | step_follow_ratio, tracking_ratio, pair_score and |
DataFrame | output_consistency_ratio. |
loop_steps
loop_steps() -> pd.DataFrame
Response metrics of every setpoint step of every loop.
Returns
| Type | Description |
|---|---|
DataFrame | One row per step (loops with at least min_steps steps): |
DataFrame | loop plus the columns of |
DataFrame | meth:`SetpointChangeEvents.control_quality_metrics |
DataFrame | <ts_shape.events.engineering.setpoint_events.SetpointChangeEvents.control_quality_metrics>`. |
loop_register
loop_register() -> pd.DataFrame
Health of every loop, worst first.
Returns
| Type | Description |
|---|---|
DataFrame | One row per loop: loop, setpoint_uuid, actual_uuid, |
DataFrame | output_uuid, step_count, settled_share_ratio, |
DataFrame | median_settle_seconds, median_overshoot_pct, |
DataFrame | median_oscillation_count, iae_per_hour_spans (IAE per |
DataFrame | hour in setpoint spans), tracking_ratio, |
DataFrame | saturated_share_ratio, mean_abs_error, diagnosis |
DataFrame | (oscillating / sluggish / ok / unknown), |
DataFrame | health_score (0 worst .. 1 best) and health_rank |
DataFrame | (1 = worst). |
evaluation_window
evaluation_window() -> pd.DataFrame
Whether each loop's metrics can be trusted, and why not.
Returns
| Type | Description |
|---|---|
DataFrame | One row per loop (or one all row without any): scope, |
DataFrame | unit_count (setpoint steps), evaluable, reason, |
DataFrame | time_resolution_seconds (the common grid period) and |
DataFrame | lookahead_seconds (the response window). |
summary
summary() -> dict[str, Any]
Headline numbers (JSON-able).
Returns
| Type | Description |
|---|---|
dict[str, Any] | evaluable (at least one loop is), reason, loop_count, |
dict[str, Any] | diagnoses (count per diagnosis) and worst_loop. |