Skip to main content
Version: 0.0.98

ts_shape.events.energy.energy_performance_indicator

Classes
NameDescription
EnergyPerformanceIndicatorEventsEnergy: Performance Indicator (EnPI) per ISO 50001

EnergyPerformanceIndicatorEvents​

classsource
EnergyPerformanceIndicatorEvents(
dataframe: pd.DataFrame,
*,
event_uuid: str = "energy:enpi",
time_column: str = "systime",
uuid_column: str = "uuid"
) -> None

Bases: Base

Energy: Performance Indicator (EnPI) per ISO 50001

Calculate energy consumed per unit of production output (EnPI = kWh/unit). Tracks EnPI against a rolling baseline and identifies improvement/degradation trends. Supports comparison across multiple meters / production areas.

Supports two data models via constructor parameters:

  • Standard (ts-shape default)::

    EnergyPerformanceIndicatorEvents(df)

    expects: systime | uuid | value_double | value_integer

  • Raw CSV::

    EnergyPerformanceIndicatorEvents(df, time_column="time", uuid_column="id")

Methods:

  • enpi_by_window: EnPI (energy / units) per time window.
  • enpi_vs_baseline: EnPI vs rolling baseline with anomaly flags.
  • enpi_by_hierarchy: EnPI across multiple meters for area comparison.
Functions
NameDescription
enpi_by_windowCalculate energy per unit produced (EnPI) for each time window.
enpi_vs_baselineCompare current EnPI against a baseline.
enpi_by_hierarchyCalculate EnPI per meter for cross-area comparison.
Parameters
NameTypeDescriptionDefault
dataframeDataFrameLong-format timeseries frame (one row per sample, uuid identifies the signal).required
event_uuidstrUUID stamped on emitted events.'energy:enpi'
time_columnstrTimestamp column.'systime'
uuid_columnstrColumn identifying the signal (e.g. "id" for a raw CSV frame).'uuid'

enpi_by_window​

methodsource
enpi_by_window(
meter_uuid: str,
counter_uuid: str,
*,
value_column_energy: str = "value_double",
value_column_counter: str = "value_integer",
window: str = "1D",
handle_resets: bool = True
) -> pd.DataFrame

Calculate energy per unit produced (EnPI) for each time window.

Parameters
NameTypeDescriptionDefault
meter_uuidstrIdentifier of the energy meter signal.required
counter_uuidstrIdentifier of the production counter signal.required
value_column_energystrColumn containing energy readings.'value_double'
value_column_counterstrColumn containing counter readings.'value_integer'
windowstrAggregation window (e.g. '1D', '1h', '1W').'1D'
handle_resetsboolTrue (default) treats a decreasing production counter as a reset and sums reset-aware increments per window (see :func:ts_shape.utils.counters.counter_per_window), so a window with a reset still reports what was produced. False uses the per-window max - min.True
Returns
NameTypeDescription
DataFrameDataFramestart, end, duration_seconds, uuid, source_uuid, is_delta, energy_kwh, units_produced, enpi. end is start plus window.

enpi_vs_baseline​

methodsource
enpi_vs_baseline(
meter_uuid: str,
counter_uuid: str,
*,
value_column_energy: str = "value_double",
value_column_counter: str = "value_integer",
window: str = "1D",
handle_resets: bool = True,
baseline_window: int = 30,
deviation_threshold: float = 0.1,
baseline: str = "rolling",
baseline_period: tuple[str | pd.Timestamp, str | pd.Timestamp] | None = None
) -> pd.DataFrame

Compare current EnPI against a baseline.

baseline="rolling" (default) compares each window with the EnPI of the preceding baseline_window windows (itself included) taken as one period: their summed energy over their summed output (ISO 50006), not the mean of the per-window EnPI values, which over-weights low-output windows. A rolling baseline drifts with the process, so it never shows a lasting improvement, and kWh/unit is biased by load: a fixed base load makes EnPI look worse whenever output is low.

baseline="regression" is the ISO 50006 energy baseline: fit energy = a + b * units on a fixed baseline period, then compare each window's energy with what the model expects for its output. Baseline windows without production output (zero or missing units) are left out of the fit, with a DataQualityWarning naming them. baseline_enpi is that expected energy per unit and deviation_pct is (actual - expected) / expected energy, so the comparison is normalized for production volume. Two columns are added: expected_energy_kwh and energy_savings_kwh (expected - actual; its cumulative sum is the CUSUM of savings).

Parameters
NameTypeDescriptionDefault
meter_uuidstrIdentifier of the energy meter signal.required
counter_uuidstrIdentifier of the production counter signal.required
value_column_energystrColumn containing energy readings.'value_double'
value_column_counterstrColumn containing counter readings.'value_integer'
windowstrAggregation window.'1D'
baseline_windowintNumber of windows for rolling baseline.30
deviation_thresholdfloatFractional deviation to flag as anomaly (0.1 = 10%).0.1
baselinestr"rolling" or "regression" (see above).'rolling'
baseline_periodtuple[str | Timestamp, str | Timestamp] | None(start, end) of the regression baseline period, end exclusive. Default: the first baseline_window windows.None
handle_resetsboolTrue (default) treats a decreasing production counter as a reset and sums reset-aware increments per window (see :func:ts_shape.utils.counters.counter_per_window), so a window with a reset still reports what was produced. False uses the per-window max - min.True
Returns
NameTypeDescription
DataFrameDataFramestart, end, duration_seconds, uuid, source_uuid, enpi, baseline_enpi, deviation_pct, is_anomaly, trend

enpi_by_hierarchy​

methodsource
enpi_by_hierarchy(
meter_uuids: list[str],
counter_uuid: str,
*,
value_column_energy: str = "value_double",
value_column_counter: str = "value_integer",
window: str = "1D",
handle_resets: bool = True
) -> pd.DataFrame

Calculate EnPI per meter for cross-area comparison.

Useful for comparing energy intensity across production lines, buildings, or hierarchy levels. Combine with series metadata to map meter_uuid to label_lvl / hierarchy columns.

Parameters
NameTypeDescriptionDefault
meter_uuidslist[str]List of energy meter identifiers.required
counter_uuidstrShared production counter identifier.required
value_column_energystrColumn containing energy readings.'value_double'
value_column_counterstrColumn containing counter readings.'value_integer'
windowstrAggregation window.'1D'
handle_resetsboolTrue (default) treats a decreasing production counter as a reset and sums reset-aware increments per window (see :func:ts_shape.utils.counters.counter_per_window), so a window with a reset still reports what was produced. False uses the per-window max - min.True
Returns
NameTypeDescription
DataFrameDataFramestart, end, duration_seconds, meter_uuid, energy_kwh, units_produced, enpi