|
@@ -1,6 +1,7 @@
|
|
|
from __future__ import print_function
|
|
|
|
|
|
from PyQt4 import QtGui, QtCore
|
|
|
+from PyQt4.QtCore import pyqtSlot
|
|
|
import pyqtgraph as pg
|
|
|
from PyQt4.QtGui import QFont, QTableWidget
|
|
|
|
|
@@ -9,6 +10,8 @@ from scipy.stats import chisquare
|
|
|
from scipy.stats import chi2_contingency
|
|
|
from scipy.special import erfc, erf
|
|
|
|
|
|
+import copy
|
|
|
+
|
|
|
from ..base import kcgwidget as kcgw
|
|
|
from ..base.backend import board
|
|
|
from ..base.backend.DataSet import DataSet
|
|
@@ -219,8 +222,13 @@ class ScanThread(QtCore.QObject):
|
|
|
tmpmeans=[0,0,0,0,0,0,0,0]
|
|
|
|
|
|
for adc in range(self.adc_number):
|
|
|
-
|
|
|
- tmp = data.array[:,adc]
|
|
|
+ try:
|
|
|
+ tmp = data.array[:,adc]
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ self.stop = True
|
|
|
+ self.finished(c_step, c25_step, f_step)
|
|
|
+ return
|
|
|
#print('{:4.3f} Calc ADC {} '.format(time.time()-self.startTime, adc))
|
|
|
|
|
|
if self.meanMode in [MODE_THREASHOLD]:
|
|
@@ -249,7 +257,8 @@ class ScanThread(QtCore.QObject):
|
|
|
|
|
|
if c25_step_b == 4 and c_step_b == 0:
|
|
|
print('{:4.3f} emit pbar'.format(time.time()-self.startTime))
|
|
|
- self.pbarSignal.emit(self.timescan,
|
|
|
+ tmpScan = copy.deepcopy(self.timescan)
|
|
|
+ self.pbarSignal.emit(tmpScan,
|
|
|
((c_step-self.c_min)*(self.c25_max-self.c25_min+1.0) * (self.f_max-self.f_min+1.0) + (c25_step-self.c25_min)*(self.f_max-self.f_min+1.0) + (f_step-self.f_min))/
|
|
|
((self.c_max-self.c_min+1.0) * (self.c25_max-self.c25_min+1.0) * (self.f_max-self.f_min+1.0))
|
|
|
)
|
|
@@ -335,7 +344,7 @@ class ScanPlotWidget(kcgw.KCGWidgets):
|
|
|
self.par = parent
|
|
|
self.board_id = board_id
|
|
|
self.timeScan = None
|
|
|
- self.block = False
|
|
|
+ #self.block = False
|
|
|
|
|
|
# ------[ Variable declaration ]------------
|
|
|
self.xrange = (0, 1) #T/H
|
|
@@ -390,8 +399,8 @@ class ScanPlotWidget(kcgw.KCGWidgets):
|
|
|
self.plotSelect.currentIndexChanged.connect(self.changePlotType)
|
|
|
self.layout.addWidget(self.plotSelect, lineindex, 1)
|
|
|
|
|
|
- self.showerror=self.createCheckbox('show Error', connect=self.plot)
|
|
|
- self.layout.addWidget(self.showerror, lineindex,2)
|
|
|
+ self.showError=self.createCheckbox('show Error', connect=self.plot)
|
|
|
+ self.layout.addWidget(self.showError, lineindex,2)
|
|
|
self.useCalib=self.createCheckbox('use Calib', connect=self.plot)
|
|
|
self.layout.addWidget(self.useCalib, lineindex,3)
|
|
|
self.showADC=self.createCheckbox('show ADCs', connect=self.plot)
|
|
@@ -400,10 +409,7 @@ class ScanPlotWidget(kcgw.KCGWidgets):
|
|
|
self.layout.addWidget(self.updateCalib, lineindex, 5)
|
|
|
self.correlationTest = self.createButton('Correlation Test', connect=self.onCorrelation)
|
|
|
self.layout.addWidget(self.correlationTest, lineindex, 6)
|
|
|
- Elements.addButton(['timescan', 'acquire_{}'.format(self.board_id)], [
|
|
|
- self.updateCalib,
|
|
|
- self.correlationTest
|
|
|
- ])
|
|
|
+
|
|
|
lineindex += 1
|
|
|
|
|
|
self.multiBunchSelector = self.createSpinbox(0,184, start_value=0, interval=1, connect=self.plot)
|
|
@@ -444,16 +450,25 @@ class ScanPlotWidget(kcgw.KCGWidgets):
|
|
|
self.outerLayout.addLayout(self.layout)
|
|
|
self.setWindowTitle("Scan Results")
|
|
|
|
|
|
+
|
|
|
+ Elements.addButton(['timescan', 'acquire_{}'.format(self.board_id)], [
|
|
|
+ self.updateCalib,
|
|
|
+ self.correlationTest,
|
|
|
+ self.useCalib,
|
|
|
+ self.showError,
|
|
|
+ self.showADC,
|
|
|
+ self.fitSin
|
|
|
+ ])
|
|
|
+
|
|
|
# Initially show the plot
|
|
|
self.line_plot()
|
|
|
|
|
|
|
|
|
|
|
|
- self.board_config.observe(
|
|
|
- self,
|
|
|
- self.setADCdelays,
|
|
|
- 'chip_delay'
|
|
|
- )
|
|
|
+ self.board_config.observe(self, self.setADCdelays, 'chip_delay')
|
|
|
+ self.board_config.observe(self, self.setADCdelays, 'delay_330_th')
|
|
|
+ self.board_config.observe(self, self.setADCdelays, 'delay_25_th')
|
|
|
+ self.board_config.observe(self, self.setADCdelays, 'delay_25_th_2')
|
|
|
|
|
|
|
|
|
def setADCdelays(self, value):
|
|
@@ -477,9 +492,10 @@ class ScanPlotWidget(kcgw.KCGWidgets):
|
|
|
self.yrange = (f_min, f_max)
|
|
|
self.step4 = step4
|
|
|
|
|
|
+ @pyqtSlot(object)
|
|
|
def new_data(self, timeScan):
|
|
|
- while self.block:
|
|
|
- pass
|
|
|
+ #while self.block:
|
|
|
+ # pass
|
|
|
|
|
|
self.block = True
|
|
|
self.timeScan = timeScan
|
|
@@ -607,13 +623,15 @@ class ScanPlotWidget(kcgw.KCGWidgets):
|
|
|
Plot Data
|
|
|
:return: -
|
|
|
"""
|
|
|
+ """
|
|
|
if self.block:
|
|
|
if nonblock == False:
|
|
|
return
|
|
|
else:
|
|
|
self.block = True
|
|
|
+ """
|
|
|
try:
|
|
|
- print('plot')
|
|
|
+ #print('plot')
|
|
|
if self.timeScan is None:
|
|
|
return
|
|
|
|
|
@@ -642,31 +660,33 @@ class ScanPlotWidget(kcgw.KCGWidgets):
|
|
|
text = ""
|
|
|
for i in range(self.adc_number):
|
|
|
if self.adccb[i].isChecked():
|
|
|
- scanx, scany, scane = self.timeScan.getScanOverTime(i, calibrateX=self.useCalib.isChecked(), calibrateY=self.useCalib.isChecked(), force=True, bunch=self.multiBunchSelector.value())
|
|
|
+ scanx, scany, scane = self.timeScan.getScanOverTime(i, calibrateX=self.useCalib.isChecked(), calibrateY=self.useCalib.isChecked(), bunch=self.multiBunchSelector.value())
|
|
|
#scanx, scany = self.calibrate(self.data[i], i)
|
|
|
self.scanyAll.append(scany)
|
|
|
self.all_plot_widget.plotItem.plot(scanx, scany, pen=None, symbolPen=pg.mkPen(colours[i]), symbolSize=2, pxMode=True, symbolBrush=pg.mkBrush(colours[i]), downsample=200)
|
|
|
|
|
|
- if self.showerror.isChecked():
|
|
|
+ if self.showError.isChecked():
|
|
|
self.all_plot_widget.plotItem.addItem(pg.ErrorBarItem(x=scanx, y=scany, height=scane, pen=pg.mkPen(coloursTrans[i], width=2), autoDownsample=True, clipToView=True ))
|
|
|
|
|
|
if self.fitSin.isChecked():
|
|
|
# display fit
|
|
|
- type = self.fitSelect.currentIndex()
|
|
|
- popt, perr, fitFun, pcov, label, x = self.doFit(scanx, scany, type)
|
|
|
-
|
|
|
- fitx = np.linspace(np.min(scanx), np.max(scanx), 100000)
|
|
|
- fity = fitFun(fitx, *popt)
|
|
|
- self.plot_widget.plotItem.plot(fitx, fity, pen=pg.mkPen(colours[i]), downsample=200)
|
|
|
-
|
|
|
- if type == SINUS:
|
|
|
- dt.append(popt[3]/(2*np.pi)/popt[1]*1e12)
|
|
|
- elif type in [GAUSS, EGAUSS, SKEW, EGAUSSB, GAUSSB]:
|
|
|
- try:
|
|
|
- dt.append(fitx[np.where(fity==np.min(fity))][0]*1e12)
|
|
|
- except:
|
|
|
- pass
|
|
|
-
|
|
|
+ try:
|
|
|
+ type = self.fitSelect.currentIndex()
|
|
|
+ popt, perr, fitFun, pcov, label, x = self.doFit(scanx, scany, type)
|
|
|
+
|
|
|
+ fitx = np.linspace(np.min(scanx), np.max(scanx), 100000)
|
|
|
+ fity = fitFun(fitx, *popt)
|
|
|
+ self.plot_widget.plotItem.plot(fitx, fity, pen=pg.mkPen(colours[i]), downsample=200)
|
|
|
+
|
|
|
+ if type == SINUS:
|
|
|
+ dt.append(popt[3]/(2*np.pi)/popt[1]*1e12)
|
|
|
+ elif type in [GAUSS, EGAUSS, SKEW, EGAUSSB, GAUSSB]:
|
|
|
+ try:
|
|
|
+ dt.append(fitx[np.where(fity==np.min(fity))][0]*1e12)
|
|
|
+ except:
|
|
|
+ pass
|
|
|
+ except:
|
|
|
+ pass
|
|
|
|
|
|
|
|
|
if self.fitSin.isChecked():
|
|
@@ -695,7 +715,7 @@ class ScanPlotWidget(kcgw.KCGWidgets):
|
|
|
if not self.showADC.isChecked():
|
|
|
return
|
|
|
|
|
|
- print('plot delays')
|
|
|
+ #print('plot delays')
|
|
|
if self.scanyAll == []:
|
|
|
self.scanyAll.extend([0,1])
|
|
|
i=1
|
|
@@ -709,7 +729,7 @@ class ScanPlotWidget(kcgw.KCGWidgets):
|
|
|
for x in self.delays:
|
|
|
if self.adccb[i-1].isChecked():
|
|
|
self.plotList.append(self.all_plot_widget.plotItem.plot([x,x], [np.min(self.scanyAll)-10, np.max(self.scanyAll)+20], pen=pg.mkPen(colours[0]), downsample=200))
|
|
|
- text = pg.TextItem(str(i), anchor=(0.5,1), color=(0,0,0))
|
|
|
+ text = pg.TextItem(str(i), anchor=(0.5,1), color=colours[i-1])
|
|
|
text.setFont(font)
|
|
|
text.setPos(x,np.max(self.scanyAll)+24)
|
|
|
self.all_plot_widget.addItem(text)
|
|
@@ -807,6 +827,9 @@ class ScanPlotWidget(kcgw.KCGWidgets):
|
|
|
Event handler for closing this window
|
|
|
"""
|
|
|
self.board_config.unobserve(self, 'chip_delay')
|
|
|
+ self.board_config.unobserve(self, 'delay_330_th')
|
|
|
+ self.board_config.unobserve(self, 'delay_25_th')
|
|
|
+ self.board_config.unobserve(self, 'delay_25_th_2')
|
|
|
|
|
|
|
|
|
global __timing_plot_widget_id__
|
|
@@ -1149,7 +1172,7 @@ class TimeScanWidget(kcgw.KCGWidgets):
|
|
|
lineindex += 1
|
|
|
|
|
|
self.layout.addWidget(self.createLabel("Threshold / Bucket"), lineindex, 0)
|
|
|
- self.threshold = self.createSpinbox(-2000,2000, start_value=0)
|
|
|
+ self.threshold = self.createSpinbox(-2000,2000, start_value=15)
|
|
|
self.layout.addWidget(self.threshold, lineindex, 1)
|
|
|
lineindex += 1
|
|
|
Elements.addButton(['timescan'], [
|
|
@@ -1222,7 +1245,7 @@ class TimeScanWidget(kcgw.KCGWidgets):
|
|
|
self.delay25max.setValue(12)
|
|
|
self.delayfinemax.setValue(0)
|
|
|
self.delayfinemin.setValue(0)
|
|
|
- self.threshold.setValue(30)
|
|
|
+ self.threshold.setValue(15)
|
|
|
self.comboBox.setCurrentIndex(1)
|
|
|
self.stepSwitcher.setState(False)
|
|
|
self.calibSelector.setState(False)
|
|
@@ -1264,11 +1287,24 @@ class TimeScanWidget(kcgw.KCGWidgets):
|
|
|
Elements.setEnabled('acquire_{}'.format(self.board_id), False, exclude=[self.button])
|
|
|
Elements.setEnabled("acquireTrigger_{}".format(self.board_id), False)
|
|
|
|
|
|
+ if __timing_plot_widget__ == None:
|
|
|
+ __timing_plot_widget__.showError.setChecked(False)
|
|
|
+ __timing_plot_widget__.useCalib.setChecked(False)
|
|
|
+ __timing_plot_widget__.fitSin.setChecked(False)
|
|
|
+ __timing_plot_widget__.showADC.setChecked(False)
|
|
|
+
|
|
|
outdir = os.path.join(storage.storage.save_location, storage.storage.subdirname, 'TimeScan')
|
|
|
if not os.path.isdir(outdir):
|
|
|
bif._bif_update_working_dir()
|
|
|
os.makedirs(outdir)
|
|
|
|
|
|
+ self.scanNumber = 0
|
|
|
+ filelist = np.sort(os.listdir(outdir))
|
|
|
+ for file in filelist:
|
|
|
+ if '.scan' in file:
|
|
|
+ self.scanNumber += 1
|
|
|
+
|
|
|
+
|
|
|
saveraw = self.saverawCB.isChecked()
|
|
|
#print(saveraw)
|
|
|
|