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

akvoGUI.py 56KB

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