Surface NMR processing and inversion GUI
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

akvoGUI.py 51KB

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