flexmeasures.data.models.reporting.pandas_reporter

Classes

class flexmeasures.data.models.reporting.pandas_reporter.PandasReporter(config: dict | None = None, save_config=True, save_parameters=False, **kwargs)

This reporter applies a series of pandas methods on

_apply_transformations()

Convert the series using the given list of transformation specs, which is called in the order given.

Each transformation specs should include a ‘method’ key specifying a method name of a Pandas DataFrame.

Optionally, ‘args’ and ‘kwargs’ keys can be specified to pass on arguments or keyword arguments to the given method.

All data exchange is made through the dictionary self.data. The superclass Reporter already fetches BeliefsDataFrames of the sensors and saves them in the self.data dictionary fields sensor_<sensor_id>. In case you need to perform complex operations on dataframes, you can split the operations in several steps and saving the intermediate results using the parameters df_input and df_output for the input and output dataframes, respectively.

Example:

The example below converts from hourly meter readings in kWh to electricity demand in kW.
transformations = [

{“method”: “diff”}, {“method”: “shift”, “kwargs”: {“periods”: -1}}, {“method”: “head”, “args”: [-1]},

],

_clean_belief_dataframe(bdf: tb.BeliefsDataFrame, belief_time: datetime | None = None, belief_horizon: timedelta | None = None) tb.BeliefsDataFrame

Add missing indexes to build a proper BeliefDataFrame.

_clean_belief_series(belief_series: tb.BeliefsSeries, belief_time: datetime | None = None, belief_horizon: timedelta | None = None) tb.BeliefsDataFrame

Create a BeliefDataFrame from a BeliefsSeries creating the necessary indexes.

_compute_report(**kwargs) list[dict[str, Any]]

This method applies the transformations and outputs the dataframe defined in final_df_output field of the report_config.

_parameters_schema: Schema | None = <PandasReporterParametersSchema(many=False)>
_process_pandas_args(args: list, method: str) list

This method applies the function get_object_or_literal to all the arguments to detect where to replace a string “@<object-name>” with the actual object stored in self.data[“<object-name>”].

_process_pandas_kwargs(kwargs: dict, method: str) dict

This method applies the function get_object_or_literal to all the keyword arguments to detect where to replace a string “@<object-name>” with the actual object stored in self.data[“<object-name>”].

fetch_data(start: datetime, end: datetime, input: dict, resolution: timedelta | None = None, belief_time: datetime | None = None)

Fetches the time_beliefs from the database

get_object_or_literal(value: Any, method: str) Any

This method allows using the dataframes as inputs of the Pandas methods that are run in the transformations. Make sure that they have been created before accessed.

This works by putting the symbol @ in front of the name of the dataframe that we want to reference. For instance, to reference the dataframe test_df, which lives in self.data, we would do @test_df.

This functionality is disabled for methods eval`and `query to avoid interfering their internal behaviour given that they also use @ to allow using local variables.

Example: >>> self.get_object_or_literal([“@df_wind”, “@df_solar”], “sum”) [<BeliefsDataFrame for Wind Turbine sensor>, <BeliefsDataFrame for Solar Panel sensor>]