Surface NMR processing and inversion GUI
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

akvoGUI.py 52KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203
  1. #/usr/bin/env python
  2. import sys
  3. #import readline
  4. try:
  5. from akvo.gui.main_ui import Ui_MainWindow
  6. uicerr = False
  7. except: # Fallback
  8. from akvo.gui.mainui import Ui_MainWindow
  9. uicerr = """
  10. USING THE DEFAULT GUI FILES, AKVO MAY NOT WORK CORRECTLY!
  11. See INSTALL.txt for details regarding GUI configuration
  12. if you are encountering problems.
  13. Clicking ignore will prevent this warning from showing
  14. each time you launch Akvo.
  15. """
  16. import matplotlib
  17. #matplotlib.use("QT4Agg")
  18. from PyQt5 import QtCore, QtGui, QtWidgets
  19. import numpy as np
  20. import time
  21. import os
  22. from copy import deepcopy
  23. from matplotlib.backends.backend_qt4 import NavigationToolbar2QT #as NavigationToolbar
  24. import datetime, time
  25. from akvo.tressel import mrsurvey
  26. import pkg_resources # part of setuptools
  27. version = pkg_resources.require("Akvo")[0].version
  28. import yaml
  29. # Writes out numpy arrays into Eigen vectors as serialized by Lemma
  30. class MatrixXr(yaml.YAMLObject):
  31. yaml_tag = u'MatrixXr'
  32. def __init__(self, rows, cols, data):
  33. self.rows = rows
  34. self.cols = cols
  35. self.data = np.zeros((rows,cols))
  36. def __repr__(self):
  37. return "%s(rows=%r, cols=%r, data=%r)" % (self.__class__.__name__, self.rows, self.cols, self.data)
  38. class VectorXr(yaml.YAMLObject):
  39. yaml_tag = r'VectorXr'
  40. def __init__(self, array):
  41. self.size = np.shape(array)[0]
  42. self.data = array.tolist()
  43. def __repr__(self):
  44. # Converts to numpy array on import
  45. return "np.array(%r)" % (self.data)
  46. from collections import OrderedDict
  47. def represent_ordereddict(dumper, data):
  48. value = []
  49. for item_key, item_value in data.items():
  50. node_key = dumper.represent_data(item_key)
  51. node_value = dumper.represent_data(item_value)
  52. value.append((node_key, node_value))
  53. return yaml.nodes.MappingNode(u'tag:yaml.org,2002:map', value)
  54. yaml.add_representer(OrderedDict, represent_ordereddict)
  55. class AkvoYamlNode(yaml.YAMLObject):
  56. yaml_tag = u'!AkvoData'
  57. def __init__(self):
  58. self.Akvo_VERSION = version
  59. self.Import = {}
  60. self.Processing = OrderedDict()
  61. #self.ProcessingFlow = []
  62. #self.Data = {}
  63. # For going the other way, data import based on Yaml serialization,
  64. def __repr__(self):
  65. return "%s(name=%r, Akvo_VESION=%r, Import=%r, Processing=%r)" % (
  66. self.__class__.__name__, self.Akvo_VERSION, self.Import, OrderedDict(dict(self.Processing)) )
  67. try:
  68. import thread
  69. except ImportError:
  70. import _thread as thread #Py3K compatibility
  71. class MyPopup(QtWidgets.QWidget):
  72. def __init__(self, name):
  73. super().__init__()
  74. self.name = name
  75. self.initUI()
  76. def initUI(self):
  77. lblName = QtWidgets.QLabel(self.name, self)
  78. class ApplicationWindow(QtWidgets.QMainWindow):
  79. def __init__(self):
  80. QtWidgets.QMainWindow.__init__(self)
  81. self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
  82. akvohome = os.path.expanduser("~") + "/.akvo"
  83. if not os.path.exists(akvohome):
  84. os.makedirs(akvohome)
  85. self.ui = Ui_MainWindow()
  86. self.ui.setupUi(self)
  87. if uicerr != False and not os.path.exists(akvohome+"/pyuic-warned"):
  88. reply = QtGui.QMessageBox.warning(self, 'Warning', uicerr, QtGui.QMessageBox.Ok, QtGui.QMessageBox.Ignore)
  89. if reply == 1024: # "0x400" in hex
  90. pass
  91. elif reply == 1048576: # "0x100000" in hex
  92. warn = open( akvohome+"/pyuic-warned" ,"w" )
  93. warn.write("Gui files were not compiled locally using pyuic! Further warnings have been supressed")
  94. warn.close()
  95. self.RAWDataProc = None
  96. self.YamlNode = AkvoYamlNode()
  97. # initialise some stuff
  98. self.ui.lcdNumberTauPulse2.setEnabled(0)
  99. self.ui.lcdNumberTauPulse1.setEnabled(0)
  100. self.ui.lcdNumberNuTx.setEnabled(0)
  101. self.ui.lcdNumberTuneuF.setEnabled(0)
  102. self.ui.lcdNumberSampFreq.setEnabled(0)
  103. self.ui.lcdNumberTauDelay.setEnabled(0)
  104. self.ui.lcdNumberNQ.setEnabled(0)
  105. #MAK 20170126: add in a list to hold processing steps
  106. self.logText = []
  107. ####################
  108. # Make connections #
  109. ####################
  110. # Menu items
  111. self.ui.actionOpen_GMR.triggered.connect(self.openGMRRAWDataset)
  112. self.ui.actionSave_Preprocessed_Dataset.triggered.connect(self.SavePreprocess)
  113. self.ui.actionExport_Preprocessed_Dataset.triggered.connect(self.ExportPreprocess)
  114. self.ui.actionExport_Preprocessed_Dataset.setEnabled(False)
  115. self.ui.actionOpen_Preprocessed_Dataset.triggered.connect(self.OpenPreprocess)
  116. self.ui.actionAboutAkvo.triggered.connect(self.about)
  117. # Buttons
  118. # #QtCore.QObject.connect(self.ui.fullWorkflowPushButton, QtCore.SIGNAL("clicked()"), self.preprocess )
  119. self.ui.loadDataPushButton.pressed.connect(self.loadRAW)
  120. self.ui.sumDataGO.pressed.connect( self.sumDataChans )
  121. self.ui.bandPassGO.pressed.connect( self.bandPassFilter )
  122. self.ui.filterDesignPushButton.pressed.connect( self.designFilter )
  123. self.ui.fdDesignPushButton.pressed.connect( self.designFDFilter )
  124. self.ui.downSampleGO.pressed.connect( self.downsample )
  125. self.ui.windowFilterGO.pressed.connect( self.windowFilter )
  126. # self.ui.despikeGO.pressed.connect( self.despikeFilter ) # use smart stack instead
  127. self.ui.adaptGO.pressed.connect( self.adaptFilter )
  128. self.ui.adaptFDGO.pressed.connect( self.adaptFilterFD )
  129. self.ui.qdGO.pressed.connect( self.quadDet )
  130. self.ui.gateIntegrateGO.pressed.connect( self.gateIntegrate )
  131. self.ui.calcQGO.pressed.connect( self.calcQ )
  132. self.ui.FDSmartStackGO.pressed.connect( self.FDSmartStack )
  133. self.ui.plotQD.setEnabled(False)
  134. self.ui.plotQD.pressed.connect( self.plotQD )
  135. self.ui.plotGI.setEnabled(False)
  136. self.ui.plotGI.pressed.connect( self.plotGI )
  137. # Add progressbar to statusbar
  138. self.ui.barProgress = QtWidgets.QProgressBar()
  139. self.ui.statusbar.addPermanentWidget(self.ui.barProgress, 0);
  140. self.ui.barProgress.setMaximumSize(100, 16777215);
  141. self.ui.barProgress.hide();
  142. self.ui.mplwidget_navigator.setCanvas(self.ui.mplwidget)
  143. self.ui.mplwidget_navigator_2.setCanvas(self.ui.mplwidget_2)
  144. ##########################################################################
  145. # Loop Table
  146. self.ui.loopTableWidget.setRowCount(80)
  147. self.ui.loopTableWidget.setColumnCount(6)
  148. self.ui.loopTableWidget.setHorizontalHeaderLabels( ["ch. tag", \
  149. "Northing [m]","Easting [m]","Height [m]", "Radius","Tx"] )
  150. for ir in range(0, self.ui.loopTableWidget.rowCount() ):
  151. for ic in range(1, self.ui.loopTableWidget.columnCount() ):
  152. pCell = QtWidgets.QTableWidgetItem()
  153. #pCell.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable)
  154. pCell.setFlags(QtCore.Qt.NoItemFlags) # not selectable
  155. pCell.setBackground( QtGui.QColor("lightgrey").lighter(110) )
  156. self.ui.loopTableWidget.setItem(ir, ic, pCell)
  157. self.ui.loopTableWidget.cellChanged.connect(self.loopCellChanged)
  158. self.ui.loopTableWidget.setDragDropOverwriteMode(False)
  159. self.ui.loopTableWidget.setDragEnabled(True)
  160. self.ui.loopTableWidget.setDragDropMode(QtWidgets.QAbstractItemView.InternalMove)
  161. self.loops = {}
  162. ##########################################################################
  163. # layer Table
  164. self.ui.layerTableWidget.setRowCount(80)
  165. self.ui.layerTableWidget.setColumnCount(3)
  166. self.ui.layerTableWidget.setHorizontalHeaderLabels( [r"top [m]", r"bottom [m]", "σ [ Ωm]" ] )
  167. self.ui.layerTableWidget.setDragDropOverwriteMode(False)
  168. self.ui.layerTableWidget.setDragEnabled(True)
  169. self.ui.layerTableWidget.setDragDropMode(QtWidgets.QAbstractItemView.InternalMove)
  170. pCell = QtWidgets.QTableWidgetItem()
  171. pCell.setFlags(QtCore.Qt.NoItemFlags) # not selectable
  172. pCell.setBackground( QtGui.QColor("lightgrey").lighter(110) )
  173. self.ui.layerTableWidget.setItem(0, 1, pCell)
  174. for ir in range(1, self.ui.layerTableWidget.rowCount() ):
  175. for ic in range(0, self.ui.layerTableWidget.columnCount() ):
  176. pCell = QtWidgets.QTableWidgetItem()
  177. #pCell.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable)
  178. pCell.setFlags(QtCore.Qt.NoItemFlags) # not selectable
  179. pCell.setBackground( QtGui.QColor("lightgrey").lighter(110) )
  180. self.ui.layerTableWidget.setItem(ir, ic, pCell)
  181. self.ui.layerTableWidget.cellChanged.connect(self.sigmaCellChanged)
  182. def sigmaCellChanged(self):
  183. self.ui.layerTableWidget.cellChanged.disconnect(self.sigmaCellChanged)
  184. # TODO consider building the model whenever this is called. Would be nice to be able to
  185. # do that. Would require instead dist of T2 I guess.
  186. jj = self.ui.layerTableWidget.currentColumn()
  187. ii = self.ui.layerTableWidget.currentRow()
  188. val = "class 'NoneType'>"
  189. try:
  190. val = eval (str( self.ui.layerTableWidget.item(ii, jj).text() ))
  191. except:
  192. #if jj != 0:
  193. # Error = QtWidgets.QMessageBox()
  194. # Error.setWindowTitle("Error!")
  195. # Error.setText("Non-numeric value encountered")
  196. self.ui.layerTableWidget.cellChanged.connect(self.sigmaCellChanged)
  197. return
  198. if jj == 1:
  199. #item.setFlags(QtCore.Qt.ItemIsEnabled)
  200. pCell = self.ui.layerTableWidget.item(ii, jj)
  201. pCell.setBackground( QtGui.QColor("white"))
  202. pCell = self.ui.layerTableWidget.item(ii+1, jj-1)
  203. if str(type(pCell)) == "<class 'NoneType'>":
  204. pCell = QtWidgets.QTableWidgetItem()
  205. pCell.setFlags(QtCore.Qt.ItemIsEnabled)
  206. self.ui.layerTableWidget.setItem(ii+1, jj-1, pCell)
  207. if ii == 0:
  208. pCell.setText(str(val))
  209. #pCell3 = self.ui.layerTableWidget.item(ii+1, jj)
  210. #print ("setting", ii, jj, type(pCell3))
  211. #print ( "setting", ii, jj, type(pCell3))
  212. #pCell3.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsEnabled )
  213. #pCell3.setFlags( QtCore.Qt.ItemIsEditable )
  214. elif ii > 0:
  215. val2 = eval (str( self.ui.layerTableWidget.item(ii-1, jj).text() ))
  216. #print ("val2", val2, val, type(val))
  217. #if str(type(pCell)) == "<class 'NoneType'>":
  218. if type(val) == str or val > val2:
  219. pCell.setText(str(val))
  220. else:
  221. Error = QtWidgets.QMessageBox()
  222. Error.setWindowTitle("Error!")
  223. Error.setText("Non-increasing layer detected")
  224. Error.setDetailedText("Each layer interface must be below the one above it.")
  225. Error.exec_()
  226. pCell2 = self.ui.layerTableWidget.item(ii, jj)
  227. pCell2.setText(str(""))
  228. self.ui.layerTableWidget.cellChanged.connect(self.sigmaCellChanged)
  229. return
  230. # enable next layer
  231. pCell4 = self.ui.layerTableWidget.item(ii+1, jj)
  232. pCell4.setBackground( QtGui.QColor("lightblue") ) #.lighter(110))
  233. pCell4.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsEnabled )
  234. pCell5 = self.ui.layerTableWidget.item(ii+1, jj+1)
  235. pCell5.setBackground( QtGui.QColor("white"))
  236. pCell5.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsEnabled )
  237. print("ii", ii, "jj", jj)
  238. if ii == 0 and jj == 0:
  239. pCell = self.ui.layerTableWidget.item(0, 1)
  240. pCell.setBackground( QtGui.QColor("lightblue")) #.lighter(110) )
  241. pCell.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsEnabled )
  242. self.ui.layerTableWidget.cellChanged.connect(self.sigmaCellChanged)
  243. def loopCellChanged(self):
  244. self.ui.loopTableWidget.cellChanged.disconnect(self.loopCellChanged)
  245. jj = self.ui.loopTableWidget.currentColumn()
  246. ii = self.ui.loopTableWidget.currentRow()
  247. if jj == 0: # ch. tag modified
  248. for jjj in range(jj+1,jj+5):
  249. pCell = self.ui.loopTableWidget.item(ii, jjj)
  250. pCell.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsEnabled )
  251. pCell.setBackground( QtGui.QColor("lightblue") )
  252. if self.ui.loopTableWidget.item(ii, jj).text() not in self.loops.keys():
  253. self.loops[ self.ui.loopTableWidget.item(ii, jj).text() ] = {}
  254. print (self.loops.keys())
  255. # Transmitter cell
  256. pCell = self.ui.loopTableWidget.item(ii, jj+5)
  257. pCell.setCheckState(QtCore.Qt.Unchecked);
  258. pCell.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled )
  259. pCell.setBackground( QtGui.QColor("lightblue") )
  260. else:
  261. pCell = self.ui.loopTableWidget.item(ii, jj+5)
  262. pCell.setCheckState(QtCore.Qt.Unchecked);
  263. #pCell.setFlags( )
  264. pCell.setBackground( QtGui.QColor("lightblue") )
  265. self.plotLoops()
  266. self.ui.loopTableWidget.cellChanged.connect(self.loopCellChanged)
  267. def plotLoops(self):
  268. #self.ui.mplwidget_3.fig.clear()
  269. self.ui.mplwidget_3.ax1.clear()
  270. self.ui.mplwidget_3.ax2.clear()
  271. nor = dict()
  272. eas = dict()
  273. dep = dict()
  274. for ii in range( self.ui.loopTableWidget.rowCount() ):
  275. for jj in range( self.ui.loopTableWidget.columnCount() ):
  276. tp = type(self.ui.loopTableWidget.item(ii, jj))
  277. if str(tp) == "<class 'NoneType'>":
  278. pass
  279. elif not len(self.ui.loopTableWidget.item(ii, jj).text()):
  280. pass
  281. else:
  282. if jj == 0:
  283. idx = self.ui.loopTableWidget.item(ii, 0).text()
  284. if idx not in nor.keys():
  285. nor[idx] = list()
  286. eas[idx] = list()
  287. dep[idx] = list()
  288. if jj == 1:
  289. nor[idx].append( eval(self.ui.loopTableWidget.item(ii, 1).text()) )
  290. elif jj == 2:
  291. eas[idx].append( eval(self.ui.loopTableWidget.item(ii, 2).text()) )
  292. elif jj == 3:
  293. dep[idx].append( eval(self.ui.loopTableWidget.item(ii, 3).text()) )
  294. for ii in nor.keys():
  295. try:
  296. self.ui.mplwidget_3.ax1.plot( np.array(nor[ii]), np.array(eas[ii]) )
  297. except:
  298. pass
  299. #self.ui.mplwidget_3.figure.axes().set
  300. plt.gca().set_aspect('equal') #, adjustable='box')
  301. self.ui.mplwidget_3.draw()
  302. def about(self):
  303. # TODO proper popup with info
  304. #self.w = MyPopup("""About Akvo \n
  305. # Akvo is an open source project developed primarily by Trevor Irons.
  306. #""")
  307. #self.w.setGeometry(100, 100, 400, 200)
  308. #self.w.show()
  309. # Just a splash screen for now
  310. logo = pkg_resources.resource_filename(__name__, 'akvo_about.png')
  311. pixmap = QtGui.QPixmap(logo)
  312. self.splash = QtWidgets.QSplashScreen(pixmap, QtCore.Qt.WindowStaysOnTopHint)
  313. self.splash.show()
  314. def connectGMRDataProcessor(self):
  315. self.RAWDataProc = mrsurvey.GMRDataProcessor()
  316. self.RAWDataProc.progressTrigger.connect(self.updateProgressBar)
  317. self.RAWDataProc.enableDSPTrigger.connect(self.enableDSP)
  318. self.RAWDataProc.doneTrigger.connect(self.doneStatus)
  319. self.RAWDataProc.updateProcTrigger.connect(self.updateProc)
  320. def openGMRRAWDataset(self):
  321. try:
  322. with open('.gmr.last.path') as f:
  323. fpath = f.readline()
  324. pass
  325. except IOError as e:
  326. fpath = '.'
  327. self.headerstr = QtWidgets.QFileDialog.getOpenFileName(self, 'Open File', fpath)[0] # arg2 = File Type 'All Files (*)'
  328. self.ui.headerFileTextBrowser.clear()
  329. self.ui.headerFileTextBrowser.append(self.headerstr)
  330. if len(self.headerstr) == 0:
  331. return
  332. # clear the processing log
  333. self.ui.logTextBrowser.clear()
  334. self.logText = [] #MAK 20170126
  335. path,filen=os.path.split(str(self.headerstr))
  336. f = open('.gmr.last.path', 'w')
  337. f.write( str(self.headerstr) ) # prompt last file
  338. self.connectGMRDataProcessor()
  339. self.RAWDataProc.readHeaderFile(str(self.headerstr))
  340. # If we got this far, enable all the widgets
  341. self.ui.lcdNumberTauPulse1.setEnabled(True)
  342. self.ui.lcdNumberNuTx.setEnabled(True)
  343. self.ui.lcdNumberTuneuF.setEnabled(True)
  344. self.ui.lcdNumberSampFreq.setEnabled(True)
  345. self.ui.lcdNumberNQ.setEnabled(True)
  346. self.ui.headerFileBox.setEnabled(True)
  347. self.ui.inputRAWParametersBox.setEnabled(True)
  348. self.ui.loadDataPushButton.setEnabled(True)
  349. # make plots as you import the dataset
  350. self.ui.plotImportCheckBox.setEnabled(True)
  351. self.ui.plotImportCheckBox.setChecked(True)
  352. # Update info from the header into the GUI
  353. self.ui.pulseTypeTextBrowser.clear()
  354. self.ui.pulseTypeTextBrowser.append(self.RAWDataProc.pulseType)
  355. self.ui.lcdNumberNuTx.display(self.RAWDataProc.transFreq)
  356. self.ui.lcdNumberTauPulse1.display(1e3*self.RAWDataProc.pulseLength[0])
  357. self.ui.lcdNumberTuneuF.display(self.RAWDataProc.TuneCapacitance)
  358. self.ui.lcdNumberSampFreq.display(self.RAWDataProc.samp)
  359. self.ui.lcdNumberNQ.display(self.RAWDataProc.nPulseMoments)
  360. self.ui.DeadTimeSpinBox.setValue(1e3*self.RAWDataProc.deadTime)
  361. self.ui.CentralVSpinBox.setValue( self.RAWDataProc.transFreq )
  362. if self.RAWDataProc.pulseType != "FID":
  363. self.ui.lcdNumberTauPulse2.setEnabled(1)
  364. self.ui.lcdNumberTauPulse2.display(1e3*self.RAWDataProc.pulseLength[1])
  365. self.ui.lcdNumberTauDelay.setEnabled(1)
  366. self.ui.lcdNumberTauDelay.display(1e3*self.RAWDataProc.interpulseDelay)
  367. self.ui.FIDProcComboBox.clear()
  368. if self.RAWDataProc.pulseType == "4PhaseT1":
  369. self.ui.FIDProcComboBox.insertItem(0, "Pulse 1")
  370. self.ui.FIDProcComboBox.insertItem(1, "Pulse 2")
  371. self.ui.FIDProcComboBox.insertItem(2, "Both")
  372. self.ui.FIDProcComboBox.setCurrentIndex (1)
  373. elif self.RAWDataProc.pulseType == "FID":
  374. self.ui.FIDProcComboBox.insertItem(0, "Pulse 1")
  375. self.ui.FIDProcComboBox.setCurrentIndex (0)
  376. def ExportPreprocess(self):
  377. """ This method export to YAML
  378. """
  379. try:
  380. with open('.akvo.last.yaml.path') as f:
  381. fpath = f.readline()
  382. pass
  383. except IOError as e:
  384. fpath = '.'
  385. fdir = os.path.dirname(fpath)
  386. # Pickle the preprocessed data dictionary
  387. SaveStr = QtWidgets.QFileDialog.getSaveFileName(self, "Save as", fdir, r"Processed data (*.yaml)")[0]
  388. spath,filen=os.path.split(str(SaveStr))
  389. f = open('.akvo.last.yaml.path', 'w')
  390. f.write( str(spath) ) # prompt last file
  391. INFO = {}
  392. INFO["headerstr"] = str(self.headerstr)
  393. INFO["pulseType"] = self.RAWDataProc.pulseType
  394. INFO["transFreq"] = self.RAWDataProc.transFreq.tolist()
  395. INFO["pulseLength"] = self.RAWDataProc.pulseLength.tolist()
  396. INFO["TuneCapacitance"] = self.RAWDataProc.TuneCapacitance.tolist()
  397. #INFO["samp"] = self.RAWDataProc.samp
  398. INFO["nPulseMoments"] = self.RAWDataProc.nPulseMoments
  399. #INFO["deadTime"] = self.RAWDataProc.deadTime
  400. INFO["processed"] = "Akvo v. 1.0, on " + time.strftime("%d/%m/%Y")
  401. # Pulse current info
  402. ip = 0
  403. INFO["Pulses"] = {}
  404. for pulse in self.RAWDataProc.DATADICT["PULSES"]:
  405. qq = []
  406. qv = []
  407. for ipm in range(self.RAWDataProc.DATADICT["nPulseMoments"]):
  408. #for istack in self.RAWDataProc.DATADICT["stacks"]:
  409. # print ("stack q", self.RAWDataProc.DATADICT[pulse]["Q"][ipm,istack-1])
  410. qq.append(np.mean( self.RAWDataProc.DATADICT[pulse]["Q"][ipm,:]) )
  411. qv.append(np.std( self.RAWDataProc.DATADICT[pulse]["Q"][ipm,:]/self.RAWDataProc.pulseLength[ip] ))
  412. INFO["Pulses"][pulse] = {}
  413. INFO["Pulses"][pulse]["units"] = "A"
  414. INFO["Pulses"][pulse]["current"] = VectorXr(np.array(qq)/self.RAWDataProc.pulseLength[ip])
  415. INFO["Pulses"][pulse]["variance"] = VectorXr(np.array(qv))
  416. ip += 1
  417. # Data
  418. if self.RAWDataProc.gated == True:
  419. INFO["Gated"] = {}
  420. INFO["Gated"]["abscissa units"] = "ms"
  421. INFO["Gated"]["data units"] = "nT"
  422. for pulse in self.RAWDataProc.DATADICT["PULSES"]:
  423. INFO["Gated"][pulse] = {}
  424. INFO["Gated"][pulse]["abscissa"] = VectorXr( self.RAWDataProc.GATEDABSCISSA )
  425. INFO["Gated"][pulse]["windows"] = VectorXr( self.RAWDataProc.GATEDWINDOW )
  426. for ichan in self.RAWDataProc.DATADICT[pulse]["chan"]:
  427. INFO["Gated"][pulse]["Chan. " + str(ichan)] = {}
  428. INFO["Gated"][pulse]["Chan. " + str(ichan)]["STD"] = VectorXr( np.std(self.RAWDataProc.GATED[ichan]["NR"], axis=0) )
  429. for ipm in range(self.RAWDataProc.DATADICT["nPulseMoments"]):
  430. INFO["Gated"][pulse]["Chan. " + str(ichan)]["Q-"+str(ipm) + " CA"] = VectorXr(self.RAWDataProc.GATED[ichan]["CA"][ipm])
  431. INFO["Gated"][pulse]["Chan. " + str(ichan)]["Q-"+str(ipm) + " RE"] = VectorXr(self.RAWDataProc.GATED[ichan]["RE"][ipm])
  432. INFO["Gated"][pulse]["Chan. " + str(ichan)]["Q-"+str(ipm) + " IM"] = VectorXr(self.RAWDataProc.GATED[ichan]["IM"][ipm])
  433. #INFO["Gated"][pulse]["Chan. " + str(ichan)]["Q-"+str(ipm) + " IP"] = VectorXr(self.RAWDataProc.GATED[ichan]["IP"][ipm])
  434. #INFO["Gated"][pulse]["Chan. " + str(ichan)]["Q-"+str(ipm) + " NR"] = VectorXr(self.RAWDataProc.GATED[ichan]["NR"][ipm])
  435. #INFO["Gated"][pulse]["Chan. " + str(ichan)]["Q-"+str(ipm) + " STD" ] = VectorXr(self.RAWDataProc.GATED[ichan]["SIGMA"][ipm])
  436. # we have gated data
  437. # Window edges
  438. # Window centres
  439. with open(SaveStr, 'w') as outfile:
  440. for line in self.logText:
  441. outfile.write(line+"\n")
  442. yaml.dump(INFO, outfile, default_flow_style=False)
  443. def SavePreprocess(self):
  444. #if "Saved" not in self.YamlNode.Processing.keys():
  445. # self.YamlNode.Processing["Saved"] = []
  446. #self.YamlNode.Processing["Saved"].append(datetime.datetime.now().isoformat())
  447. #self.Log()
  448. import pickle, os
  449. try:
  450. with open('.akvo.last.path') as f:
  451. fpath = f.readline()
  452. pass
  453. except IOError as e:
  454. fpath = '.'
  455. fdir = os.path.dirname(fpath)
  456. # Pickle the preprocessed data dictionary
  457. SaveStr = QtWidgets.QFileDialog.getSaveFileName(self, "Save as", fdir, r"Pickle (*.dmp)")
  458. print(SaveStr)
  459. spath,filen=os.path.split(str(SaveStr[0]))
  460. f = open('.akvo.last.path', 'w')
  461. f.write( str(spath) ) # prompt last file
  462. save = open(SaveStr[0], 'wb')
  463. # Add some extra info
  464. INFO = {}
  465. INFO["pulseType"] = self.RAWDataProc.pulseType
  466. INFO["transFreq"] = self.RAWDataProc.transFreq
  467. INFO["pulseLength"] = self.RAWDataProc.pulseLength
  468. INFO["TuneCapacitance"] = self.RAWDataProc.TuneCapacitance
  469. INFO["samp"] = self.RAWDataProc.samp
  470. INFO["nPulseMoments"] = self.RAWDataProc.nPulseMoments
  471. INFO["deadTime"] = self.RAWDataProc.deadTime
  472. INFO["transFreq"] = self.RAWDataProc.transFreq
  473. INFO["headerstr"] = str(self.headerstr)
  474. INFO["log"] = yaml.dump( self.YamlNode ) #self.logText #MAK 20170127
  475. print ("YAML NODE", yaml.dump( self.YamlNode ) )
  476. self.RAWDataProc.DATADICT["INFO"] = INFO
  477. pickle.dump(self.RAWDataProc.DATADICT, save)
  478. save.close()
  479. # Export XML file suitable for USGS ScienceBase Data Release
  480. def ExportXML(self):
  481. return 42
  482. def OpenPreprocess(self):
  483. import pickle
  484. try:
  485. with open('.akvo.last.path') as f:
  486. fpath = f.readline()
  487. pass
  488. except IOError as e:
  489. fpath = '.'
  490. #filename = QtWidgets.QFileDialog.getOpenFileName(self, 'Open File', '.')
  491. fpath = QtWidgets.QFileDialog.getOpenFileName(self, 'Open preprocessed file', fpath, r"Pickle Files (*.dmp)")[0]
  492. f = open('.akvo.last.path', 'w')
  493. f.write( str(fpath) ) # prompt last file
  494. self.ui.logTextBrowser.clear()
  495. self.logText = []
  496. if len(fpath) == 0:
  497. return
  498. pfile = open(fpath,'rb')
  499. unpickle = pickle.Unpickler(pfile)
  500. self.connectGMRDataProcessor()
  501. self.RAWDataProc.DATADICT = unpickle.load()
  502. self.RAWDataProc.readHeaderFile(self.RAWDataProc.DATADICT["INFO"]["headerstr"])
  503. self.headerstr = self.RAWDataProc.DATADICT["INFO"]["headerstr"]
  504. self.RAWDataProc.pulseType = self.RAWDataProc.DATADICT["INFO"]["pulseType"]
  505. self.RAWDataProc.transFreq = self.RAWDataProc.DATADICT["INFO"]["transFreq"]
  506. self.RAWDataProc.pulseLength = self.RAWDataProc.DATADICT["INFO"]["pulseLength"]
  507. self.RAWDataProc.TuneCapacitance = self.RAWDataProc.DATADICT["INFO"]["TuneCapacitance"]
  508. self.RAWDataProc.samp = self.RAWDataProc.DATADICT["INFO"]["samp"]
  509. self.RAWDataProc.nPulseMoments = self.RAWDataProc.DATADICT["INFO"]["nPulseMoments"]
  510. self.RAWDataProc.deadTime = self.RAWDataProc.DATADICT["INFO"]["deadTime"]
  511. self.RAWDataProc.transFreq = self.RAWDataProc.DATADICT["INFO"]["transFreq"]
  512. self.RAWDataProc.dt = 1./self.RAWDataProc.samp
  513. self.dataChan = self.RAWDataProc.DATADICT[ self.RAWDataProc.DATADICT["PULSES"][0] ]["chan"]
  514. # Keep backwards compatibility with prior saved pickles???
  515. #self.ui.logTextBrowser.clear()
  516. #self.ui.logTextBrowser.append( yaml.dump(self.YamlNode)) #, default_flow_style=False) )
  517. #for a in self.logText:
  518. # self.ui.logTextBrowser.append(str(a))
  519. #self.ui.logTextBrowser
  520. #self.ui.logTextBrowser.clear()
  521. #print ( self.RAWDataProc.DATADICT["INFO"]["log"] )
  522. self.logText = self.RAWDataProc.DATADICT["INFO"]["log"] # YAML
  523. self.YamlNode = yaml.load( self.logText )
  524. #self.ui.logTextBrowser.append( yaml.dump(self.YamlNode)) #, default_flow_style=False) )
  525. #except KeyError:
  526. # pass
  527. # Remove "Saved" and "Loaded" from processing flow
  528. #if "Loaded" not in self.YamlNode.Processing.keys():
  529. # self.YamlNode.Processing["Loaded"] = []
  530. #self.YamlNode.Processing["Loaded"].append(datetime.datetime.now().isoformat())
  531. #self.Log()
  532. # If we got this far, enable all the widgets
  533. self.ui.lcdNumberTauPulse1.setEnabled(True)
  534. self.ui.lcdNumberNuTx.setEnabled(True)
  535. self.ui.lcdNumberTuneuF.setEnabled(True)
  536. self.ui.lcdNumberSampFreq.setEnabled(True)
  537. self.ui.lcdNumberNQ.setEnabled(True)
  538. self.ui.headerFileBox.setEnabled(True)
  539. self.ui.inputRAWParametersBox.setEnabled(True)
  540. self.ui.loadDataPushButton.setEnabled(True)
  541. # make plots as you import the dataset
  542. self.ui.plotImportCheckBox.setEnabled(True)
  543. self.ui.plotImportCheckBox.setChecked(True)
  544. # Update info from the header into the GUI
  545. self.ui.pulseTypeTextBrowser.clear()
  546. self.ui.pulseTypeTextBrowser.append(self.RAWDataProc.pulseType)
  547. self.ui.lcdNumberNuTx.display(self.RAWDataProc.transFreq)
  548. self.ui.lcdNumberTauPulse1.display(1e3*self.RAWDataProc.pulseLength[0])
  549. self.ui.lcdNumberTuneuF.display(self.RAWDataProc.TuneCapacitance)
  550. self.ui.lcdNumberSampFreq.display(self.RAWDataProc.samp)
  551. self.ui.lcdNumberNQ.display(self.RAWDataProc.nPulseMoments)
  552. self.ui.DeadTimeSpinBox.setValue(1e3*self.RAWDataProc.deadTime)
  553. self.ui.CentralVSpinBox.setValue( self.RAWDataProc.transFreq )
  554. if self.RAWDataProc.pulseType != "FID":
  555. self.ui.lcdNumberTauPulse2.setEnabled(1)
  556. self.ui.lcdNumberTauPulse2.display(1e3*self.RAWDataProc.pulseLength[1])
  557. self.ui.lcdNumberTauDelay.setEnabled(1)
  558. self.ui.lcdNumberTauDelay.display(1e3*self.RAWDataProc.interpulseDelay)
  559. self.ui.FIDProcComboBox.clear()
  560. if self.RAWDataProc.pulseType == "4PhaseT1":
  561. self.ui.FIDProcComboBox.insertItem(0, "Pulse 1") #, const QVariant & userData = QVariant() )
  562. self.ui.FIDProcComboBox.insertItem(1, "Pulse 2") #, const QVariant & userData = QVariant() )
  563. self.ui.FIDProcComboBox.insertItem(2, "Both") #, const QVariant & userData = QVariant() )
  564. if len( self.RAWDataProc.DATADICT["PULSES"]) == 2:
  565. self.ui.FIDProcComboBox.setCurrentIndex (2)
  566. elif self.RAWDataProc.DATADICT["PULSES"][0] == "Pulse 1":
  567. self.ui.FIDProcComboBox.setCurrentIndex (0)
  568. else:
  569. self.ui.FIDProcComboBox.setCurrentIndex (1)
  570. elif self.RAWDataProc.pulseType == "FID":
  571. self.ui.FIDProcComboBox.insertItem(0, "Pulse 1") #, const QVariant & userData = QVariant() )
  572. self.ui.FIDProcComboBox.setCurrentIndex (0)
  573. # QtCore.QObject.connect(self.RAWDataProc, QtCore.SIGNAL("updateProgress(int)"), self.updateProgressBar)
  574. # QtCore.QObject.connect(self.RAWDataProc, QtCore.SIGNAL("enableDSP()"), self.enableDSP)
  575. # QtCore.QObject.connect(self.RAWDataProc, QtCore.SIGNAL("doneStatus()"), self.doneStatus)
  576. self.RAWDataProc.progressTrigger.connect(self.updateProgressBar)
  577. self.RAWDataProc.enableDSPTrigger.connect(self.enableDSP)
  578. self.RAWDataProc.doneTrigger.connect(self.doneStatus)
  579. self.enableAll()
  580. def loadRAW(self):
  581. #################################################
  582. # Check to make sure we are ready to process
  583. # Header
  584. if self.RAWDataProc == None:
  585. err_msg = "You need to load a header first."
  586. reply = QtGui.QMessageBox.critical(self, 'Error',
  587. err_msg) #, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
  588. return
  589. # Stacks
  590. try:
  591. self.procStacks = np.array(eval(str("np.r_["+self.ui.stacksLineEdit.text())+"]"))
  592. except:
  593. err_msg = "You need to set your stacks correctly.\n" + \
  594. "This should be a Python Numpy interpretable list\n" + \
  595. "of stack indices. For example 1:24 or 1:4,8:24"
  596. QtGui.QMessageBox.critical(self, 'Error', err_msg)
  597. return
  598. # Data Channels
  599. #Chan = np.arange(0,9,1)
  600. try:
  601. self.dataChan = np.array(eval(str("np.r_["+self.ui.dataChanLineEdit.text())+"]"))
  602. except:
  603. #QMessageBox messageBox;
  604. #messageBox.critical(0,"Error","An error has occured !");
  605. #messageBox.setFixedSize(500,200);
  606. #quit_msg = "Are you sure you want to exit the program?"
  607. #reply = QtGui.QMessageBox.question(self, 'Message',
  608. # quit_msg, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
  609. err_msg = "You need to set your data channels correctly.\n" + \
  610. "This should be a Python Numpy interpretable list\n" + \
  611. "of indices. For example 1 or 1:3 or 1:3 5\n\n" + \
  612. "valid GMR data channels fall between 1 and 8. Note that\n" +\
  613. "1:3 is not inclusive of 3 and is the same as 1,2 "
  614. reply = QtGui.QMessageBox.critical(self, 'Error',
  615. err_msg) #, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
  616. return
  617. #############################
  618. # Reference Channels
  619. # TODO make sure no overlap between data and ref channels
  620. self.refChan = np.array( () )
  621. if str(self.ui.refChanLineEdit.text()): # != "none":
  622. try:
  623. self.refChan = np.array(eval(str("np.r_["+self.ui.refChanLineEdit.text())+"]"))
  624. except:
  625. err_msg = "You need to set your reference channels correctly.\n" + \
  626. "This should be a Python Numpy interpretable list\n" + \
  627. "of indices. For example 1 or 1:3 or 1:3 5\n\n" + \
  628. "valid GMR data channels fall between 1 and 8. Note that\n" +\
  629. "1:3 is not inclusive of 3 and is the same as 1,2 "
  630. QtGui.QMessageBox.critical(self, 'Error', err_msg)
  631. return
  632. #####################################################
  633. # Load data
  634. self.lock("loading RAW GMR dataset")
  635. if self.RAWDataProc.pulseType == "FID":
  636. self.procThread = thread.start_new_thread(self.RAWDataProc.loadFIDData, \
  637. (str(self.headerstr), self.procStacks, self.dataChan, self.refChan, \
  638. str(self.ui.FIDProcComboBox.currentText()), self.ui.mplwidget, \
  639. 1e-3 * self.ui.DeadTimeSpinBox.value( ), self.ui.plotImportCheckBox.isChecked() )) #, self))
  640. elif self.RAWDataProc.pulseType == "4PhaseT1":
  641. self.procThread = thread.start_new_thread(self.RAWDataProc.load4PhaseT1Data, \
  642. (str(self.headerstr), self.procStacks, self.dataChan, self.refChan, \
  643. str(self.ui.FIDProcComboBox.currentText()), self.ui.mplwidget, \
  644. 1e-3 * self.ui.DeadTimeSpinBox.value( ), self.ui.plotImportCheckBox.isChecked() )) #, self))
  645. self.YamlNode.Import["GMR Header"] = self.headerstr
  646. self.YamlNode.Import["opened"] = datetime.datetime.now().isoformat()
  647. self.YamlNode.Import["pulse Type"] = str(self.RAWDataProc.pulseType)
  648. self.YamlNode.Import["stacks"] = self.procStacks.tolist()
  649. self.YamlNode.Import["data channels"] = self.dataChan.tolist()
  650. self.YamlNode.Import["reference channels"] = self.refChan.tolist()
  651. self.YamlNode.Import["pulse records"] = str(self.ui.FIDProcComboBox.currentText())
  652. self.YamlNode.Import["instrument dead time"] = (1e-3 * self.ui.DeadTimeSpinBox.value( ))
  653. self.Log ( )
  654. # should be already done
  655. # QtCore.QObject.connect(self.RAWDataProc, QtCore.SIGNAL("updateProgress(int)"), self.updateProgressBar)
  656. # QtCore.QObject.connect(self.RAWDataProc, QtCore.SIGNAL("enableDSP()"), self.enableDSP)
  657. # QtCore.QObject.connect(self.RAWDataProc, QtCore.SIGNAL("doneStatus()"), self.doneStatus)
  658. self.ui.ProcessedBox.setEnabled(True)
  659. self.ui.lcdNumberFID1Length.setEnabled(1)
  660. self.ui.lcdNumberFID2Length.setEnabled(1)
  661. self.ui.lcdNumberResampFreq.setEnabled(1)
  662. self.ui.lcdTotalDeadTime.setEnabled(1)
  663. self.ui.lcdTotalDeadTime.display( self.ui.DeadTimeSpinBox.value( ) )
  664. #self.ui.lcdNumberFID1Length.display(0)
  665. #self.ui.lcdNumberFID2Length.display(0)
  666. #self.ui.lcdNumberResampFreq.display( self.RAWDataProc.samp )
  667. self.mpl_toolbar = NavigationToolbar2QT(self.ui.mplwidget, self.ui.mplwidget)
  668. self.ui.mplwidget.draw()
  669. def Log(self):
  670. #for line in yaml.dump(self.YamlNode, default_flow_style=False):
  671. #for line in nlogText:
  672. # self.ui.logTextBrowser.append( line )
  673. # self.logText.append( line )
  674. self.ui.logTextBrowser.clear()
  675. self.ui.logTextBrowser.append( yaml.dump(self.YamlNode)) #, default_flow_style=False) )
  676. def disable(self):
  677. self.ui.BandPassBox.setEnabled(False)
  678. self.ui.downSampleGroupBox.setEnabled(False)
  679. self.ui.windowFilterGroupBox.setEnabled(False)
  680. # self.ui.despikeGroupBox.setEnabled(False)
  681. self.ui.adaptBox.setEnabled(False)
  682. self.ui.adaptFDBox.setEnabled(False)
  683. self.ui.qCalcGroupBox.setEnabled(False)
  684. self.ui.FDSmartStackGroupBox.setEnabled(False)
  685. self.ui.sumDataBox.setEnabled(False)
  686. self.ui.qdGroupBox.setEnabled(False)
  687. self.ui.gateBox.setEnabled(False)
  688. def enableAll(self):
  689. self.enableDSP()
  690. self.enableQC()
  691. def enableDSP(self):
  692. # Bandpass filter
  693. self.ui.BandPassBox.setEnabled(True)
  694. self.ui.BandPassBox.setChecked(True)
  695. self.ui.bandPassGO.setEnabled(False) # need to design first
  696. self.ui.plotBP.setEnabled(True)
  697. self.ui.plotBP.setChecked(True)
  698. # downsample
  699. self.ui.downSampleGroupBox.setEnabled(True)
  700. self.ui.downSampleGroupBox.setChecked(True)
  701. # window
  702. self.ui.windowFilterGroupBox.setEnabled(True)
  703. self.ui.windowFilterGroupBox.setChecked(True)
  704. # Despike
  705. # self.ui.despikeGroupBox.setEnabled(True)
  706. # self.ui.despikeGroupBox.setChecked(False)
  707. # Adaptive filtering
  708. self.ui.adaptBox.setEnabled(True)
  709. self.ui.adaptBox.setChecked(True)
  710. # FD Adaptive filtering
  711. self.ui.adaptFDBox.setEnabled(True)
  712. self.ui.adaptFDBox.setChecked(True)
  713. # sum group box
  714. try:
  715. if len(self.dataChan) > 1:
  716. self.ui.sumDataBox.setEnabled(True)
  717. self.ui.sumDataBox.setChecked(True)
  718. except:
  719. pass
  720. # Quadrature Detect
  721. self.ui.qdGroupBox.setEnabled(True)
  722. self.ui.qdGroupBox.setChecked(True)
  723. self.enableQC()
  724. def enableQC(self):
  725. # Q calc
  726. self.ui.qCalcGroupBox.setEnabled(True)
  727. self.ui.qCalcGroupBox.setChecked(True)
  728. # FD SmartStack
  729. self.ui.FDSmartStackGroupBox.setEnabled(True)
  730. self.ui.FDSmartStackGroupBox.setChecked(True)
  731. # Quadrature detect
  732. try:
  733. for pulse in self.RAWDataProc.DATADICT["PULSES"]:
  734. np.shape(self.RAWDataProc.DATADICT[pulse]["Q"])
  735. self.RAWDataProc.DATADICT["stack"]
  736. self.ui.qdGroupBox.setEnabled(True)
  737. self.ui.qdGroupBox.setChecked(True)
  738. except:
  739. self.ui.qdGroupBox.setEnabled(False)
  740. self.ui.qdGroupBox.setChecked(False)
  741. # Gating
  742. try:
  743. self.RAWDataProc.DATADICT["CA"]
  744. self.ui.gateBox.setEnabled(True)
  745. self.ui.gateBox.setChecked(True)
  746. except:
  747. self.ui.gateBox.setEnabled(False)
  748. self.ui.gateBox.setChecked(False)
  749. def despikeFilter(self):
  750. self.lock("despike filter")
  751. thread.start_new_thread(self.RAWDataProc.despike, \
  752. (self.ui.windowSpinBox.value(), \
  753. self.ui.thresholdSpinBox.value(), \
  754. str(self.ui.replComboBox.currentText()), \
  755. self.ui.rollOnSpinBox.value(), \
  756. self.ui.despikeInterpWinSpinBox.value(),
  757. self.ui.mplwidget))
  758. def calcQ(self):
  759. if "Calc Q" not in self.YamlNode.Processing.keys():
  760. self.YamlNode.Processing["Calc Q"] = True
  761. self.Log()
  762. else:
  763. err_msg = "Q values have already been calculated"
  764. reply =QtWidgets.QMessageBox.critical(self, 'Error',
  765. err_msg)
  766. return
  767. self.lock("pulse moment calculation")
  768. thread.start_new_thread(self.RAWDataProc.effectivePulseMoment, \
  769. (self.ui.CentralVSpinBox.value(), \
  770. self.ui.mplwidget_2))
  771. def FDSmartStack(self):
  772. if "TD stack" not in self.YamlNode.Processing.keys():
  773. self.YamlNode.Processing["TD stack"] = {}
  774. self.YamlNode.Processing["TD stack"]["outlier"] = str( self.ui.outlierTestCB.currentText() )
  775. self.YamlNode.Processing["TD stack"]["cutoff"] = str( self.ui.MADCutoff.value() )
  776. self.Log()
  777. else:
  778. err_msg = "TD noise cancellation has already been applied!"
  779. reply =QtWidgets.QMessageBox.critical(self, 'Error',
  780. err_msg)
  781. return
  782. self.lock("time-domain smart stack")
  783. thread.start_new_thread(self.RAWDataProc.TDSmartStack, \
  784. (str(self.ui.outlierTestCB.currentText()), \
  785. self.ui.MADCutoff.value(),
  786. self.ui.mplwidget_2))
  787. def adaptFilter(self):
  788. if "TD noise cancellation" not in self.YamlNode.Processing.keys():
  789. self.YamlNode.Processing["TD noise cancellation"] = {}
  790. self.YamlNode.Processing["TD noise cancellation"]["n_Taps"] = str(self.ui.MTapsSpinBox.value())
  791. self.YamlNode.Processing["TD noise cancellation"]["lambda"] = str(self.ui.adaptLambdaSpinBox.value())
  792. self.YamlNode.Processing["TD noise cancellation"]["truncate"] = str(self.ui.adaptTruncateSpinBox.value())
  793. self.YamlNode.Processing["TD noise cancellation"]["mu"] = str(self.ui.adaptMuSpinBox.value())
  794. self.YamlNode.Processing["TD noise cancellation"]["PCA"] = str(self.ui.PCAComboBox.currentText())
  795. self.Log()
  796. else:
  797. err_msg = "TD noise cancellation has already been applied!"
  798. reply =QtWidgets.QMessageBox.critical(self, 'Error',
  799. err_msg)
  800. return
  801. self.lock("TD noise cancellation filter")
  802. thread.start_new_thread(self.RAWDataProc.adaptiveFilter, \
  803. (self.ui.MTapsSpinBox.value(), \
  804. self.ui.adaptLambdaSpinBox.value(), \
  805. self.ui.adaptTruncateSpinBox.value(), \
  806. self.ui.adaptMuSpinBox.value(), \
  807. str(self.ui.PCAComboBox.currentText()), \
  808. self.ui.mplwidget))
  809. def sumDataChans(self):
  810. if "Data sum" not in self.YamlNode.Processing.keys():
  811. self.YamlNode.Processing["Data sum"] = True
  812. self.Log()
  813. else:
  814. err_msg = "Data channels have already been summed!"
  815. reply =QtWidgets.QMessageBox.critical(self, 'Error',
  816. err_msg)
  817. return
  818. self.lock("Summing data channels")
  819. self.dataChan = [self.dataChan[0]]
  820. self.ui.sumDataBox.setEnabled(False)
  821. thread.start_new_thread( self.RAWDataProc.sumData, ( self.ui.mplwidget, 7 ) )
  822. def adaptFilterFD(self):
  823. self.lock("FD noise cancellation filter")
  824. thread.start_new_thread(self.RAWDataProc.adaptiveFilterFD, \
  825. (str(self.ui.windowTypeComboBox.currentText()), \
  826. self.ui.windowBandwidthSpinBox.value(), \
  827. self.ui.CentralVSpinBox.value(), \
  828. self.ui.mplwidget))
  829. def bandPassFilter(self):
  830. if "Bandpass filter" not in self.YamlNode.Processing.keys():
  831. self.YamlNode.Processing["Bandpass filter"] = {}
  832. self.YamlNode.Processing["Bandpass filter"]["central_nu"] = str(self.ui.CentralVSpinBox.value())
  833. self.YamlNode.Processing["Bandpass filter"]["passband"] = str(self.ui.passBandSpinBox.value())
  834. self.YamlNode.Processing["Bandpass filter"]["stopband"] = str(self.ui.stopBandSpinBox.value())
  835. self.YamlNode.Processing["Bandpass filter"]["gpass"] = str(self.ui.gpassSpinBox.value())
  836. self.YamlNode.Processing["Bandpass filter"]["gstop"] = str(self.ui.gstopSpinBox.value())
  837. self.YamlNode.Processing["Bandpass filter"]["type"] = str(self.ui.fTypeComboBox.currentText())
  838. self.Log()
  839. else:
  840. err_msg = "Bandpass filter has already been applied!"
  841. reply =QtWidgets.QMessageBox.critical(self, 'Error',
  842. err_msg)
  843. return
  844. self.lock("bandpass filter")
  845. nv = self.ui.lcdTotalDeadTime.value( ) + self.ui.lcdNumberFTauDead.value()
  846. self.ui.lcdTotalDeadTime.display( nv )
  847. thread.start_new_thread(self.RAWDataProc.bandpassFilter, \
  848. (self.ui.mplwidget, 0, self.ui.plotBP.isChecked() ))
  849. def downsample(self):
  850. self.lock("resampling")
  851. if "Resample" not in self.YamlNode.Processing.keys():
  852. self.YamlNode.Processing["Resample"] = {}
  853. self.YamlNode.Processing["Resample"]["downsample factor"] = []
  854. self.YamlNode.Processing["Resample"]["truncate length"] = []
  855. self.YamlNode.Processing["Resample"]["downsample factor"].append( str(self.ui.downSampleSpinBox.value() ) )
  856. self.YamlNode.Processing["Resample"]["truncate length"].append( str( self.ui.truncateSpinBox.value() ) )
  857. self.Log( )
  858. thread.start_new_thread(self.RAWDataProc.downsample, \
  859. (self.ui.truncateSpinBox.value(), \
  860. self.ui.downSampleSpinBox.value(),
  861. self.ui.mplwidget))
  862. def quadDet(self):
  863. if "Quadrature detection" not in self.YamlNode.Processing.keys():
  864. self.YamlNode.Processing["Quadrature detection"] = {}
  865. self.YamlNode.Processing["Quadrature detection"]["trim"] = str( self.ui.trimSpin.value() )
  866. self.Log()
  867. else:
  868. err_msg = "Quadrature detection has already been done!"
  869. reply =QtWidgets.QMessageBox.critical(self, 'Error',
  870. err_msg)
  871. return
  872. self.lock("quadrature detection")
  873. thread.start_new_thread(self.RAWDataProc.quadDet, \
  874. (self.ui.trimSpin.value(), int(self.ui.QDType.currentIndex()), self.ui.mplwidget_2))
  875. self.ui.plotQD.setEnabled(True)
  876. def plotQD(self):
  877. self.lock("plot QD")
  878. thread.start_new_thread(self.RAWDataProc.plotQuadDet, \
  879. (self.ui.trimSpin.value(), int(self.ui.QDType.currentIndex()), self.ui.mplwidget_2))
  880. def gateIntegrate(self):
  881. if "Gate integrate" not in self.YamlNode.Processing.keys():
  882. self.YamlNode.Processing["Gate integrate"] = {}
  883. self.YamlNode.Processing["Gate integrate"]["gpd"] = str(self.ui.GPDspinBox.value( ) )
  884. self.Log()
  885. self.lock("gate integration")
  886. thread.start_new_thread(self.RAWDataProc.gateIntegrate, \
  887. (self.ui.GPDspinBox.value(), self.ui.trimSpin.value(), self.ui.mplwidget_2))
  888. self.ui.actionExport_Preprocessed_Dataset.setEnabled(True)
  889. self.ui.plotGI.setEnabled(True)
  890. def plotGI(self):
  891. self.lock("plot gate integrate")
  892. thread.start_new_thread(self.RAWDataProc.plotGateIntegrate, \
  893. (self.ui.GPDspinBox.value(), self.ui.trimSpin.value(), \
  894. self.ui.QDType_2.currentIndex(), self.ui.mplwidget_2))
  895. def designFilter(self):
  896. [bord, fe] = self.RAWDataProc.designFilter( \
  897. self.ui.CentralVSpinBox.value(), \
  898. self.ui.passBandSpinBox.value(), \
  899. self.ui.stopBandSpinBox.value(), \
  900. self.ui.gpassSpinBox.value(), \
  901. self.ui.gstopSpinBox.value(), \
  902. str(self.ui.fTypeComboBox.currentText()),
  903. self.ui.mplwidget)
  904. self.ui.lcdNumberFilterOrder.display(bord)
  905. self.ui.lcdNumberFTauDead.display(1e3*fe)
  906. #self.ui.lcdNumberFilterOrder.display(bord)
  907. self.ui.bandPassGO.setEnabled(1)
  908. # self.ui.lcdNumberTauPulse2.display(1e3*self.RAWDataProc.pulseLength[1])
  909. def windowFilter(self):
  910. if "Window filter" not in self.YamlNode.Processing.keys():
  911. self.YamlNode.Processing["Window filter"] = {}
  912. self.YamlNode.Processing["Window filter"]["type"] = str(self.ui.windowTypeComboBox.currentText())
  913. self.YamlNode.Processing["Window filter"]["width"] = str(self.ui.windowBandwidthSpinBox.value())
  914. self.YamlNode.Processing["Window filter"]["centre"] = str(self.ui.CentralVSpinBox.value() )
  915. self.Log()
  916. else:
  917. err_msg = "FD window has already been applied!"
  918. reply =QtWidgets.QMessageBox.critical(self, 'Error',
  919. err_msg)
  920. return
  921. self.lock("window filter")
  922. thread.start_new_thread(self.RAWDataProc.windowFilter, \
  923. (str(self.ui.windowTypeComboBox.currentText()), \
  924. self.ui.windowBandwidthSpinBox.value(), \
  925. self.ui.CentralVSpinBox.value(), \
  926. self.ui.mplwidget))
  927. def designFDFilter(self):
  928. # thread.start_new_thread(self.RAWDataProc.computeWindow, ( \
  929. # "Pulse 1",
  930. # self.ui.windowBandwidthSpinBox.value(), \
  931. # self.ui.CentralVSpinBox.value(), \
  932. # str(self.ui.windowTypeComboBox.currentText()), \
  933. # self.ui.mplwidget ))
  934. a,b,c,d,dead = self.RAWDataProc.computeWindow( \
  935. "Pulse 1",
  936. self.ui.windowBandwidthSpinBox.value(), \
  937. self.ui.CentralVSpinBox.value(), \
  938. str(self.ui.windowTypeComboBox.currentText()), \
  939. self.ui.mplwidget )
  940. self.ui.lcdWinDead.display(dead)
  941. def updateProgressBar(self, percent):
  942. self.ui.barProgress.setValue(percent)
  943. def updateProc(self):
  944. if str(self.ui.FIDProcComboBox.currentText()) == "Pulse 1":
  945. self.ui.lcdNumberFID1Length.display(self.RAWDataProc.DATADICT["Pulse 1"]["TIMES"][-1]- self.RAWDataProc.DATADICT["Pulse 1"]["TIMES"][0])
  946. elif str(self.ui.FIDProcComboBox.currentText()) == "Pulse 2":
  947. self.ui.lcdNumberFID2Length.display(self.RAWDataProc.DATADICT["Pulse 2"]["TIMES"][-1]- self.RAWDataProc.DATADICT["Pulse 2"]["TIMES"][0])
  948. else:
  949. self.ui.lcdNumberFID1Length.display(self.RAWDataProc.DATADICT["Pulse 1"]["TIMES"][-1]- self.RAWDataProc.DATADICT["Pulse 1"]["TIMES"][0])
  950. self.ui.lcdNumberFID2Length.display(self.RAWDataProc.DATADICT["Pulse 2"]["TIMES"][-1]- self.RAWDataProc.DATADICT["Pulse 2"]["TIMES"][0])
  951. self.ui.lcdNumberResampFreq.display( self.RAWDataProc.samp )
  952. def doneStatus(self): # unlocks GUI
  953. self.ui.statusbar.clearMessage ( )
  954. self.ui.barProgress.hide()
  955. self.updateProc()
  956. self.enableAll()
  957. def lock(self, string):
  958. self.ui.statusbar.showMessage ( string )
  959. self.ui.barProgress.show()
  960. self.ui.barProgress.setValue(0)
  961. self.disable()
  962. def unlock(self):
  963. self.ui.statusbar.clearMessage ( )
  964. self.ui.barProgress.hide()
  965. self.enableAll()
  966. def done(self):
  967. self.ui.statusbar.showMessage ( "" )
  968. ################################################################
  969. ################################################################
  970. # Boiler plate main function
  971. import pkg_resources
  972. from pkg_resources import resource_string
  973. import matplotlib.image as mpimg
  974. import matplotlib.pyplot as plt
  975. def main():
  976. # splash screen logo
  977. logo = pkg_resources.resource_filename(__name__, 'akvo.png')
  978. logo2 = pkg_resources.resource_filename(__name__, 'akvo2.png')
  979. qApp = QtWidgets.QApplication(sys.argv)
  980. ssplash = False
  981. if ssplash:
  982. pixmap = QtGui.QPixmap(logo)
  983. splash = QtWidgets.QSplashScreen(pixmap, QtCore.Qt.WindowStaysOnTopHint)
  984. splash.show()
  985. aw = ApplicationWindow()
  986. img=mpimg.imread(logo)
  987. for ax in [ aw.ui.mplwidget ]:
  988. ax.fig.clear()
  989. subplot = ax.fig.add_subplot(111)
  990. ax.fig.patch.set_facecolor( None )
  991. ax.fig.patch.set_alpha( .0 )
  992. subplot.imshow(img)
  993. subplot.xaxis.set_major_locator(plt.NullLocator())
  994. subplot.yaxis.set_major_locator(plt.NullLocator())
  995. ax.draw()
  996. if ssplash:
  997. splash.showMessage("Loading modules")
  998. splash.finish(aw)
  999. #time.sleep(1)
  1000. aw.setWindowTitle("Akvo v"+str(version))
  1001. aw.show()
  1002. qApp.setWindowIcon(QtGui.QIcon(logo2))
  1003. sys.exit(qApp.exec_())
  1004. if __name__ == "__main__":
  1005. main()