models
frequenz.lib.notebooks.solar.maintenance.models ¤
This module contains the functions to prepare prediction models.
The main function prepare_prediction_models
prepares prediction models based
on the provided specifications. The function takes the time series data with
timestamps as the index, a dictionary containing model labels as keys and their
corresponding specifications as values, and a list of model labels to extract
from the model specifications. It returns a dictionary with model labels as keys
and dictionaries containing the predictions as values. The predictions are stored
as pandas Series with the same index as the input data and the name 'predictions'.
Functions¤
frequenz.lib.notebooks.solar.maintenance.models.naive_efficiency_factor_irr_to_power ¤
naive_efficiency_factor_irr_to_power(
data: DataFrame,
*,
col_label: str,
eff: float,
peak_power_watts: float,
rated_power_watts: float,
resample_rate: (
str | DateOffset | Timedelta | None
) = None
) -> SeriesFloat
Compute the predicted power output based on the solar radiation data.
Uses a naive approach in which one efficiency factor is used to model all inefficiencies in the system. The efficiency factor is applied to the solar radiation data and scaled by the peak power to compute the power output. The power output is then clipped to the rated power of the inverter(s).
PARAMETER | DESCRIPTION |
---|---|
data
|
The input time series data.
TYPE:
|
col_label
|
The column label containing the solar radiation data.
TYPE:
|
eff
|
The efficiency factor value.
TYPE:
|
peak_power_watts
|
The total peak power of the solar system in watts.
TYPE:
|
rated_power_watts
|
The total rated power of the inverters in watts.
TYPE:
|
resample_rate
|
The rate at which to resample the data.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
SeriesFloat
|
A pandas Series containing the predicted power (in kilo-Watts) output. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the input dataframe contains duplicate index entries. |
Source code in frequenz/lib/notebooks/solar/maintenance/models.py
frequenz.lib.notebooks.solar.maintenance.models.prepare_prediction_models ¤
prepare_prediction_models(
data: DataFrame,
model_specs: dict[str, ModelSpec],
keys_to_extract: list[str],
) -> dict[str, dict[str, SeriesFloat]]
Prepare prediction models based on the provided specifications.
PARAMETER | DESCRIPTION |
---|---|
data
|
The time series data with timestamps as the index.
TYPE:
|
model_specs
|
A dictionary containing model labels as keys and their corresponding specifications as values (a dictionary). Each specification dictionary contains: - 'model': A string or a callable representing the identifier or the model function respectively. Currently, 4 models are supported, with the following identifiers: - 'wma' for weighted moving average. - 'sampled_ma' for sampled moving average. - 'naive_eff_irr2power' for naive efficiency factor model. - 'pvlib' for running a simulation using PVLib. - 'target_label': An optional string representing the column label to be used for processing. If None, the entire input data will be used. - 'resample_params': An optional tuple containing resampling parameters (rule, aggregation function) to be passed to pd.Series.resample. If None, no resampling will be performed. - 'model_params': A dictionary containing parameters to be passed to the model function. |
keys_to_extract
|
A list of model labels to extract from the model_specs. |
RETURNS | DESCRIPTION |
---|---|
dict[str, dict[str, SeriesFloat]]
|
A dictionary with model labels as keys and dictionaries containing the |
dict[str, dict[str, SeriesFloat]]
|
predictions as values. The predictions are stored as pandas Series with |
dict[str, dict[str, SeriesFloat]]
|
the same index as the input data and the name 'predictions'. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If a specified model is not supported or if the target_label is not of type ColumnLabel or if the resample_params is not of type ResampleParams or if the model_params is not of type ModelParams. |
Example:
example set up of model_specs¤
model_specs = { '7-day MA': { "model": "wma", 'target_label': "energy_kWh", "resample_params": ("D", "sum"), "model_params": {"mode": "uniform", "win_size": 7} }, '7-day MA - 15min': { "model": "sampled_ma", 'target_label': "power_kW", "resample_params": ("15min", "sum"), "model_params": {"window": pd.Timedelta(days=7), "sampling_interval": 96} }, }
Source code in frequenz/lib/notebooks/solar/maintenance/models.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 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 |
|
frequenz.lib.notebooks.solar.maintenance.models.run_pvlib_simulation ¤
run_pvlib_simulation(
data: DataFrame,
*,
location_parameters: dict[str, Any],
pv_system_arrays: list[dict[str, Any]],
inverter_parameters: dict[str, Any],
start_year: int,
end_year: int,
sampling_rate: (
str | DateOffset | Timedelta | None
) = None,
weather_option: str = "tmy",
time_zone: ZoneInfo = ZoneInfo("UTC")
) -> SeriesFloat
Run a PVLib simulation using the provided parameters for a single site.
Note: This is WIP. The PV system set up needs more work to become more general and flexible. The parameters should eventually be exposed to the user. For now they are fixed to east and west arrays so that simulation works as a demo.
PARAMETER | DESCRIPTION |
---|---|
data
|
Placeholder for the input data. Not used in this function.
TYPE:
|
location_parameters
|
A dictionary containing the location parameters with the following keys: - 'latitude': The latitude of the location. - 'longitude': The longitude of the location. - 'altitude': The altitude of the location. - 'timezone': The timezone of the location. - 'name': The name of the location. |
pv_system_arrays
|
A list of dictionaries, each containing the following keys: - 'name': The name of the array. - 'surface_tilt': The tilt angle of the surface in degrees. - 'surface_azimuth': The azimuth angle of the surface in degrees. - 'module': A dictionary containing the module parameters. - 'modules_per_string': The number of modules per string. - 'temperature_parameters': A dictionary containing the temperature model parameters. - 'strings': The number of strings. |
inverter_parameters
|
A dictionary containing the inverter parameters. |
start_year
|
The start year for the simulation.
TYPE:
|
end_year
|
The end year for the simulation.
TYPE:
|
sampling_rate
|
The rate at which to resample the data.
TYPE:
|
weather_option
|
The weather data option to use. Choose one of: - 'tmy': Typical Meteorological Year. Considers at least 10 years in identifying the most typical month for each month. - 'hourly': Get hourly historical solar irradiation and modeled PV power output from PVGIS by specifying the start and end years from which to get the data.
TYPE:
|
time_zone
|
The timezone to convert the index of the returned Series to. Should be a valid zoneinfo.ZoneInfo object. Defaults to 'UTC'. |
RETURNS | DESCRIPTION |
---|---|
SeriesFloat
|
A pandas Series containing the power predictions in Watts. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the specified weather option is not supported. |
Source code in frequenz/lib/notebooks/solar/maintenance/models.py
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 469 470 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 |
|
frequenz.lib.notebooks.solar.maintenance.models.sampled_moving_average ¤
sampled_moving_average(
data: SeriesFloat | DataFrame,
*,
window: Timedelta,
sampling_interval: int,
verbose: bool = False
) -> SeriesFloat
Compute the moving average of a time series.
The moving average is computed over a specified window size, taking samples at specified step intervals within each moving window.
PARAMETER | DESCRIPTION |
---|---|
data
|
The input time series data with timestamps as the index.
TYPE:
|
window
|
The moving window as a pandas Timedelta object.
TYPE:
|
sampling_interval
|
The interval at which to sample the data within each window. Forced to be a positive integer.
TYPE:
|
verbose
|
A boolean flag to print additional information.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
SeriesFloat
|
A pandas Series containing the moving averages, with the same index as |
SeriesFloat
|
the input data. Each value is the average of the samples taken at the |
SeriesFloat
|
specified interval within the moving window and includes the value at |
SeriesFloat
|
the index itself. In order to be used as predictions, one needs to shift |
SeriesFloat
|
the array accordingly so that it aligns with the original data and the |
SeriesFloat
|
prediction (i.e. the moving average) corresponding to the ground truth |
SeriesFloat
|
does not include the ground truth itself. This can be achieved by |
SeriesFloat
|
shifting the Series by sampling_interval. |
Source code in frequenz/lib/notebooks/solar/maintenance/models.py
frequenz.lib.notebooks.solar.maintenance.models.weighted_moving_average ¤
weighted_moving_average(
data: NDArray[float64] | SeriesFloat | DataFrame,
*,
mode: str | None = None,
win_size: int | None = None,
weights: NDArray[float64] | None = None
) -> NDArray[float64]
Perform moving average with different weighting schemes.
PARAMETER | DESCRIPTION |
---|---|
data
|
The input data with datetime index.
TYPE:
|
mode
|
Type of moving average with options: - 'uniform': The same weight is applied to all samples - 'recent': Uses weights of decreasing value for older samples - 'older': Uses weights of increasing value for older samples - 'exp': Uses exponential weights
TYPE:
|
win_size
|
The size of the sliding window.
TYPE:
|
weights
|
The weight values to apply on each sample, defined as [w_t, w_t-1, w_t-2, ...] i.e. the weight of most recent sample comes first. If defined, mode and win_size are ignored.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
NDArray[float64]
|
An array of shape (len(data) - (win_size - 1),). The values correspond |
NDArray[float64]
|
to weighted averages between past win_size - 1 samples and the current |
NDArray[float64]
|
sample. In order to be used as predictions, one needs to shift the array |
NDArray[float64]
|
accordingly so that it aligns with the original data and the prediction |
NDArray[float64]
|
(i.e. the weighted average) corresponding to the ground truth does not |
NDArray[float64]
|
include the ground truth itself. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
|