diff --git a/scripts/tcd/Troubled_Cell_Detector.py b/scripts/tcd/Troubled_Cell_Detector.py index c84e2820407940cf59666efde8bba57928bee1f7..dab248add77ad31d436f195ab40b7920bc91a39c 100644 --- a/scripts/tcd/Troubled_Cell_Detector.py +++ b/scripts/tcd/Troubled_Cell_Detector.py @@ -432,13 +432,12 @@ class Boxplot(WaveletDetector): class Theoretical(WaveletDetector): - """Class for troubled-cell detection based on the projection averages and - a cutoff factor. + """Class for troubled-cell detection based on theoretical thresholding. Attributes ---------- - cutoff_factor : float - Cutoff factor above which a cell is considered troubled. + threshold : float + Threshold above which a cell is considered troubled. """ def _reset(self, config): @@ -453,9 +452,10 @@ class Theoretical(WaveletDetector): super()._reset(config) # Unpack necessary configurations - self._cutoff_factor = config.pop('cutoff_factor', - np.sqrt(2) * self._mesh.cell_len) - # comment to line above: or 2 or 3 + cutoff_factor = config.pop('cutoff_factor', + np.sqrt(2) * self._mesh.cell_len) + self._threshold = cutoff_factor / ( + self._mesh.cell_len*self._mesh.num_cells) def get_cells(self, projection): """Calculate troubled cells in a given projection. @@ -473,37 +473,9 @@ class Theoretical(WaveletDetector): """ coeffs = self._select_degree(self._calculate_wavelet_coeffs( projection)) - troubled_cells = [] - max_avg = np.sqrt(0.5) \ - * max(1, max(abs(projection[0][cell+1]) - for cell in range(self._mesh.num_cells))) - for cell in range(self._mesh.num_cells): - if self._is_troubled_cell(coeffs, cell, max_avg): - troubled_cells.append(cell) + max_avg = np.sqrt(0.5) * max(1, np.max(np.abs(projection[0]))) + troubled_cells = np.flatnonzero( + np.abs(coeffs)/max_avg > self._threshold).tolist() return troubled_cells - - def _is_troubled_cell(self, coeffs, cell, max_avg): - """Checks whether a cell is troubled. - - Parameters - ---------- - coeffs : ndarray - Matrix of multiwavelet coefficients. - cell : int - Index of cell. - max_avg : float - Maximum average of projection. - - Returns - ------- - bool - Flag whether cell is troubled. - - """ - max_value = abs(coeffs[cell])/max_avg - eps = self._cutoff_factor\ - / (self._mesh.cell_len*self._mesh.num_cells) - - return max_value > eps