Surface NMR processing and inversion GUI
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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