ts_shape.events.energy.carbon_intensity
| Name | Description |
|---|---|
CarbonIntensityEvents | Energy: Carbon Intensity Tracking (Scope 1 & 2) |
CarbonIntensityEvents
CarbonIntensityEvents(
dataframe: pd.DataFrame,
emission_factors: dict[str, float],
*,
scope_map: dict[str, int] | None = None,
event_uuid: str = "energy:carbon",
time_column: str = "systime",
uuid_column: str = "uuid"
) -> None
Bases: Base
Energy: Carbon Intensity Tracking (Scope 1 & 2)
Converts energy and fuel consumption signals to CO2-equivalent emissions using configurable emission factors. Supports Scope 1 (direct fuel) and Scope 2 (electricity) calculations, plus carbon intensity per unit produced. Designed for CSRD and ISO 14064 reporting.
Supports two data models via constructor parameters:
-
Standard (ts-shape default)::
CarbonIntensityEvents(df, emission_factors={"meter:elec": 0.233})
expects: systime | uuid | value_double
-
Raw CSV::
CarbonIntensityEvents(df, emission_factors={"sensor_01": 0.233}, time_column="time", uuid_column="id")
emission_factors is a dict mapping signal identifier → kgCO2e per unit
of the energy/fuel reading::
emission_factors = {
"meter:electricity": 0.233, # kgCO2e/kWh (UK grid average 2026)
"meter:gas": 2.034, # kgCO2e/m³ (natural gas)
}
Each factor's scope is inferred from scope_map. Any uuid not in
scope_map defaults to Scope 2.
Methods:
- emissions_by_window: CO2e per source per time window.
- total_emissions_by_window: Aggregated Scope 1 + 2 per window.
- carbon_intensity_per_unit: kgCO2e per unit produced.
- emission_factor_audit: Return configured factors for audit trail.
| Name | Description |
|---|---|
emissions_by_window | CO2e emissions per configured source per time window. |
total_emissions_by_window | Aggregate Scope 1 + Scope 2 emissions across all configured meters. |
carbon_intensity_per_unit | Carbon intensity per unit produced (kgCO2e / unit). |
emission_factor_audit | Return the configured emission factors for audit and reporting. |
emission_factors: Mapping of signal identifier → kgCO2e per unit.
Each factor must be a finite number >= 0; an identifier that
is not in the data emits a ``DataQualityWarning``.
scope_map: Optional mapping of signal identifier → scope (1 or 2).
Defaults to Scope 2 for any uuid not in the map.
event_uuid: UUID assigned to output events.
time_column: Name of the timestamp column.
uuid_column: Name of the signal identifier column.
emissions_by_window
emissions_by_window(
*,
scope: int = 0,
value_column: str = "value_double",
window: str = "1D",
signal_kind: str = "interval"
) -> pd.DataFrame
CO2e emissions per configured source per time window.
| Name | Type | Description | Default |
|---|---|---|---|
scope | int | Filter by scope: 1 = fuel only, 2 = electricity only, 0 = all sources (default). | 0 |
value_column | str | Column containing consumption readings. | 'value_double' |
window | str | Aggregation window (e.g. '1D', '1h'). | '1D' |
signal_kind | str | What a reading is (see :data:SIGNAL_KINDS): "interval" -- the consumption since the previous reading (summed per window); "meter" -- a cumulative meter (reset-aware increments per window); "power" -- a rate such as kW (integrated over time: value x hours, so kW gives kWh; a sampled signal is not held across a gap longer than its inferred max_gap); "auto" -- inferred per source from its data (:func:ts_shape.signals.infer.infer_spec): a counter is a meter, a continuous signal sampled at most once a minute or logged on change is a power reading, anything else an interval reading. Default "interval" (the readings are summed); a source that looks like a meter or a power reading then emits a DataQualityWarning naming the signal_kind to pass. "auto" states its choice in a DataQualityWarning too. | 'interval' |
| Name | Type | Description |
|---|---|---|
DataFrame | DataFrame | start, end, duration_seconds, uuid, source_uuid, scope, consumption, emission_factor, kgco2e. end is start plus window. |
total_emissions_by_window
total_emissions_by_window(
*,
value_column: str = "value_double",
window: str = "1D",
signal_kind: str = "interval"
) -> pd.DataFrame
Aggregate Scope 1 + Scope 2 emissions across all configured meters.
| Name | Type | Description | Default |
|---|---|---|---|
value_column | str | Column containing consumption readings. | 'value_double' |
window | str | Aggregation window. | '1D' |
signal_kind | str | What a reading is; see :meth:emissions_by_window. | 'interval' |
| Name | Type | Description |
|---|---|---|
DataFrame | DataFrame | start, end, duration_seconds, uuid, scope1_kgco2e, scope2_kgco2e, total_kgco2e |
carbon_intensity_per_unit
carbon_intensity_per_unit(
counter_uuid: str,
*,
value_column: str = "value_double",
value_column_counter: str = "value_integer",
window: str = "1D",
handle_resets: bool = True,
signal_kind: str = "interval"
) -> pd.DataFrame
Carbon intensity per unit produced (kgCO2e / unit).
| Name | Type | Description | Default |
|---|---|---|---|
counter_uuid | str | Identifier of the production counter signal. | required |
value_column | str | Column containing energy/fuel readings. | 'value_double' |
value_column_counter | str | Column containing counter readings. | 'value_integer' |
window | str | Aggregation window. | '1D' |
handle_resets | bool | True (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 |
signal_kind | str | What an energy reading is; see :meth:emissions_by_window. | 'interval' |
| Name | Type | Description |
|---|---|---|
DataFrame | DataFrame | start, end, duration_seconds, uuid, total_kgco2e, units_produced, carbon_intensity, trend |
emission_factor_audit
emission_factor_audit() -> pd.DataFrame
Return the configured emission factors for audit and reporting.
| Name | Type | Description |
|---|---|---|
DataFrame | DataFrame | source_uuid, scope, emission_factor_kgco2e_per_unit |