Skip to content
Snippets Groups Projects
Commit cdf9c9e7 authored by Laura Christine Kühle's avatar Laura Christine Kühle
Browse files

Reworked Theoretical method for efficiency.

parent e01ce015
No related branches found
No related tags found
No related merge requests found
...@@ -432,13 +432,12 @@ class Boxplot(WaveletDetector): ...@@ -432,13 +432,12 @@ class Boxplot(WaveletDetector):
class Theoretical(WaveletDetector): class Theoretical(WaveletDetector):
"""Class for troubled-cell detection based on the projection averages and """Class for troubled-cell detection based on theoretical thresholding.
a cutoff factor.
Attributes Attributes
---------- ----------
cutoff_factor : float threshold : float
Cutoff factor above which a cell is considered troubled. Threshold above which a cell is considered troubled.
""" """
def _reset(self, config): def _reset(self, config):
...@@ -453,9 +452,10 @@ class Theoretical(WaveletDetector): ...@@ -453,9 +452,10 @@ class Theoretical(WaveletDetector):
super()._reset(config) super()._reset(config)
# Unpack necessary configurations # Unpack necessary configurations
self._cutoff_factor = config.pop('cutoff_factor', cutoff_factor = config.pop('cutoff_factor',
np.sqrt(2) * self._mesh.cell_len) np.sqrt(2) * self._mesh.cell_len)
# comment to line above: or 2 or 3 self._threshold = cutoff_factor / (
self._mesh.cell_len*self._mesh.num_cells)
def get_cells(self, projection): def get_cells(self, projection):
"""Calculate troubled cells in a given projection. """Calculate troubled cells in a given projection.
...@@ -473,37 +473,9 @@ class Theoretical(WaveletDetector): ...@@ -473,37 +473,9 @@ class Theoretical(WaveletDetector):
""" """
coeffs = self._select_degree(self._calculate_wavelet_coeffs( coeffs = self._select_degree(self._calculate_wavelet_coeffs(
projection)) 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): max_avg = np.sqrt(0.5) * max(1, np.max(np.abs(projection[0])))
if self._is_troubled_cell(coeffs, cell, max_avg): troubled_cells = np.flatnonzero(
troubled_cells.append(cell) np.abs(coeffs)/max_avg > self._threshold).tolist()
return troubled_cells 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment