Browse Source

added feature: in time scan possibility to average only over one bunch (if and which can be selected in time scan widget)

Miriam Brosi 7 years ago
parent
commit
ba62421d91
2 changed files with 32 additions and 10 deletions
  1. 13 8
      KCG/base/backendinterface.py
  2. 19 2
      KCG/widgets/timingWidget.py

+ 13 - 8
KCG/base/backendinterface.py

@@ -953,7 +953,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):
+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):
     """
     Toggle Timescan.
     :param board_id: id of the board do manipulate
@@ -970,7 +970,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)
+        _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)
 
 
 def _bif_stop_time_scan(board_id, ts_pbar):
@@ -999,7 +999,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):
+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):
     """
     Start the timscan. This starts the timer
     :param board_id: id of the board do manipulate
@@ -1007,10 +1007,11 @@ def _bif_start_time_scan(board_id, c_frm, c_to, f_frm, f_to, timescan_progressba
     :param c_to: To value for coarse scan
     :param f_frm: From value for fine scan
     :param f_to: To value for fine scan
-    :param timescan_progressbar: Handle for the timescanprogressbar
+    :param timescan_progressbar: Handle for the timescan progressbar
     :param plot_func: Function to use to plot the data
     :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 skipfor 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)
     :return: -
     """
     thread = storage.get_board_specific_storage(board_id).setdefault("TimeScanThread", storage.ThreadStorage())
@@ -1055,13 +1056,14 @@ 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):
+        def __init__(self, c_frm, c_to, f_frm, f_to, timescan_progressbar, bucket_to_use):
             super(thread_time_scan, self).__init__()
             self.c_frm = c_frm
             self.c_to = c_to
             self.f_frm = f_frm
             self.f_to = f_to
             self.timescan_progressbar = timescan_progressbar
+            self.bucket_to_use = bucket_to_use
 
         def time_scan(self):
             '''Method to run in the thread that does the timescan'''
@@ -1128,7 +1130,10 @@ def _bif_start_time_scan(board_id, c_frm, c_to, f_frm, f_to, timescan_progressba
                         return
 
                     for adc in range(4):
-                        buckets = data.array[:, adc:adc + 1].reshape(-1)
+                        if self.bucket_to_use is None:
+                            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]
                         if heatmap[adc, f_step, c_step] > maximum[adc, 0]:
                             maximum[adc, 0] = heatmap[adc, f_step, c_step]
@@ -1209,7 +1214,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)
+    tst = thread_time_scan(c_frm, c_to, f_frm, f_to, timescan_progressbar, bucket_to_use)
     thread.register(tst)
     thread.connect('pbarSignal', timescan_progressbar.setValue)
     thread.connect('finished', lambda: finished(timescan_progressbar))

+ 19 - 2
KCG/widgets/timingWidget.py

@@ -370,6 +370,12 @@ class timingPart(kcgw.KCGWidgets):
         self.fine_scan_min_spinbox = self.createSpinbox(0, bif.bk_get_config(board_id, 'chip_delay_max'), start_value=0)
         self.fine_scan_max_spinbox = self.createSpinbox(0, bif.bk_get_config(board_id, 'chip_delay_max'), start_value=bif.bk_get_config(board_id, 'chip_delay_max'))
 
+        self.average_one_bunch_label = self.createLabel(tr("Label", "Average bunch number"))
+        self.average_all_bunches_checkbox = self.createCheckbox(tr("Button", "Average all bunches"), tr("Tooltip", "Average over signal from all bunches for timescan"),
+                                                         checked=True,connect=self.showAverageOneBunch)
+        self.average_one_bunch_spinbox = self.createSpinbox(0, BUNCHES_PER_TURN-1, start_value=0)
+        self.average_one_bunch_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)
 
@@ -396,7 +402,10 @@ class timingPart(kcgw.KCGWidgets):
         self.timeScanLayout.addWidget(self.orbits_observe_spinbox, 3, 2)
         self.timeScanLayout.addWidget(self.createLabel("Orbits to Skip"), 4, 1)
         self.timeScanLayout.addWidget(self.orbits_skip_spinbox, 4, 2)
-        self.timeScanLayout.addWidget(self.time_scan_button, 5, 2)
+        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.setTabOrder(self.fine_scan_max_spinbox, self.time_scan_button)
 
         #  --------[ End Time Scan Part ]-------------
@@ -562,6 +571,13 @@ class timingPart(kcgw.KCGWidgets):
         if not self.adc1CoarseInput.isEnabled():
             board.get_board_config(self.board_id).update('adc_1_delay_individual', -1) # Be careful this does no silent update
 
+    def showAverageOneBunch(self):
+        """
+        Toggle to use an individual bunch for the averaging in the time delay scan or to use all bunches
+        :return: -
+        """
+        self.average_one_bunch_spinbox.setEnabled(not self.average_all_bunches_checkbox.checkState())
+
     def showTimeScan(self):
         """
         Show the time scan part of this window
@@ -605,7 +621,8 @@ class timingPart(kcgw.KCGWidgets):
             self.time_scan_progressbar,
             self.plotWidget.plot,
             orbits_observe = self.orbits_observe_spinbox.value(),
-            orbits_skip = self.orbits_skip_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
         )
 
     def setValueSilent(self, element, value):