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.

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