Skip to main content
Version: Next

ts_shape.events.correlation.signal_correlation

Classes
NameDescription
SignalCorrelationEventsCorrelation: Signal Correlation Analysis

SignalCorrelationEvents​

classsource
SignalCorrelationEvents(
dataframe: pd.DataFrame,
*,
event_uuid: str = "corr:signal",
value_column: str = "value_double",
time_column: str = "systime"
) -> None

Bases: Base

Correlation: Signal Correlation Analysis

Analyze time-windowed correlations between pairs of numeric signals. Useful for detecting when normally correlated process variables diverge.

Methods:

  • rolling_correlation: Pearson correlation over rolling windows.
  • correlation_breakdown: Detect periods where correlation drops below threshold.
  • lag_correlation: Cross-correlation with time lag to find delayed relationships.
Functions
NameDescription
rolling_correlationCompute rolling Pearson correlation between two signals.
correlation_breakdownDetect periods where correlation drops below a threshold.
lag_correlationCross-correlation with time lag analysis.
Parameters
NameTypeDescriptionDefault
dataframeDataFrameLong-format timeseries frame holding the signals to correlate (uuid identifies the signal).required
event_uuidstrUUID stamped on emitted events.'corr:signal'
value_columnstrNumeric column holding the signal values.'value_double'
time_columnstrTimestamp column.'systime'

rolling_correlation​

methodsource
rolling_correlation(
signal_uuid_a: str,
signal_uuid_b: str,
*,
window: str = "1min",
window_size: int = 60
) -> pd.DataFrame

Compute rolling Pearson correlation between two signals.

Parameters
NameTypeDescriptionDefault
signal_uuid_astrUUID of first signal.required
signal_uuid_bstrUUID of second signal.required
windowstrResample interval for alignment (offset string).'1min'
window_sizeintRolling window size, in resampled periods (rows).60
Returns
NameTypeDescription
DataFrameDataFramesystime, uuid, source_uuid, source_uuid_a, source_uuid_b, is_delta, correlation. source_uuid is "<signal_uuid_a>,<signal_uuid_b>".

correlation_breakdown​

methodsource
correlation_breakdown(
signal_uuid_a: str,
signal_uuid_b: str,
*,
window: str = "1min",
window_size: int = 60,
threshold: float = 0.5,
interval_end: str = "next_change"
) -> pd.DataFrame

Detect periods where correlation drops below a threshold.

Returns intervals where previously correlated signals diverge, which may indicate process issues.

Parameters
NameTypeDescriptionDefault
signal_uuid_astrUUID of first signal.required
signal_uuid_bstrUUID of second signal.required
windowstrResample interval for alignment (offset string).'1min'
window_sizeintRolling window size, in resampled periods (rows).60
thresholdfloatCorrelation threshold below which to flag.0.5
interval_endstr"next_change" (default) ends an interval at the next sample (the transition), so the interval spans the time the condition held and change-encoded signals -- one row per change -- keep their duration. "last_sample" ends it at its last flagged sample. See :func:ts_shape.utils.intervals.interval_end_times.'next_change'
Returns
NameTypeDescription
DataFrameDataFramestart, end, uuid, source_uuid_a, source_uuid_b, is_delta, min_correlation, duration_seconds. Empty (same columns) when no breakdown is found.

lag_correlation​

methodsource
lag_correlation(
signal_uuid_a: str,
signal_uuid_b: str,
*,
window: str = "1min",
max_lag: int = 30
) -> pd.DataFrame

Cross-correlation with time lag analysis.

Finds the time lag at which two signals are most correlated.

Sign convention: lag_periods = k correlates a[t] with b[t - k] (b shifted forward by k grid periods). A positive best lag means b leads a (a follows b by k periods); a negative best lag means b lags a. For example, b(t) = a(t - 5) (b delayed by 5 periods) gives a best lag of -5.

Parameters
NameTypeDescriptionDefault
signal_uuid_astrUUID of first signal (reference).required
signal_uuid_bstrUUID of second signal, shifted against the reference.required
windowstrResample interval for alignment (offset string).'1min'
max_lagintMaximum lag periods to test (in both directions).30
Returns
NameTypeDescription
DataFrameDataFramelag_periods, correlation, is_best_lag