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: feature dictionary containing all the input features
- Return type
dict
-
DefectDetection.
compute_features_grad
(mat)¶ Calculates spatial and temporal gradients
- Parameters
mat (ndarray) – raw data
- Returns
features_grad: dictionary containing spatial and temporal gradient features
- Return type
dict
-
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: dictionary containing spatial domain features
- Return type
dict
-
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: dictionary containing time domain features
- Return type
dict
-
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: dictionary containing wavelet features
- Return type
dict
-
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: dictionary containing all the necessary parameters of all the defined defects
- Return type
dict
-
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: result of Isolation Forest model over the data
- Return type
ndarray
-
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: mean filtered raw data based on kernel size
- Return type
ndarray
-
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: dictionary containing all normalized features
- Return type
dict
-
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: contains the result of computing Mahalanobis distance over the data
- Return type
ndarray
-
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: matlab data that has been converted to numpy array
- Return type
ndarray
-
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: scaled array where the elements lie between 0-1
- Return type
ndarray
-
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