Skip to main content
Version: 0.0.98

ts_shape.events.quality.environmental_compensation

Classes
NameDescription
EnvironmentalCompensationEventsQuality: Environmental Compensation for Inline Sensors

EnvironmentalCompensationEvents​

classsource
EnvironmentalCompensationEvents(
dataframe: pd.DataFrame,
signal_uuid: str,
*,
env_uuid: str,
env_value: float | None = None,
value_column: str = "value_double",
event_uuid: str = "quality:env_compensation",
time_column: str = "systime"
) -> None

Bases: Base

Quality: Environmental Compensation for Inline Sensors

Detect and compensate for environmental effects (temperature, humidity, pressure) on inline measurement sensors. Tracks correlation, estimates sensitivity coefficients, applies compensation, and flags out-of-range conditions.

Methods:

  • detect_correlation: Pearson correlation per window.
  • sensitivity: Linear regression coefficient per window.
  • compensated_signal: Apply compensation model to signal.
  • detect_env_exceedance: Flag out-of-range environmental conditions.

env_uuid (the environment signal) is required; the constructor raises ValueError without it. env_value is optional and only sets the nominal environment value used by compensated_signal.

Functions
NameDescription
detect_correlationPearson correlation between measurement and env signal per window.
sensitivityEstimate environmental sensitivity coefficient per window.
compensated_signalApply linear compensation to the measurement signal.
detect_env_exceedanceFlag windows where environmental conditions exceed valid range.
Parameters
NameTypeDescriptionDefault
dataframeDataFrameLong-format timeseries frame (one row per sample, uuid identifies the signal).required
signal_uuidstrUUID of the measurement signal.required
env_uuidstrUUID of the environment signal (temperature, humidity, ...). Required: None raises ValueError.required
env_valuefloat | NoneNominal environment value used by :meth:compensated_signal. Optional.None
value_columnstrColumn holding the signal values.'value_double'
event_uuidstrUUID stamped on emitted events.'quality:env_compensation'
time_columnstrTimestamp column.'systime'

detect_correlation​

methodsource
detect_correlation(window: str = '4h') -> pd.DataFrame

Pearson correlation between measurement and env signal per window.

Parameters
NameTypeDescriptionDefault
windowstrResample window size.'4h'
Returns
TypeDescription
DataFrameSummary DataFrame with columns: start, end, duration_seconds
DataFrame(the window bounds), window_start (the resample label; a
DataFramedeprecated twin of start), correlation, p_value,
DataFramesignificant.

sensitivity​

methodsource
sensitivity(window: str = '8h') -> pd.DataFrame

Estimate environmental sensitivity coefficient per window.

Fits measurement = a × env + b per window.

Parameters
NameTypeDescriptionDefault
windowstrResample window size.'8h'
Returns
TypeDescription
DataFrameSummary DataFrame with columns: start, end, duration_seconds
DataFrame(the window bounds), window_start (the resample label; a
DataFramedeprecated twin of start), coefficient, intercept,
DataFramer_squared, unit_change_per_degree.

compensated_signal​

methodsource
compensated_signal(coefficient: float | None = None) -> pd.DataFrame

Apply linear compensation to the measurement signal.

corrected = measured - coefficient × (env - env_nominal)

If coefficient is not provided, estimates from data using overall linear regression.

Parameters
NameTypeDescriptionDefault
coefficientfloat | NoneEnvironmental sensitivity coefficient. If None, estimated from data.None
Returns
TypeDescription
DataFrameDataFrame with columns: systime, uuid, value_double,
DataFramecompensated_value, correction_applied, source_uuid. uuid
DataFrameis the event uuid and source_uuid the measured signal's uuid.

detect_env_exceedance​

methodsource
detect_env_exceedance(
valid_range: tuple[float, float], window: str = "1h"
) -> pd.DataFrame

Flag windows where environmental conditions exceed valid range.

Parameters
NameTypeDescriptionDefault
valid_rangetuple[float, float]Tuple (min, max) of acceptable env values.required
windowstrResample window: a fixed length ("1h") or a calendar frequency ("1D" a calendar day, "W", "MS").'1h'
Returns
TypeDescription
DataFrameSummary DataFrame with columns: start, end, duration_seconds
DataFrame(the window bounds), window_start (the resample label; a
DataFramedeprecated twin of start), window_end (the window's end, as
DataFrameend), env_mean,
DataFrameenv_min, env_max, exceedance_type, severity.