energy_fault_detector
The energy-fault-detector package
- class Config(config_filename=None, config_dict=None)[source]
Bases:
BaseConfigConfiguration class. Either config_filename or config_dict must be provided. Reads a yaml file with the anomaly detection configuration and sets corresponding settings.
- property arcana_params: Dict[str, Any]
Get the ARCANA parameters.
- property data_clipping: bool
Whether to clip training data.
- property data_clipping_params: Dict[str, Any]
Data clipping parameters.
- property data_preprocessor_steps: List[Dict[str, Any]]
Get the data preprocessor steps.
- property data_split_params: Dict[str, Any]
DataSplitter or train_test_split parameters.
- property dtype
Data type, float32 by default.
- property fit_threshold_on_val: bool
Whether to fit threshold on validation data only.
- property max_criticality: int | None
Max criticality value.
- property protect_conditional_features: bool
Whether to protect conditional features from being dropped by preprocessing.
- property root_cause_analysis: bool
Whether to run ARCANA.
- class FaultDetector(config=None, model_directory='fault_detector_model')[source]
Bases:
FaultDetectionModelMain class for fault detection in renewable energy assets and power grids.
- Parameters:
config (
Optional[Config]) – Config object with fault detection configuration. Defaults to None. If None, the models need to be loaded from a path using the load_models method.model_directory (
str|Path) – Directory to save models to. Defaults to ‘fault_detector_model’.
- anomaly_score
AnomalyScore object.
- autoencoder
Autoencoder object.
- threshold_selector
ThresholdSelector object.
- data_preprocessor
DataPreprocessorPipeline object.
- save_timestamps
a list of string timestamps indicating when the model was saved.
- fit(sensor_data, normal_index=None, save_models=True, overwrite_models=False, fit_autoencoder_only=False, fit_preprocessor=True, **kwargs)[source]
Fit models on the given sensor_data and save them locally and return the metadata.
- Return type:
- predict(sensor_data, model_path=None, root_cause_analysis=False, track_losses=False, track_bias=False)[source]
Predict with given models for a specific asset
- Parameters:
sensor_data (
DataFrame) – DataFrame with the sensor data of one asset for a specific time window. The timestamp should be the index and the sensor values as columns.model_path (
Optional[str]) – Path to the models to be applied. If None, assumes the attributes data_preprocessor, autoencoder, anomaly_score, and threshold_selector contain fitted instances.root_cause_analysis (
bool) – Whether to run ARCANA. Defaults to False.track_losses (
bool) – Optional; if True, ARCANA losses will be tracked over the iterations. Defaults to False.track_bias (
bool) – Optional; if True, ARCANA bias will be tracked over the iterations. Defaults to False.
- Returns:
- with the following DataFrames:
predicted_anomalies: Series with detected anomalies (bool).
reconstruction: DataFrame with reconstruction of the sensor data with timestamp as index.
recon_error: DataFrame with reconstruction errors.
anomaly_score: Series with anomaly scores for each timestamp.
bias_data: DataFrame with ARCANA results with timestamp as index. None if ARCANA was not run.
arcana_losses: DataFrame containing recorded values for all losses in ARCANA. None if ARCANA was not run.
tracked_bias: List of DataFrames. None if ARCANA was not run.
- Return type:
- predict_anomalies(scores, x_prepped=None)[source]
Predict anomalies based on anomaly scores.
- Return type:
Series
- preprocess_train_data(sensor_data, normal_index, fit_preprocessor=True)[source]
Preprocesses the training data using the configured data_preprocessor.
- Return type:
Tuple[DataFrame,DataFrame,Series]
- run_root_cause_analysis(sensor_data, track_losses=False, track_bias=False)[source]
Run ARCANA
- Parameters:
sensor_data (
DataFrame) – pandas DataFrame containing the sensor data which should be analyzed.track_losses (
bool) – optional bool. If True the arcana losses will be tracked over the iterationstrack_bias (
bool) – optional bool. If True the arcana bias will be tracked over the iterations
- Return type:
Tuple[DataFrame,DataFrame,List[DataFrame]]
- Returns: Tuple of (pd.DataFrame, pd.DataFrame, List[pd.DataFrame])
df_arcana_bias: pandas dataframe containing the arcana bias. arcana_losses: dictionary containing loss names as keys and lists of loss values as values. tracked_bias: list of pandas dataframe containing the arcana bias recorded over the iterations.
- tune(sensor_data, normal_index=None, pretrained_model_path=None, new_learning_rate=0.0001, tune_epochs=10, tune_method='full', save_models=True, overwrite_models=False, data_preprocessor=None)[source]
- FaultDetector finetuning via the following methods:
‘full’ (all autoencoder weights + threshold and anomaly-score scaling will be adapted), ‘decoder’ (only decoder weights + threshold will be adapted), ‘threshold’ (only the threshold and anomaly-score scaling is adapted)
- Notes: Parameters tune_epochs and new_learning_rate should be chosen carefully while considering
potential overfitting issues depending on the similarity of the tuning data and the training data.
- Parameters:
sensor_data (
DataFrame) – DataFrame with the sensor data of one asset for a specific time window. The timestamp should be the index and the sensor values as columns.normal_index (
Optional[Series]) – Series indicating normal behavior as boolean with the timestamp as index. If not provided, it is assumed all data in sensor_data represents normal behaviour. Defaults to None.pretrained_model_path (
Optional[str]) – Path to pretrained model. If None, assumes attributes data_preprocessor, autoencoder, anomaly_score, and threshold_selector contain fitted instances.tune_epochs (
int) – Number of epochs to fine-tune. Defaults to 10.new_learning_rate (
float) – Learning rate to tune the autoencoder with. Defaults to 0.0001.tune_method (
str) – Possible options: ‘full’ (all autoencoder weights + threshold and anomaly-score scaling will be adapted), ‘decoder’ (only decoder weights + threshold will be adapted), ‘threshold’ (only the threshold and anomaly-score scaling is adapted) Defaults to ‘full’.save_models (
bool) – Whether to save models. Defaults to True.overwrite_models (
bool) – If True, existing model directories can be overwritten. Defaults to False.data_preprocessor (
Optional[DataPreprocessor]) – Optional prefitted data preprocessor. Useful when using a generic preprocessor for all models.
- Returns:
metadata of the trained model with model_date, model_path, model reconstruction errors of the training and validation data.
- Return type:
- energy_fault_detector.anomaly_scores
- energy_fault_detector.autoencoders
BidirectionalLSTMSeq2OneAutoencoderCNNAutoencoderCNNSeq2OneAutoencoderConditionalAELSTMSeq2OneAutoencoderLSTMSeqAutoencoderMultilayerAutoencoder- energy_fault_detector.autoencoders.seq2one_autoencoder
- energy_fault_detector.autoencoders.seq2seq_autoencoder
- energy_fault_detector.autoencoders.sequence_autoencoder
- energy_fault_detector.config
- energy_fault_detector.core
AnomalyScoreDataTransformerFaultDetectionResultFaultDetectionResult.anomaly_scoreFaultDetectionResult.arcana_lossesFaultDetectionResult.bias_dataFaultDetectionResult.criticality()FaultDetectionResult.load()FaultDetectionResult.predicted_anomaliesFaultDetectionResult.recon_errorFaultDetectionResult.reconstructionFaultDetectionResult.save()FaultDetectionResult.tracked_bias
ModelMetadataThresholdSelector- energy_fault_detector.core.autoencoder
AutoencoderAutoencoder.is_conditionalAutoencoder.modelAutoencoder.encoderAutoencoder.historyAutoencoder.callbacksAutoencoder.__call__()Autoencoder.compile_model()Autoencoder.create_model()Autoencoder.encode()Autoencoder.epochs_completedAutoencoder.fit()Autoencoder.get_reconstruction_error()Autoencoder.load()Autoencoder.predict()Autoencoder.save()Autoencoder.summary()Autoencoder.tune()Autoencoder.tune_decoder()
split_inputs()
- energy_fault_detector.data_preprocessing
- energy_fault_detector.data_preprocessing.angle_transformer
AngleTransformerAngleTransformer.anglesAngleTransformer.trust_bad_anglesAngleTransformer.fit()AngleTransformer.get_feature_names_out()AngleTransformer.inverse_transform()AngleTransformer.set_fit_request()AngleTransformer.set_inverse_transform_request()AngleTransformer.set_transform_request()AngleTransformer.transform()
- energy_fault_detector.data_preprocessing.column_selector
ColumnSelectorColumnSelector.feature_names_in_ColumnSelector.n_features_in_ColumnSelector.feature_names_out_ColumnSelector.columns_dropped_ColumnSelector.fit()ColumnSelector.get_feature_names_out()ColumnSelector.inverse_transform()ColumnSelector.set_fit_request()ColumnSelector.set_inverse_transform_request()ColumnSelector.set_transform_request()ColumnSelector.transform()
- energy_fault_detector.data_preprocessing.counter_diff_transformer
- energy_fault_detector.data_preprocessing.data_clipper
- energy_fault_detector.data_preprocessing.data_preprocessor
DataPreprocessorDataPreprocessor.NAME_ALIASESDataPreprocessor.STEP_REGISTRYDataPreprocessor.fit()DataPreprocessor.fit_transform()DataPreprocessor.inverse_transform()DataPreprocessor.set_inverse_transform_request()DataPreprocessor.set_score_request()DataPreprocessor.set_transform_request()DataPreprocessor.transform()
- energy_fault_detector.data_preprocessing.duplicate_value_to_nan
DuplicateValuesToNanDuplicateValuesToNan.feature_names_in_DuplicateValuesToNan.feature_names_out_DuplicateValuesToNan.fit()DuplicateValuesToNan.get_feature_names_out()DuplicateValuesToNan.inverse_transform()DuplicateValuesToNan.set_fit_request()DuplicateValuesToNan.set_inverse_transform_request()DuplicateValuesToNan.set_transform_request()DuplicateValuesToNan.transform()
- energy_fault_detector.data_preprocessing.low_unique_value_filter
LowUniqueValueFilterLowUniqueValueFilter.feature_names_in_LowUniqueValueFilter.n_features_in_LowUniqueValueFilter.feature_names_out_LowUniqueValueFilter.columns_dropped_LowUniqueValueFilter.fit()LowUniqueValueFilter.get_feature_names_out()LowUniqueValueFilter.inverse_transform()LowUniqueValueFilter.set_fit_request()LowUniqueValueFilter.set_inverse_transform_request()LowUniqueValueFilter.set_transform_request()LowUniqueValueFilter.transform()
- energy_fault_detector.data_preprocessing.timestamp_transformer
TimestampTransformerTimestampTransformer.__sklearn_is_fitted__()TimestampTransformer.fit()TimestampTransformer.get_feature_names_out()TimestampTransformer.inverse_transform()TimestampTransformer.set_fit_request()TimestampTransformer.set_inverse_transform_request()TimestampTransformer.set_transform_request()TimestampTransformer.transform()
- energy_fault_detector.data_preprocessing.angle_transformer
- energy_fault_detector.data_splitting
- energy_fault_detector.evaluation
- energy_fault_detector.evaluation.care2compare
Care2CompareDatasetCare2CompareDataset.format_event_dataset()Care2CompareDataset.get_event_info()Care2CompareDataset.iter_datasets()Care2CompareDataset.iter_formatted_datasets()Care2CompareDataset.iter_train_datasets_per_asset()Care2CompareDataset.load_and_format_event_dataset()Care2CompareDataset.load_event_dataset()Care2CompareDataset.update_c2c_config()
- energy_fault_detector.evaluation.care_score
CAREScoreCAREScore.calculate_avg_accuracy()CAREScore.calculate_avg_coverage()CAREScore.calculate_avg_earliness()CAREScore.calculate_reliability()CAREScore.create_ground_truth()CAREScore.evaluate_event()CAREScore.evaluated_eventsCAREScore.get_final_score()CAREScore.load_evaluated_events()CAREScore.save_evaluated_events()
- energy_fault_detector.evaluation.predist_dataset
- energy_fault_detector.evaluation.care2compare
- energy_fault_detector.quick_fault_detection
- energy_fault_detector.root_cause_analysis
- energy_fault_detector.threshold_selectors
- energy_fault_detector.utils