|
@@ -14,6 +14,7 @@ from ..base import backendinterface as bif
|
|
|
from ..base.groupedelements import Elements
|
|
|
from ..base.globals import glob as global_objects
|
|
|
from .. import config
|
|
|
+from ..base import storage
|
|
|
|
|
|
tr = kcgw.tr
|
|
|
|
|
@@ -68,12 +69,22 @@ class timingPlotWidget(kcgw.KCGWidgets):
|
|
|
self.position_label = self.createLabel("")
|
|
|
self.position_label.setAlignment(QtCore.Qt.AlignCenter)
|
|
|
self.plot_type_switcher = self.createSwitch(connect=self.switch)
|
|
|
+ self.zero_correction_switcher = self.createSwitch(connect=self.zero_correction)
|
|
|
+ self.uses_zero_correction = False
|
|
|
+ self.zero_correction_values = None
|
|
|
|
|
|
# ------[ Add Elements to various layouts ]--------------
|
|
|
self.headerLayout.addWidget(self.position_label)
|
|
|
self.headerLayout.addWidget(self.createLabel("Colour Plot"))
|
|
|
self.headerLayout.addWidget(self.plot_type_switcher)
|
|
|
self.headerLayout.addWidget(self.createLabel("Line Plot"))
|
|
|
+ t = QtGui.QFrame()
|
|
|
+ t.setFrameShape(QtGui.QFrame.VLine)
|
|
|
+ t.setFrameShadow(QtGui.QFrame.Sunken)
|
|
|
+ self.headerLayout.addWidget(t)
|
|
|
+ self.headerLayout.addWidget(self.createLabel("RawData"))
|
|
|
+ self.headerLayout.addWidget(self.zero_correction_switcher)
|
|
|
+ self.headerLayout.addWidget(self.createLabel("Corrected"))
|
|
|
self.headerLayout.setAlignment(QtCore.Qt.AlignRight)
|
|
|
self.layout.addWidget(self.adc1_plot_widget, 0, 0)
|
|
|
self.layout.addWidget(self.adc2_plot_widget, 0, 1)
|
|
@@ -102,6 +113,46 @@ class timingPlotWidget(kcgw.KCGWidgets):
|
|
|
self.colour_plot()
|
|
|
self.plot()
|
|
|
|
|
|
+ def zero_correction(self):
|
|
|
+ """
|
|
|
+ Toggle Zero (50Ohm) Correction
|
|
|
+ """
|
|
|
+ # Note: when selecting a slice the upper bound has to be included since that's how the timescan works. Python array slicing does not include the upper bound => +1
|
|
|
+ if self.uses_zero_correction:
|
|
|
+ self.uses_zero_correction = False
|
|
|
+ self.data += self.zero_correction_values[:, self.xrange[0]:self.xrange[1]+1, self.yrange[0]:self.yrange[1]+1]
|
|
|
+
|
|
|
+ else:
|
|
|
+ self.uses_zero_correction = True
|
|
|
+ if self.zero_correction_values is None:
|
|
|
+ # Adjust for closed measurement of 0 (Measured using a 50 ohm impedance
|
|
|
+ # This will read the complete file into memory. Could be optimized to read only necessary values
|
|
|
+# f = file(config.fifty_ohm_timescan_datafile)
|
|
|
+ f = file(storage.storage.offset_correction)
|
|
|
+ c_adc = -1 # -1 because first adc will have #ADC0 and this will increment c_adc
|
|
|
+ self.zero_correction_values = np.zeros((4, 32, 16)) # we know there are 4 adcs, 16 coarse delays and 32 fine delays
|
|
|
+ all_check = np.zeros((4, 32, 16), dtype=np.bool)
|
|
|
+ for line in f:
|
|
|
+ line = line.strip()
|
|
|
+ if line == "": continue # skip empty lines
|
|
|
+ if line.startswith("#"):
|
|
|
+ c_adc += 1 # c_adc = int(line.split("_")[-1])
|
|
|
+ continue
|
|
|
+ coarse, fine, value = line.split(";")
|
|
|
+ self.zero_correction_values[c_adc, int(fine), int(coarse)] = value
|
|
|
+ all_check[c_adc, int(fine), int(coarse)] = True
|
|
|
+ if False in all_check:
|
|
|
+ logging.warn("Read 50Ohm timescan for offset correction does not include all delay values")
|
|
|
+
|
|
|
+ self.data -= self.zero_correction_values[:, self.xrange[0]:self.xrange[1]+1, self.yrange[0]:self.yrange[1]+1]
|
|
|
+
|
|
|
+ maxima = np.zeros((4, 3))
|
|
|
+ for adc, a in enumerate(self.data):
|
|
|
+ f, c = np.unravel_index(np.argmax(a), a.shape)
|
|
|
+ maxima[adc] = [a[f, c], c+self.yrange[0], f+self.xrange[0]]
|
|
|
+
|
|
|
+ self.plot(maxima=maxima)
|
|
|
+
|
|
|
def colour_plot(self):
|
|
|
"""
|
|
|
Initialize Color Plot
|
|
@@ -200,7 +251,9 @@ class timingPlotWidget(kcgw.KCGWidgets):
|
|
|
:param spacing:
|
|
|
:return:
|
|
|
"""
|
|
|
- return [str(int(v)) for v in values]
|
|
|
+ if np.mean(values) > 3:
|
|
|
+ return [str(int(v)) for v in values]
|
|
|
+ return [str(v) for v in values]
|
|
|
|
|
|
def line_plot(self):
|
|
|
"""
|
|
@@ -298,15 +351,15 @@ class timingPlotWidget(kcgw.KCGWidgets):
|
|
|
self.setWindowTitle(tr("Heading", "Timescan Result:") + " " + newTitle + " " +
|
|
|
available_boards.get_board_name_from_id(self.board_id))
|
|
|
|
|
|
- if maxima is not None:
|
|
|
- self.adc1_plot_widget.getPlotItem().setTitle(str(tr("Heading", "ADC 1: Maximum C:{c} F:{f}")).format(
|
|
|
- c=int(maxima[0, 1]), f=int(maxima[0, 2])))
|
|
|
- self.adc2_plot_widget.getPlotItem().setTitle(str(tr("Heading", "ADC 2: Maximum C:{c} F:{f}")).format(
|
|
|
- c=int(maxima[1, 1]), f=int(maxima[1, 2])))
|
|
|
- self.adc3_plot_widget.getPlotItem().setTitle(str(tr("Heading", "ADC 3: Maximum C:{c} F:{f}")).format(
|
|
|
- c=int(maxima[2, 1]), f=int(maxima[2, 2])))
|
|
|
- self.adc4_plot_widget.getPlotItem().setTitle(str(tr("Heading", "ADC 4: Maximum C:{c} F:{f}")).format(
|
|
|
- c=int(maxima[3, 1]), f=int(maxima[3, 2])))
|
|
|
+ if maxima is not None:
|
|
|
+ self.adc1_plot_widget.getPlotItem().setTitle(str(tr("Heading", "ADC 1: Maximum C:{c} F:{f}")).format(
|
|
|
+ c=int(maxima[0, 1]), f=int(maxima[0, 2])))
|
|
|
+ self.adc2_plot_widget.getPlotItem().setTitle(str(tr("Heading", "ADC 2: Maximum C:{c} F:{f}")).format(
|
|
|
+ c=int(maxima[1, 1]), f=int(maxima[1, 2])))
|
|
|
+ self.adc3_plot_widget.getPlotItem().setTitle(str(tr("Heading", "ADC 3: Maximum C:{c} F:{f}")).format(
|
|
|
+ c=int(maxima[2, 1]), f=int(maxima[2, 2])))
|
|
|
+ self.adc4_plot_widget.getPlotItem().setTitle(str(tr("Heading", "ADC 4: Maximum C:{c} F:{f}")).format(
|
|
|
+ c=int(maxima[3, 1]), f=int(maxima[3, 2])))
|
|
|
if self.plot_type == 'line':
|
|
|
# self.line_plot()
|
|
|
def reshape(data):
|