reporting_nb_functions
frequenz.lib.notebooks.reporting.utils.reporting_nb_functions ¤
Utilities for analyzing and summarizing microgrid energy-flow data.
This module contains helper functions for transforming, aggregating, and summarizing power and energy data used throughout the reporting pipeline. It supports component-level analysis, overview table construction, energy summaries, and site-level metric aggregation.
Functions¤
-
build_component_analysis()Produce a tidy (long-format) DataFrame for a specific component type (e.g., Battery, PV, CHP), based on selected component IDs. -
build_overview_df()Select and return only the relevant reporting columns for overview plots, depending on available component types. -
compute_energy_summary()Compute relative distribution among production and grid consumption sources. -
aggregate_metrics()Compute high-level site metrics including production totals, self- consumption energy and share, battery-related flows, grid import and feed-in, and peak grid consumption with localized date.
Usage¤
These functions are typically applied to DataFrames produced by the normalized Energy Report pipeline. Input columns are assumed to represent instantaneous power measurements (in kW) sampled at a known fixed resolution. Energy values (kWh) are derived by multiplying power samples by the sampling interval.
Typical workflow:
1. Build an energy report DataFrame upstream (e.g., via create_energy_report_df).
2. Use build_overview_df to extract relevant columns for dashboards.
3. Use build_component_analysis to analyze per-component contributions.
4. Use compute_energy_summary to generate energy-mix tables.
5. Use aggregate_metrics to calculate site-wide KPIs such as production
totals, self-consumption share, and grid import peaks.
All missing or unavailable columns are treated safely (as zero-valued Series), ensuring resilient operation even with partially populated datasets.
Classes¤
Functions¤
frequenz.lib.notebooks.reporting.utils.reporting_nb_functions.aggregate_metrics ¤
aggregate_metrics(
energy_report_df: DataFrame,
resolution: timedelta,
*,
tz_name: str = "Europe/Berlin"
) -> dict[str, float | None | str]
Aggregate key site-level energy and performance metrics from time-series data.
This function converts instantaneous power measurements (kW) into energy values (kWh) using the given sampling resolution and computes aggregated indicators across all major energy sources: PV, CHP, Wind, Battery, Grid, and total site consumption. It also evaluates self-consumption ratios and determines the peak grid consumption including its calendar date.
| PARAMETER | DESCRIPTION |
|---|---|
energy_report_df
|
DataFrame containing time-series power data (kW). Missing columns are
treated as zero. Expected canonical column names include:
-
TYPE:
|
resolution
|
Sampling interval between measurements (e.g.
TYPE:
|
tz_name
|
Timezone used when reporting the date of the peak grid consumption.
Defaults to
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, float | None | str]
|
dict[str, float | None | str]:
A dictionary of aggregated metrics including:
- |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Notes
- Missing columns are treated as zero-valued Series.
- Peak date is determined from the index label of the maximum grid import.
- Naive timestamps are assumed to be in UTC before timezone conversion.
Source code in frequenz/lib/notebooks/reporting/utils/reporting_nb_functions.py
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 | |
frequenz.lib.notebooks.reporting.utils.reporting_nb_functions.assemble_component_analysis ¤
assemble_component_analysis(
component_filter: list[str],
component_key: str,
component_types: list[str],
energy_report_df: DataFrame,
timestep_hours: float,
mapper: ColumnMapper,
component_label: str,
value_col_name: str,
invert_sign: bool = False,
trunc_values: bool = False,
) -> tuple[DataFrame, float, str]
Assemble a component-level analysis table and compute its energy total.
This function retrieves one or more component columns from the
Energy Report DataFrame (e.g., individual PV strings, batteries, CHP
units), converts them into long-form using build_component_analysis(),
applies display-name mapping, scales values by the timestep duration,
optionally inverts the sign, and returns both the transformed DataFrame
and the aggregated energy.
| PARAMETER | DESCRIPTION |
|---|---|
component_filter
|
List of component selectors. Can contain component numbers
(e.g. |
component_key
|
Component type key (e.g.
TYPE:
|
component_types
|
List of component types present in the Energy Report. |
energy_report_df
|
Source DataFrame containing timestamped component data.
Must include a
TYPE:
|
timestep_hours
|
Sampling interval expressed in hours (e.g.
TYPE:
|
mapper
|
ColumnMapper used to convert column names into display labels.
TYPE:
|
component_label
|
Human-readable label to inject into the melted output
(e.g.,
TYPE:
|
value_col_name
|
Name of the value column in the melted long-format DataFrame.
TYPE:
|
invert_sign
|
Whether to multiply results by
TYPE:
|
trunc_values
|
If
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
|
float
|
|
str
|
|
Notes
- If the component type is not present or the DataFrame lacks a
"timestamp"column, an empty result is returned.
Source code in frequenz/lib/notebooks/reporting/utils/reporting_nb_functions.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
frequenz.lib.notebooks.reporting.utils.reporting_nb_functions.build_component_analysis ¤
build_component_analysis(
energy_report_df: DataFrame,
selection_filter: Iterable[str],
component_label: str,
value_col_name: str,
) -> DataFrame
Build a long-format analysis table for a single component type.
Selects component columns such as "
| PARAMETER | DESCRIPTION |
|---|---|
energy_report_df
|
DataFrame containing timestamped component data with columns named in the
form "
TYPE:
|
selection_filter
|
Iterable defining which components to include: - If any entry equals "All" (case-insensitive), all matching component columns are selected. - Otherwise, entries should be component identifiers such as ["#1", "#3"]. |
component_label
|
The base label used in the component column names and in the resulting identifier column (e.g., "Battery", "CHP", "EV").
TYPE:
|
value_col_name
|
Name of the output column containing the selected component data (e.g., "battery", "chp", "ev").
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
pd.DataFrame:
A long-format DataFrame with columns:
- "timestamp"
- If no matching columns are found, returns an empty DataFrame with the appropriate columns. |
Source code in frequenz/lib/notebooks/reporting/utils/reporting_nb_functions.py
frequenz.lib.notebooks.reporting.utils.reporting_nb_functions.build_overview_df ¤
Return a compact overview subset of the energy report DataFrame.
This function extracts a core set of site-level energy columns together with optional production-related columns, depending on which component types are present (e.g., PV, battery, wind, CHP). Missing columns are ignored safely.
| PARAMETER | DESCRIPTION |
|---|---|
energy_report_df
|
The full energy report DataFrame containing timestamped power data and optionally component-specific production/throughput columns.
TYPE:
|
component_types
|
Iterable of component type identifiers (e.g., {"pv", "battery", "wind"}). Only columns corresponding to these component types are included. |
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
pd.DataFrame:
A subset of Columns that do not exist in the input DataFrame are silently skipped. |
Source code in frequenz/lib/notebooks/reporting/utils/reporting_nb_functions.py
frequenz.lib.notebooks.reporting.utils.reporting_nb_functions.compute_energy_summary ¤
compute_energy_summary(
df: DataFrame,
resolution: timedelta,
include_rollups: bool = False,
drop_zeros: bool = True,
) -> DataFrame
Compute energy totals, average power, and percentage shares for key energy sources.
This function aggregates instantaneous power measurements (kW) over a fixed sampling interval to produce energy statistics (kWh) for major sources such as PV, wind, CHP, and grid consumption. It supports optional roll-ups of total on-site production and configurable filtering of near-zero results.
| PARAMETER | DESCRIPTION |
|---|---|
df
|
Input DataFrame containing instantaneous power columns in kW. Only the
following canonical columns are considered when present and numeric:
-
TYPE:
|
resolution
|
Sampling interval between observations (e.g.
TYPE:
|
include_rollups
|
If
TYPE:
|
drop_zeros
|
If
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
pd.DataFrame:
A summary table with one row per included energy source and columns:
- |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Source code in frequenz/lib/notebooks/reporting/utils/reporting_nb_functions.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 | |