energy_fault_detector.utils.analysis
Analysis utility functions
- calculate_criticality(anomalies, normal_idx=None, init_criticality=0, max_criticality=1000)[source]
Calculate criticality based on anomaly detection results. Increases if an anomaly is detected during normal operation, eases if no anomalies are detected during normal operation. If normal_idx is not provided, it is assumed that all detected anomalies occur during normal operation.
- Parameters:
anomalies (
Series) – A pandas Series with boolean values indicating whether an anomaly was detected, indexed by timestamp, or MultiIndex (device_id, timestamp).normal_idx (
Series) – A pandas Series with boolean values indicating normal operation, same index as the anomalies pd.Series.init_criticality (
int) – The initial criticality value. Defaults to 0.max_criticality (
int) – The maximum criticality value. Defaults to 1000.
- Returns:
A pandas Series representing the criticality over time, indexed by timestamp.
- Return type:
Series- Raises:
ValueError – If the lengths of the given pandas Series for anomalies and normal_idx do not match.
- create_events(sensor_data, boolean_information, min_event_length=10)[source]
Create an event DataFrame based on boolean information such as predicted anomalies or a normal index and return a list of event DataFrames intended for further evaluation.
Works with both a simple DatetimeIndex and a MultiIndex as index of
sensor_data. For a MultiIndex, we assume there is exactly one datetime-like level and at most one non-datetime grouping level (e.g. (asset_id, timestamp)) and create events per group.- Parameters:
sensor_data (
DataFrame) – A DataFrame with a timestamp (or MultiIndex including a timestamp) as index and numerical sensor data.boolean_information (
Series) – A Series with the same index (or broadcastable) and boolean values indicating events.min_event_length (
int) – The smallest number of consecutive True timestamps needed to define an event. Defaults to 10.
- Returns:
- A tuple containing:
event_meta_data (pd.DataFrame): Columns ‘start’, ‘end’, ‘duration’ and, for MultiIndex, an additional ‘group’ column with the grouping key.
event_data (List[pd.DataFrame]): A list of DataFrames corresponding to the sensor data during the defined events.
- Return type:
Tuple[DataFrame,List[DataFrame]]