flexmeasures.data.models.forecasting.model_spec_factory
Functions
- flexmeasures.data.models.forecasting.model_spec_factory.configure_regressors_for_nearest_weather_sensor(sensor: Sensor, query_window, horizon, forecast_start, regressor_transformation, transform_to_normal) list[TBSeriesSpecs]
We use weather data as regressors. Here, we configure them.
- flexmeasures.data.models.forecasting.model_spec_factory.create_initial_model_specs(sensor: Sensor, forecast_start: datetime, forecast_end: datetime, forecast_horizon: timedelta, ex_post_horizon: timedelta | None = None, transform_to_normal: bool = True, use_regressors: bool = True, use_periodicity: bool = True, custom_model_params: dict | None = None, time_series_class: type | None = <class 'flexmeasures.data.models.time_series.TimedBelief'>) ModelSpecs
Generic model specs for all asset types (also for markets and weather sensors) and horizons. Fills in training, testing periods, lags. Specifies input and regressor data. Does not fill in which model to actually use. TODO: check if enough data is available both for lagged variables and regressors TODO: refactor assets and markets to store a list of pandas offset or timedelta instead of booleans for
seasonality, because e.g. although solar and building assets both have daily seasonality, only the former is insensitive to daylight savings. Therefore: solar periodicity is 24 hours, while building periodicity is 1 calendar day.
- flexmeasures.data.models.forecasting.model_spec_factory.get_normalization_transformation_from_sensor_attributes(sensor: Sensor) Transformation | None
Transform data to be normal, using the BoxCox transformation. Lambda parameter is chosen according to the asset type.
Classes
- class flexmeasures.data.models.forecasting.model_spec_factory.TBSeriesSpecs(search_params: dict, name: str, time_series_class: type | None = <class 'flexmeasures.data.models.time_series.TimedBelief'>, search_fnc: str = 'search', original_tz: tzinfo | None = <UTC>, feature_transformation: ReversibleTransformation | None = None, post_load_processing: Transformation | None = None, resampling_config: dict[str, ~typing.Any]=None, interpolation_config: dict[str, ~typing.Any]=None)
Compatibility for using timetomodel.SeriesSpecs with timely_beliefs.BeliefsDataFrames.
This implements _load_series such that <time_series_class>.search is called, with the parameters in search_params. The search function is expected to return a BeliefsDataFrame.
- __init__(search_params: dict, name: str, time_series_class: type | None = <class 'flexmeasures.data.models.time_series.TimedBelief'>, search_fnc: str = 'search', original_tz: tzinfo | None = <UTC>, feature_transformation: ReversibleTransformation | None = None, post_load_processing: Transformation | None = None, resampling_config: dict[str, ~typing.Any]=None, interpolation_config: dict[str, ~typing.Any]=None)
- static _collapse_regressor_duplicates(df: DataFrame, issue_time: Timestamp) DataFrame
Keep one belief per event_start with source-aware tie-breaking.
Strategy: - Historical events (< issue_time): prefer source “flex.service”. - Future events (>= issue_time): prefer source “Thiink forecaster”. - Within same preference bucket, keep most recent belief_time.
- static _extract_regressor_policy(search_params: dict[str, Any]) tuple[dict[str, Any], datetime | None]
Return cleaned search params and optional regressor-policy context.
- _load_regressor_beliefs_split_by_issue_time(search_params: dict[str, Any], issue_time: datetime) BeliefsDataFrame
Load regressor beliefs with policy split.
Historical events (< issue_time) have no horizon floor. Future events (>= issue_time) also avoid hard horizon filtering here, so simulation/backfill data remains usable.
- _load_series() Series
Subclasses overwrite this function to get the raw data. This method is responsible to call any post_load_processing at the right place.
- check_data(df: DataFrame)
Raise error if data is empty or contains nan values. Here, other than in load_series, we can show the query, which is quite helpful.