CalibrationValidationEvents¤
Checks whether an inline sensor still reads true: linearity and a fitted calibration curve from a multi-point check, and per-window bias, drift and stability against a reference value or a reference sensor.
ts_shape.events.quality.calibration_validation · Quality guide · API reference
Example¤
import ts_shape
from ts_shape.events.quality.calibration_validation import CalibrationValidationEvents
points = {0.0: [0.02, 0.01, 0.03], 50.0: [50.10, 50.08, 50.12], 100.0: [100.25, 100.21, 100.27]}
print(CalibrationValidationEvents.linearity_assessment(points))
curve = CalibrationValidationEvents.calibration_curve(points, degree=2)
df = ts_shape.make_timeseries(["ft201", "ft201_ref"], n_points=5000, freq="1min", noise=0.2)
df.loc[df["uuid"] == "ft201", "value_double"] += 0.6 # biased sensor
cal = CalibrationValidationEvents(df, "ft201", reference_uuid="ft201_ref")
recal = cal.detect_recalibration_need(window="1D", max_bias=0.5, max_drift_rate=0.1)
stability = cal.calibration_stability(window="8h", lookback=10)
Methods¤
| Method | Returns |
|---|---|
linearity_assessment(calibration_points) (static) |
per reference point: reference, measured_mean, measured_std, bias, linearity_error |
calibration_curve(calibration_points, degree=1) (static) |
per polynomial coefficient: coefficient_index, coefficient_value, r_squared, max_residual |
detect_recalibration_need(window='1D', max_bias=None, max_drift_rate=None) |
per window: start, end, duration_seconds, bias, drift_rate, recalibration_needed, reason |
calibration_stability(window='8h', lookback=10) |
per window: start, end, duration_seconds, bias_mean, bias_std, bias_trend, stability_score |
Notes¤
- The static methods take
{reference_value: [measured, ...]}and need no DataFrame. - The window methods need a reference:
reference_value(a constant, e.g. a check standard) orreference_uuid(that signal's mean in the same window). Without one they return an empty frame. Windows with fewer than 2 samples or no reference data are skipped. bias= window mean − reference.drift_rateis the bias change from the previous window (0 for the first).linearity_erroris each point's residual from a straight line fitted through all points (at least 2 points).calibration_curvecoefficients come fromnumpy.polyfit, highest power first; the degree is capped at number of points − 1.stability_scorestarts at 100 and deducts up to 50 for the bias magnitude, 30 for its spread and 20 for its trend (slope over thelookbackwindows). The penalties are in signal units, so scores are only comparable between signals of similar scale.