reporting_metrics
frequenz.lib.notebooks.reporting.metrics.reporting_metrics ¤
Energy reporting metrics for production, consumption, and storage analysis.
This module provides helper functions for calculating and analyzing energy flows within a hybrid power system — including production, consumption, battery charging, grid feed-in, and self-consumption metrics.
Key features:
It standardizes sign conventions (via production_is_positive) and ensures
consistency in derived quantities such as:
- Production surplus (excess generation)
- Energy stored in a battery
- Grid feed-in power
- Self-consumption and self-consumption share
- Inferred consumption when not explicitly provided
Usage
These functions serve as building blocks for energy reporting and dashboards that report on the performance of energy assets.
Functions¤
frequenz.lib.notebooks.reporting.metrics.reporting_metrics.asset_production ¤
asset_production(
production: Series, production_is_positive: bool = False
) -> Series
Extract the positive production portion from a power series.
Ensures only productive (non-negative) values remain, regardless of the sign convention used for production vs. consumption.
| PARAMETER | DESCRIPTION |
|---|---|
production
|
Series of power values (e.g., kW or MW).
TYPE:
|
production_is_positive
|
Whether production values are already positive.
If False,
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Series
|
A Series where only production values (≥ 0) are retained, with all |
Series
|
non-productive values set to zero. |
Source code in frequenz/lib/notebooks/reporting/metrics/reporting_metrics.py
frequenz.lib.notebooks.reporting.metrics.reporting_metrics.consumption ¤
consumption(
grid: Series,
production: Series | None = None,
battery: Series | None = None,
) -> Series
Infer total consumption from grid power, on-site production, and battery power.
consumption = grid_power - production (raw production-neg values)
- battery (raw - with positive and negative values).
| PARAMETER | DESCRIPTION |
|---|---|
grid
|
Series of grid power values (e.g., kW or MW).
TYPE:
|
production
|
Optional Series of on-site production values. If None, production is treated as zero.
TYPE:
|
battery
|
Optional Series representing battery discharge/charge power. Positive values increase inferred consumption (battery discharge), while negative values decrease it (battery charging). If None, the battery contribution is treated as zero.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Series
|
A Series representing inferred total consumption, named |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Source code in frequenz/lib/notebooks/reporting/metrics/reporting_metrics.py
frequenz.lib.notebooks.reporting.metrics.reporting_metrics.grid_consumption ¤
grid_consumption(
grid: Series | None,
production: Series | None,
consumption: Series | None,
battery: Series | None,
) -> Series
Determine grid import using measured or derived series.
This function follows the PSC (Production-Storage-Consumption) convention: - Production is positive when generating. - Battery is positive when charging (consuming energy). - Consumption is positive when consuming energy.
Prefers the measured grid series (positive import, negative export). When unavailable, derives grid import from the remaining energy balance.
| PARAMETER | DESCRIPTION |
|---|---|
grid
|
Grid power series (positive import), or
TYPE:
|
production
|
Production power series (PSC-convention), or
TYPE:
|
consumption
|
Consumption power series (PSC-convention), or
TYPE:
|
battery
|
Battery power (PSC-convention: charging positive), or
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Series
|
Series with non-negative grid import values. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If neither a grid series nor any of production, consumption, or battery series are provided. |
Source code in frequenz/lib/notebooks/reporting/metrics/reporting_metrics.py
frequenz.lib.notebooks.reporting.metrics.reporting_metrics.grid_feed_in ¤
grid_feed_in(
production: Series,
consumption: Series,
battery: Series,
production_is_positive: bool = False,
) -> Series
Calculate the portion of excess production fed into the grid.
Subtracts the amount of excess energy stored in the battery from the total production surplus to determine how much is exported to the grid.
| PARAMETER | DESCRIPTION |
|---|---|
production
|
Series of production values (e.g., kW or MW).
TYPE:
|
consumption
|
Series of consumption values (same units as
TYPE:
|
battery
|
Series representing the battery's available charging capacity.
TYPE:
|
production_is_positive
|
Whether production values are already positive. If False,
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Series
|
A Series representing power or energy fed into the grid (≥ 0). |
Source code in frequenz/lib/notebooks/reporting/metrics/reporting_metrics.py
frequenz.lib.notebooks.reporting.metrics.reporting_metrics.production_excess ¤
production_excess(
production: Series,
consumption: Series,
production_is_positive: bool = False,
) -> Series
Compute the excess production relative to consumption.
Calculates surplus by subtracting consumption from production and removing negative results. Production is optionally sign-corrected first.
| PARAMETER | DESCRIPTION |
|---|---|
production
|
Series of production values (e.g., kW or MW).
TYPE:
|
consumption
|
Series of consumption values (same units as
TYPE:
|
production_is_positive
|
Whether production values are already positive.
If False,
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Series
|
A Series representing excess production (≥ 0). |
Source code in frequenz/lib/notebooks/reporting/metrics/reporting_metrics.py
frequenz.lib.notebooks.reporting.metrics.reporting_metrics.production_excess_in_bat ¤
production_excess_in_bat(
production: Series,
consumption: Series,
battery: Series,
production_is_positive: bool = False,
) -> Series
Calculate the portion of excess production stored in the battery.
Compares available production surplus with the battery's charging capability at each timestamp and takes the elementwise minimum.
| PARAMETER | DESCRIPTION |
|---|---|
production
|
Series of production values (e.g., kW or MW).
TYPE:
|
consumption
|
Series of consumption values (same units as
TYPE:
|
battery
|
Series representing the battery's available charging capacity or power limit at each timestamp.
TYPE:
|
production_is_positive
|
Whether production values are already positive.
If False,
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Series
|
A Series showing the actual production power stored in the battery. |
Source code in frequenz/lib/notebooks/reporting/metrics/reporting_metrics.py
frequenz.lib.notebooks.reporting.metrics.reporting_metrics.production_self_consumption ¤
production_self_consumption(
production: Series,
consumption: Series,
production_is_positive: bool = False,
) -> Series
Compute the portion of production directly self-consumed.
Calculates the part of total production that is used locally rather than stored or exported, by subtracting excess production from total production.
| PARAMETER | DESCRIPTION |
|---|---|
production
|
Series of production values (e.g., kW or MW).
TYPE:
|
consumption
|
Series of consumption values (same units as
TYPE:
|
production_is_positive
|
Whether production values are already positive.
If False,
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Series
|
A Series representing self-consumed production. |
| WARNS | DESCRIPTION |
|---|---|
UserWarning
|
If negative self-consumption values are detected, indicating that the computed excess exceeds total production for some entries. |
Source code in frequenz/lib/notebooks/reporting/metrics/reporting_metrics.py
frequenz.lib.notebooks.reporting.metrics.reporting_metrics.production_self_share ¤
production_self_share(
production: Series,
consumption: Series,
production_is_positive: bool = False,
) -> Series
Calculate the self-consumption share of total consumption.
Computes the ratio of self-used production to total consumption, representing how much of the consumed energy was covered by own production.
| PARAMETER | DESCRIPTION |
|---|---|
production
|
Series of production values (e.g., kW or MW).
TYPE:
|
consumption
|
Series of consumption values (same units as
TYPE:
|
production_is_positive
|
Whether production values are already positive.
If False,
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Series
|
A Series expressing the self-consumption share (values between 0 and 1). |
Series
|
Returns NaN where consumption is zero. |