CorrelationWidget.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. import time
  2. import os
  3. import math
  4. import numpy as np
  5. from numpy.polynomial.polynomial import polyval
  6. import h5py
  7. import traceback
  8. import csv
  9. import warnings
  10. from scipy.optimize import curve_fit
  11. from scipy.stats import chisquare
  12. from scipy.stats import chi2_contingency
  13. from scipy.special import erfc, erf
  14. import datetime
  15. import pyqtgraph as pg
  16. from PyQt4 import QtGui, QtCore, QtSvg
  17. import matplotlib
  18. matplotlib.use("Qt4Agg")
  19. #matplotlib.use("Agg")
  20. import matplotlib.pyplot as plt
  21. import logging
  22. try:
  23. #for KCG
  24. from ..base import kcgwidget as kcgw
  25. from ..base.backend import board
  26. from ..base.backend.board import available_boards
  27. from ..base.backend.DataSet import DataSet
  28. from ..base.backend.TimeScan import TimeScan
  29. from .. import config
  30. from ..config import colours, coloursTrans
  31. from ..base.backend.CalibrationHandle import theCalibration
  32. from ..base.globals import glob as global_objects
  33. from .CorrelationCorrection import CorrelationCorrection
  34. from ..base import storage
  35. except:
  36. import traceback
  37. traceback.print_exc()
  38. #for Analysis GUI
  39. import config
  40. from config import colours, coloursTrans
  41. import kcgwidget as kcgw
  42. from CalibrationHandle import theCalibration
  43. from constants import KARA
  44. from TimeScan import TimeScan
  45. from DataSet import DataSet
  46. from CorrelationCorrection import CorrelationCorrection
  47. LINEAR = 0
  48. GAUSS = 1
  49. GAUSSB = 2
  50. EGAUSSC= 3
  51. EGAUSS = 4
  52. EGAUSSB= 5
  53. SKEW = 6
  54. SINUS = 7
  55. __widget_id__ = None
  56. import shutil
  57. def sinus(x,a,b,c,d):
  58. return a*np.sin(b*x*(2*np.pi)+d)+c
  59. class CorrelationWidget(kcgw.KCGWidgets):
  60. """
  61. """
  62. def __init__(self, unique_id, parent, timeScan=None, delays=None, workingChannels=[0,1,2,3,4,5,6,7]):
  63. super(CorrelationWidget, self).__init__()
  64. self.id = unique_id
  65. self.par = parent
  66. # ------[ Variable declaration ]------------
  67. self.parent=parent
  68. self.timeScan = timeScan # Data to plot
  69. self.dataSet = None
  70. self.delays = delays
  71. self.updater = None
  72. self.workingChannels = workingChannels
  73. self.bunch = 0
  74. self.plotList = []
  75. tmp = CorrelationCorrection("",0,0,0, workingChannels=workingChannels)
  76. self.calibId = None
  77. if timeScan is not None:
  78. self.calibId = self.timeScan.calibId
  79. self.originalnotplotted = True
  80. self.running = False
  81. self.outText = self.createLabel('')
  82. self.outText.setStyleSheet("font: 12pt Courier")
  83. # -------[ Create structure ]----------
  84. self.outerLayout = QtGui.QVBoxLayout() # Outermost layout of this window
  85. self.setLayout(self.outerLayout)
  86. self.settingsLayout = QtGui.QGridLayout()
  87. lineindex = 0
  88. self.ts_label = QtGui.QLabel('selected Timescan: ')
  89. self.settingsLayout.addWidget(self.ts_label, lineindex, 0,1,2)
  90. lineindex +=1
  91. self.ds_label = QtGui.QLabel('selected DataSet: ')
  92. self.settingsLayout.addWidget(self.ds_label, lineindex, 0,1,2)
  93. lineindex +=1
  94. self.cf_label = QtGui.QLabel('selected CalibrationFile: ')
  95. self.settingsLayout.addWidget(self.cf_label, lineindex, 0,1,2)
  96. lineindex +=1
  97. if tmp.checkForCuda():
  98. self.text_label = QtGui.QLabel('working local on:')
  99. self.settingsLayout.addWidget(self.text_label, lineindex-3, 2,1,2)
  100. self.text_label = QtGui.QLabel(os.path.abspath(tmp.dirToReconstruction))
  101. self.settingsLayout.addWidget(self.text_label, lineindex-2, 2,1,2)
  102. else:
  103. self.text_label = QtGui.QLabel('working remote on:')
  104. self.settingsLayout.addWidget(self.text_label, lineindex-3, 2,1,2)
  105. self.text_label = QtGui.QLabel(tmp.host)
  106. self.settingsLayout.addWidget(self.text_label, lineindex-2, 2,1,2)
  107. self.text_label = QtGui.QLabel(tmp.remotePath)
  108. self.settingsLayout.addWidget(self.text_label, lineindex-1, 2,1,2)
  109. self.oTS_btn = QtGui.QPushButton("Open Timescan")
  110. self.oTS_btn.setStyleSheet("padding: 15px;")
  111. self.oTS_btn.clicked.connect(self.openTimeScan)
  112. self.settingsLayout.addWidget(self.oTS_btn, lineindex, 0,1,2)
  113. self.oMF_btn = QtGui.QPushButton("Open Measurement")
  114. self.oMF_btn.setStyleSheet("padding: 15px;")
  115. self.oMF_btn.clicked.connect(self.openMeasurement)
  116. self.settingsLayout.addWidget(self.oMF_btn, lineindex, 2,1,1)
  117. self.settingsLayout.addWidget(self.outText, lineindex, 3,2,1)
  118. lineindex +=1
  119. self.okay_btn = QtGui.QPushButton("Run")
  120. self.okay_btn.setStyleSheet("padding: 15px;")
  121. self.okay_btn.clicked.connect(self.on_okay)
  122. self.settingsLayout.addWidget(self.okay_btn, lineindex, 0)
  123. self.okay_btn = QtGui.QPushButton("Save")
  124. self.okay_btn.setStyleSheet("padding: 15px;")
  125. self.okay_btn.clicked.connect(self.on_save)
  126. self.settingsLayout.addWidget(self.okay_btn, lineindex, 1)
  127. self.cancel_btn = QtGui.QPushButton("Cancel")
  128. self.cancel_btn.setStyleSheet("padding: 15px;")
  129. self.cancel_btn.clicked.connect(self.on_cancel)
  130. self.settingsLayout.addWidget(self.cancel_btn, lineindex, 2)
  131. lineindex += 1
  132. self.multiBunchSelector = self.createSpinbox(0,184, start_value=0, interval=1, connect=self.plot)
  133. self.multiBunchSelectorLabel = self.createLabel('Bunch Selection:')
  134. self.settingsLayout.addWidget(self.multiBunchSelectorLabel, lineindex, 0)
  135. self.settingsLayout.addWidget(self.multiBunchSelector, lineindex, 1)
  136. self.multiBunchSelector.hide()
  137. self.multiBunchSelectorLabel.hide()
  138. #######################
  139. self.plotLayout = QtGui.QHBoxLayout()
  140. self.plotWidget1 = QtGui.QWidget()
  141. self.plotlayout1= QtGui.QGridLayout() # Main Layout to hold the most elements in this window
  142. self.all_plot_widget = pg.PlotWidget(title="Timescan")
  143. self.plotlayout1.addWidget(self.all_plot_widget, 0, 0)
  144. #self.plotlayout1.addWidget(self.outText, 2, 0,1,1)
  145. self.plotWidget1.setLayout(self.plotlayout1)
  146. self.plotWidget2 = QtGui.QWidget()
  147. self.plotlayout2 = QtGui.QGridLayout() # Main Layout to hold the most elements in this window
  148. self.result_m_plot = pg.PlotWidget(title="Mean")
  149. self.result_s_plot = pg.PlotWidget(title="Width")
  150. self.result_a_plot = pg.PlotWidget(title="Amplitude")
  151. self.syncedPlots = [self.result_m_plot, self.result_s_plot, self.result_a_plot] # put as many plots as you wish
  152. def onSigRangeChanged(r):
  153. for g in self.syncedPlots:
  154. if g !=r :
  155. g.blockSignals(True)
  156. g.setRange(xRange=r.getAxis('bottom').range)
  157. g.blockSignals(False)
  158. for g in self.syncedPlots:
  159. g.sigRangeChanged.connect(onSigRangeChanged)
  160. def setAxis(axis, lable, unit="", setSpace=False):
  161. labelStyle = {'color': '#000', 'font-size': '12pt'}
  162. axis.setLabel(lable, units=unit, **labelStyle)
  163. font=QtGui.QFont()
  164. font.setPixelSize(15)
  165. axis.tickFont = font
  166. axis.setStyle(tickTextOffset = 20)
  167. if unit != "":
  168. axis.enableAutoSIPrefix()
  169. if setSpace:
  170. axis.setWidth(int(80))
  171. setAxis(self.all_plot_widget.plotItem.getAxis('bottom'), 't', 's')
  172. setAxis(self.all_plot_widget.plotItem.getAxis('left'), '', '', True)
  173. self.plotlayout2.addWidget(self.result_m_plot, 0, 0)
  174. self.plotlayout2.addWidget(self.result_s_plot, 1, 0)
  175. self.plotlayout2.addWidget(self.result_a_plot, 2, 0)
  176. self.plotWidget2.setLayout(self.plotlayout2)
  177. self.plotLayout.addWidget(self.plotWidget1)
  178. self.plotLayout.addWidget(self.plotWidget2)
  179. # -- Create Parameter Adjust
  180. self.outerLayout.addLayout(self.settingsLayout)
  181. self.outerLayout.addLayout(self.plotLayout)
  182. self.setWindowTitle("Correlation Test")
  183. self.plot()
  184. self.updateLabels()
  185. try:
  186. board.get_board_config(available_boards[0]).observe(self, self.updateDelay, 'lastDataSet')
  187. except:
  188. traceback.print_exc()
  189. pass
  190. def openTimeScan(self):
  191. filename = str(QtGui.QFileDialog.getOpenFileName(self, "Select Time Scan"))
  192. if filename != "" and '.scan' in filename:
  193. self.timeScan = TimeScan(filename)
  194. self.calibId = self.timeScan.calibId
  195. self.updater = None
  196. self.running = False
  197. self.originalnotplotted = True
  198. self.plot()
  199. self.updateLabels()
  200. def openMeasurement(self):
  201. filename = str(QtGui.QFileDialog.getOpenFileName(self, "Select Measurementfile"))
  202. if filename != "" and '.out' in filename:
  203. self.dataSet = DataSet(filename)
  204. self.delays = self.dataSet.getCalibratedDelay()
  205. self.updater = None
  206. self.running = False
  207. #self.originalnotplotted = True
  208. self.plot()
  209. self.updateLabels()
  210. def updateLabels(self):
  211. try:
  212. self.ts_label.setText('selected Timescan: ' + (self.timeScan.fileName if self.timeScan is not None else 'None'))
  213. name = 'None'
  214. if self.dataSet is not None:
  215. if self.dataSet.fileName is None:
  216. name = 'last'
  217. else:
  218. name = self.dataSet.fileName
  219. self.ds_label.setText('selected DataSet: ' + name)
  220. self.cf_label.setText('selected CalibrationFile: ' + (self.calibId if self.calibId is not None else 'None'))
  221. except Exception as e:
  222. traceback.print_exc()
  223. def on_okay(self, param):
  224. if self.timeScan is None or self.delays is None:
  225. return
  226. self.thread = storage.ThreadStorage()
  227. if self.thread.running:
  228. logging.info("already running")
  229. return
  230. #self.processbarWidget = WaitingWidget(self)
  231. self.popup = kcgw.PopupDialog("Please Wait\nSimulation ongoing",
  232. title='Running', okonly=True)
  233. self.popup.show()
  234. #self.popup.deleteLater()
  235. #self.popup.get_return_value()
  236. scanx, scany, scane = self.timeScan.getScanOverTime(0, True, True)
  237. #self.updater = CorrelationCorrection(os.path.dirname(self.timeScan.fileName), scanx, scany, self.delays, workingChannels=self.workingChannels)
  238. self.updater = CorrelationCorrection(os.path.dirname(self.timeScan.fileName), self.scanxAll, self.scanyAll, self.delays, workingChannels=self.workingChannels)
  239. self.thread.register(self.updater)
  240. self.thread.connect('stopSignal', self._threadStop)
  241. self.thread.start('run')
  242. self.running = True
  243. """
  244. if not self.running:
  245. scanx, scany, scane = self.timeScan.getScanOverTime(0, True, True)
  246. self.updater = CorrelationCorrection(os.path.dirname(self.timeScan.fileName), scanx, scany, self.delays)
  247. self.updater.run(True)
  248. self.plot()
  249. """
  250. def on_save(self, param):
  251. print('save')
  252. if self.thread.running:
  253. print('thread still running')
  254. return
  255. if self.running:
  256. #print('save')
  257. self.updater.save(os.path.join(os.path.dirname(self.dataSet.fileName), 'correlation.hdf'))
  258. self.running = False
  259. pass
  260. def on_cancel(self, param):
  261. if self.thread.running:
  262. self.thread.stop()
  263. #print('on_cancel')
  264. self.parent.updater=None
  265. #self.close()
  266. pass
  267. def _threadStop(self):
  268. self.thread.stop()
  269. #print('_threadStop')
  270. self.popup.close()
  271. if self.processbarWidget is not None:
  272. self.processbarWidget.close()
  273. self.plot()
  274. def updateTimeScan(self, timeScan):
  275. self.timeScan = timeScan
  276. self.calibId = self.timeScan.calibId
  277. self.updater = None
  278. self.running = False
  279. self.originalnotplotted = True
  280. self.plot()
  281. self.updateLabels()
  282. def updateDelay(self, dataSet):
  283. #print('updateDelay')
  284. self.dataSet = dataSet
  285. self.delays = dataSet.getCalibratedDelay()
  286. self.updater = None
  287. self.running = False
  288. #self.originalnotplotted = True
  289. self.plot()
  290. self.updateLabels()
  291. #print('updateDelay done', self.delays)
  292. def plot(self):
  293. """
  294. Plot Data
  295. :return: -
  296. """
  297. if self.bunch != self.multiBunchSelector.value():
  298. self.originalnotplotted = True
  299. self.bunch = self.multiBunchSelector.value()
  300. try:
  301. if self.originalnotplotted:
  302. self.processbarWidget = WaitingWidget(self)
  303. self.scanxAll = []
  304. self.scanyAll = []
  305. if self.timeScan is not None:
  306. if self.timeScan.multibunch:
  307. self.multiBunchSelector.show()
  308. self.multiBunchSelectorLabel.show()
  309. else:
  310. self.multiBunchSelector.hide()
  311. self.multiBunchSelectorLabel.hide()
  312. #print('plot timeScan')
  313. self.all_plot_widget.plotItem.clear()
  314. for i in self.workingChannels:
  315. scanx, scany, scane = self.timeScan.getScanOverTime(i, True, True, bunch=self.multiBunchSelector.value())
  316. sorter = np.argsort(scanx)
  317. scanx = scanx[sorter]
  318. scany = scany[sorter]
  319. self.scanxAll.extend(scanx)
  320. self.scanyAll.extend(scany)
  321. N=3
  322. scanyAvg = np.convolve(scany, np.ones((N,))/N, mode='valid')
  323. self.all_plot_widget.plotItem.plot(scanx, scany, pen=None, symbolPen=pg.mkPen(colours[i]), symbolSize=4, pxMode=True, symbolBrush=pg.mkBrush(colours[i]), downsample=200)
  324. #self.all_plot_widget.plotItem.plot(scanx[1:-1], scanyAvg, pen=pg.mkPen(colours[i]), downsample=200)
  325. self.scanxAll = np.array(self.scanxAll)
  326. self.scanyAll = np.array(self.scanyAll)
  327. sorter = np.argsort(self.scanxAll)
  328. self.scanxAll = self.scanxAll[sorter]
  329. self.scanyAll = self.scanyAll[sorter]
  330. try:
  331. popt, perr, fitFun, pcov, label, x = self.doFit(self.scanxAll, self.scanyAll, EGAUSS)
  332. self.all_plot_widget.plotItem.plot(self.scanxAll, fitFun(self.scanxAll, *popt), pen=pg.mkPen(colours[3]), downsample=200)
  333. except Exception as e:
  334. pass
  335. self.processbarWidget.close()
  336. self.processbarWidget = None
  337. self.originalnotplotted = False
  338. if self.delays is not None:
  339. #print('plot delays')
  340. if self.scanyAll == []:
  341. self.scanyAll.extend([0,1])
  342. self.scanxAll.extend([0,1])
  343. i=1
  344. font = QtGui.QFont()
  345. font.setPixelSize(14)
  346. if self.plotList != []:
  347. for item in self.plotList:
  348. self.all_plot_widget.plotItem.removeItem(item)
  349. self.plotList = []
  350. for x in self.delays:
  351. if i-1 not in self.workingChannels:
  352. i += 1
  353. continue
  354. self.plotList.append(self.all_plot_widget.plotItem.plot([x,x], [np.min(self.scanyAll)*0.8, np.max(self.scanyAll)*1.2], pen=pg.mkPen(colours[0]), downsample=200))
  355. text = pg.TextItem(str(i), anchor=(0.5,1), color=(0,0,0))
  356. text.setFont(font)
  357. text.setPos(x,np.max(self.scanyAll)*1.22)
  358. self.all_plot_widget.addItem(text)
  359. self.plotList.append(text)
  360. i += 1
  361. if self.updater is not None:
  362. self.result_m_plot.plotItem.clear()
  363. self.result_s_plot.plotItem.clear()
  364. self.result_a_plot.plotItem.clear()
  365. self.result_m_plot.plotItem.plot(self.updater.mo, pen=pg.mkPen(colours[0]))
  366. #self.result_m_plot.plotItem.plot(self.updater.m , pen=pg.mkPen(colours[3]))
  367. self.result_m_plot.plotItem.plot(self.updater.mc, pen=pg.mkPen(colours[1]))
  368. self.result_s_plot.plotItem.plot(self.updater.so, pen=pg.mkPen(colours[0]))
  369. #self.result_s_plot.plotItem.plot(self.updater.s , pen=pg.mkPen(colours[3]))
  370. self.result_s_plot.plotItem.plot(self.updater.sc, pen=pg.mkPen(colours[1]))
  371. self.result_a_plot.plotItem.plot(self.updater.ao, pen=pg.mkPen(colours[0]))
  372. #self.result_a_plot.plotItem.plot(self.updater.a , pen=pg.mkPen(colours[3]))
  373. self.result_a_plot.plotItem.plot(self.updater.ac, pen=pg.mkPen(colours[1]))
  374. try:
  375. pov0 = self.updater.povUnCorr
  376. pov1 = self.updater.povCorr
  377. pov2 = self.updater.povOrg
  378. text = " : Org | Corr | Ideal \n"
  379. text += "A-M: {: .5f} | {: .5f} | {: .5f} \n".format(pov0[0,1], pov1[0,1], pov2[0,1])
  380. text += "A-S: {: .5f} | {: .5f} | {: .5f} \n".format(pov0[0,2], pov1[0,2], pov2[0,2])
  381. text += "M-S: {: .5f} | {: .5f} | {: .5f} ".format(pov0[1,2], pov1[1,2], pov2[1,2])
  382. self.outText.setText(text)
  383. except Exception as e:
  384. pass
  385. self.show()
  386. self.setFocus()
  387. except Exception as e:
  388. traceback.print_exc()
  389. ##################################################################################
  390. def doFit(self, x,y, type, p0=None, baseline=0, findMin=False):
  391. #np.seterr(all='warn')
  392. #warnings.filterwarnings('error')
  393. def linear(x,a,b):
  394. return a + b*x
  395. def gauss(x, sigma, mu, A, b):
  396. return A*np.exp(-0.5*((x-mu)/sigma)**2) + b
  397. def expgauss(x, s, m, a ,l, b):
  398. return a*l/2*np.exp(l/2*(2*m + l*s**2 - 2*x)) * erfc((m +l*s**2 -x)/(np.sqrt(2)*s)) + b
  399. def expgauss2(x, s, m, a, t, b):
  400. return a*s/t*np.sqrt(np.pi/2) * np.exp(0.5 * (s/t)**2 - (x-m)/t) * erfc(1/np.sqrt(2)*(s/t - (x-m)/s)) + b
  401. def sinus(x,a,b,c,d):
  402. return a*np.sin(b*x*(2*np.pi)+d)+c
  403. def skewnorm(x, s, m, a, l, b):
  404. def p(x):
  405. return 1/np.sqrt(2*np.pi) * np.exp(- x**2/2)
  406. def g(x):
  407. return 0.5*(1+erf(x/np.sqrt(2)))
  408. return a*2/s*p((x-m)/s)*g(l*(x-m)/s) + b
  409. if findMin:
  410. startx = x[np.where(y==np.min(y))]
  411. else:
  412. startx = x[np.where(y==np.max(y))]
  413. y = y[np.argsort(x)]
  414. x = x[np.argsort(x)]
  415. if type == EGAUSS:
  416. fitFun = expgauss
  417. p0 = (23e-12, startx, 7e-8, 0.02e12, 2040)
  418. if findMin:
  419. p0 = (23e-12, startx, -7e-8, 0.02e12, 2040)
  420. label = [' s ', ' m ', ' a ', ' l ', ' b ']
  421. elif type == EGAUSSB:
  422. fitFun = expgauss2
  423. p0 = [19e-12, startx, 1200, 40e-12, 2040]
  424. if findMin:
  425. p0 = [19e-12, startx, -1200, 40e-12, 2040]
  426. label = [' s ', ' m ', ' a ', ' l ', ' b ']
  427. elif type == SKEW:
  428. fitFun = skewnorm
  429. p0 = [80e-12, startx, 6e-8, 3, 2040] # 220e-12
  430. if findMin:
  431. p0 = [80e-12, startx, -6e-8, 3, 2040] # 220e-12
  432. label = [' s ', ' m ', ' a ', ' l ', ' b ']
  433. else:
  434. print('Fit type unknown ', type)
  435. return 0,0, lambda x: x , 0
  436. if baseline != 0:
  437. print('baseline', baseline)
  438. fitFunOrg = fitFun
  439. fitFun = lambda x, s, m, a, l: fitFunOrg(x,s,m,a,l, baseline)
  440. p0 = p0[:-1]
  441. if p0 is not None:
  442. popt, pcov = curve_fit(fitFun, x, y, p0=p0)
  443. else:
  444. popt, pcov = curve_fit(fitFun, x, y)
  445. #popt = p0
  446. perr = np.sqrt(np.absolute(np.diag(pcov)))
  447. if baseline != 0:
  448. fitFun = fitFunOrg
  449. popt = np.append(popt, baseline)
  450. return popt, perr, fitFun, pcov, label, x
  451. ##################################################################################
  452. def closeEvent(self, event):
  453. """
  454. Event handler for closing this window
  455. """
  456. try:
  457. board.get_board_config(available_boards[0]).unobserve(self, 'lastDataSet')
  458. except:
  459. pass
  460. if self.processbarWidget is not None:
  461. self.processbarWidget.close()
  462. if self.parent is not None:
  463. self.parent.updater = None
  464. global __widget_id__
  465. __widget_id__ = None
  466. del self.par.widgets[self.id]
  467. print('closed')
  468. def addCorrelationWidget():
  469. global __widget_id__
  470. if __widget_id__:
  471. global_objects.get_global('area').widgets[__widget_id__].setFocus()
  472. else:
  473. nid = kcgw.idg.genid()
  474. __widget_id__ = nid
  475. w = CorrelationWidget(nid, global_objects.get_global('area'), workingChannels=config.working_channels)
  476. global_objects.get_global('area').newWidget(w, "Correlation Widget", nid, widget_type=4, minSize=True)
  477. return global_objects.get_global('area').widgets[__widget_id__]
  478. kcgw.register_widget(QtGui.QIcon(config.icon_path("correlation.svg")), "Correlation Widget", addCorrelationWidget, "Ctrl+Shift+C")
  479. # 8888888b. 888 888 888 d8b 888 888
  480. # 888 Y88b 888 888 o 888 Y8P 888 888
  481. # 888 888 888 888 d8b 888 888 888
  482. # 888 d88P 888d888 .d88b. .d8888b .d88b. .d8888b 88888b. 8888b. 888d888 888 d888b 888 888 .d88888 .d88b. .d88b. 888888
  483. # 8888888P" 888P" d88""88b d88P" d8P Y8b 88K 888 "88b "88b 888P" 888d88888b888 888 d88" 888 d88P"88b d8P Y8b 888
  484. # 888 888 888 888 888 88888888 "Y8888b. 888 888 .d888888 888 88888P Y88888 888 888 888 888 888 88888888 888
  485. # 888 888 Y88..88P Y88b. Y8b. X88 888 d88P 888 888 888 8888P Y8888 888 Y88b 888 Y88b 888 Y8b. Y88b.
  486. # 888 888 "Y88P" "Y8888P "Y8888 88888P' 88888P" "Y888888 888 888P Y888 888 "Y88888 "Y88888 "Y8888 "Y888
  487. # 888
  488. # Y8b d88P
  489. # "Y88P"
  490. class ProcesbarWidget(kcgw.KCGWidgets):
  491. """
  492. The Timescan result plot subwindow.
  493. """
  494. def __init__(self, parent, twobars=False):
  495. super(ProcesbarWidget, self).__init__()
  496. self.setWindowTitle("please wait")
  497. # ------[ Variable declaration ]------------
  498. self.parent = parent
  499. self.twobars = twobars
  500. # -------[ Create structure ]----------
  501. self.outerLayout = QtGui.QVBoxLayout() # Outermost layout of this window
  502. self.setLayout(self.outerLayout)
  503. self.progressbar = QtGui.QProgressBar()
  504. #self.layout.addWidget(self.progressbar, lineindex,0,1,4)
  505. self.progressbar.setRange(0,1000)
  506. self.outerLayout.addWidget(self.createLabel(' \n ....Running.... \n '))
  507. self.outerLayout.addWidget(self.progressbar)
  508. if twobars:
  509. self.progressbar2 = QtGui.QProgressBar()
  510. #self.layout.addWidget(self.progressbar, lineindex,0,1,4)
  511. self.progressbar2.setRange(0,1000)
  512. self.outerLayout.addWidget(self.progressbar2)
  513. self.show()
  514. def update(self, value, value2=0):
  515. self.progressbar.setValue(value)
  516. if self.twobars:
  517. self.progressbar2.setValue(value2)
  518. QtGui.qApp.processEvents()
  519. ##################################################################################
  520. def closeEvent(self, event):
  521. """
  522. Event handler for closing this window
  523. """
  524. self.parent.processbarWidget = None
  525. pass
  526. class WaitingWidget(kcgw.KCGWidgets):
  527. """
  528. The Timescan result plot subwindow.
  529. """
  530. def __init__(self, parent):
  531. super(WaitingWidget, self).__init__()
  532. self.setWindowTitle("please wait")
  533. # ------[ Variable declaration ]------------
  534. self.parent = parent
  535. # -------[ Create structure ]----------
  536. self.outerLayout = QtGui.QVBoxLayout() # Outermost layout of this window
  537. self.setLayout(self.outerLayout)
  538. self.outerLayout.addWidget(self.createLabel(' \n ....Loading.... \n '))
  539. self.show()
  540. QtGui.qApp.processEvents()
  541. ##################################################################################
  542. def closeEvent(self, event):
  543. """
  544. Event handler for closing this window
  545. """
  546. self.parent.processbarWidget = None
  547. pass