Timeseries
Many ETA Ctrl functions and classes operate on timeseries data and pandas.DataFrame objects
containing timeseries data. The timeseries module in ETA Ctrl provides some additional functionality for both.
It can for example find random time slices in Dataframes or import timeseries data from multiple CSV files and map
a (random if required) section of it into a Dataframe.
ScenarioManager
Scenario data is often required to perform optimizations and simulations of factory systems.
The ScenarioManager class handles provided scenario data via the config file.
It is instantiated by the Config class.
When the use_random_time_slice argument is set to True
- class eta_ctrl.timeseries.scenario_manager.ScenarioManager[source]
Extensions for pandas.DataFrame
Simple helpers for reading timeseries data from a csv file and getting slices or resampled data. This module handles data using pandas dataframe objects.
- eta_ctrl.timeseries.dataframes.df_from_csv(path: Path, *, delimiter: str = ';', infer_datetime_from: InferDatetimeType | Sequence[int] | tuple[int, int] = 'dates', time_conversion_str: str = '%Y-%m-%d %H:%M') pd.DataFrame[source]
Take data from a csv file, process it and return a Timeseries (pandas Data Frame) object.
Open and read the .csv file, perform error checks and ensure that valid float values are obtained. This assumes that the first column is always the date and time column and provides multiple methods to convert this column. It also assumes that the first row is the header row. The header row is converted to lower case and spaces are converted to _. If header values contain special characters, everything starting from the first special character is discarded.
- Parameters:
path – Path to the .csv file.
delimiter – Delimiter used between csv fields.
infer_datetime_from –
Specify how date and time values should be inferred. This can be ‘dates’ or ‘string’ or a tuple/list with two values.
If ‘dates’ is specified, pandas will be used to automatically infer the datetime format from the file.
If ‘string’ is specified, the parameter ‘time_conversion_str’ must specify the string (in python strptime format) to convert datetime values.
If a tuple/list of two values is given, the time format specification (according to python strptime format) will be read from the specified field in the .csv file (‘row’, ‘column’).
time_conversion_str – Time conversion string according to the python (strptime) format.
- eta_ctrl.timeseries.dataframes.round_datetime_to_interval(dt: datetime, interval: float) datetime[source]
Round a datetime object down to match the given interval.
- Parameters:
dt (datetime) – Datetime object to round
interval (float) – Resampling interval
- Returns:
Rounded datetime object
- Return type:
datetime
- eta_ctrl.timeseries.dataframes.df_resample(dataframe: pd.DataFrame, *periods_deltas: TimeStep, missing_data: FillMethod | None = None) pd.DataFrame[source]
Resample the time index of a data frame.
This method can be used for resampling in multiple different periods with multiple different deltas between single time entries.
- Parameters:
df – DataFrame for processing.
periods_deltas – If one argument is specified, this will resample the data to the specified interval in seconds. If more than one argument is specified, they will be interpreted as (periods, interval) pairs. The first argument specifies a number of periods that should be resampled, the second value specifies the interval that these periods should be resampled to. A third argument would determine the next number of periods that should be resampled to the interval specified by the fourth argument and so on.
missing_data – Specify a method for handling missing data values. If this is not specified, missing data will not be handled. Valid methods are: ‘ffill’, ‘bfill’, ‘interpolate’, ‘asfreq’. Default is ‘asfreq’.
- Returns:
Resampled copy of the DataFrame.
- eta_ctrl.timeseries.dataframes.df_interpolate(dataframe: pd.DataFrame, freq: TimeStep, limit_direction: Literal['both', 'forward', 'backward'] = 'both') pd.DataFrame[source]
Interpolate missing values in a DataFrame with a specified frequency. Is able to handle unevenly spaced time series data.
- Parameters:
dataframe – DataFrame for interpolation.
freq – Frequency of the resulting DataFrame.
limit_direction – Direction in which to limit the interpolation. Defaults to “both”.
- Returns:
Interpolated DataFrame.