ts_shape.events.quality.environmental_compensation
| Name | Description |
|---|---|
EnvironmentalCompensationEvents | Quality: Environmental Compensation for Inline Sensors |
EnvironmentalCompensationEvents
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.
| Name | Description |
|---|---|
detect_correlation | Pearson correlation between measurement and env signal per window. |
sensitivity | Estimate environmental sensitivity coefficient per window. |
compensated_signal | Apply linear compensation to the measurement signal. |
detect_env_exceedance | Flag windows where environmental conditions exceed valid range. |
| 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 measurement signal. | required |
env_uuid | str | UUID of the environment signal (temperature, humidity, ...). Required: None raises ValueError. | required |
env_value | float | None | Nominal environment value used by :meth:compensated_signal. Optional. | None |
value_column | str | Column holding the signal values. | 'value_double' |
event_uuid | str | UUID stamped on emitted events. | 'quality:env_compensation' |
time_column | str | Timestamp column. | 'systime' |
detect_correlation
detect_correlation(window: str = '4h') -> pd.DataFrame
Pearson correlation between measurement and env signal per window.
| Name | Type | Description | Default |
|---|---|---|---|
window | str | Resample window size. | '4h' |
| 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), correlation, p_value, |
DataFrame | significant. |
sensitivity
sensitivity(window: str = '8h') -> pd.DataFrame
Estimate environmental sensitivity coefficient per window.
Fits measurement = a × env + b per window.
| Name | Type | Description | Default |
|---|---|---|---|
window | str | Resample window size. | '8h' |
| 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), coefficient, intercept, |
DataFrame | r_squared, unit_change_per_degree. |
compensated_signal
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.
| Name | Type | Description | Default |
|---|---|---|---|
coefficient | float | None | Environmental sensitivity coefficient. If None, estimated from data. | None |
| Type | Description |
|---|---|
DataFrame | DataFrame with columns: systime, uuid, value_double, |
DataFrame | compensated_value, correction_applied, source_uuid. uuid |
DataFrame | is the event uuid and source_uuid the measured signal's uuid. |
detect_env_exceedance
detect_env_exceedance(
valid_range: tuple[float, float], window: str = "1h"
) -> pd.DataFrame
Flag windows where environmental conditions exceed valid range.
| Name | Type | Description | Default |
|---|---|---|---|
valid_range | tuple[float, float] | Tuple (min, max) of acceptable env values. | required |
window | str | Resample window: a fixed length ("1h") or a calendar frequency ("1D" a calendar day, "W", "MS"). | '1h' |
| 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), window_end (the window's end, as |
DataFrame | end), env_mean, |
DataFrame | env_min, env_max, exceedance_type, severity. |