class flexmeasures.data.models.data_sources.DataGenerator(config: dict | None = None, save_config=True, save_parameters=False, **kwargs)
__init__(config: dict | None = None, save_config=True, save_parameters=False, **kwargs) None

Base class for the Schedulers, Reporters and Forecasters.

The configuration config stores static parameters, parameters that, if changed, trigger the creation of a new DataSource. Dynamic parameters, such as the start date, can go into the parameters. See docstring of the method DataGenerator.compute for more details. Nevertheless, the parameter save_parameters can be set to True if some parameters need to be saved to the DB. In that case, the method _clean_parameters is called to remove any field that is not to be persisted, e.g. time parameters which are already contained in the TimedBelief.

Create a new DataGenerator with a certain configuration. There are two alternatives to define the parameters:

  1. Serialized through the keyword argument config.

  2. Deserialized, passing each parameter as keyword arguments.

The configuration is validated using the schema _config_schema, to be defined by the subclass.

config cannot contain the key config at its top level, otherwise it could conflict with the constructor keyword argument config when passing the config as deserialized attributes.


The configuration requires two parameters for the PV and consumption sensors.

Option 1:
dg = DataGenerator(config = {

“sensor_pv” : 1, “sensor_consumption” : 2


Option 2:

sensor_pv = Sensor.query.get(1) sensor_consumption = Sensor.query.get(2)

dg = DataGenerator(sensor_pv = sensor_pv,

sensor_consumption = sensor_consumption)

  • config – serialized config parameters, defaults to None

  • save_config – whether to save the config into the data source attributes

  • save_parameters – whether to save the parameters into the data source attributes

_clean_parameters(parameters: dict) dict

Use this function to clean up the parameters dictionary from the fields that are not to be persisted to the DB as data source attributes (when save_parameters=True), e.g. because they are already stored as TimedBelief properties, or otherwise.


An DataGenerator has the following parameters: [“start”, “end”, “field1”, “field2”] and we want just “field1” and “field2” to be persisted.

Parameters provided to the compute method (input of the method _clean_parameters): parameters = {

“start” : “2023-01-01T00:00:00+02:00”, “end” : “2023-01-02T00:00:00+02:00”, “field1” : 1, “field2” : 2


Parameters persisted to the DB (output of the method _clean_parameters): parameters = {“field1” : 1,”field2” : 2}

compute(parameters: dict | None = None, **kwargs) list[dict[str, Any]]

The configuration parameters stores dynamic parameters, parameters that, if changed, DO NOT trigger the creation of a new DataSource. Static parameters, such as the topology of an energy system, can go into config.

parameters cannot contain the key parameters at its top level, otherwise it could conflict with keyword argument parameters of the method compute when passing the parameters as deserialized attributes.


parameters – serialized parameters parameters, defaults to None

property data_source: DataSource

DataSource property derived from the source_info: source_type (scheduler, forecaster or reporter), model (e.g AggregatorReporter) and attributes. It looks for a data source in the database the marges the source_info and, in case of not finding any, it creates a new one. This property gets created once and it’s cached for the rest of the lifetime of the DataGenerator object.

classmethod get_data_source_info() dict

Create and return the data source info, from which a data source lookup/creation is possible.

See for instance get_data_source_for_job().

class flexmeasures.data.models.data_sources.DataSource(name=None, type=None, user=None, attributes=None, **kwargs)

Each data source is a data-providing entity.

__init__(name=None, type=None, user=None, attributes=None, **kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

property description

Extended description

For example:

>>> DataSource("Seita", type="forecaster", model="naive", version="1.2").description
<<< "Seita's naive model v1.2.0"
get_attribute(attribute: str, default: Any | None = None) Any

Looks for the attribute in the DataSource’s attributes column.

property label

Human-readable label (preferably not starting with a capital letter, so it can be used in a sentence).

name: str