Browse Source

implement Follow plot

Patrick Schreiber 6 years ago
parent
commit
72f317da15
4 changed files with 34 additions and 9 deletions
  1. 7 1
      KCG/base/backend/dataset.py
  2. 2 2
      KCG/base/backend/io.py
  3. 1 1
      KCG/base/leftbar.py
  4. 24 5
      KCG/base/plotWidget.py

+ 7 - 1
KCG/base/backend/dataset.py

@@ -121,6 +121,13 @@ class DataSet(object):
         pdata = self.array[frm:to, :-1]
         return pdata[:,adc-1]
 
+    def follow(self, adc=1, frm=0, to=-1, bunch=0, **kwargs):
+        """Follow one bunch through time"""
+        # pdata = self.array[frm:to, :-1]
+        pdata = self.array[bunch::BUNCHES_PER_TURN, adc-1]
+        pdata = pdata[frm:to]
+        return pdata
+
     def combined(self, frm=0, to=-1, show_reconstructed=True):
         array = self.array[frm:to, :]
 
@@ -163,4 +170,3 @@ class DataSet(object):
             # axis.plot(xs, ys, '.', alpha=0.3)
             ret.append(np.array([xs, ys]))
         return ret
-

+ 2 - 2
KCG/base/backend/io.py

@@ -42,7 +42,7 @@ def decode_data(data):
         data = data[np.where(data != 0xDEADDEAD)]  # This is the new filling
 
         # Make sure we read multiple of fours
-        data = data[:4 * (math.floor(data.size / 4))]
+        data = data[:int(4 * (math.floor(data.size / 4)))]
 
         bunch_low = data & 0xfff
         bunch_high = np.right_shift(data, 12) & 0xfff
@@ -57,7 +57,7 @@ def decode_data(data):
         result[0::2, 4] = bunch_number[::4]
         result[1::2, 4] = bunch_number[::4] + 1
 
-        result = result[:BUNCHES_PER_TURN * (math.floor(result.shape[0] / BUNCHES_PER_TURN)), :]
+        result = result[:int(BUNCHES_PER_TURN * (math.floor(result.shape[0] / BUNCHES_PER_TURN))), :]
         return result
 
 def data_has_header(data):

+ 1 - 1
KCG/base/leftbar.py

@@ -317,7 +317,7 @@ class LeftBar(kcgw.KCGWidgets):
     # uid = unique_id
     # usid = unique_sub_id
     # upid = unique_parent_id
-    possiblePlots = ["Heatmap", "FFT", "Trains", "Combined", "Compare"]
+    possiblePlots = ["Heatmap", "FFT", "Trains", "Combined", "Compare", "Follow"]
 
     def __init__(self, parent):
         super(LeftBar, self).__init__("LeftBar")

+ 24 - 5
KCG/base/plotWidget.py

@@ -12,6 +12,7 @@ from backend import io
 from backend import board
 from backend.board import available_boards
 import kcgwidget as kcgw
+from .. import config
 
 tr = kcgw.tr
 
@@ -31,7 +32,7 @@ class Enum():
             setattr(self, i, self.idx)
             self.idx += 1
 
-plotList = [tr("Label", "Heatmap"), tr("Label", "FFT"), tr("Label", "Trains"), tr("Label", "Combined"), tr("Label", "Compare")]
+plotList = [tr("Label", "Heatmap"), tr("Label", "FFT"), tr("Label", "Trains"), tr("Label", "Combined"), tr("Label", "Compare"), tr("Label", "Follow")]
 PlotType = Enum(*[str(i) for i in plotList])
 
 # gradient = {'mode': 'rgb',
@@ -333,6 +334,8 @@ class SubPlotWidget(pg.GraphicsLayoutWidget):
         """
         def newAutoRange(*args, **kwargs):
             ''' function to handle the new autorange '''
+            if len(data) == 0:
+                return
             bounds = [np.min(data), np.max(data)]
             self.plotItem.vb.setRange(xRange=[0, len(data)],
                 yRange=[bounds[0]-0.1*(bounds[1]-bounds[0])-1, bounds[1]+0.1*(bounds[1]-bounds[0])+1], update=True)
@@ -441,7 +444,7 @@ class SubPlotWidget(pg.GraphicsLayoutWidget):
             self._disableCustomAutoRange()
             self.plotItem.setClipToView(True)
 
-        if self.plotType == PlotType.Trains:
+        if self.plotType == PlotType.Trains or self.plotType == PlotType.Follow:
             self.img.clear()
             self.plotItemPlot.show()
             self.gradient_legend.hide()
@@ -507,7 +510,7 @@ class SubPlotWidget(pg.GraphicsLayoutWidget):
         elif self.plotType == PlotType.FFT:
             self.plotItem.setLabel('left', 'Bunch Position', '')
             self.plotItem.setLabel('bottom', 'Frequency', 'Hz')
-        elif self.plotType == PlotType.Trains:
+        elif self.plotType == PlotType.Trains or self.plotType == PlotType.Follow:
             self.plotItem.setLabel('left', '', '')
             self.plotItem.setLabel('bottom', 'Sample Point', '')
         elif self.plotType == PlotType.Combined:
@@ -603,9 +606,10 @@ class PlotWidget(kcgw.KCGWidgets):
         self.trains_button = self.createButton(text=tr("Button", "Trains"), connect=lambda: self.plot(type=PlotType.Trains))
         self.combined_button = self.createButton(text=tr("Button", "Combined"), connect=lambda: self.plot(type=PlotType.Combined))
         self.compare_button = self.createButton(text=tr("Button", "Compare"), connect=lambda: self.plot(type=PlotType.Compare))
+        self.follow_button = self.createButton(text=tr("Button", "Follow"), connect=lambda: self.plot(type=PlotType.Follow))
         self.type_buttons = {PlotType.Heatmap:self.heatmap_button, PlotType.FFT:self.fft_button,
                              PlotType.Trains:self.trains_button, PlotType.Combined:self.combined_button,
-                             PlotType.Compare:self.compare_button}
+                             PlotType.Compare:self.compare_button, PlotType.Follow:self.follow_button}
         self.defaultButtonStyleSheet = self.heatmap_button.styleSheet()
 
         self.adc1 = self.createCheckbox(text="ADC 1", connect=self.change_adc)
@@ -619,6 +623,7 @@ class PlotWidget(kcgw.KCGWidgets):
         self.plot_buttons_layout.addWidget(self.trains_button)
         self.plot_buttons_layout.addWidget(self.combined_button)
         self.plot_buttons_layout.addWidget(self.compare_button)
+        self.plot_buttons_layout.addWidget(self.follow_button)
 
         self.adc_checkbox_layout = QtGui.QHBoxLayout()
         self.adc_checkbox_layout.addWidget(self.adc1)
@@ -669,9 +674,16 @@ class PlotWidget(kcgw.KCGWidgets):
         self.groupWidgetCompare.hide()
 
         self.from_to_layout = QtGui.QHBoxLayout()
+        self.bucket_part = QtGui.QWidget()
+        self.bucket_layout = QtGui.QHBoxLayout()
+        self.bucket_layout.addWidget(self.createLabel(tr("Label", "Bucket:")))
+        self.bucket_spinbox = self.createSpinbox(0, config.bunches_per_turn-1, interval=1, connect=lambda: self.plot(self.theType))
+        self.bucket_layout.addWidget(self.bucket_spinbox)
+        self.bucket_part.setLayout(self.bucket_layout)
         self.from_spinbox = self.createSpinbox(0, 100000000, interval=100, connect=lambda: self.plot(self.theType))
         self.to_spinbox = self.createSpinbox(0, 100000000, start_value=1000, interval=100, connect=lambda: self.plot(self.theType))
         self.from_to_layout.addStretch()
+        self.from_to_layout.addWidget(self.bucket_part)
         self.from_to_layout.addWidget(self.createLabel(tr("Label", "From:")))
         self.from_to_layout.addWidget(self.from_spinbox)
         self.from_to_layout.addWidget(self.createLabel(tr("Label", "To:")))
@@ -748,6 +760,10 @@ class PlotWidget(kcgw.KCGWidgets):
                 style += self.defaultButtonStyleSheet
             style += "QPushButton:focus{background-color: lightgrey!important; border-color: lightblue;}"  # Note: this does not work
             button.setStyleSheet(style)
+        if self.theType == PlotType.Follow:
+            self.bucket_part.show()
+        else:
+            self.bucket_part.hide()
     def plot(self, type=None):
         """
         Wrapper function to call the correct plot function depending on type
@@ -782,7 +798,7 @@ class PlotWidget(kcgw.KCGWidgets):
                     type = self._old_type
                 else:
                     type = self.theType
-            if type == PlotType.Trains or type == PlotType.Combined:
+            if type == PlotType.Trains or type == PlotType.Combined or type == PlotType.Follow:
                 self.do_plot(type, autorange=True)
             else:
                 self.do_plot(type, autorange=False)
@@ -831,6 +847,7 @@ class PlotWidget(kcgw.KCGWidgets):
 
         f = self.from_spinbox.value()
         t = self.to_spinbox.value() if self.to_spinbox.value() > f else f+1
+        b = self.bucket_spinbox.value()
         if type == PlotType.FFT:
             self.plot_widget.plot(np.abs(self.data.fft(adc=self.adc, frm=f, to=t+1, drop_first_bin=True)).transpose(),
                                   autorange=autorange,
@@ -841,6 +858,8 @@ class PlotWidget(kcgw.KCGWidgets):
             self.plot_widget.plot([self.data.heatmap(adc=self.adc, frm=f, to=t).transpose(),self.data.heatmap(adc=self.secadc, frm=f, to=t).transpose()], autorange=autorange)
         if type == PlotType.Trains:
             self.plot_widget.plot(self.data.train(adc=self.adc, frm=f, to=t), autorange=autorange)
+        if type == PlotType.Follow:
+            self.plot_widget.plot(self.data.follow(adc=self.adc, frm=f, to=t, bunch=b), autorange=autorange)
         if type == PlotType.Combined:
             self.plot_widget.plot(self.data.combined(frm=f, to=t), autorange=autorange)