ts_shape.events.quality.calibration_validation
Classes
| Name | Description |
|---|---|
CalibrationValidationEvents | Quality: Calibration Validation & Linearity |
CalibrationValidationEvents
CalibrationValidationEvents(
dataframe: pd.DataFrame,
signal_uuid: str,
*,
reference_uuid: str | None = None,
reference_value: float | None = None,
value_column: str = "value_double",
event_uuid: str = "quality:calibration",
time_column: str = "systime"
) -> None
Bases: Base
Quality: Calibration Validation & Linearity
Multi-point calibration validation for inline sensors. Assesses linearity across measurement range, detects calibration degradation, and determines when recalibration is needed.
Methods:
- linearity_assessment: Residual analysis at calibration points.
- calibration_curve: Polynomial fit to calibration data.
- detect_recalibration_need: Monitor bias/drift for recal triggers.
- calibration_stability: Bias stability scoring over time.
Functions
| Name | Description |
|---|---|
linearity_assessment | Assess linearity at multiple calibration points. |
calibration_curve | Fit polynomial calibration curve. |
detect_recalibration_need | Monitor bias and drift to detect recalibration need. |
calibration_stability | Track calibration bias stability over rolling windows. |
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
dataframe | DataFrame | Long-format timeseries frame (one row per sample, uuid identifies the signal). | required |
signal_uuid | str | UUID of the sensor signal to validate. | required |
reference_uuid | str | None | UUID of a time-aligned reference signal. Optional. | None |
reference_value | float | None | Fixed reference value. Optional. | None |
value_column | str | Column holding the signal values. | 'value_double' |
event_uuid | str | UUID stamped on emitted events. | 'quality:calibration' |
time_column | str | Timestamp column. | 'systime' |
linearity_assessment
linearity_assessment(
calibration_points: dict[float, list[float]],
) -> pd.DataFrame
Assess linearity at multiple calibration points.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
calibration_points | dict[float, list[float]] | Dict mapping reference values to lists of measured values, e.g. {10.0: [10.1, 9.9, 10.0]}. | required |
Returns
| Type | Description |
|---|---|
DataFrame | DataFrame with columns: reference, measured_mean, |
DataFrame | measured_std, bias, linearity_error. |
calibration_curve
calibration_curve(
calibration_points: dict[float, list[float]], degree: int = 1
) -> pd.DataFrame
Fit polynomial calibration curve.
The fit is the instrument response: the mean measured value as a
polynomial of the reference value, measured = f(reference) (to
correct readings, invert it). The degree is capped at the number of
calibration points minus one.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
calibration_points | dict[float, list[float]] | Dict mapping reference values to measured value lists. | required |
degree | int | Polynomial degree (1=linear, 2=quadratic, etc). | 1 |
Returns
| Type | Description |
|---|---|
DataFrame | DataFrame with one row per coefficient and columns: |
DataFrame | coefficient_index, power, coefficient_value, r_squared, |
DataFrame | max_residual. The coefficients come highest power first |
numpy.polyfit`` order, ready for ``numpy.polyval | |
DataFrame | coefficient_index is the position in that order and |
DataFrame | power the exponent of the reference value it multiplies |
DataFrame | (degree_used - coefficient_index). |
detect_recalibration_need
detect_recalibration_need(
window: str = "1D",
max_bias: float | None = None,
max_drift_rate: float | None = None,
) -> pd.DataFrame
Monitor bias and drift to detect recalibration need.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
window | str | Resample window: a fixed length ("8h") or a calendar frequency ("1D" a calendar day, "W", "MS"). | '1D' |
max_bias | float | None | Maximum acceptable absolute bias. | None |
max_drift_rate | float | None | Maximum acceptable bias change per window. | None |
Returns
| Type | Description |
|---|---|
DataFrame | Summary DataFrame with columns: start, end, duration_seconds |
DataFrame | (the window bounds), window_start (the resample label; a |
DataFrame | deprecated twin of start), bias, drift_rate, |
DataFrame | recalibration_needed, reason. |
calibration_stability
calibration_stability(window: str = '8h', lookback: int = 10) -> pd.DataFrame
Track calibration bias stability over rolling windows.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
window | str | Resample window: a fixed length ("8h") or a calendar frequency ("1D" a calendar day, "W", "MS"). | '8h' |
lookback | int | Number of previous windows for trend assessment. | 10 |
Returns
| Type | Description |
|---|---|
DataFrame | Summary DataFrame with columns: start, end, duration_seconds |
DataFrame | (the window bounds), window_start (the resample label; a |
DataFrame | deprecated twin of start), bias_mean, bias_std, |
DataFrame | bias_trend, stability_score. |