Skip to main content
Version: 0.0.98

ts_shape.events.engineering.setpoint_events

Classes
NameDescription
SetpointChangeEventsDetect step/ramp changes on a setpoint signal and compute follow-up KPIs

SetpointChangeEvents​

classsource
SetpointChangeEvents(
dataframe: pd.DataFrame,
setpoint_uuid: str,
*,
event_uuid: str = "eng:setpoint_change",
value_column: str = "value_double",
time_column: str = "systime"
) -> None

Bases: Base

Detect step/ramp changes on a setpoint signal and compute follow-up KPIs like time-to-settle and overshoot based on an actual (process) value.

Schema assumptions (columns):

  • uuid, sequence_number, systime, plctime, is_delta
  • value_integer, value_string, value_double, value_bool, value_bytes
Example
>>> import pandas as pd
>>> from ts_shape import SetpointChangeEvents
>>> df = pd.DataFrame({
... "systime": pd.date_range("2025-01-01 08:00", periods=4, freq="10min"),
... "uuid": "oven:setpoint",
... "value_double": [50.0, 50.0, 60.0, 60.0],
... })
>>> steps = SetpointChangeEvents(df, "oven:setpoint").detect_setpoint_steps(min_delta=5.0)
>>> steps[["start", "prev_level", "new_level", "magnitude"]]
start prev_level new_level magnitude
0 2025-01-01 08:20:00 50.0 60.0 10.0
Functions
NameDescription
detect_setpoint_stepsPoint events at times where the setpoint changes by >= min_delta and the
detect_setpoint_rampsInterval events where
detect_setpoint_changesUnified setpoint change table (steps + ramps) with standardized columns.
time_to_settleFor each setpoint change (any change), compute the settling time: the
overshoot_metricsFor each change, compute peak overshoot, undershoot, and oscillation metrics
time_to_settle_derivativeDetect settling based on rate of change (derivative) falling below threshold.
rise_timeCompute rise time: time for actual to go from start_pct to end_pct of the setpoint change.
decay_rateEstimate exponential decay rate of the settling behavior.
oscillation_frequencyEstimate the frequency of oscillations during settling.
control_quality_metricsComprehensive control quality metrics combining multiple performance indicators.
Parameters
NameTypeDescriptionDefault
dataframeDataFrameLong-format timeseries frame (one row per sample, uuid identifies the signal).required
setpoint_uuidstrUUID of the setpoint signal. The actual signal is passed to the KPI methods.required
event_uuidstrUUID stamped on emitted events.'eng:setpoint_change'
value_columnstrNumeric column holding setpoint and actual values.'value_double'
time_columnstrTimestamp column.'systime'

detect_setpoint_steps​

methodsource
detect_setpoint_steps(
min_delta: float,
min_duration: str = "0s",
filter_noise: bool = False,
noise_threshold: float = 0.01,
) -> pd.DataFrame

Point events at times where the setpoint changes by >= min_delta and the new level holds for at least min_duration (no subsequent change within that time).

Parameters
NameTypeDescriptionDefault
min_deltafloatMinimum magnitude of change to detectrequired
min_durationstrMinimum duration the new level must hold (formerly min_hold)'0s'
filter_noiseboolIf True, filter out changes smaller than noise_thresholdFalse
noise_thresholdfloatThreshold for noise filtering (absolute value)0.01
Returns
TypeDescription
DataFrameDataFrame with columns: start, end (== start), duration_seconds
DataFrame(0.0), uuid, source_uuid, is_delta, change_type='step', magnitude,
DataFrameprev_level, new_level.

detect_setpoint_ramps​

methodsource
detect_setpoint_ramps(
min_rate: float, min_duration: str = "0s"
) -> pd.DataFrame

Interval events where |dS/dt| >= min_rate for at least min_duration.

Parameters
NameTypeDescriptionDefault
min_ratefloatMinimum absolute setpoint rate of change, in setpoint units per second, for a sample-to-sample step to count as ramping.required
min_durationstrMinimum time from the first to the last ramping sample of a contiguous run (pandas offset string). Default "0s".'0s'
Returns
TypeDescription
DataFrameDataFrame with columns: start, end, duration_seconds, uuid,
DataFramesource_uuid, is_delta, change_type='ramp', avg_rate, delta.

detect_setpoint_changes​

methodsource
detect_setpoint_changes(
*,
min_delta: float = 0.0,
min_rate: float | None = None,
min_step_duration: str = "0s",
min_duration: str = "0s"
) -> pd.DataFrame

Unified setpoint change table (steps + ramps) with standardized columns.

Parameters
NameTypeDescriptionDefault
min_deltafloatMinimum step magnitude, passed to :meth:detect_setpoint_steps.0.0
min_ratefloat | NoneMinimum ramp rate in setpoint units per second, passed to :meth:detect_setpoint_ramps. None skips ramp detection.None
min_step_durationstrMinimum time a new step level must hold, passed to :meth:detect_setpoint_steps as its min_duration (formerly min_hold).'0s'
min_durationstrMinimum ramp duration, passed to :meth:detect_setpoint_ramps.'0s'
Returns
TypeDescription
DataFrameDataFrame with columns: start, end, duration_seconds, uuid,
DataFramesource_uuid, is_delta, change_type, magnitude, prev_level,
DataFramenew_level, avg_rate, delta.

time_to_settle​

methodsource
time_to_settle(
actual_uuid: str,
*,
tol: float = 0.0,
settle_pct: float | None = None,
hold: str = "0s",
lookahead: str = "10min"
) -> pd.DataFrame

For each setpoint change (any change), compute the settling time: the time after which the actual signal enters the ±tolerance band around the new setpoint and stays inside it until the end of the evaluation window (Ogata, Modern Control Engineering, settling time t_s). The first entry into the band is not the settling time: an underdamped response crosses the band on every swing long before it settles.

Parameters
NameTypeDescriptionDefault
actual_uuidstrUUID of the actual/process value signalrequired
tolfloatAbsolute tolerance, used when settle_pct is None.0.0
settle_pctfloat | NoneTolerance as a fraction of the step magnitude (e.g. 0.02 for 2%). When given it wins over tol; passing both emits a UserWarning.None
holdstrMinimum duration the final inside-band run must last before the window ends for the settle to count as confirmed (settled).'0s'
lookaheadstrEvaluation window after each change. It also ends at the next (later) setpoint change, after which the process follows a different setpoint. The response must be inside the band at the window's last sample to have settled.'10min'
Returns
TypeDescription
DataFrameDataFrame with columns: start, end (start + the lookahead window),
DataFrameduration_seconds, uuid, source_uuid ("<setpoint_uuid>,<actual_uuid>"),
DataFrameis_delta, t_settle_seconds (seconds from the change to the start
DataFrameof the final inside-band run; None when the response is
DataFrameoutside the band at the end of the window), settled_within_window
DataFrame(True when the response is inside the band at the end of the
DataFramewindow, so a settling time exists) and settled
DataFrame(settled_within_window and the final inside-band run lasts at
DataFrameleast hold).

overshoot_metrics​

methodsource
overshoot_metrics(
actual_uuid: str, *, window: str = "10min", deadband: float = 0.0
) -> pd.DataFrame

For each change, compute peak overshoot, undershoot, and oscillation metrics relative to the new setpoint within a lookahead window.

Parameters
NameTypeDescriptionDefault
actual_uuidstrUUID of the actual (process value) signal.required
windowstrLookahead window after each setpoint change in which the peak, undershoot and oscillations are measured (pandas offset string).'10min'
deadbandfloatAbsolute band around the new setpoint for oscillation_count. A crossing counts only once the error leaves the band on the other side, so measurement noise around the setpoint is not counted. 0 counts every sign change of the error.0.0
Returns
TypeDescription
DataFrameDataFrame with columns: start, end (start + the lookahead window),
DataFrameduration_seconds, uuid, source_uuid ("<setpoint_uuid>,<actual_uuid>"),
DataFrameis_delta, overshoot_abs, overshoot_pct, overshoot_ratio,
DataFramet_peak_seconds, undershoot_abs, undershoot_pct, undershoot_ratio,
DataFramet_undershoot_seconds, oscillation_count, oscillation_amplitude.
DataFrameovershoot_pct is the peak overshoot in percent of the step
DataFramemagnitude (0-100+, Ogata's maximum percent overshoot M_p);
DataFrameovershoot_ratio is the same quantity as a fraction (0-1+).
DataFrameundershoot_pct / undershoot_ratio are the swing back past
DataFramethe new setpoint after it is first reached, in the same two units.

time_to_settle_derivative​

methodsource
time_to_settle_derivative(
actual_uuid: str,
*,
rate_threshold: float = 0.01,
lookahead: str = "10min",
hold: str = "0s"
) -> pd.DataFrame

Detect settling based on rate of change (derivative) falling below threshold. More sensitive to when the process has truly stopped moving.

Parameters
NameTypeDescriptionDefault
actual_uuidstrUUID of the actual/process value signalrequired
rate_thresholdfloatMaximum absolute rate of change to consider settled0.01
lookaheadstrMaximum time window to search for settling'10min'
holdstrMinimum duration the rate must stay below threshold'0s'
Returns
TypeDescription
DataFrameDataFrame with columns: start, end (start + the lookahead window),
DataFrameduration_seconds, uuid, source_uuid ("<setpoint_uuid>,<actual_uuid>"),
DataFrameis_delta, t_settle_seconds, settled, final_rate.

rise_time​

methodsource
rise_time(
actual_uuid: str,
*,
start_pct: float = 0.1,
end_pct: float = 0.9,
lookahead: str = "10min"
) -> pd.DataFrame

Compute rise time: time for actual to go from start_pct to end_pct of the setpoint change. Typically measured from 10% to 90% of the final value.

Parameters
NameTypeDescriptionDefault
actual_uuidstrUUID of the actual/process value signalrequired
start_pctfloatStarting percentage of change (e.g., 0.1 for 10%)0.1
end_pctfloatEnding percentage of change (e.g., 0.9 for 90%)0.9
lookaheadstrMaximum time window to search'10min'
Returns
TypeDescription
DataFrameDataFrame with columns: start, end (start + the lookahead window),
DataFrameduration_seconds, uuid, source_uuid ("<setpoint_uuid>,<actual_uuid>"),
DataFrameis_delta, rise_time_seconds, reached_end.

decay_rate​

methodsource
decay_rate(
actual_uuid: str, *, lookahead: str = "10min", min_points: int = 5
) -> pd.DataFrame

Estimate exponential decay rate of the settling behavior. Fits error(t) = A * exp(-lambda * t) and returns lambda.

Parameters
NameTypeDescriptionDefault
actual_uuidstrUUID of the actual/process value signalrequired
lookaheadstrTime window for analysis'10min'
min_pointsintMinimum number of points required for fitting5
Returns
TypeDescription
DataFrameDataFrame with columns: start, end (start + the lookahead window),
DataFrameduration_seconds, uuid, source_uuid ("<setpoint_uuid>,<actual_uuid>"),
DataFrameis_delta, decay_rate_lambda, fit_quality_r2.

oscillation_frequency​

methodsource
oscillation_frequency(
actual_uuid: str,
*,
window: str = "10min",
min_oscillations: int = 2,
deadband: float = 0.0
) -> pd.DataFrame

Estimate the frequency of oscillations during settling. Counts crossings of the setpoint and estimates the period.

Parameters
NameTypeDescriptionDefault
actual_uuidstrUUID of the actual/process value signalrequired
windowstrTime window for analysis'10min'
min_oscillationsintMinimum number of oscillations to compute frequency2
deadbandfloatAbsolute band around the new setpoint; a crossing counts only once the error leaves the band on the other side (see overshoot_metrics). 0 counts every sign change.0.0
Returns
TypeDescription
DataFrameDataFrame with columns: start, end (start + the lookahead window),
DataFrameduration_seconds, uuid, source_uuid ("<setpoint_uuid>,<actual_uuid>"),
DataFrameis_delta, oscillation_freq_hz, period_seconds.

control_quality_metrics​

methodsource
control_quality_metrics(
actual_uuid: str,
*,
tol: float = 0.0,
settle_pct: float | None = None,
hold: str = "0s",
lookahead: str = "10min",
rate_threshold: float = 0.01,
deadband: float | None = None
) -> pd.DataFrame

Comprehensive control quality metrics combining multiple performance indicators.

Computes all available metrics for each setpoint change and returns them in a single DataFrame. This includes: settling time, rise time, overshoot, undershoot, oscillations, and decay characteristics. The change table and the response windows are gathered once and shared by all of them.

Parameters
NameTypeDescriptionDefault
actual_uuidstrUUID of the actual/process value signalrequired
tolfloatAbsolute tolerance for settling, used when settle_pct is None.0.0
settle_pctfloat | NoneSettling tolerance as a fraction of the step magnitude. When given it wins over tol; passing both emits a UserWarning.None
holdstrMinimum duration to confirm settling'0s'
lookaheadstrTime window for all analyses'10min'
rate_thresholdfloatRate threshold for derivative-based settling0.01
deadbandfloat | NoneAbsolute band around the new setpoint for oscillation_count and oscillation_freq_hz: a crossing counts only once the error leaves the band on the other side. None (the default) uses the settle band, tol or settle_pct of each step, so noise inside the band a settled response may stay in is not counted as oscillation. 0 counts every sign change of the error.None
Returns
TypeDescription
DataFrameDataFrame with comprehensive metrics including:
DataFrame- start, end (start + lookahead), duration_seconds, uuid, source_uuid ("<setpoint_uuid>,<actual_uuid>"), is_delta
DataFrame- t_settle_seconds, settled, settled_within_window (from time_to_settle)
DataFrame- t_settle_derivative_seconds (from time_to_settle_derivative)
DataFrame- rise_time_seconds (from rise_time)
DataFrame- overshoot_abs, overshoot_pct (percent), overshoot_ratio (fraction) (from overshoot_metrics)
DataFrame- undershoot_abs, undershoot_pct (percent), undershoot_ratio
DataFrame- oscillation_count, oscillation_amplitude, oscillation_freq_hz
DataFrame- decay_rate_lambda, fit_quality_r2
DataFrame- steady_state_error (final error in window)