Skip to main content
Version: Next

ts_shape.events.quality.value_distribution

Value distribution: shape and stability of a signal's values.

Detects mode changes and bimodality, tests normality per window, and tracks percentiles over time: the distribution checks behind capability indices and SPC limits.

Classes
NameDescription
ValueDistributionEventsQuality: Value Distribution Analysis

ValueDistributionEvents​

classsource
ValueDistributionEvents(
dataframe: pd.DataFrame,
signal_uuid: str,
*,
event_uuid: str = "quality:distribution",
value_column: str = "value_double",
time_column: str = "systime"
) -> None

Bases: Base

Quality: Value Distribution Analysis

Answer the question "is my process behaving normally?" by examining the statistical distribution of a numeric signal over time.

Methods:

  • detect_mode_changes: Detect shifts between distinct operating modes.
  • detect_bimodal: Test whether the signal has a bimodal distribution.
  • normality_windows: Flag time windows with non-normal distributions.
  • percentile_tracking: Track selected percentiles over time windows.
Functions
NameDescription
detect_mode_changesDetect shifts between distinct operating modes.
detect_bimodalTest whether the overall signal distribution is bimodal.
normality_windowsFlag time windows whose values are not normally distributed.
percentile_trackingTrack selected percentiles over time windows.
Parameters
NameTypeDescriptionDefault
dataframeDataFrameLong-format timeseries frame (one row per sample, uuid identifies the signal).required
signal_uuidstrUUID of the signal to analyze.required
event_uuidstrUUID stamped on emitted events.'quality:distribution'
value_columnstrColumn holding the signal values.'value_double'
time_columnstrTimestamp column.'systime'

detect_mode_changes​

methodsource
detect_mode_changes(
window: str = "1h", n_modes: int = 2, min_separation: float = 1.0
) -> pd.DataFrame

Detect shifts between distinct operating modes.

Splits the signal into time windows, computes the histogram peaks (modes) in each window, and flags when the dominant mode shifts.

Parameters
NameTypeDescriptionDefault
windowstrTime window for analysis.'1h'
n_modesintMaximum number of modes to look for per window.2
min_separationfloatMinimum separation between modes in units of the signal's standard deviation to count as distinct.1.0
Returns
TypeDescription
DataFrameDataFrame with columns: start, end, duration_seconds, uuid,
DataFramesource_uuid, dominant_mode, n_modes_detected, mode_count (the
DataFramenumber of modes found in the window), mode_values, mode_changed.
DataFrameend is start plus one window.
DataFrameCanonical twin columns: mode_count (after n_modes_detected); it holds the same
DataFramevalues as the deprecated column right before it, which is removed
DataFramein the next major release.

detect_bimodal​

methodsource
detect_bimodal(min_samples: int = 30) -> pd.DataFrame

Test whether the overall signal distribution is bimodal.

Uses Hartigan's dip test statistic approximated via the sorted data's inter-mode gap relative to overall range. A simpler, dependency-free alternative to the full dip test.

Parameters
NameTypeDescriptionDefault
min_samplesintMinimum sample count required to run the test.30
Returns
TypeDescription
DataFrameSingle-row DataFrame with columns: is_bimodal, dip_score,
DataFramen_samples, mode_1, mode_2, valley (empty when there are fewer
DataFramethan min_samples values). A constant signal is unimodal with
DataFramemode_1 at its value.
DataFrameCanonical twin columns: sample_count (after n_samples); each holds
DataFramethe same values as the deprecated column right before it, which is removed
DataFramein the next major release.

normality_windows​

methodsource
normality_windows(
window: str = "1h", alpha: float = 0.05, min_samples: int = 20
) -> pd.DataFrame

Flag time windows whose values are not normally distributed.

Uses the Shapiro-Wilk test per window.

Parameters
NameTypeDescriptionDefault
windowstrResample window.'1h'
alphafloatSignificance level for the normality test.0.05
min_samplesintMinimum samples per window to run the test.20
Returns
TypeDescription
DataFrameDataFrame with columns: start, end, duration_seconds, uuid,
DataFramesource_uuid, n_samples, is_normal, p_value, skewness, kurtosis.
DataFrameend is start plus one window.
DataFrameCanonical twin columns: sample_count (after n_samples); each holds
DataFramethe same values as the deprecated column right before it, which is removed
DataFramein the next major release.

percentile_tracking​

methodsource
percentile_tracking(
percentiles: Sequence[float] = (5, 25, 50, 75, 95), window: str = "1h"
) -> pd.DataFrame

Track selected percentiles over time windows.

Useful for spotting distribution spread changes even when the mean stays constant.

Parameters
NameTypeDescriptionDefault
percentilesSequence[float]Percentile values to track (0-100).(5, 25, 50, 75, 95)
windowstrResample window.'1h'
Returns
TypeDescription
DataFrameDataFrame with columns: start, end, duration_seconds, uuid,
DataFramesource_uuid, n_samples, plus one column per percentile (e.g.
DataFramep5, p95). end is start plus one window.
DataFrameCanonical twin columns: sample_count (after n_samples); each holds
DataFramethe same values as the deprecated column right before it, which is removed
DataFramein the next major release.