瀏覽代碼

fixed bugs: time scan now displays (and returns for click) the correct numbers for coarse and fine delay also in partial scans, enabled auto range for switching between color and line plot.

Miriam Brosi 7 年之前
父節點
當前提交
e4923697d1
共有 2 個文件被更改,包括 38 次插入21 次删除
  1. 2 2
      KCG/base/backendinterface.py
  2. 36 19
      KCG/widgets/timingWidget.py

+ 2 - 2
KCG/base/backendinterface.py

@@ -1072,7 +1072,7 @@ def _bif_start_time_scan(board_id, c_frm, c_to, f_frm, f_to, timescan_progressba
                 storage.storage.orbits_observe_before_timescan[board_id] = board.get_board_config(board_id).get("orbits_observe") # save old values to restore after timescan
                 board.get_board_config(board_id).update("orbits_observe", orbits_observe)
                 bk_change_num_of_orbits(board_id, orbits_observe)
-            if orbits_skip:
+            if orbits_skip is not None:
                 if not hasattr(storage.storage, 'orbits_skip_before_timescan'):
                     storage.storage.orbits_skip_before_timescan = {}
                 storage.storage.orbits_skip_before_timescan[board_id] = board.get_board_config(board_id).get("orbits_skip")
@@ -1174,7 +1174,7 @@ def _bif_start_time_scan(board_id, c_frm, c_to, f_frm, f_to, timescan_progressba
 
 
         m = [np.min(heatmap[heatmap != 0]), np.max(heatmap)]  # this gives the same levels for all 4 adcs
-        plot_func(heatmap, levels=m, newTitle=str(tr("sw", "Coarserange:{c_f}-{c_t} ; Finerange:{f_f}-{f_t}")).format(
+        plot_func(heatmap, levels=m, ranges=[c_frm,c_to,f_frm,f_to], newTitle=str(tr("sw", "Coarserange:{c_f}-{c_t} ; Finerange:{f_f}-{f_t}")).format(
             c_f=c_frm,
             c_t=c_to,
             f_f=f_frm,

+ 36 - 19
KCG/widgets/timingWidget.py

@@ -42,6 +42,8 @@ class timingPlotWidget(kcgw.KCGWidgets):
 
         # ------[ Variable declaration ]------------
         self.plot_type = "colour"  # The Plot Type for this window (Changeable in this window)
+        self.xrange = (None, None)
+        self.yrange = (None, None)
         self.x = None  # Number of Ticks in the x-direction     This is set by the gui programmatically
         self.y = None  # Number of Ticks in the y-direction     This is set by the gui programmatically
         self.data = None  # Data to plot
@@ -116,27 +118,33 @@ class timingPlotWidget(kcgw.KCGWidgets):
         self.adc3.mouseClickEvent = lambda x: self.click("ADC 3", x)
         self.adc4.mouseClickEvent = lambda x: self.click("ADC 4", x)
 
-        def tickStrings(values, scale, spacing):
+        def xtickStrings(values, scale, spacing):
             """
             Generate the strings for ticks
             """
-            if len(values) > 20:
-                return [str(i) for i in range(int(values[0]), int(values[-1]), 2)]
-            else:
-                return [str(int(i)) for i in values]
+            return [str(i + self.xrange[0]) for i in range(int(values[0]), int(values[-1]),int(spacing))]
+
+        def ytickStrings(values, scale, spacing):
+            """
+            Generate the strings for ticks
+            """
+            return [str(int(i) + self.yrange[0]) for i in values]
 
         # ----------[ Configure and add color plots for ADC1 ]----------
 
         for i in range(1, 5):
+            getattr(self, "adc{}_plot_widget".format(i)).enableAutoRange() #axis=getattr(self, "adc{}_plot_widget".format(i)).getViewBox().YAxis)
             getattr(self, "adc{}_plot_widget".format(i)).getPlotItem().setLabel("left", tr("Heading", "Coarse delay"))
             getattr(self, "adc{}_plot_widget".format(i)).getPlotItem().setLabel("bottom", tr("Heading", "Fine delay"))
             getattr(self, "adc{}_plot_widget".format(i)).plotItem.addItem(getattr(self, "adc"+str(i)))
             bax = getattr(self, "adc{}_plot_widget".format(i)).plotItem.getAxis('bottom')
             lax = getattr(self, "adc{}_plot_widget".format(i)).plotItem.getAxis('left')
-            bax.setTickSpacing(levels=[(1, 2.5),])
-            bax.tickStrings = tickStrings
+
+            bax.tickSpacing = self.spacing
+            bax.tickStrings = xtickStrings
             lax.setTickSpacing(levels=[(1, 1.5),])
-            lax.tickStrings = tickStrings
+            lax.tickStrings = ytickStrings
+
 
         pos = np.array([0, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 1])
         color = np.array([[0, 0, 255, 255], [0, 255, 255, 255], [0, 255, 0, 255], [130, 255, 0, 255], [255, 255, 0, 255], [255, 180, 0, 255], [255, 100, 0, 255], [255, 0, 0, 255]])
@@ -166,8 +174,8 @@ class timingPlotWidget(kcgw.KCGWidgets):
         :param spacing: See pyqtgraph.AxisItem.tickStrings
         :return: See pyqtgraph.AxisItem.tickStrings
         """
-        coarses = [i//(self.x) for i in values]
-        fines = [i%(self.x) for i in values]
+        coarses = [self.yrange[0] + i//(self.x) for i in values]
+        fines = [self.xrange[0] + i%(self.x) for i in values]
         return [str(int(c))+"\n"+str(int(f)) for c, f in zip(coarses, fines)]
 
     def spacing(self, minVal, maxVal, size):
@@ -179,10 +187,10 @@ class timingPlotWidget(kcgw.KCGWidgets):
         :param size: See pyqtgraph.AxisItem.tickSpacing
         :return: See pyqtgraph.AxisItem.tickSpacing
         """
-        if maxVal - minVal < 20.:
+        if maxVal - minVal < 10.:
             return [(1, 0),]
         else:
-            return [(round((maxVal-minVal)/20.), 0),]
+            return [(round((maxVal-minVal)/10.), 0),]
 
     def y_axis_strings(self, values, scale, spacing):
         """
@@ -202,10 +210,13 @@ class timingPlotWidget(kcgw.KCGWidgets):
         self.plot_type = "line"
 
         for i in range(1, 5):
+            getattr(self, "adc{}_plot_widget".format(i)).enableAutoRange() #axis=getattr(self, "adc{}_plot_widget".format(i)).getViewBox().YAxis)
             getattr(self, "adc{}_plot_widget".format(i)).getPlotItem().setLabel("left", tr("Heading", "Intensity"))
             getattr(self, "adc{}_plot_widget".format(i)).getPlotItem().setLabel("bottom", tr("Heading", "Coarse over Fine"))
             bax = getattr(self, "adc{}_plot_widget".format(i)).plotItem.getAxis('bottom')
             lax = getattr(self, "adc{}_plot_widget".format(i)).plotItem.getAxis('left')
+
+            bax.setTickSpacing()
             bax.tickSpacing = self.spacing
             bax.tickStrings = self.line_plot_axis_strings
             lax.setTickSpacing()
@@ -234,25 +245,26 @@ class timingPlotWidget(kcgw.KCGWidgets):
         """
         event.accept()
         pos = event.pos()
-        self.position_label.setText(adc + " - " + str(int(pos.x())) + ":"+str(int(pos.y())))
+        self.position_label.setText(adc + " - " + str(int(pos.x())+self.xrange[0]) + ":"+str(int(pos.y())+self.yrange[0]))
         if not self.inputsSet:
             return
 
-        self.c_input.setValue(int(pos.y()))
+        self.c_input.setValue(int(pos.y())+self.yrange[0])
         if adc == "ADC 1":
-            self.adc1_f_input.setValue(int(pos.x()))
+            self.adc1_f_input.setValue(int(pos.x())+self.xrange[0])
         elif adc == "ADC 2":
-            self.adc2_f_input.setValue(int(pos.x()))
+            self.adc2_f_input.setValue(int(pos.x())+self.xrange[0])
         elif adc == "ADC 3":
-            self.adc3_f_input.setValue(int(pos.x()))
+            self.adc3_f_input.setValue(int(pos.x())+self.xrange[0])
         elif adc == "ADC 4":
-            self.adc4_f_input.setValue(int(pos.x()))
+            self.adc4_f_input.setValue(int(pos.x())+self.xrange[0])
 
-    def plot(self, data=None, levels=None, newTitle=None, maxima=None):
+    def plot(self, data=None, levels=None, ranges=None, newTitle=None, maxima=None):
         """
         Plot Data
         :param data: (numpy 4d array) data to plot
         :param levels: (tuple) Min and Max Values for color plot
+        :param ranges: (list) From to range of coarse (y) and fine (x) delay scan
         :param newTitle: (str) The title for the window
         :param maxima: (list) Maximum for each adc
         :return: -
@@ -265,6 +277,10 @@ class timingPlotWidget(kcgw.KCGWidgets):
             self.data = data # if called with no data a replot is performed (if data is set previously)
         if levels is not None:
             self.levels = levels
+        if ranges is not None:
+            self.yrange = ranges[0:2]
+            self.xrange = ranges[2:4]
+
         self.x = self.data.shape[1]
         self.y = self.data.shape[2]
         if self.plot_type == 'colour':
@@ -300,6 +316,7 @@ class timingPlotWidget(kcgw.KCGWidgets):
             self.adc2_plot_widget.plotItem.clear()
             self.adc3_plot_widget.plotItem.clear()
             self.adc4_plot_widget.plotItem.clear()
+
             self.adc1_plot_widget.plotItem.plot(reshape(self.data[0]))
             self.adc2_plot_widget.plotItem.plot(reshape(self.data[1]))
             self.adc3_plot_widget.plotItem.plot(reshape(self.data[2]))