data_fetch
frequenz.lib.notebooks.solar.maintenance.data_fetch ¤
Dedicated to data retrieval functionalities for the solar maintenance project.
This module provides functions that fetch and transform data from the weather and reporting APIs or csv files.
Classes¤
frequenz.lib.notebooks.solar.maintenance.data_fetch.BaseRetrievalConfig
dataclass
¤
Base configuration for data retrieval.
Source code in frequenz/lib/notebooks/solar/maintenance/data_fetch.py
frequenz.lib.notebooks.solar.maintenance.data_fetch.ReportingRetrievalConfig
dataclass
¤
Bases: BaseRetrievalConfig
Configuration for retrieving reporting data.
Source code in frequenz/lib/notebooks/solar/maintenance/data_fetch.py
frequenz.lib.notebooks.solar.maintenance.data_fetch.WeatherRetrievalConfig
dataclass
¤
Bases: BaseRetrievalConfig
Configuration for retrieving weather data.
Source code in frequenz/lib/notebooks/solar/maintenance/data_fetch.py
Functions¤
frequenz.lib.notebooks.solar.maintenance.data_fetch._convert_to_timezone ¤
Convert timestamp to the given timezone.
Timestamps are numpy.datetime64 (timezone-naive) and in UTC by default.
PARAMETER | DESCRIPTION |
---|---|
data
|
The reporting data.
TYPE:
|
time_zone
|
The timezone to convert the timestamps to.
TYPE:
|
verbose
|
A boolean flag to print additional information.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DataFrame
|
The reporting data with the timestamp converted to the given timezone. |
Source code in frequenz/lib/notebooks/solar/maintenance/data_fetch.py
frequenz.lib.notebooks.solar.maintenance.data_fetch._handle_outliers ¤
_handle_outliers(
data: DataFrame,
params: dict[
str, str | tuple[float, float] | dict[str, Any]
],
power_column_labels: list[str],
verbose: bool,
) -> DataFrame
Handle outlier detection.
PARAMETER | DESCRIPTION |
---|---|
data
|
The reporting data.
TYPE:
|
params
|
Dictionary of parameters for outlier detection. |
power_column_labels
|
List of power column labels. |
verbose
|
A boolean flag to print additional information.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DataFrame
|
The reporting data after outlier detection and replacement. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the bounds, method, or method_params are not of the expected type. |
Source code in frequenz/lib/notebooks/solar/maintenance/data_fetch.py
frequenz.lib.notebooks.solar.maintenance.data_fetch._pivot_and_aggregate_data ¤
_pivot_and_aggregate_data(
data: DataFrame,
microgrid_components: list[tuple[int, list[int]]],
) -> tuple[DataFrame, dict[str, str]]
Pivot and aggregate data based on microgrid components.
PARAMETER | DESCRIPTION |
---|---|
data
|
The reporting data.
TYPE:
|
microgrid_components
|
List of microgrid-component ID pairs. |
RETURNS | DESCRIPTION |
---|---|
tuple[DataFrame, dict[str, str]]
|
The pivoted and aggregated data and a dictionary of power columns. |
Source code in frequenz/lib/notebooks/solar/maintenance/data_fetch.py
frequenz.lib.notebooks.solar.maintenance.data_fetch.retrieve_data
async
¤
retrieve_data(
config: (
WeatherRetrievalConfig | ReportingRetrievalConfig
),
) -> DataFrame
Retrieve data from the weather or reporting API or from a file.
PARAMETER | DESCRIPTION |
---|---|
config
|
The configuration object for data retrieval containing all necessary parameters. See WeatherRetrievalConfig and ReportingRetrievalConfig. |
RETURNS | DESCRIPTION |
---|---|
DataFrame
|
A pandas DataFrame containing the retrieved data. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
|
TypeError
|
If an unknown configuration type is provided. |
Source code in frequenz/lib/notebooks/solar/maintenance/data_fetch.py
frequenz.lib.notebooks.solar.maintenance.data_fetch.transform_reporting_data ¤
transform_reporting_data(
data: DataFrame,
microgrid_components: (
list[tuple[int, list[int]]] | None
) = None,
outlier_detection_params: (
dict[
str, str | tuple[float, float] | dict[str, Any]
]
| None
) = None,
time_zone: ZoneInfo = ZoneInfo("UTC"),
verbose: bool = False,
) -> DataFrame
Transform weather reporting data.
Note: This wrapper function expects the timestamps to be in UTC and converts them to the provided timezone.
PARAMETER | DESCRIPTION |
---|---|
data
|
The reporting data.
TYPE:
|
microgrid_components
|
List of microgrid-component ID pairs. If provided, the data is assumed to come from the reporting api and is subsequently pivoted and aggregated based on the microgrid components. |
outlier_detection_params
|
Dictionary of parameters for outlier detection.
TYPE:
|
time_zone
|
The timezone to convert the timestamps to. Should be a valid zoneinfo.ZoneInfo object. |
verbose
|
A boolean flag to print additional information.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DataFrame
|
The transformed reporting data. |
Source code in frequenz/lib/notebooks/solar/maintenance/data_fetch.py
frequenz.lib.notebooks.solar.maintenance.data_fetch.transform_weather_data ¤
transform_weather_data(
data: DataFrame,
weather_feature_names_mapping: dict[str, str],
time_zone: ZoneInfo = ZoneInfo("UTC"),
verbose: bool = False,
) -> DataFrame
Transform weather forecast data.
PARAMETER | DESCRIPTION |
---|---|
data
|
The weather forecast data.
TYPE:
|
weather_feature_names_mapping
|
Mapping of weather API feature names to internal feature names. |
time_zone
|
The timezone to convert the timestamps to. Should be a valid zoneinfo.ZoneInfo object. |
verbose
|
A boolean flag to print additional information.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DataFrame
|
The transformed weather forecast data. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If missing or invalid date entries are found in 'validity_ts'. |