ts_shape.events.quality.signal_quality
Signal quality: is the data itself trustworthy?
Finds missing data (gaps longer than the expected period), measures sampling regularity, flags out-of-range values, and reports data completeness per calendar window (real window lengths on DST days).
| Name | Description |
|---|---|
SignalQualityEvents | Quality: Signal Quality Monitoring |
SignalQualityEvents
SignalQualityEvents(
dataframe: pd.DataFrame,
signal_uuid: str,
*,
event_uuid: str = "quality:signal",
value_column: str = "value_double",
time_column: str = "systime"
) -> None
Bases: Base
Quality: Signal Quality Monitoring
Detect data quality issues in a numeric signal: missing data, irregular sampling, out-of-range values, and data completeness.
Methods:
- detect_missing_data: Find gaps exceeding expected sampling frequency.
- sampling_regularity: Inter-sample interval statistics per window.
- detect_out_of_range: Flag values outside physical/expected bounds.
- data_completeness: Percentage of expected samples received per window.
Example
A 1 s signal with an 8 s gap and one implausible reading:
>>> import pandas as pd
>>> from ts_shape import SignalQualityEvents
>>> df = pd.DataFrame({
... "systime": pd.to_datetime([
... "2025-01-01 00:00:00", "2025-01-01 00:00:01", "2025-01-01 00:00:02",
... "2025-01-01 00:00:10", "2025-01-01 00:00:11"]),
... "uuid": "temp",
... "value_double": [20.0, 20.5, 21.0, 95.0, 21.0],
... })
>>> quality = SignalQualityEvents(df, "temp")
>>> quality.detect_missing_data(expected_interval="1s")[["start", "end", "duration_seconds"]]
start end duration_seconds
0 2025-01-01 00:00:02 2025-01-01 00:00:10 8.0
>>> quality.detect_out_of_range(0.0, 50.0)[["start", "end", "duration_seconds"]]
start end duration_seconds
0 2025-01-01 00:00:10 2025-01-01 00:00:11 1.0
| Name | Description |
|---|---|
detect_missing_data | Find gaps where time between samples exceeds expected frequency. |
sampling_regularity | Inter-sample interval statistics per window. |
detect_out_of_range | Flag intervals where signal is outside expected range. |
data_completeness | Percentage of expected samples actually received per window. |
| 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 signal to analyze. | required |
event_uuid | str | UUID stamped on emitted events. | 'quality:signal' |
value_column | str | Column holding the signal values. | 'value_double' |
time_column | str | Timestamp column. | 'systime' |
detect_missing_data
detect_missing_data(
expected_interval: str = "1s", tolerance_factor: float = 2.0
) -> pd.DataFrame
Find gaps where time between samples exceeds expected frequency.
| Name | Type | Description | Default |
|---|---|---|---|
expected_interval | str | Expected sampling interval (e.g. '1s', '100ms'). | '1s' |
tolerance_factor | float | Multiplier on expected_interval to trigger a gap. | 2.0 |
| Type | Description |
|---|---|
DataFrame | DataFrame with columns: start, end, duration_seconds, uuid, |
DataFrame | source_uuid, gap_duration, gap_duration_seconds, |
DataFrame | expected_samples_missing. gap_duration is a Timedelta; |
DataFrame | gap_duration_seconds (and duration_seconds) is the same |
DataFrame | span in float seconds. |
sampling_regularity
sampling_regularity(window: str = '1h') -> pd.DataFrame
Inter-sample interval statistics per window.
| Name | Type | Description | Default |
|---|---|---|---|
window | str | Resample window. | '1h' |
| Type | Description |
|---|---|
DataFrame | DataFrame with columns: start, end, duration_seconds, uuid, |
DataFrame | source_uuid, mean_interval, mean_interval_seconds, std_interval, |
DataFrame | std_interval_seconds, min_interval, min_interval_seconds, |
DataFrame | max_interval, max_interval_seconds, regularity_score. end is |
DataFrame | start plus one window. Intervals are in seconds. |
DataFrame | Canonical twin columns: mean_interval_seconds, |
DataFrame | std_interval_seconds, min_interval_seconds, |
DataFrame | max_interval_seconds, each right after its deprecated |
DataFrame | unitless column (same values), which is removed in the next major |
DataFrame | release. |
detect_out_of_range
detect_out_of_range(
min_value: float, max_value: float, *, interval_end: str = "next_change"
) -> pd.DataFrame
Flag intervals where signal is outside expected range.
| Name | Type | Description | Default |
|---|---|---|---|
min_value | float | Minimum acceptable value. | required |
max_value | float | Maximum acceptable value. | required |
interval_end | str | "next_change" (default) ends an interval at the next sample (the transition), so change-encoded signals -- one row per change -- report the real time out of range. "last_sample" ends it at its last flagged sample. See :func:ts_shape.utils.intervals.interval_end_times. | 'next_change' |
| Type | Description |
|---|---|
DataFrame | DataFrame with columns: start, end, duration_seconds, uuid, |
DataFrame | source_uuid, duration, min_observed, max_observed, direction. |
DataFrame | duration is a Timedelta; duration_seconds is the same |
DataFrame | span in float seconds. |
data_completeness
data_completeness(
window: str = "1h", expected_interval: str = "1s"
) -> pd.DataFrame
Percentage of expected samples actually received per window.
The expected count is the full window's length over
expected_interval, so a window the data covers only partly (the
first and last one) reads below 100 %: 1 s data from 10:30:00 to
11:29:59 reads 50 % in both hourly windows, as
DataGapAnalysisEvents.coverage_by_period does.
| Name | Type | Description | Default |
|---|---|---|---|
window | str | Resample window. | '1h' |
expected_interval | str | Expected sampling interval. | '1s' |
| Type | Description |
|---|---|
DataFrame | DataFrame with columns: start, end, duration_seconds, uuid, |
DataFrame | source_uuid, expected_count, actual_count, completeness_pct. |
DataFrame | end is start plus one window. |