DefectDetection module
- DefectDetection.annotate_plots(ax, defs)
Annotate charts with locations of defects
- Parameters
- ax: axis object
plot axis
- defs: dict
defect parameters
- Returns
- None
- DefectDetection.combine_features(feature_list)
Combine all features from different methods into one single dict
- Parameters
- feature_list: list
list containing all entries of input features that need to be concatenated
- Returns
- features: dict
feature dictionary containing all the input features
- DefectDetection.compute_features_grad(mat)
Calculates spatial and temporal gradients
- Parameters
- mat: ndarray
raw data
- Returns
- features_grad: dict
dictionary containing spatial and temporal gradient features
- DefectDetection.compute_features_sd(mat, t_stamps)
Calculates spatial features at every location and time stamp
- Parameters
- mat: ndarray
raw data
- t_stamps: list
time stamps at which time domain features are calculated
- Returns
- features_sd: dict
dictionary containing spatial domain features
- DefectDetection.compute_features_td(mat, t_stamps)
Calculating temporal features at every spatial location
- Parameters
- mat: ndarray
raw data
- t_stamps: list
time stamps at which time domain features are calculated
- Returns
- features_td: dict
dictionary containing time domain features
- DefectDetection.compute_features_wav(mat, t_stamps)
Calculates wavelet transformed features at every location
- Parameters
- mat: ndarray
raw data
- t_stamps: list
time stamps at which wavelet features are calculated
- Returns
- features_wav: dict
dictionary containing wavelet features
- DefectDetection.defect_detection_metrics(mat, mah, iso, s1_2d, s2_2d, defs, t_stamps, t, units, plot=True)
Quantification of defect detection, and plotting the results
True-Positive Rate (TPR), False-Positive Rate (FPR), Receiver Operating Curves (ROC) are calculated for the raw data, Mahalanobis distance and result of Isolation Forest method. In addition, Area Under Curve (AUC) is also calculated to quantify the performance. Often, performance in terms of higher TPR is desired at lower FPR. To aid this, TPR values are calculated at 2%, 5% and 10% FPR. Further, the results are presented graphically if needed.
- Parameters
- mat: ndarray
raw data - 3D float array
- mah: ndarray
result of performing Mahalanobis distance - 3D float array
- iso: ndarray
result of performing Isolation Forest algorithm - 3D float array
- s1_2d: ndarray
2D meshgrid representation of s1 axis
- s2_2d: ndarray
2D meshgrid representation of s2 axis
- defs: dict
defect parameters
- t_stamps: list
time stamps at which features were calculated and where results are desired
- t: list
time coordinates
- units: dict
units of the different dimensions
- plot: Bool
Boolean to indicate if plots are needed to visualize
- Returns
- None
- DefectDetection.define_defects(s1, s2, defs_coord, def_names)
Define coordinates of defects
- Parameters
- s1: list
spatial axis 1
- s2: list
spatial axis 2
- defs_coord: list
list containing all defects - each defect contains a list of tuples containing the vertices of defect
- def_names: dict
dictionary containing the names of defects
- Returns
- defs: dict
dictionary containing all the necessary parameters of all the defined defects
- DefectDetection.fit_isolationforest_model(features, t_stamps, pca_var)
Fit Isolation Forest model
- Parameters
- features: dict
dictionary containing all input features
- t_stamps: list
time stamps at which features were calculated and where results are desired
- pca_var: float
contains the desired explained variance parameter, if less than 1.0, PCA will be performed
- Returns
- iso: ndarray
result of Isolation Forest model over the data
- DefectDetection.main()
All the subroutines will be called from here
- DefectDetection.mean_filter(mat, t, s1, s2, units, size, plot_sample)
Performs mean filtering at each location
- Parameters
- mat: ndarray
raw data
- t: list
time axis
- s1: list
spatial axis 1
- s2: list
spatial axis 2
- units: dict
units of the different dimensions
- size: int
number of elements to use in the mean filter. The higher, the more aggresive the filtering
- plot_sample: Bool
Boolean to indicate if time series plots are needed to compare raw and filtered data
- Returns
- filt_mat: ndarray
mean filtered raw data based on kernel size
- DefectDetection.normalize_features(features, t_stamps)
Normalize features
- Parameters
- features: dict
dictionary containing all input features
- t_stamps: list
time stamps at which features were calculated and where results are desired
- Returns
- features: dict
dictionary containing all normalized features
- DefectDetection.outlier_mah(features, t_stamps, pca_var)
Mahalanobis distance to identify outliers
- Parameters
- features: dict
dictionary containing all input features
- t_stamps: list
time stamps at which features were calculated and where results are desired
- pca_var: float
contains the desired explained variance parameter, if less than 1.0, PCA will be performed
- Returns
- mah: ndarray
contains the result of computing Mahalanobis distance over the data
- DefectDetection.read_matlab_data(dataset, table)
Reads in raw matlab data using scipy IO modules
- Parameters
- dataset: ndarray
name of the Matlab dataset
- table: str
name of table within Matlab
- Returns
- mat: ndarray
matlab data that has been converted to numpy array
- DefectDetection.scale_frames(arr, t_stamps)
Scale frames between 0-1 for better interpretability
- Parameters
- arr: ndarray
input array that needs to be scaled
- t_stamps: list
time stamps at which features were calculated and where results are desired
- Returns
- outarr: ndarray
scaled array where the elements lie between 0-1
- DefectDetection.visualize_features(mat, features, s1_2d, s2_2d, feature, t_idx, t, units)
Visualize computed features
- Parameters
- mat: ndarray
raw data
- features: dict
dictionary containing input features
- s1_2d: ndarray
2D meshgrid representation of s1 axis
- s2_2d: ndarray
2D meshgrid representation of s2 axis
- feature: str
desired feature that needs to be visualized
- t_idx: int
time index at which visualization is needed
- units: dict
units of the different dimensions
- Returns
- None
- DefectDetection.visualize_spatial_data(mat, t, s1_2d, s2_2d, t_min_idx, t_max_idx, del_t_idx, units)
Visualize spatial slices of data at certain time stamps
- Parameters
- mat: ndarray
raw data
- t: list
time axis
- s1_2d: ndarray
2D meshgrid representation of s1 axis
- s2_2d: ndarray
2D meshgrid representation of s2 axis
- t_min_idx: int
lower bound time index for visualization
- t_max_idx: int
upper bound time index for visualization
- del_t_idx: int
time index steps for visualization
- units: dict
units of the different dimensions
- Returns
- None
- DefectDetection.visualize_time_series(mat, t, s1, s2, units)
Pick 4 random spatial coordinates and chart the time-series
- Parameters
- mat: ndarray
raw data
- t: list
time axis
- s1: list
spatial axis 1
- s2: list
spatial axis 2
- units: dict
units of the different dimensions
- Returns
- None