energy_fault_detector.utils.analysis

Analysis utility functions

calculate_criticality(anomalies, normal_idx=None, init_criticality=0, max_criticality=1000)

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 (pd.Series) – A pandas Series with boolean values indicating whether an anomaly was detected, indexed by timestamp.

  • normal_idx (pd.Series, optional) – A pandas Series with boolean values indicating normal operation, indexed by timestamp.

  • init_criticality (int, optional) – The initial criticality value. Defaults to 0.

  • max_criticality (int, optional) – The maximum criticality value. Defaults to 1000.

Returns:

A pandas Series representing the criticality over time, indexed by timestamp.

Return type:

pd.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)

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.

Parameters:
  • sensor_data (pd.DataFrame) – A DataFrame with a timestamp as index and numerical sensor data.

  • boolean_information (pd.Series) – A Series with a timestamp as index and boolean values indicating events.

  • min_event_length (int, optional) – The smallest number of consecutive True timestamps needed to define an event. Defaults to 10.

Returns:

A tuple containing:
  • event_meta_data (pd.DataFrame): A DataFrame with columns ‘start’, ‘end’, and ‘duration’ for each event.

  • event_data (List[pd.DataFrame]): A list of DataFrames corresponding to the sensor data during the defined events.

Return type:

Tuple[pd.DataFrame, List[pd.DataFrame]]