From 742500c7c42b8c7d0b377b5aeff30d9859d0e78b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?K=C3=BChle=2C=20Laura=20Christine=20=28lakue103=29?=
 <laura.kuehle@uni-duesseldorf.de>
Date: Fri, 16 Sep 2022 00:58:41 +0200
Subject: [PATCH] Combined 'get_cells()' and '_get_cells()'.

---
 DG_Approximation.py       |  4 +++
 Troubled_Cell_Detector.py | 65 ++++++++-------------------------------
 2 files changed, 17 insertions(+), 52 deletions(-)

diff --git a/DG_Approximation.py b/DG_Approximation.py
index bb8d8af..babce4b 100644
--- a/DG_Approximation.py
+++ b/DG_Approximation.py
@@ -16,6 +16,10 @@ TODO: Contemplate saving training data for each IC separately
 TODO: Contemplate removing TrainingDataGenerator class
 TODO: Ask why no fine mesh is used for calculate_coarse_projection()
 
+TODO: Ask the meaning of the shifted bounds in Boxplot (Modified script)
+TODO: Ask whether the indices for the wavelet calculation are i or i+1
+TODO: Ask why wavelet matrix has unset ghost cells
+
 Urgent:
 TODO: Enforce mesh with 2^n cells
 TODO: Change heaviside random to uniform(-100, 100)
diff --git a/Troubled_Cell_Detector.py b/Troubled_Cell_Detector.py
index becf169..3cb1ce1 100644
--- a/Troubled_Cell_Detector.py
+++ b/Troubled_Cell_Detector.py
@@ -8,12 +8,10 @@ TODO: Change method of calculating quartiles -> Done
 TODO: Include overlapping cells in quartile calculation (if needed) -> Done
 TODO: Determine max_value for Theoretical only over highest degree
     -> Done (now optional)
-TODO: Check if indexing in wavelets is correct
-TODO: Combine get_cells() and _get_cells()
-TODO: Add TC condition to only flag cell if left-adjacent one is flagged as
-    well (remove this condition)
-TODO: Check coarse_projection calculation for indexing errors
-TODO: Adjust Boxplot approach (adjacent cells, outer fence, etc.)
+TODO: Check if indexing in wavelets is correct -> Done
+TODO: Combine get_cells() and _get_cells() -> Done
+TODO: Check coarse_projection calculation for indexing errors -> Done
+TODO: Adjust Boxplot approach (adjacent cells, outer fence, etc.) -> Done
 TODO: Give detailed description of wavelet detection
 
 """
@@ -237,24 +235,6 @@ class WaveletDetector(TroubledCellDetector):
         self._wavelet_projection_left, self._wavelet_projection_right \
             = self._basis.multiwavelet_projection
 
-    def get_cells(self, projection):
-        """Calculates troubled cells in a given projection.
-
-        Parameters
-        ----------
-        projection : ndarray
-            Matrix of projection for each polynomial degree.
-
-        Returns
-        -------
-        list
-            List of indices for all detected troubled cells.
-
-        """
-        multiwavelet_coeffs = self._calculate_wavelet_coeffs(projection)
-        multiwavelet_coeffs = self._select_degree(multiwavelet_coeffs)
-        return self._get_cells(multiwavelet_coeffs, projection)
-
     def _calculate_wavelet_coeffs(self, projection):
         """Calculates wavelet coefficients used for projection to coarser grid.
 
@@ -303,25 +283,6 @@ class WaveletDetector(TroubledCellDetector):
             min_values = np.min(wavelet_matrix, axis=0)
             return np.where(-min_values > max_values, min_values, max_values)
 
-    @abstractmethod
-    def _get_cells(self, multiwavelet_coeffs, projection):
-        """Calculates troubled cells using multiwavelet coefficients.
-
-        Parameters
-        ----------
-        multiwavelet_coeffs : ndarray
-            Matrix of multiwavelet coefficients.
-        projection : ndarray
-            Matrix of projection for each polynomial degree.
-
-        Returns
-        -------
-        list
-            List of indices for all detected troubled cells.
-
-        """
-        pass
-
     def _calculate_coarse_projection(self, projection):
         """Calculates coarse projection.
 
@@ -419,23 +380,23 @@ class Boxplot(WaveletDetector):
                     fold * self._fold_len - num_overlapping_cells,
                     (fold+1) * self._fold_len + num_overlapping_cells)])
 
-    def _get_cells(self, coeffs, projection):
-        """Calculate troubled cells using multiwavelet coefficients.
+    def get_cells(self, projection):
+        """Calculate troubled cells in a given projection.
 
         Parameters
         ----------
-        coeffs : ndarray
-            Matrix of multiwavelet coefficients.
         projection : ndarray
             Matrix of projection for each polynomial degree.
 
         Returns
         -------
         list
-            List of indices of all detected troubled cells.
+            List of indices for all detected troubled cells.
 
         """
         # Determine quartiles of folds
+        coeffs = self._select_degree(self._calculate_wavelet_coeffs(
+            projection))
         folds = coeffs[self._fold_indices]
         first_quartiles = np.quantile(folds, 0.25, axis=1,
                                       method=self._quantile_method)
@@ -508,13 +469,11 @@ class Theoretical(WaveletDetector):
                                          np.sqrt(2) * self._mesh.cell_len)
         # comment to line above: or 2 or 3
 
-    def _get_cells(self, coeffs, projection):
-        """Calculates troubled cells using multiwavelet coefficients.
+    def get_cells(self, projection):
+        """Calculate troubled cells in a given projection.
 
         Parameters
         ----------
-        coeffs : ndarray
-            Matrix of multiwavelet coefficients.
         projection : ndarray
             Matrix of projection for each polynomial degree.
 
@@ -524,6 +483,8 @@ class Theoretical(WaveletDetector):
             List of indices for all detected troubled cells.
 
         """
+        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])
-- 
GitLab