瀏覽代碼

Introduce Threshold for Timescan Averaging

This only uses Data points which are outside of 2048 +- set value for averaging.
Miriam Brosi 7 年之前
父節點
當前提交
ee88dc3e46
共有 2 個文件被更改,包括 38 次插入8 次删除
  1. 15 6
      KCG/base/backendinterface.py
  2. 23 2
      KCG/widgets/timingWidget.py

+ 15 - 6
KCG/base/backendinterface.py

@@ -954,7 +954,7 @@ def bk_get_temperature(board_id):
 backup_get_temp = bk_get_temperature
 
 
-def bk_time_scan(board_id, c_frm, c_to, f_frm, f_to, ts_pbar, plot_func, orbits_observe=None, orbits_skip=None, bucket_to_use=None):
+def bk_time_scan(board_id, c_frm, c_to, f_frm, f_to, ts_pbar, plot_func, orbits_observe=None, orbits_skip=None, bucket_to_use=None, threshold_counts=None):
     """
     Toggle Timescan.
     :param board_id: id of the board do manipulate
@@ -971,7 +971,7 @@ def bk_time_scan(board_id, c_frm, c_to, f_frm, f_to, ts_pbar, plot_func, orbits_
     if board.get_board_status(board_id).time_scan:
         _bif_stop_time_scan(board_id, ts_pbar)
     else:
-        _bif_start_time_scan(board_id, c_frm, c_to, f_frm, f_to, ts_pbar, plot_func, orbits_observe, orbits_skip, bucket_to_use)
+        _bif_start_time_scan(board_id, c_frm, c_to, f_frm, f_to, ts_pbar, plot_func, orbits_observe, orbits_skip, bucket_to_use, threshold_counts)
 
 
 def _bif_stop_time_scan(board_id, ts_pbar):
@@ -1000,7 +1000,7 @@ def _bif_stop_time_scan(board_id, ts_pbar):
 # thread_ts = None
 
 
-def _bif_start_time_scan(board_id, c_frm, c_to, f_frm, f_to, timescan_progressbar, plot_func, orbits_observe, orbits_skip, bucket_to_use=None):
+def _bif_start_time_scan(board_id, c_frm, c_to, f_frm, f_to, timescan_progressbar, plot_func, orbits_observe, orbits_skip, bucket_to_use=None, threshold_counts=None):
     """
     Start the timscan. This starts the timer
     :param board_id: id of the board do manipulate
@@ -1013,6 +1013,7 @@ def _bif_start_time_scan(board_id, c_frm, c_to, f_frm, f_to, timescan_progressba
     :param orbits_observe: Number of orbits to observe for the timescan (original values will be restored after timescan)
     :param orbits_skip: Number of orbits to skip for the timescan (original values will be restored after timescan)
     :param bucket_to_use: Number of the bucket whos data will be used to calculate the average signal at each timescan step (if None all bunches will be used)
+    :param threshold_counts: Skip buckets with adc counts between 2048 +- threshold_counts
     :return: -
     """
     thread = storage.get_board_specific_storage(board_id).setdefault("TimeScanThread", storage.ThreadStorage())
@@ -1057,7 +1058,7 @@ def _bif_start_time_scan(board_id, c_frm, c_to, f_frm, f_to, timescan_progressba
         stopSignal = QtCore.pyqtSignal()
         finished = QtCore.pyqtSignal()
 
-        def __init__(self, c_frm, c_to, f_frm, f_to, timescan_progressbar, bucket_to_use):
+        def __init__(self, c_frm, c_to, f_frm, f_to, timescan_progressbar, bucket_to_use, threshold_counts):
             super(thread_time_scan, self).__init__()
             self.c_frm = c_frm
             self.c_to = c_to
@@ -1065,6 +1066,7 @@ def _bif_start_time_scan(board_id, c_frm, c_to, f_frm, f_to, timescan_progressba
             self.f_to = f_to
             self.timescan_progressbar = timescan_progressbar
             self.bucket_to_use = bucket_to_use
+            self.threshold_counts = threshold_counts
 
         def time_scan(self):
             '''Method to run in the thread that does the timescan'''
@@ -1132,7 +1134,14 @@ def _bif_start_time_scan(board_id, c_frm, c_to, f_frm, f_to, timescan_progressba
 
                     for adc in range(4):
                         if self.bucket_to_use is None:
-                            buckets = data.array[:, adc]
+                            if self.threshold_counts is not None:
+                                indexes = np.where(np.logical_or(data.array[:, adc] > 2048+self.threshold_counts, data.array[:, adc] < 2048-self.threshold_counts))[0]
+                                if indexes.shape[0] == 0:
+                                    buckets = data.array[:, adc]
+                                else:
+                                    buckets = data.array[indexes, adc]
+                            else:
+                                buckets = data.array[:, adc]
                         else:
                             buckets = data.array[self.bucket_to_use::config.bunches_per_turn, adc]
                         heatmap[adc, f_step, c_step] = float(buckets.sum()) / buckets.shape[0]
@@ -1215,7 +1224,7 @@ def _bif_start_time_scan(board_id, c_frm, c_to, f_frm, f_to, timescan_progressba
 
         return
 
-    tst = thread_time_scan(c_frm, c_to, f_frm, f_to, timescan_progressbar, bucket_to_use)
+    tst = thread_time_scan(c_frm, c_to, f_frm, f_to, timescan_progressbar, bucket_to_use, threshold_counts)
     thread.register(tst)
     thread.connect('pbarSignal', timescan_progressbar.setValue)
     thread.connect('finished', lambda: finished(timescan_progressbar))

+ 23 - 2
KCG/widgets/timingWidget.py

@@ -376,6 +376,12 @@ class timingPart(kcgw.KCGWidgets):
         self.average_one_bunch_spinbox = self.createSpinbox(0, BUNCHES_PER_TURN-1, start_value=0)
         self.average_one_bunch_spinbox.setEnabled(False)
 
+        self.average_threshold_label = self.createLabel(tr("Label", "Averaging Threshold"))
+        self.average_threshold_checkbox = self.createCheckbox(tr("Button", "Use Threshold"), tr("Tooltip", "Average over signal from all bunches that are above/below the specified threshold for timescan"),
+                                                         checked=False,connect=self.considerThreshold)
+        self.average_threshold_spinbox = self.createSpinbox(0, 2048, start_value=0)
+        self.average_threshold_spinbox.setEnabled(False)
+
         self.orbits_observe_spinbox = self.createSpinbox(1, 10000000, start_value=100)
         self.orbits_skip_spinbox = self.createSpinbox(0, 100, start_value=2)
 
@@ -405,7 +411,10 @@ class timingPart(kcgw.KCGWidgets):
         self.timeScanLayout.addWidget(self.average_all_bunches_checkbox, 5, 0)
         self.timeScanLayout.addWidget(self.average_one_bunch_label, 5, 1)
         self.timeScanLayout.addWidget(self.average_one_bunch_spinbox, 5, 2)
-        self.timeScanLayout.addWidget(self.time_scan_button, 6, 2)
+        self.timeScanLayout.addWidget(self.average_threshold_checkbox, 6, 0)
+        self.timeScanLayout.addWidget(self.average_threshold_label, 6, 1)
+        self.timeScanLayout.addWidget(self.average_threshold_spinbox, 6, 2)
+        self.timeScanLayout.addWidget(self.time_scan_button, 7, 2)
         self.setTabOrder(self.fine_scan_max_spinbox, self.time_scan_button)
 
         #  --------[ End Time Scan Part ]-------------
@@ -577,6 +586,17 @@ class timingPart(kcgw.KCGWidgets):
         :return: -
         """
         self.average_one_bunch_spinbox.setEnabled(not self.average_all_bunches_checkbox.checkState())
+        self.average_threshold_spinbox.setEnabled(self.average_all_bunches_checkbox.checkState() and self.average_threshold_checkbox.checkState())
+        self.average_threshold_checkbox.setEnabled(self.average_all_bunches_checkbox.checkState())
+        self.average_threshold_checkbox.setChecked(False)
+
+    def considerThreshold(self):
+        """
+        Toggle to consider the Threshold for the averaging in the time delay scan
+        :return: -
+        """
+        self.average_threshold_spinbox.setEnabled(self.average_threshold_checkbox.checkState() and self.average_all_bunches_checkbox.checkState())
+
 
     def showTimeScan(self):
         """
@@ -622,7 +642,8 @@ class timingPart(kcgw.KCGWidgets):
             self.plotWidget.plot,
             orbits_observe = self.orbits_observe_spinbox.value(),
             orbits_skip = self.orbits_skip_spinbox.value(),
-            bucket_to_use = self.average_one_bunch_spinbox.value() if self.average_one_bunch_spinbox.isEnabled() else None
+            bucket_to_use = self.average_one_bunch_spinbox.value() if self.average_one_bunch_spinbox.isEnabled() else None,
+            threshold_counts = self.average_threshold_spinbox.value() if self.average_threshold_spinbox.isEnabled() else None
         )
 
     def setValueSilent(self, element, value):