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 75KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676
  1. #/usr/bin/env python
  2. import sys
  3. import matplotlib
  4. matplotlib.use("QT5Agg")
  5. from PyQt5 import QtCore, QtGui, QtWidgets #, uic
  6. import numpy as np
  7. import time
  8. import os
  9. from copy import deepcopy
  10. from matplotlib.backends.backend_qt4 import NavigationToolbar2QT #as NavigationToolbar
  11. import datetime, time
  12. import pkg_resources # part of setuptools
  13. from collections import OrderedDict
  14. from ruamel import yaml
  15. from akvo.gui.main_ui import Ui_MainWindow
  16. from akvo.gui.addCircularLoop_ui import Ui_circularLoopAdd
  17. from akvo.gui.addFigure8Loop_ui import Ui_figure8LoopAdd
  18. from akvo.tressel import mrsurvey
  19. from pyLemma import LemmaCore
  20. from pyLemma import FDEM1D
  21. from pyLemma import Merlin
  22. VERSION = pkg_resources.require("Akvo")[0].version
  23. # Writes out numpy arrays into Eigen vectors as serialized by Lemma
  24. class MatrixXr(yaml.YAMLObject):
  25. yaml_tag = u'MatrixXr'
  26. def __init__(self, rows, cols, data):
  27. self.rows = rows
  28. self.cols = cols
  29. self.data = np.zeros((rows,cols))
  30. def __repr__(self):
  31. return "%s(rows=%r, cols=%r, data=%r)" % (self.__class__.__name__, self.rows, self.cols, self.data)
  32. class VectorXr(yaml.YAMLObject):
  33. yaml_tag = r'VectorXr'
  34. def __init__(self, array):
  35. self.size = np.shape(array)[0]
  36. self.data = array.tolist()
  37. def __repr__(self):
  38. # Converts to numpy array on import
  39. return "np.array(%r)" % (self.data)
  40. def setup_yaml():
  41. """ https://stackoverflow.com/a/8661021 """
  42. represent_dict_order = lambda self, data: self.represent_mapping('tag:yaml.org,2002:map', data.items())
  43. yaml.add_representer(OrderedDict, represent_dict_order)
  44. setup_yaml()
  45. class AkvoYamlNode(yaml.YAMLObject):
  46. yaml_tag = u'AkvoData'
  47. def __init__(self):
  48. self.Akvo_VERSION = VERSION
  49. self.Import = OrderedDict() # {}
  50. self.Processing = [] # OrderedDict()
  51. self.Stacking = OrderedDict()
  52. self.META = OrderedDict()
  53. def __repr__(self):
  54. return "%s(name=%r, Akvo_VERSION=%r, Import=%r, Processing=%r, self.Stacking=%r, self.META=%r)" % (
  55. self.__class__.__name__, self.Akvo_VERSION, self.Import, self.Processing, self.Stacking, self.META )
  56. try:
  57. import thread
  58. except ImportError:
  59. import _thread as thread #Py3K compatibility
  60. class MyPopup(QtWidgets.QWidget):
  61. def __init__(self, name):
  62. super().__init__()
  63. self.name = name
  64. self.initUI()
  65. def initUI(self):
  66. lblName = QtWidgets.QLabel(self.name, self)
  67. class ApplicationWindow(QtWidgets.QMainWindow):
  68. def __init__(self):
  69. super().__init__()
  70. #QtWidgets.QMainWindow.__init__(self)
  71. self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
  72. # alternative to calling pyuic
  73. #self.ui = uic.loadUi('main.ui', self)
  74. self.ui = Ui_MainWindow()
  75. self.ui.setupUi(self)
  76. self.RAWDataProc = None
  77. self.YamlNode = AkvoYamlNode()
  78. # initialise some stuff
  79. self.ui.lcdNumberTauPulse2.setEnabled(0)
  80. self.ui.lcdNumberTauPulse1.setEnabled(0)
  81. self.ui.lcdNumberNuTx.setEnabled(0)
  82. self.ui.lcdNumberTuneuF.setEnabled(0)
  83. self.ui.lcdNumberSampFreq.setEnabled(0)
  84. self.ui.lcdNumberTauDelay.setEnabled(0)
  85. self.ui.lcdNumberNQ.setEnabled(0)
  86. self.logText = []
  87. #######################
  88. ##################### #
  89. ## Make connections # #
  90. ##################### #
  91. #######################
  92. ##############
  93. # Menu items #
  94. ##############
  95. self.ui.actionOpen_GMR.triggered.connect(self.openGMRRAWDataset)
  96. self.ui.actionSave_Preprocessed_Dataset.triggered.connect(self.SavePreprocess)
  97. self.ui.actionExport_Preprocessed_Dataset.triggered.connect(self.ExportPreprocess)
  98. self.ui.actionExport_Preprocessed_Dataset.setEnabled(False)
  99. self.ui.actionOpen_Preprocessed_Dataset.triggered.connect(self.OpenPreprocess)
  100. self.ui.actionAboutAkvo.triggered.connect(self.about)
  101. ###########
  102. # Buttons #
  103. ###########
  104. self.ui.loadDataPushButton.pressed.connect(self.loadRAW)
  105. self.ui.sumDataGO.pressed.connect( self.sumDataChans )
  106. self.ui.bandPassGO.pressed.connect( self.bandPassFilter )
  107. self.ui.filterDesignPushButton.pressed.connect( self.designFilter )
  108. self.ui.fdDesignPushButton.pressed.connect( self.designFDFilter )
  109. self.ui.downSampleGO.pressed.connect( self.downsample )
  110. self.ui.windowFilterGO.pressed.connect( self.windowFilter )
  111. self.ui.adaptGO.pressed.connect( self.adaptFilter )
  112. self.ui.adaptFDGO.pressed.connect( self.adaptFilterFD )
  113. self.ui.qdGO.pressed.connect( self.quadDet )
  114. self.ui.gateIntegrateGO.pressed.connect( self.gateIntegrate )
  115. self.ui.calcQGO.pressed.connect( self.calcQ )
  116. self.ui.FDSmartStackGO.pressed.connect( self.FDSmartStack )
  117. self.ui.harmonicGO.pressed.connect( self.harmonicModel )
  118. self.ui.f0K1Spin.valueChanged.connect( self.LCDHarmonics )
  119. self.ui.f0KNSpin.valueChanged.connect( self.LCDHarmonics )
  120. self.ui.f0KsSpin.valueChanged.connect( self.LCDHarmonics )
  121. self.ui.f0Spin.valueChanged.connect( self.LCDHarmonics )
  122. self.ui.NHarmonicsFreqsSpin.valueChanged.connect( self.LCDHarmonics2 )
  123. self.ui.f1K1Spin.valueChanged.connect( self.LCDHarmonics2 )
  124. self.ui.f1KNSpin.valueChanged.connect( self.LCDHarmonics2 )
  125. self.ui.f1KsSpin.valueChanged.connect( self.LCDHarmonics2 )
  126. self.ui.f1Spin.valueChanged.connect( self.LCDHarmonics2 )
  127. self.ui.plotQD.setEnabled(False)
  128. self.ui.plotQD.pressed.connect( self.plotQD )
  129. self.ui.plotGI.setEnabled(False)
  130. self.ui.plotGI.pressed.connect( self.plotGI )
  131. # META
  132. self.ui.locEdit.editingFinished.connect( self.logSite )
  133. self.ui.UTMzone.currentIndexChanged.connect( self.logSite )
  134. self.ui.latBand.currentIndexChanged.connect( self.logSite )
  135. self.ui.ellipsoid.currentIndexChanged.connect( self.logSite )
  136. self.ui.incSpinBox.valueChanged.connect( self.logSite )
  137. self.ui.decSpinBox.valueChanged.connect( self.logSite )
  138. self.ui.intensitySpinBox.valueChanged.connect( self.logSite )
  139. self.ui.tempSpinBox.valueChanged.connect( self.logSite )
  140. self.ui.timeEdit.timeChanged.connect( self.logSite )
  141. self.ui.dateEdit.dateChanged.connect( self.logSite )
  142. # this may call the yaml stuff too often...
  143. self.ui.txtComments.textChanged.connect( self.logSite )
  144. self.ui.plotLoops.pressed.connect( self.plotLoops2 )
  145. self.ui.removeLoopButton.pressed.connect( self.removeLoop )
  146. # Loops
  147. self.ui.addLoopButton.pressed.connect( self.loopAdd )
  148. self.loops = {}
  149. # hide header info box
  150. #self.ui.headerFileBox.setVisible(False)
  151. self.ui.headerFileBox.clicked.connect( self.headerBoxShrink )
  152. self.ui.headerBox2.setVisible(False)
  153. # Clean up the tab widget
  154. self.ui.actionPreprocessing.triggered.connect(self.addPreProc)
  155. self.ui.actionModelling.triggered.connect(self.addModelling)
  156. self.ui.actionInversion.triggered.connect(self.addInversion)
  157. # tabs
  158. #self.ui.ProcTabs.tabCloseRequested.connect( self.closeTabs )
  159. #self.ui.ProcTabs.tabBar().setTabButton(7, QtWidgets.QTabBar.RightSide,None)
  160. self.ui.ProcTabs.removeTab(4)
  161. self.ui.ProcTabs.removeTab(4)
  162. self.ui.ProcTabs.removeTab(4)
  163. self.ui.ProcTabs.removeTab(4)
  164. #self.ui.LoadTab.close( )
  165. # Add progressbar to statusbar
  166. self.ui.barProgress = QtWidgets.QProgressBar()
  167. self.ui.statusbar.addPermanentWidget(self.ui.barProgress, 0);
  168. self.ui.barProgress.setMaximumSize(100, 16777215);
  169. self.ui.barProgress.hide();
  170. self.ui.mplwidget_navigator.setCanvas(self.ui.mplwidget)
  171. #self.ui.mplwidget_navigator_2.setCanvas(self.ui.mplwidget)
  172. ##########################################################################
  173. # Loop Table
  174. self.ui.loopTableWidget.setRowCount(80)
  175. self.ui.loopTableWidget.setColumnCount(6)
  176. self.ui.loopTableWidget.setHorizontalHeaderLabels( ["ch. tag", \
  177. "Northing [m]","Easting [m]","Height [m]", "Radius","Tx"] )
  178. for ir in range(0, self.ui.loopTableWidget.rowCount() ):
  179. for ic in range(1, self.ui.loopTableWidget.columnCount() ):
  180. pCell = QtWidgets.QTableWidgetItem()
  181. #pCell.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable)
  182. pCell.setFlags(QtCore.Qt.NoItemFlags) # not selectable
  183. pCell.setBackground( QtGui.QColor("lightgrey").lighter(110) )
  184. self.ui.loopTableWidget.setItem(ir, ic, pCell)
  185. self.ui.loopTableWidget.cellChanged.connect(self.loopCellChanged)
  186. #self.ui.loopTableWidget.cellPressed.connect(self.loopCellChanged)
  187. self.ui.loopTableWidget.itemClicked.connect(self.loopCellClicked)
  188. #self.ui.loopTableWidget.cellPressed.connect(self.loopCellClicked)
  189. self.ui.loopTableWidget.setDragDropOverwriteMode(False)
  190. self.ui.loopTableWidget.setDragEnabled(False)
  191. #self.ui.loopTableWidget.setDragDropMode(QtWidgets.QAbstractItemView.InternalMove)
  192. self.ui.txRxTable.setColumnCount(4)
  193. self.ui.txRxTable.setRowCount(0)
  194. self.ui.txRxTable.setHorizontalHeaderLabels( ["Label", "Geom.","Turns","Tx/Rx"] )
  195. ##########################################################################
  196. # layer Table
  197. self.ui.layerTableWidget.setRowCount(80)
  198. self.ui.layerTableWidget.setColumnCount(3)
  199. self.ui.layerTableWidget.setHorizontalHeaderLabels( [r"top [m]", r"bottom [m]", "σ [ Ωm]" ] )
  200. # do we want this
  201. self.ui.layerTableWidget.setDragDropOverwriteMode(False)
  202. self.ui.layerTableWidget.setDragEnabled(True)
  203. self.ui.layerTableWidget.setDragDropMode(QtWidgets.QAbstractItemView.InternalMove)
  204. pCell = QtWidgets.QTableWidgetItem()
  205. pCell.setFlags(QtCore.Qt.NoItemFlags) # not selectable
  206. pCell.setBackground( QtGui.QColor("lightgrey").lighter(110) )
  207. self.ui.layerTableWidget.setItem(0, 1, pCell)
  208. for ir in range(1, self.ui.layerTableWidget.rowCount() ):
  209. for ic in range(0, self.ui.layerTableWidget.columnCount() ):
  210. pCell = QtWidgets.QTableWidgetItem()
  211. #pCell.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable)
  212. pCell.setFlags(QtCore.Qt.NoItemFlags) # not selectable
  213. pCell.setBackground( QtGui.QColor("lightgrey").lighter(110) )
  214. self.ui.layerTableWidget.setItem(ir, ic, pCell)
  215. self.ui.layerTableWidget.cellChanged.connect(self.sigmaCellChanged)
  216. def LCDHarmonics(self):
  217. self.ui.lcdH1F.setEnabled(True)
  218. self.ui.lcdH1F.display( self.ui.f0Spin.value() * self.ui.f0K1Spin.value() )
  219. self.ui.lcdHNF.setEnabled(True)
  220. self.ui.lcdHNF.display( self.ui.f0Spin.value() * self.ui.f0KNSpin.value() )
  221. self.ui.lcdf0NK.setEnabled(True)
  222. self.ui.lcdf0NK.display( (self.ui.f0KNSpin.value()+1-self.ui.f0K1Spin.value()) * self.ui.f0KsSpin.value() )
  223. def LCDHarmonics2(self):
  224. if self.ui.NHarmonicsFreqsSpin.value() == 2:
  225. self.ui.lcdH1F2.setEnabled(True)
  226. self.ui.lcdH1F2.display( self.ui.f1Spin.value() * self.ui.f1K1Spin.value() )
  227. self.ui.lcdHNF2.setEnabled(True)
  228. self.ui.lcdHNF2.display( self.ui.f1Spin.value() * self.ui.f1KNSpin.value() )
  229. self.ui.lcdf0NK2.setEnabled(True)
  230. self.ui.lcdf0NK2.display( (self.ui.f1KNSpin.value()+1-self.ui.f1K1Spin.value()) * self.ui.f1KsSpin.value() )
  231. else:
  232. self.ui.lcdH1F2.setEnabled(False)
  233. self.ui.lcdHNF2.setEnabled(False)
  234. self.ui.lcdf0NK2.setEnabled(False)
  235. def closeTabs(self):
  236. #self.ui.ProcTabs.removeTab(idx)
  237. self.ui.ProcTabs.clear( )
  238. def addPreProc(self):
  239. if self.ui.actionPreprocessing.isChecked():
  240. self.ui.actionModelling.setChecked(False)
  241. self.ui.actionInversion.setChecked(False)
  242. self.ui.ProcTabs.clear( )
  243. self.ui.ProcTabs.insertTab( 0, self.ui.LoadTab, "Load" )
  244. self.ui.ProcTabs.insertTab( 1, self.ui.NCTab, "NC" )
  245. self.ui.ProcTabs.insertTab( 2, self.ui.QCTab, "QC" )
  246. self.ui.ProcTabs.insertTab( 3, self.ui.METATab, "META" )
  247. self.ui.ProcTabs.insertTab( 4, self.ui.LogTab, "Log" )
  248. else:
  249. self.ui.ProcTabs.removeTab(0)
  250. self.ui.ProcTabs.removeTab(0)
  251. self.ui.ProcTabs.removeTab(0)
  252. self.ui.ProcTabs.removeTab(0)
  253. def addModelling(self):
  254. if self.ui.actionModelling.isChecked():
  255. self.ui.actionPreprocessing.setChecked(False)
  256. self.ui.actionInversion.setChecked(False)
  257. self.ui.ProcTabs.clear( )
  258. self.ui.ProcTabs.insertTab( 0, self.ui.KernTab, "Kernel" )
  259. self.ui.ProcTabs.insertTab( 1, self.ui.ModelTab, "Modelling" )
  260. self.ui.ProcTabs.insertTab( 2, self.ui.LogTab, "Log" )
  261. else:
  262. self.ui.ProcTabs.removeTab(0)
  263. self.ui.ProcTabs.removeTab(0)
  264. def addInversion(self, idx):
  265. if self.ui.actionInversion.isChecked():
  266. self.ui.actionPreprocessing.setChecked(False)
  267. self.ui.actionModelling.setChecked(False)
  268. self.ui.ProcTabs.clear( )
  269. self.ui.ProcTabs.insertTab( 0, self.ui.InvertTab, "Inversion" )
  270. self.ui.ProcTabs.insertTab( 1, self.ui.AppraiseTab, "Appraisal" )
  271. self.ui.ProcTabs.insertTab( 2, self.ui.LogTab, "Log" )
  272. else:
  273. self.ui.ProcTabs.removeTab(0)
  274. self.ui.ProcTabs.removeTab(0)
  275. def loopAdd(self):
  276. #print(self.ui.loopLabel.text())
  277. #print(self.ui.loopGeom.currentText())
  278. #print(self.ui.loopType.currentText())
  279. #print( "label len", len(self.ui.loopLabel.text()) )
  280. if len(self.ui.loopLabel.text().strip()) == 0:
  281. Error = QtWidgets.QMessageBox()
  282. Error.setWindowTitle("Error!")
  283. Error.setText("Loop label cannot be blank or repeated")
  284. Error.setDetailedText("Each loop label must be unique and comprise at least one character. Leading and trailing whitespace will be trimmed.")
  285. Error.exec_()
  286. else:
  287. ### Circular loop
  288. if self.ui.loopGeom.currentText() == "Circular":
  289. dialog = QtWidgets.QDialog()
  290. dialog.ui = Ui_circularLoopAdd()
  291. dialog.ui.setupUi(dialog)
  292. dialog.exec_()
  293. dialog.show()
  294. if dialog.result():
  295. cn = dialog.ui.centreNorth.value()
  296. ce = dialog.ui.centreEast.value()
  297. ht = dialog.ui.loopHeight.value()
  298. rad = dialog.ui.loopRadius.value()
  299. turns = dialog.ui.loopTurns.value()
  300. ns = dialog.ui.segments.value()
  301. cwise = dialog.ui.cwiseBox.currentIndex()
  302. print("cwise", cwise)
  303. #dip = dialog.ui.dip.value()
  304. #azimuth = dialog.ui.az.value()
  305. self.loops[self.ui.loopLabel.text()] = FDEM1D.PolygonalWireAntenna()
  306. self.loops[self.ui.loopLabel.text()].SetNumberOfPoints( dialog.ui.segments.value() + 1 )
  307. self.loops[self.ui.loopLabel.text()].SetNumberOfTurns( dialog.ui.loopTurns.value() )
  308. points = np.linspace(0, 2*np.pi, dialog.ui.segments.value()+1)
  309. for iseg, ipt in enumerate(points):
  310. if cwise == 0:
  311. self.loops[self.ui.loopLabel.text()].SetPoint(iseg, ( cn+rad*np.sin(ipt), ce+rad*np.cos(ipt), ht) )
  312. else:
  313. self.loops[self.ui.loopLabel.text()].SetPoint(iseg, ( -cn+rad*np.sin(ipt), ce+rad*np.cos(ipt), ht) )
  314. self.loops[self.ui.loopLabel.text()].SetNumberOfFrequencies(1)
  315. self.loops[self.ui.loopLabel.text()].SetCurrent(1.)
  316. if self.ui.loopGeom.currentText() == "figure-8":
  317. dialog = QtWidgets.QDialog()
  318. dialog.ui = Ui_figure8LoopAdd()
  319. dialog.ui.setupUi(dialog)
  320. dialog.exec_()
  321. dialog.show()
  322. if dialog.result():
  323. cn1 = dialog.ui.centreNorth1.value()
  324. ce1 = dialog.ui.centreEast1.value()
  325. cn2 = dialog.ui.centreNorth2.value()
  326. ce2 = dialog.ui.centreEast2.value()
  327. ht = dialog.ui.loopHeight.value()
  328. rad = dialog.ui.loopRadius.value()
  329. turns = dialog.ui.loopTurns.value()
  330. ns = dialog.ui.segments.value()
  331. #cwise = dialog.ui.cwiseBox.currentIndex()
  332. print(cn1, ce1, cn2, ce2, ht, rad, turns, ns)
  333. # general across all types
  334. if dialog.result():
  335. # update the table
  336. self.ui.txRxTable.setRowCount( len(self.loops.keys()) )
  337. pCell = QtWidgets.QTableWidgetItem()
  338. pCell.setText( self.ui.loopLabel.text() )
  339. pCell.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled )
  340. self.ui.txRxTable.setItem( len(self.loops.keys())-1, 0, pCell)
  341. gCell = QtWidgets.QTableWidgetItem()
  342. gCell.setText( self.ui.loopGeom.currentText() )
  343. gCell.setFlags( QtCore.Qt.ItemIsEnabled )
  344. self.ui.txRxTable.setItem( len(self.loops.keys())-1, 1, gCell)
  345. tCell = QtWidgets.QTableWidgetItem()
  346. tCell.setText( str(dialog.ui.loopTurns.value()) )
  347. tCell.setFlags( QtCore.Qt.ItemIsEnabled )
  348. self.ui.txRxTable.setItem( len(self.loops.keys())-1, 2, tCell)
  349. txCell = QtWidgets.QTableWidgetItem()
  350. txCell.setText( str(self.ui.loopType.currentText()) )
  351. txCell.setFlags( QtCore.Qt.ItemIsEnabled )
  352. self.ui.txRxTable.setItem( len(self.loops.keys())-1, 3, txCell)
  353. def headerBoxShrink(self):
  354. #self.ui.headerFileBox.setVisible(False)
  355. if self.ui.headerFileBox.isChecked( ):
  356. #self.ui.headerFileBox.setMinimumSize(460,250)
  357. self.ui.headerBox2.setVisible(True)
  358. else:
  359. #self.ui.headerFileBox.setMinimumSize(460,50)
  360. self.ui.headerBox2.setVisible(False)
  361. def sigmaCellChanged(self):
  362. self.ui.layerTableWidget.cellChanged.disconnect(self.sigmaCellChanged)
  363. # TODO consider building the model whenever this is called. Would be nice to be able to
  364. # do that. Would require instead dist of T2 I guess.
  365. jj = self.ui.layerTableWidget.currentColumn()
  366. ii = self.ui.layerTableWidget.currentRow()
  367. val = "class 'NoneType'>"
  368. try:
  369. val = eval (str( self.ui.layerTableWidget.item(ii, jj).text() ))
  370. except:
  371. #if jj != 0:
  372. # Error = QtWidgets.QMessageBox()
  373. # Error.setWindowTitle("Error!")
  374. # Error.setText("Non-numeric value encountered")
  375. self.ui.layerTableWidget.cellChanged.connect(self.sigmaCellChanged)
  376. return
  377. if jj == 1:
  378. #item.setFlags(QtCore.Qt.ItemIsEnabled)
  379. pCell = self.ui.layerTableWidget.item(ii, jj)
  380. pCell.setBackground( QtGui.QColor("white"))
  381. pCell = self.ui.layerTableWidget.item(ii+1, jj-1)
  382. if str(type(pCell)) == "<class 'NoneType'>":
  383. pCell = QtWidgets.QTableWidgetItem()
  384. pCell.setFlags(QtCore.Qt.ItemIsEnabled)
  385. self.ui.layerTableWidget.setItem(ii+1, jj-1, pCell)
  386. if ii == 0:
  387. pCell.setText(str(val))
  388. #pCell3 = self.ui.layerTableWidget.item(ii+1, jj)
  389. #print ("setting", ii, jj, type(pCell3))
  390. #print ( "setting", ii, jj, type(pCell3))
  391. #pCell3.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsEnabled )
  392. #pCell3.setFlags( QtCore.Qt.ItemIsEditable )
  393. elif ii > 0:
  394. val2 = eval (str( self.ui.layerTableWidget.item(ii-1, jj).text() ))
  395. #print ("val2", val2, val, type(val))
  396. #if str(type(pCell)) == "<class 'NoneType'>":
  397. if type(val) == str or val > val2:
  398. pCell.setText(str(val))
  399. else:
  400. Error = QtWidgets.QMessageBox()
  401. Error.setWindowTitle("Error!")
  402. Error.setText("Non-increasing layer detected")
  403. Error.setDetailedText("Each layer interface must be below the one above it.")
  404. Error.exec_()
  405. #err_msg = "Quadrature detection has already been done!"
  406. #reply =QtWidgets.QMessageBox.critical(self, 'Error',
  407. # err_msg)
  408. pCell2 = self.ui.layerTableWidget.item(ii, jj)
  409. pCell2.setText(str(""))
  410. self.ui.layerTableWidget.cellChanged.connect(self.sigmaCellChanged)
  411. return
  412. # enable next layer
  413. pCell4 = self.ui.layerTableWidget.item(ii+1, jj)
  414. pCell4.setBackground( QtGui.QColor("lightblue") ) #.lighter(110))
  415. pCell4.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsEnabled )
  416. pCell5 = self.ui.layerTableWidget.item(ii+1, jj+1)
  417. pCell5.setBackground( QtGui.QColor("white"))
  418. pCell5.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsEnabled )
  419. print("ii", ii, "jj", jj)
  420. if ii == 0 and jj == 0:
  421. pCell = self.ui.layerTableWidget.item(0, 1)
  422. pCell.setBackground( QtGui.QColor("lightblue")) #.lighter(110) )
  423. pCell.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsEnabled )
  424. self.ui.layerTableWidget.cellChanged.connect(self.sigmaCellChanged)
  425. def loopCellClicked(self, item):
  426. print("checkstate", item.checkState(),item.row())
  427. #self.ui.loopTableWidget.itemClicked.disconnect(self.loopCellClicked)
  428. jj = item.column()
  429. ii = item.row()
  430. tp = type(self.ui.loopTableWidget.item(ii, 0))
  431. print("tp", tp, ii, jj)
  432. if str(tp) == "<class 'NoneType'>":
  433. return
  434. #print("Clicked", ii, jj)
  435. if jj == 5 and self.ui.loopTableWidget.item(ii, 0).text() in self.loops.keys():
  436. #print("jj=5")
  437. self.loops[ self.ui.loopTableWidget.item(ii, 0).text() ]["Tx"] = self.ui.loopTableWidget.item(ii, 5).checkState()
  438. # update surrogates
  439. print("updating surrogates")
  440. for point in self.loops[ self.ui.loopTableWidget.item(ii, 0).text() ]["points"][1:]:
  441. pCell = self.ui.loopTableWidget.item(point, 5)
  442. if self.ui.loopTableWidget.item(ii, 5).checkState():
  443. pCell.setCheckState(QtCore.Qt.Checked);
  444. else:
  445. pCell.setCheckState(QtCore.Qt.Unchecked);
  446. #print( "loops", self.loops[ self.ui.loopTableWidget.item(ii, 0).text() ]["Tx"])
  447. #self.ui.loopTableWidget.itemClicked.connect(self.loopCellClicked)
  448. def loopCellChanged(self):
  449. self.ui.loopTableWidget.cellChanged.disconnect(self.loopCellChanged)
  450. jj = self.ui.loopTableWidget.currentColumn()
  451. ii = self.ui.loopTableWidget.currentRow()
  452. if jj == 0 and len( self.ui.loopTableWidget.item(ii, jj).text().strip()) == 0:
  453. for jjj in range(jj+1,jj+6):
  454. pCell = self.ui.loopTableWidget.item(ii, jjj)
  455. pCell.setBackground( QtGui.QColor("white") )
  456. pCell.setFlags( QtCore.Qt.NoItemFlags | QtCore.Qt.ItemIsUserCheckable ) # not selectable
  457. elif jj == 0 and len( self.ui.loopTableWidget.item(ii, jj).text().strip() ): # ch. tag modified
  458. for jjj in range(jj+1,jj+5):
  459. pCell = self.ui.loopTableWidget.item(ii, jjj)
  460. pCell.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsEnabled )
  461. pCell.setBackground( QtGui.QColor("lightblue") )
  462. if self.ui.loopTableWidget.item(ii, jj).text() not in self.loops.keys():
  463. # This is a new loop ID
  464. self.loops[ self.ui.loopTableWidget.item(ii, jj).text() ] = {}
  465. self.loops[ self.ui.loopTableWidget.item(ii, jj).text() ]["Tx"] = self.ui.loopTableWidget.item(ii, 5).checkState()
  466. self.loops[ self.ui.loopTableWidget.item(ii, jj).text() ]["points"] = [ii]
  467. # Transmitter cell
  468. pCell = self.ui.loopTableWidget.item(ii, jj+5)
  469. pCell.setCheckState(QtCore.Qt.Unchecked)
  470. pCell.setFlags( QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled )
  471. pCell.setBackground( QtGui.QColor("lightblue") )
  472. else:
  473. # This is an existing loop ID
  474. self.loops[ self.ui.loopTableWidget.item(ii, jj).text() ]["points"].append( ii )
  475. pCell = self.ui.loopTableWidget.item(ii, jj+5)
  476. pCell.setFlags(QtCore.Qt.NoItemFlags) # not selectable
  477. if self.loops[ self.ui.loopTableWidget.item(ii, 0).text() ]["Tx"]:
  478. pCell.setCheckState(QtCore.Qt.Checked);
  479. else:
  480. pCell.setCheckState(QtCore.Qt.Unchecked);
  481. #pCell.setFlags( )
  482. pCell.setBackground( QtGui.QColor("lightblue") )
  483. self.plotLoops()
  484. self.ui.loopTableWidget.cellChanged.connect(self.loopCellChanged)
  485. def plotLoops2(self):
  486. self.ui.mplwidget.reAxH(1)
  487. for loop in self.loops:
  488. POINTS = self.loops[loop].GetPoints().T
  489. self.ui.mplwidget.ax1.plot( POINTS[:,1], POINTS[:,0], label=loop )
  490. self.ui.mplwidget.ax1.spines['right'].set_visible(False)
  491. self.ui.mplwidget.ax1.spines['top'].set_visible(False)
  492. self.ui.mplwidget.ax1.set_xlabel("easting (m)")
  493. self.ui.mplwidget.ax1.set_ylabel("northing (m)")
  494. self.ui.mplwidget.ax1.legend()
  495. self.ui.mplwidget.ax1.set_aspect('equal') #, adjustable='box')
  496. self.ui.mplwidget.draw()
  497. def removeLoop(self):
  498. del self.loops[ self.ui.txRxTable.item( self.ui.txRxTable.currentRow(), 0).text() ]
  499. self.ui.txRxTable.removeRow(self.ui.txRxTable.currentRow())
  500. def plotLoops(self):
  501. self.ui.mplwidget.reAxH(1)
  502. #self.ui.mplwidget.ax1.clear()
  503. #self.ui.mplwidget.ax2.clear()
  504. nor = dict()
  505. eas = dict()
  506. dep = dict()
  507. for ii in range( self.ui.loopTableWidget.rowCount() ):
  508. for jj in range( self.ui.loopTableWidget.columnCount() ):
  509. tp = type(self.ui.loopTableWidget.item(ii, jj))
  510. if str(tp) == "<class 'NoneType'>":
  511. pass
  512. elif not len(self.ui.loopTableWidget.item(ii, jj).text()):
  513. pass
  514. else:
  515. if jj == 0:
  516. idx = self.ui.loopTableWidget.item(ii, 0).text()
  517. if idx not in nor.keys():
  518. nor[idx] = list()
  519. eas[idx] = list()
  520. dep[idx] = list()
  521. if jj == 4:
  522. # circular loop
  523. m2pi = np.linspace(0,2*np.pi,10)
  524. rad = 30.
  525. nor[idx] = np.concatenate((np.array(nor[idx]), rad * np.sin(m2pi)))
  526. eas[idx] = np.concatenate((np.array(eas[idx]), rad * np.cos(m2pi)))
  527. dep[idx] = np.concatenate((np.array(dep[idx]), np.ones(len(m2pi))))
  528. print("nor", nor[idx])
  529. if jj == 1:
  530. nor[idx].append( eval(self.ui.loopTableWidget.item(ii, 1).text()) )
  531. elif jj == 2:
  532. eas[idx].append( eval(self.ui.loopTableWidget.item(ii, 2).text()) )
  533. elif jj == 3:
  534. dep[idx].append( eval(self.ui.loopTableWidget.item(ii, 3).text()) )
  535. for ii in nor.keys():
  536. try:
  537. self.ui.mplwidget.ax1.plot( np.array(nor[ii]), np.array(eas[ii]) )
  538. except:
  539. pass
  540. #self.ui.mplwidget.figure.axes().set
  541. self.ui.mplwidget.ax1.set_aspect('equal') #, adjustable='box')
  542. self.ui.mplwidget.draw()
  543. def about(self):
  544. # TODO proper popup with info
  545. #self.w = MyPopup("""About Akvo \n
  546. # Akvo is an open source project developed primarily by Trevor Irons.
  547. #""")
  548. #self.w.setGeometry(100, 100, 400, 200)
  549. #self.w.show()
  550. # Just a splash screen for now
  551. logo = pkg_resources.resource_filename(__name__, 'akvo_about.png')
  552. pixmap = QtGui.QPixmap(logo)
  553. self.splash = QtWidgets.QSplashScreen(pixmap, QtCore.Qt.WindowStaysOnTopHint)
  554. self.splash.show()
  555. def connectGMRDataProcessor(self):
  556. self.RAWDataProc = mrsurvey.GMRDataProcessor()
  557. self.RAWDataProc.progressTrigger.connect(self.updateProgressBar)
  558. self.RAWDataProc.enableDSPTrigger.connect(self.enableDSP)
  559. self.RAWDataProc.doneTrigger.connect(self.doneStatus)
  560. self.RAWDataProc.updateProcTrigger.connect(self.updateProc)
  561. def openGMRRAWDataset(self):
  562. """ Opens a GMR header file
  563. """
  564. try:
  565. with open('.gmr.last.path') as f:
  566. fpath = f.readline()
  567. pass
  568. except IOError as e:
  569. fpath = '.'
  570. self.headerstr = QtWidgets.QFileDialog.getOpenFileName(self, 'Open File', fpath)[0] # arg2 = File Type 'All Files (*)'
  571. self.ui.headerFileTextBrowser.clear()
  572. self.ui.headerFileTextBrowser.append(self.headerstr)
  573. if len(self.headerstr) == 0:
  574. return
  575. # clear the processing log
  576. self.ui.logTextBrowser.clear()
  577. self.logText = [] #MAK 20170126
  578. path,filen=os.path.split(str(self.headerstr))
  579. f = open('.gmr.last.path', 'w')
  580. f.write( str(self.headerstr) ) # prompt last file
  581. self.connectGMRDataProcessor()
  582. self.RAWDataProc.readHeaderFile(str(self.headerstr))
  583. # If we got this far, enable all the widgets
  584. self.ui.lcdNumberTauPulse1.setEnabled(True)
  585. self.ui.lcdNumberNuTx.setEnabled(True)
  586. self.ui.lcdNumberTuneuF.setEnabled(True)
  587. self.ui.lcdNumberSampFreq.setEnabled(True)
  588. self.ui.lcdNumberNQ.setEnabled(True)
  589. self.ui.headerFileBox.setEnabled(True)
  590. self.ui.headerFileBox.setChecked( True )
  591. self.ui.headerBox2.setVisible(True)
  592. self.ui.inputRAWParametersBox.setEnabled(True)
  593. self.ui.loadDataPushButton.setEnabled(True)
  594. # make plots as you import the dataset
  595. self.ui.plotImportCheckBox.setEnabled(True)
  596. self.ui.plotImportCheckBox.setChecked(True)
  597. # Update info from the header into the GUI
  598. self.ui.pulseTypeTextBrowser.clear()
  599. self.ui.pulseTypeTextBrowser.append(self.RAWDataProc.pulseType)
  600. self.ui.lcdNumberNuTx.display(self.RAWDataProc.transFreq)
  601. self.ui.lcdNumberTauPulse1.display(1e3*self.RAWDataProc.pulseLength[0])
  602. self.ui.lcdNumberTuneuF.display(self.RAWDataProc.TuneCapacitance)
  603. self.ui.lcdNumberSampFreq.display(self.RAWDataProc.samp)
  604. self.ui.lcdNumberNQ.display(self.RAWDataProc.nPulseMoments)
  605. self.ui.DeadTimeSpinBox.setValue(1e3*self.RAWDataProc.deadTime)
  606. self.ui.CentralVSpinBox.setValue( self.RAWDataProc.transFreq )
  607. if self.RAWDataProc.pulseType != "FID":
  608. self.ui.lcdNumberTauPulse2.setEnabled(1)
  609. self.ui.lcdNumberTauPulse2.display(1e3*self.RAWDataProc.pulseLength[1])
  610. self.ui.lcdNumberTauDelay.setEnabled(1)
  611. self.ui.lcdNumberTauDelay.display(1e3*self.RAWDataProc.interpulseDelay)
  612. self.ui.FIDProcComboBox.clear()
  613. if self.RAWDataProc.pulseType == "4PhaseT1" or self.RAWDataProc.pulseType == "T1":
  614. self.ui.FIDProcComboBox.insertItem(0, "Pulse 1")
  615. self.ui.FIDProcComboBox.insertItem(1, "Pulse 2")
  616. self.ui.FIDProcComboBox.insertItem(2, "Both")
  617. self.ui.FIDProcComboBox.setCurrentIndex (1)
  618. elif self.RAWDataProc.pulseType == "FID":
  619. self.ui.FIDProcComboBox.insertItem(0, "Pulse 1")
  620. self.ui.FIDProcComboBox.setCurrentIndex (0)
  621. def ExportPreprocess(self):
  622. """ This method exports to YAML
  623. """
  624. try:
  625. with open('.akvo.last.yaml.path') as f:
  626. fpath = f.readline()
  627. pass
  628. except IOError as e:
  629. fpath = '.'
  630. fdir = os.path.dirname(fpath)
  631. # Pickle the preprocessed data dictionary
  632. SaveStr = QtWidgets.QFileDialog.getSaveFileName(self, "Save as", fdir, r"Processed data (*.yaml)")[0]
  633. spath,filen=os.path.split(str(SaveStr))
  634. f = open('.akvo.last.yaml.path', 'w')
  635. f.write( str(spath) ) # prompt last file
  636. INFO = {}
  637. INFO["headerstr"] = str(self.headerstr)
  638. INFO["pulseType"] = self.RAWDataProc.pulseType
  639. INFO["transFreq"] = self.RAWDataProc.transFreq.tolist()
  640. INFO["pulseLength"] = self.RAWDataProc.pulseLength.tolist()
  641. INFO["TuneCapacitance"] = self.RAWDataProc.TuneCapacitance.tolist()
  642. #INFO["samp"] = self.RAWDataProc.samp
  643. INFO["nPulseMoments"] = self.RAWDataProc.nPulseMoments
  644. #INFO["deadTime"] = self.RAWDataProc.deadTime
  645. INFO["processed"] = "Akvo v. 1.0, on " + time.strftime("%d/%m/%Y")
  646. # Pulse current info
  647. ip = 0
  648. INFO["Pulses"] = {}
  649. for pulse in self.RAWDataProc.DATADICT["PULSES"]:
  650. qq = []
  651. qv = []
  652. for ipm in range(self.RAWDataProc.DATADICT["nPulseMoments"]):
  653. #for istack in self.RAWDataProc.DATADICT["stacks"]:
  654. # print ("stack q", self.RAWDataProc.DATADICT[pulse]["Q"][ipm,istack-1])
  655. qq.append(np.mean( self.RAWDataProc.DATADICT[pulse]["Q"][ipm,:]) )
  656. qv.append(np.std( self.RAWDataProc.DATADICT[pulse]["Q"][ipm,:]/self.RAWDataProc.pulseLength[ip] ))
  657. qq = np.array(qq)
  658. qv = np.array(qv)
  659. iQ = np.argsort(np.array(qq))
  660. qq = np.array(qq)[iQ]
  661. print("qq", qq, iQ)
  662. qv = np.array(qv)[iQ]
  663. INFO["Pulses"][pulse] = {}
  664. INFO["Pulses"][pulse]["units"] = "A"
  665. INFO["Pulses"][pulse]["current"] = VectorXr(qq/self.RAWDataProc.pulseLength[ip])
  666. INFO["Pulses"][pulse]["variance"] = VectorXr(qv)
  667. ip += 1
  668. # Data
  669. if self.RAWDataProc.gated == True:
  670. INFO["Gated"] = {}
  671. INFO["Gated"]["abscissa units"] = "ms"
  672. INFO["Gated"]["data units"] = "nT"
  673. for pulse in self.RAWDataProc.DATADICT["PULSES"]:
  674. INFO["Gated"][pulse] = {}
  675. INFO["Gated"][pulse]["abscissa"] = VectorXr( self.RAWDataProc.GATEDABSCISSA )
  676. INFO["Gated"][pulse]["windows"] = VectorXr( self.RAWDataProc.GATEDWINDOW )
  677. for ichan in self.RAWDataProc.DATADICT[pulse]["chan"]:
  678. INFO["Gated"][pulse]["Chan. " + str(ichan)] = {}
  679. INFO["Gated"][pulse]["Chan. " + str(ichan)]["STD"] = VectorXr( np.std(self.RAWDataProc.GATED[ichan]["NR"], axis=0) )
  680. for ipm in range(self.RAWDataProc.DATADICT["nPulseMoments"]):
  681. INFO["Gated"][pulse]["Chan. " + str(ichan)]["Q-"+str(ipm) + " CA"] = VectorXr(self.RAWDataProc.GATED[ichan]["CA"][ipm])
  682. INFO["Gated"][pulse]["Chan. " + str(ichan)]["Q-"+str(ipm) + " RE"] = VectorXr(self.RAWDataProc.GATED[ichan]["RE"][ipm])
  683. INFO["Gated"][pulse]["Chan. " + str(ichan)]["Q-"+str(ipm) + " IM"] = VectorXr(self.RAWDataProc.GATED[ichan]["IM"][ipm])
  684. #INFO["Gated"][pulse]["Chan. " + str(ichan)]["Q-"+str(ipm) + " IP"] = VectorXr(self.RAWDataProc.GATED[ichan]["IP"][ipm])
  685. #INFO["Gated"][pulse]["Chan. " + str(ichan)]["Q-"+str(ipm) + " NR"] = VectorXr(self.RAWDataProc.GATED[ichan]["NR"][ipm])
  686. #INFO["Gated"][pulse]["Chan. " + str(ichan)]["Q-"+str(ipm) + " STD" ] = VectorXr(self.RAWDataProc.GATED[ichan]["SIGMA"][ipm])
  687. # we have gated data
  688. # Window edges
  689. # Window centres
  690. with open(SaveStr, 'w') as outfile:
  691. #for line in self.logText:
  692. # outfile.write(line+"\n")
  693. yaml.dump(self.YamlNode, outfile)
  694. yaml.dump(INFO, outfile) #, default_flow_style=False)
  695. def SavePreprocess(self):
  696. #if "Saved" not in self.YamlNode.Processing.keys():
  697. # self.YamlNode.Processing["Saved"] = []
  698. #self.YamlNode.Processing["Saved"].append(datetime.datetime.now().isoformat())
  699. #self.Log()
  700. import pickle, os
  701. try:
  702. with open('.akvo.last.path') as f:
  703. fpath = f.readline()
  704. pass
  705. except IOError as e:
  706. fpath = '.'
  707. fdir = os.path.dirname(fpath)
  708. # Pickle the preprocessed data dictionary
  709. SaveStr = QtWidgets.QFileDialog.getSaveFileName(self, "Save as", fdir, r"Pickle (*.dmp)")
  710. print(SaveStr)
  711. spath,filen=os.path.split(str(SaveStr[0]))
  712. f = open('.akvo.last.path', 'w')
  713. f.write( str(spath) ) # prompt last file
  714. save = open(SaveStr[0], 'wb')
  715. # Add some extra info
  716. INFO = {}
  717. INFO["pulseType"] = self.RAWDataProc.pulseType
  718. INFO["prePulseDelay"] = self.RAWDataProc.prePulseDelay
  719. INFO["interpulseDelay"] = self.RAWDataProc.interpulseDelay
  720. INFO["transFreq"] = self.RAWDataProc.transFreq
  721. INFO["pulseLength"] = self.RAWDataProc.pulseLength
  722. INFO["TuneCapacitance"] = self.RAWDataProc.TuneCapacitance
  723. INFO["samp"] = self.RAWDataProc.samp
  724. INFO["nPulseMoments"] = self.RAWDataProc.nPulseMoments
  725. INFO["deadTime"] = self.RAWDataProc.deadTime
  726. INFO["transFreq"] = self.RAWDataProc.transFreq
  727. INFO["headerstr"] = str(self.headerstr)
  728. INFO["nDAQVersion"] = self.RAWDataProc.nDAQVersion
  729. INFO["log"] = yaml.dump( self.YamlNode )
  730. self.RAWDataProc.DATADICT["INFO"] = INFO
  731. pickle.dump(self.RAWDataProc.DATADICT, save)
  732. save.close()
  733. # Export XML file suitable for USGS ScienceBase Data Release
  734. def ExportXML(self):
  735. """ This is a filler function for use by USGS collaborators
  736. """
  737. return 42
  738. def OpenPreprocess(self):
  739. import pickle
  740. try:
  741. with open('.akvo.last.path') as f:
  742. fpath = f.readline()
  743. pass
  744. except IOError as e:
  745. fpath = '.'
  746. #filename = QtWidgets.QFileDialog.getOpenFileName(self, 'Open File', '.')
  747. fpath = QtWidgets.QFileDialog.getOpenFileName(self, 'Open preprocessed file', fpath, r"Pickle Files (*.dmp)")[0]
  748. f = open('.akvo.last.path', 'w')
  749. f.write( str(fpath) ) # prompt last file
  750. self.ui.logTextBrowser.clear()
  751. self.logText = []
  752. if len(fpath) == 0:
  753. return
  754. pfile = open(fpath,'rb')
  755. unpickle = pickle.Unpickler(pfile)
  756. self.connectGMRDataProcessor()
  757. self.RAWDataProc.DATADICT = unpickle.load()
  758. # This line causes Akvo to crash, if the header file is no longer there. We don't need to load the
  759. # file. TODO, need to disable "Load Data" in Load command though, as that is no longer possible.
  760. #self.RAWDataProc.readHeaderFile(self.RAWDataProc.DATADICT["INFO"]["headerstr"])
  761. self.headerstr = self.RAWDataProc.DATADICT["INFO"]["headerstr"]
  762. self.RAWDataProc.pulseType = self.RAWDataProc.DATADICT["INFO"]["pulseType"]
  763. self.RAWDataProc.transFreq = self.RAWDataProc.DATADICT["INFO"]["transFreq"]
  764. self.RAWDataProc.pulseLength = self.RAWDataProc.DATADICT["INFO"]["pulseLength"]
  765. self.RAWDataProc.TuneCapacitance = self.RAWDataProc.DATADICT["INFO"]["TuneCapacitance"]
  766. self.RAWDataProc.samp = self.RAWDataProc.DATADICT["INFO"]["samp"]
  767. self.RAWDataProc.nPulseMoments = self.RAWDataProc.DATADICT["INFO"]["nPulseMoments"]
  768. self.RAWDataProc.deadTime = self.RAWDataProc.DATADICT["INFO"]["deadTime"]
  769. self.RAWDataProc.transFreq = self.RAWDataProc.DATADICT["INFO"]["transFreq"]
  770. self.RAWDataProc.nDAQVersion = self.RAWDataProc.DATADICT["INFO"]["nDAQVersion"]
  771. #self.RAWDataProc.prePulseDelay = self.RAWDataProc.DATADICT["INFO"]["prePulseDelay"]
  772. self.RAWDataProc.dt = 1./self.RAWDataProc.samp
  773. self.dataChan = self.RAWDataProc.DATADICT[ self.RAWDataProc.DATADICT["PULSES"][0] ]["chan"]
  774. # Keep backwards compatibility with prior saved pickles???
  775. #self.ui.logTextBrowser.clear()
  776. #self.ui.logTextBrowser.append( yaml.dump(self.YamlNode)) #, default_flow_style=False) )
  777. #for a in self.logText:
  778. # self.ui.logTextBrowser.append(str(a))
  779. #self.ui.logTextBrowser
  780. #self.ui.logTextBrowser.clear()
  781. #print ( self.RAWDataProc.DATADICT["INFO"]["log"] )
  782. self.logText = self.RAWDataProc.DATADICT["INFO"]["log"] # YAML
  783. self.YamlNode = AkvoYamlNode( ) #self.logText )
  784. self.YamlNode.Akvo_VERSION = (yaml.load( self.logText, Loader=yaml.Loader )).Akvo_VERSION
  785. AKVO_VERSION = np.array(self.YamlNode.Akvo_VERSION.split("."), dtype=int)
  786. if AKVO_VERSION[0] >= 1 and AKVO_VERSION[1] >= 2 and AKVO_VERSION[2] >= 3:
  787. self.RAWDataProc.interpulseDelay = self.RAWDataProc.DATADICT["INFO"]["interpulseDelay"]
  788. self.YamlNode.Import = OrderedDict((yaml.load( self.logText, Loader=yaml.Loader )).Import)
  789. self.YamlNode.Processing = list((yaml.load( self.logText, Loader=yaml.Loader )).Processing)
  790. self.YamlNode.Stacking = OrderedDict((yaml.load( self.logText, Loader=yaml.Loader )).Stacking)
  791. self.YamlNode.META = OrderedDict((yaml.load( self.logText, Loader=yaml.Loader )).META)
  792. self.Log()
  793. #self.ui.logTextBrowser.append( yaml.dump(self.YamlNode)) #, default_flow_style=False) )
  794. #except KeyError:
  795. # pass
  796. # Remove "Saved" and "Loaded" from processing flow
  797. #if "Loaded" not in self.YamlNode.Processing.keys():
  798. # self.YamlNode.Processing["Loaded"] = []
  799. #self.YamlNode.Processing["Loaded"].append(datetime.datetime.now().isoformat())
  800. #self.Log()
  801. # If we got this far, enable all the widgets
  802. self.ui.lcdNumberTauPulse1.setEnabled(True)
  803. self.ui.lcdNumberNuTx.setEnabled(True)
  804. self.ui.lcdNumberTuneuF.setEnabled(True)
  805. self.ui.lcdNumberSampFreq.setEnabled(True)
  806. self.ui.lcdNumberNQ.setEnabled(True)
  807. self.ui.headerFileBox.setEnabled(True)
  808. self.ui.headerFileBox.setChecked( True )
  809. self.headerBoxShrink()
  810. #self.ui.headerBox2.setVisible(True)
  811. self.ui.inputRAWParametersBox.setEnabled(False)
  812. self.ui.loadDataPushButton.setEnabled(True)
  813. # make plots as you import the datasetmost
  814. self.ui.plotImportCheckBox.setEnabled(True)
  815. self.ui.plotImportCheckBox.setChecked(True)
  816. # enable the LCDs
  817. self.ui.lcdNumberFID1Length.setEnabled(1)
  818. self.ui.lcdNumberFID2Length.setEnabled(1)
  819. self.ui.lcdNumberResampFreq.setEnabled(1)
  820. self.ui.lcdTotalDeadTime.setEnabled(1)
  821. # enable META tab
  822. self.ui.METATab.setEnabled(1)
  823. self.ui.siteBox.setEnabled(1)
  824. #self.ui.lcdTotalDeadTime.display( 1e3*self.RAWDataProc.DATADICT["INFO"]["deadTime"] )
  825. self.ui.headerFileTextBrowser.clear( )
  826. self.ui.headerFileTextBrowser.append( self.RAWDataProc.DATADICT["INFO"]["headerstr"] )
  827. if u"Pulse 1" in self.RAWDataProc.DATADICT.keys():
  828. self.ui.lcdNumberFID1Length.display(self.RAWDataProc.DATADICT["Pulse 1"]["TIMES"][-1]- self.RAWDataProc.DATADICT["Pulse 1"]["TIMES"][0])
  829. self.ui.lcdTotalDeadTime.display( round(1e3*(self.RAWDataProc.DATADICT["Pulse 1"]["TIMES"][0]-self.RAWDataProc.DATADICT["Pulse 1"]["PULSE_TIMES"][-1]), 3) )
  830. print("CALC DEAD", (1e3*(self.RAWDataProc.prePulseDelay))) # - (self.RAWDataProc.DATADICT["Pulse 1"]["TIMES"][0]-self.RAWDataProc.DATADICT["Pulse 1"]["PULSE_TIMES"][-1])), 3) )
  831. if u"Pulse 2" in self.RAWDataProc.DATADICT.keys():
  832. self.ui.lcdNumberFID1Length.display(self.RAWDataProc.DATADICT["Pulse 2"]["TIMES"][-1]- self.RAWDataProc.DATADICT["Pulse 2"]["TIMES"][0])
  833. self.ui.lcdTotalDeadTime.display( 1e3 * (self.RAWDataProc.DATADICT["Pulse 2"]["TIMES"][0]-self.RAWDataProc.DATADICT["Pulse 2"]["PULSE_TIMES"][-1]) )
  834. # Update info from the header into the GUI
  835. self.ui.pulseTypeTextBrowser.clear()
  836. self.ui.pulseTypeTextBrowser.append(self.RAWDataProc.pulseType)
  837. self.ui.lcdNumberNuTx.display(self.RAWDataProc.transFreq)
  838. self.ui.lcdNumberTauPulse1.display(1e3*self.RAWDataProc.pulseLength[0])
  839. self.ui.lcdNumberTuneuF.display(self.RAWDataProc.TuneCapacitance)
  840. self.ui.lcdNumberResampFreq.display(self.RAWDataProc.samp)
  841. self.ui.lcdNumberSampFreq.display(50000) # TODO, if non GMR is supported, query
  842. self.ui.lcdNumberNQ.display(self.RAWDataProc.nPulseMoments)
  843. self.ui.DeadTimeSpinBox.setValue(1e3*self.RAWDataProc.deadTime)
  844. self.ui.CentralVSpinBox.setValue( self.RAWDataProc.transFreq )
  845. if self.RAWDataProc.pulseType != "FID":
  846. self.ui.lcdNumberTauPulse2.setEnabled(1)
  847. self.ui.lcdNumberTauPulse2.display(1e3*self.RAWDataProc.pulseLength[1])
  848. self.ui.lcdNumberTauDelay.setEnabled(1)
  849. self.ui.lcdNumberTauDelay.display(1e3*self.RAWDataProc.interpulseDelay)
  850. self.ui.FIDProcComboBox.clear()
  851. if self.RAWDataProc.pulseType == "4PhaseT1" or self.RAWDataProc.pulseType == "T1":
  852. self.ui.FIDProcComboBox.insertItem(0, "Pulse 1") #, const QVariant & userData = QVariant() )
  853. self.ui.FIDProcComboBox.insertItem(1, "Pulse 2") #, const QVariant & userData = QVariant() )
  854. self.ui.FIDProcComboBox.insertItem(2, "Both") #, const QVariant & userData = QVariant() )
  855. if len( self.RAWDataProc.DATADICT["PULSES"]) == 2:
  856. self.ui.FIDProcComboBox.setCurrentIndex (2)
  857. elif self.RAWDataProc.DATADICT["PULSES"][0] == "Pulse 1":
  858. self.ui.FIDProcComboBox.setCurrentIndex (0)
  859. else:
  860. self.ui.FIDProcComboBox.setCurrentIndex (1)
  861. elif self.RAWDataProc.pulseType == "FID":
  862. self.ui.FIDProcComboBox.insertItem(0, "Pulse 1") #, const QVariant & userData = QVariant() )
  863. self.ui.FIDProcComboBox.setCurrentIndex (0)
  864. # QtCore.QObject.connect(self.RAWDataProc, QtCore.SIGNAL("updateProgress(int)"), self.updateProgressBar)
  865. # QtCore.QObject.connect(self.RAWDataProc, QtCore.SIGNAL("enableDSP()"), self.enableDSP)
  866. # QtCore.QObject.connect(self.RAWDataProc, QtCore.SIGNAL("doneStatus()"), self.doneStatus)
  867. self.RAWDataProc.progressTrigger.connect(self.updateProgressBar)
  868. self.RAWDataProc.enableDSPTrigger.connect(self.enableDSP)
  869. self.RAWDataProc.doneTrigger.connect(self.doneStatus)
  870. self.enableAll()
  871. def loadRAW(self):
  872. #################################################
  873. # Check to make sure we are ready to process
  874. # Header
  875. if self.RAWDataProc == None:
  876. err_msg = "You need to load a header first."
  877. reply = QtGui.QMessageBox.critical(self, 'Error',
  878. err_msg) #, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
  879. return
  880. # Stacks
  881. try:
  882. self.procStacks = np.array(eval(str("np.r_["+self.ui.stacksLineEdit.text())+"]"))
  883. except:
  884. err_msg = "You need to set your stacks correctly.\n" + \
  885. "This should be a Python Numpy interpretable list\n" + \
  886. "of stack indices. For example 1:24 or 1:4,8:24"
  887. QtGui.QMessageBox.critical(self, 'Error', err_msg)
  888. return
  889. # Data Channels
  890. #Chan = np.arange(0,9,1)
  891. try:
  892. self.dataChan = np.array(eval(str("np.r_["+self.ui.dataChanLineEdit.text())+"]"))
  893. except:
  894. #QMessageBox messageBox;
  895. #messageBox.critical(0,"Error","An error has occured !");
  896. #messageBox.setFixedSize(500,200);
  897. #quit_msg = "Are you sure you want to exit the program?"
  898. #reply = QtGui.QMessageBox.question(self, 'Message',
  899. # quit_msg, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
  900. err_msg = "You need to set your data channels correctly.\n" + \
  901. "This should be a Python Numpy interpretable list\n" + \
  902. "of indices. For example 1 or 1:3 or 1:3 5\n\n" + \
  903. "valid GMR data channels fall between 1 and 8. Note that\n" +\
  904. "1:3 is not inclusive of 3 and is the same as 1,2 "
  905. reply = QtGui.QMessageBox.critical(self, 'Error',
  906. err_msg) #, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
  907. return
  908. #############################
  909. # Reference Channels
  910. # TODO make sure no overlap between data and ref channels
  911. self.refChan = np.array( () )
  912. if str(self.ui.refChanLineEdit.text()): # != "none":
  913. try:
  914. self.refChan = np.array(eval(str("np.r_["+self.ui.refChanLineEdit.text())+"]"))
  915. except:
  916. err_msg = "You need to set your reference channels correctly.\n" + \
  917. "This should be a Python Numpy interpretable list\n" + \
  918. "of indices. For example 1 or 1:3 or 1:3 5\n\n" + \
  919. "valid GMR data channels fall between 1 and 8. Note that\n" +\
  920. "1:3 is not inclusive of 3 and is the same as 1,2 "
  921. QtGui.QMessageBox.critical(self, 'Error', err_msg)
  922. return
  923. #####################################################
  924. # Load data
  925. self.lock("loading RAW GMR dataset")
  926. if self.RAWDataProc.pulseType == "FID":
  927. self.procThread = thread.start_new_thread(self.RAWDataProc.loadFIDData, \
  928. (str(self.headerstr), self.procStacks, self.dataChan, self.refChan, \
  929. str(self.ui.FIDProcComboBox.currentText()), self.ui.mplwidget, \
  930. 1e-3 * self.ui.DeadTimeSpinBox.value( ), self.ui.plotImportCheckBox.isChecked() )) #, self))
  931. elif self.RAWDataProc.pulseType == "4PhaseT1":
  932. self.procThread = thread.start_new_thread(self.RAWDataProc.load4PhaseT1Data, \
  933. (str(self.headerstr), self.procStacks, self.dataChan, self.refChan, \
  934. str(self.ui.FIDProcComboBox.currentText()), self.ui.mplwidget, \
  935. 1e-3 * self.ui.DeadTimeSpinBox.value( ), self.ui.plotImportCheckBox.isChecked() )) #, self))
  936. elif self.RAWDataProc.pulseType == "T1":
  937. self.procThread = thread.start_new_thread(self.RAWDataProc.loadT1Data, \
  938. (str(self.headerstr), self.procStacks, self.dataChan, self.refChan, \
  939. str(self.ui.FIDProcComboBox.currentText()), self.ui.mplwidget, \
  940. 1e-3 * self.ui.DeadTimeSpinBox.value( ), self.ui.plotImportCheckBox.isChecked() )) #, self))
  941. #self.procThread = thread.start_new_thread(self.RAWDataProc.load4PhaseT1Data, \
  942. # (str(self.headerstr), self.procStacks, self.dataChan, self.refChan, \
  943. # str(self.ui.FIDProcComboBox.currentText()), self.ui.mplwidget, \
  944. # 1e-3 * self.ui.DeadTimeSpinBox.value( ), self.ui.plotImportCheckBox.isChecked() )) #, self))
  945. self.YamlNode.Import["GMR Header"] = self.headerstr
  946. self.YamlNode.Import["opened"] = datetime.datetime.now().isoformat()
  947. self.YamlNode.Import["pulse Type"] = str(self.RAWDataProc.pulseType)
  948. self.YamlNode.Import["stacks"] = self.procStacks.tolist()
  949. self.YamlNode.Import["data channels"] = self.dataChan.tolist()
  950. self.YamlNode.Import["reference channels"] = self.refChan.tolist()
  951. self.YamlNode.Import["pulse records"] = str(self.ui.FIDProcComboBox.currentText())
  952. self.YamlNode.Import["instrument dead time"] = (1e-3 * self.ui.DeadTimeSpinBox.value( ))
  953. self.Log ( )
  954. # enable META tab
  955. self.ui.METATab.setEnabled(1)
  956. self.ui.siteBox.setEnabled(1)
  957. # should be already done
  958. # QtCore.QObject.connect(self.RAWDataProc, QtCore.SIGNAL("updateProgress(int)"), self.updateProgressBar)
  959. # QtCore.QObject.connect(self.RAWDataProc, QtCore.SIGNAL("enableDSP()"), self.enableDSP)
  960. # QtCore.QObject.connect(self.RAWDataProc, QtCore.SIGNAL("doneStatus()"), self.doneStatus)
  961. #self.ui.ProcessedBox.setEnabled(True)
  962. self.ui.lcdNumberFID1Length.setEnabled(1)
  963. self.ui.lcdNumberFID2Length.setEnabled(1)
  964. self.ui.lcdNumberResampFreq.setEnabled(1)
  965. self.ui.lcdTotalDeadTime.setEnabled(1)
  966. self.ui.lcdTotalDeadTime.display( self.ui.DeadTimeSpinBox.value( ) )
  967. #self.ui.lcdTotalDeadTime.display( round(1e3*(self.RAWDataProc.DATADICT["Pulse 1"]["TIMES"][0]-self.RAWDataProc.DATADICT["Pulse 1"]["PULSE_TIMES"][-1]), 3) )
  968. #self.ui.lcdNumberFID1Length.display(0)
  969. #self.ui.lcdNumberFID2Length.display(0)
  970. #self.ui.lcdNumberResampFreq.display( self.RAWDataProc.samp )
  971. self.mpl_toolbar = NavigationToolbar2QT(self.ui.mplwidget, self.ui.mplwidget)
  972. self.ui.mplwidget.draw()
  973. def Log(self):
  974. #for line in yaml.dump(self.YamlNode, default_flow_style=False):
  975. #for line in nlogText:
  976. # self.ui.logTextBrowser.append( line )
  977. # self.logText.append( line )
  978. self.ui.logTextBrowser.clear()
  979. self.ui.logTextBrowser.append( yaml.dump(self.YamlNode ))
  980. def disable(self):
  981. self.ui.inputRAWParametersBox.setEnabled(False)
  982. self.ui.BandPassBox.setEnabled(False)
  983. self.ui.downSampleGroupBox.setEnabled(False)
  984. self.ui.windowFilterGroupBox.setEnabled(False)
  985. self.ui.harmonicBox.setEnabled(False)
  986. # self.ui.despikeGroupBox.setEnabled(False)
  987. self.ui.adaptBox.setEnabled(False)
  988. self.ui.adaptFDBox.setEnabled(False)
  989. self.ui.qCalcGroupBox.setEnabled(False)
  990. self.ui.FDSmartStackGroupBox.setEnabled(False)
  991. self.ui.sumDataBox.setEnabled(False)
  992. self.ui.qdGroupBox.setEnabled(False)
  993. self.ui.gateBox.setEnabled(False)
  994. def enableAll(self):
  995. self.enableDSP()
  996. self.enableQC()
  997. def enableDSP(self):
  998. # Bandpass filter
  999. self.ui.BandPassBox.setEnabled(True)
  1000. self.ui.BandPassBox.setChecked(True)
  1001. self.ui.bandPassGO.setEnabled(False) # need to design first
  1002. self.ui.plotBP.setEnabled(True)
  1003. self.ui.plotBP.setChecked(True)
  1004. # downsample
  1005. self.ui.downSampleGroupBox.setEnabled(True)
  1006. self.ui.downSampleGroupBox.setChecked(True)
  1007. # window
  1008. self.ui.windowFilterGroupBox.setEnabled(True)
  1009. self.ui.windowFilterGroupBox.setChecked(True)
  1010. # Despike
  1011. # self.ui.despikeGroupBox.setEnabled(True)
  1012. # self.ui.despikeGroupBox.setChecked(False)
  1013. # Adaptive filtering
  1014. self.ui.adaptBox.setEnabled(True)
  1015. self.ui.adaptBox.setChecked(True)
  1016. # FD Adaptive filtering
  1017. self.ui.adaptFDBox.setEnabled(True)
  1018. self.ui.adaptFDBox.setChecked(False)
  1019. # Harmonic
  1020. self.ui.harmonicBox.setEnabled(True)
  1021. self.ui.harmonicBox.setChecked(True)
  1022. self.LCDHarmonics()
  1023. self.LCDHarmonics2()
  1024. # sum group box
  1025. try:
  1026. if len(self.dataChan) > 1:
  1027. self.ui.sumDataBox.setEnabled(True)
  1028. self.ui.sumDataBox.setChecked(False)
  1029. except:
  1030. pass
  1031. # Quadrature Detect
  1032. self.ui.qdGroupBox.setEnabled(True)
  1033. self.ui.qdGroupBox.setChecked(True)
  1034. self.enableQC()
  1035. def enableQC(self):
  1036. # Q calc
  1037. self.ui.qCalcGroupBox.setEnabled(True)
  1038. self.ui.qCalcGroupBox.setChecked(True)
  1039. # FD SmartStack
  1040. self.ui.FDSmartStackGroupBox.setEnabled(True)
  1041. self.ui.FDSmartStackGroupBox.setChecked(True)
  1042. # Quadrature detect
  1043. try:
  1044. for pulse in self.RAWDataProc.DATADICT["PULSES"]:
  1045. np.shape(self.RAWDataProc.DATADICT[pulse]["Q"])
  1046. self.RAWDataProc.DATADICT["stack"]
  1047. self.ui.qdGroupBox.setEnabled(True)
  1048. self.ui.qdGroupBox.setChecked(True)
  1049. except:
  1050. self.ui.qdGroupBox.setEnabled(False)
  1051. self.ui.qdGroupBox.setChecked(False)
  1052. # Gating
  1053. try:
  1054. self.RAWDataProc.DATADICT["CA"]
  1055. self.ui.gateBox.setEnabled(True)
  1056. self.ui.gateBox.setChecked(True)
  1057. except:
  1058. self.ui.gateBox.setEnabled(False)
  1059. self.ui.gateBox.setChecked(False)
  1060. def despikeFilter(self):
  1061. self.lock("despike filter")
  1062. thread.start_new_thread(self.RAWDataProc.despike, \
  1063. (self.ui.windowSpinBox.value(), \
  1064. self.ui.thresholdSpinBox.value(), \
  1065. str(self.ui.replComboBox.currentText()), \
  1066. self.ui.rollOnSpinBox.value(), \
  1067. self.ui.despikeInterpWinSpinBox.value(),
  1068. self.ui.mplwidget))
  1069. def calcQ(self):
  1070. if "Calc Q" not in self.YamlNode.Stacking.keys():
  1071. #print("In CalcQ", yaml.dump(self.YamlNode.Processing) )
  1072. self.YamlNode.Stacking["Calc Q"] = True
  1073. #print( yaml.dump(self.YamlNode.Processing) )
  1074. self.Log()
  1075. else:
  1076. err_msg = "Q values have already been calculated"
  1077. reply =QtWidgets.QMessageBox.critical(self, 'Error',
  1078. err_msg)
  1079. return
  1080. self.lock("pulse moment calculation")
  1081. thread.start_new_thread(self.RAWDataProc.effectivePulseMoment, \
  1082. (self.ui.CentralVSpinBox.value(), \
  1083. self.ui.mplwidget))
  1084. def harmonicModel(self):
  1085. self.lock("harmonic noise modelling")
  1086. Harm = OrderedDict()
  1087. Harm["STEP"] = "Harmonic modelling"
  1088. Harm["NF"] = str( self.ui.NHarmonicsFreqsSpin.value() )
  1089. Harm["Segments"] = str( self.ui.NSegments.value() )
  1090. Harm["Proc. ref."] = self.ui.harmRef.isChecked()
  1091. if self.ui.searchAll.currentText() == "All":
  1092. Harm["search"] = self.ui.searchAll.currentText()
  1093. Search = False
  1094. else:
  1095. #Harm["search"] = self.ui.searchAll.currentText()
  1096. Harm["search"] = str(self.ui.Nsearch.value())
  1097. Search = self.ui.Nsearch.value()
  1098. if self.ui.boundsCheck.isChecked():
  1099. Harm["Bounds"] = str(self.ui.bounds.value())
  1100. Bounds = self.ui.bounds.value()
  1101. else:
  1102. Harm["Bounds"] = self.ui.boundsCheck.isChecked()
  1103. Bounds = 0
  1104. Harm["f0K1"] = str( self.ui.f0K1Spin.value() )
  1105. Harm["f0KN"] = str( self.ui.f0KNSpin.value() )
  1106. Harm["f0Ks"] = str( self.ui.f0KsSpin.value() )
  1107. Harm["f0"] = str( self.ui.f0Spin.value() )
  1108. if self.ui.NHarmonicsFreqsSpin.value() > 1:
  1109. Harm["f1K1"] = str( self.ui.f1K1Spin.value() )
  1110. Harm["f1KN"] = str( self.ui.f1KNSpin.value() )
  1111. Harm["f1Ks"] = str( self.ui.f1KsSpin.value() )
  1112. Harm["f1"] = str( self.ui.f1Spin.value() )
  1113. self.YamlNode.Processing.append(Harm)
  1114. self.Log()
  1115. thread.start_new_thread(self.RAWDataProc.harmonicModel, \
  1116. ( \
  1117. self.ui.NHarmonicsFreqsSpin.value(), \
  1118. self.ui.f0Spin.value(), \
  1119. self.ui.f0K1Spin.value(), \
  1120. self.ui.f0KNSpin.value(), \
  1121. self.ui.f0KsSpin.value(), \
  1122. self.ui.NSegments.value(), \
  1123. self.ui.f1Spin.value(), \
  1124. self.ui.f1K1Spin.value(), \
  1125. self.ui.f1KNSpin.value(), \
  1126. self.ui.f1KsSpin.value(), \
  1127. Search, \
  1128. Bounds, \
  1129. self.ui.harmRef.isChecked(), \
  1130. self.ui.plotHarmonic.isChecked(), \
  1131. self.ui.mplwidget \
  1132. ) \
  1133. )
  1134. def FDSmartStack(self):
  1135. if "TD stack" not in self.YamlNode.Stacking.keys():
  1136. self.YamlNode.Stacking["TD stack"] = {}
  1137. self.YamlNode.Stacking["TD stack"]["outlier"] = str( self.ui.outlierTestCB.currentText() )
  1138. self.YamlNode.Stacking["TD stack"]["cutoff"] = str( self.ui.MADCutoff.value() )
  1139. self.Log()
  1140. else:
  1141. err_msg = "TD noise cancellation has already been applied!"
  1142. reply =QtWidgets.QMessageBox.critical(self, 'Error',
  1143. err_msg)
  1144. return
  1145. self.lock("time-domain smart stack")
  1146. thread.start_new_thread(self.RAWDataProc.TDSmartStack, \
  1147. (str(self.ui.outlierTestCB.currentText()), \
  1148. self.ui.MADCutoff.value(),
  1149. self.ui.mplwidget))
  1150. def adaptFilter(self):
  1151. self.lock("TD noise cancellation filter")
  1152. # Log processing
  1153. Adapt = OrderedDict()
  1154. Adapt["STEP"] = "TD noise cancellation"
  1155. #print(Adapt)
  1156. Adapt["n_Taps"] = str(self.ui.MTapsSpinBox.value())
  1157. Adapt["lambda"] = str(self.ui.adaptLambdaSpinBox.value())
  1158. Adapt["truncate"] = str(self.ui.adaptTruncateSpinBox.value())
  1159. Adapt["mu"] = str(self.ui.adaptMuSpinBox.value())
  1160. Adapt["PCA"] = str(self.ui.PCAComboBox.currentText())
  1161. #print(Adapt)
  1162. self.YamlNode.Processing.append(Adapt)
  1163. self.Log( )
  1164. thread.start_new_thread(self.RAWDataProc.adaptiveFilter, \
  1165. (self.ui.MTapsSpinBox.value(), \
  1166. self.ui.adaptLambdaSpinBox.value(), \
  1167. self.ui.adaptTruncateSpinBox.value(), \
  1168. self.ui.adaptMuSpinBox.value(), \
  1169. str(self.ui.PCAComboBox.currentText()), \
  1170. self.ui.mplwidget))
  1171. def sumDataChans(self):
  1172. self.lock("Summing data channels")
  1173. Sum = OrderedDict()
  1174. Sum["STEP"] = "Channel sum"
  1175. self.YamlNode.Processing.append(Sum)
  1176. self.Log( )
  1177. self.dataChan = [self.dataChan[0]]
  1178. self.ui.sumDataBox.setEnabled(False)
  1179. thread.start_new_thread( self.RAWDataProc.sumData, ( self.ui.mplwidget, 7 ) )
  1180. def adaptFilterFD(self):
  1181. self.lock("FD noise cancellation filter")
  1182. thread.start_new_thread(self.RAWDataProc.adaptiveFilterFD, \
  1183. (str(self.ui.windowTypeComboBox.currentText()), \
  1184. self.ui.windowBandwidthSpinBox.value(), \
  1185. self.ui.CentralVSpinBox.value(), \
  1186. self.ui.mplwidget))
  1187. def logSite(self):
  1188. self.YamlNode.META["Location"] = self.ui.locEdit.text()
  1189. self.YamlNode.META["Coordinates"] = OrderedDict()
  1190. self.YamlNode.META["Coordinates"]["UTM"] = self.ui.UTMzone.currentText()
  1191. self.YamlNode.META["Coordinates"]["LatBand"] = self.ui.latBand.currentText()
  1192. self.YamlNode.META["Coordinates"]["ellipsoid"] = self.ui.ellipsoid.currentText()
  1193. self.YamlNode.META["DateTime"] = self.ui.dateEdit.date().toString("yyyy-MM-dd") + "T" + str( self.ui.timeEdit.time().toString("hh:mm") )
  1194. self.YamlNode.META["Temp"] = self.ui.tempSpinBox.value()
  1195. self.YamlNode.META["B_0"] = OrderedDict()
  1196. self.YamlNode.META["B_0"]["inc"] = self.ui.incSpinBox.value()
  1197. self.YamlNode.META["B_0"]["dec"] = self.ui.decSpinBox.value()
  1198. self.YamlNode.META["B_0"]["intensity"] = self.ui.intensitySpinBox.value()
  1199. self.YamlNode.META["Field Notes"] = self.ui.txtComments.toPlainText()
  1200. self.Log()
  1201. def bandPassFilter(self):
  1202. self.lock("bandpass filter")
  1203. # Log processing
  1204. Band = OrderedDict()
  1205. Band["STEP"] = "Bandpass filter"
  1206. Band["central_nu"] = str(self.ui.CentralVSpinBox.value())
  1207. Band["passband"] = str(self.ui.passBandSpinBox.value())
  1208. Band["stopband"] = str(self.ui.stopBandSpinBox.value())
  1209. Band["gpass"] = str(self.ui.gpassSpinBox.value())
  1210. Band["gstop"] = str(self.ui.gstopSpinBox.value())
  1211. Band["type"] = str(self.ui.fTypeComboBox.currentText())
  1212. self.YamlNode.Processing.append(Band)
  1213. self.Log( )
  1214. nv = self.ui.lcdTotalDeadTime.value( ) + self.ui.lcdNumberFTauDead.value()
  1215. self.ui.lcdTotalDeadTime.display( nv )
  1216. thread.start_new_thread(self.RAWDataProc.bandpassFilter, \
  1217. (self.ui.mplwidget, 0, self.ui.plotBP.isChecked() ))
  1218. def downsample(self):
  1219. self.lock("resampling")
  1220. # Log processing
  1221. Resample = OrderedDict()
  1222. Resample["STEP"] = "Resample"
  1223. Resample["downsample factor"] = str(self.ui.downSampleSpinBox.value())
  1224. Resample["truncate length"] = str(self.ui.truncateSpinBox.value())
  1225. self.YamlNode.Processing.append(Resample)
  1226. self.Log( )
  1227. thread.start_new_thread(self.RAWDataProc.downsample, \
  1228. (self.ui.truncateSpinBox.value(), \
  1229. self.ui.downSampleSpinBox.value(), \
  1230. self.ui.dsPlot.isChecked(), \
  1231. self.ui.mplwidget))
  1232. def quadDet(self):
  1233. method = ['trf','dogbox','lm'][int(self.ui.QDMethod.currentIndex())]
  1234. loss = ['linear','soft_l1','cauchy','huber'][int(self.ui.QDLoss.currentIndex())]
  1235. # allow overwrite of Quad Det.
  1236. self.YamlNode.Stacking["Quadrature detection"] = {}
  1237. self.YamlNode.Stacking["Quadrature detection"]["trim"] = str( self.ui.trimSpin.value() )
  1238. self.YamlNode.Stacking["Quadrature detection"]["method"] = method
  1239. self.YamlNode.Stacking["Quadrature detection"]["loss"] = loss
  1240. self.Log()
  1241. #if "Quadrature detection" not in self.YamlNode.Processing.keys():
  1242. # self.YamlNode.Processing["Quadrature detection"] = {}
  1243. # self.YamlNode.Processing["Quadrature detection"]["trim"] = str( self.ui.trimSpin.value() )
  1244. # self.Log()
  1245. #else:
  1246. # self.YamlNode.Processing["Quadrature detection"] = {}
  1247. # self.YamlNode.Processing["Quadrature detection"]["trim"] = str( self.ui.trimSpin.value() )
  1248. # self.Log()
  1249. #err_msg = "Quadrature detection has already been done!"
  1250. #reply =QtWidgets.QMessageBox.critical(self, 'Error',
  1251. # err_msg)
  1252. #return
  1253. self.lock("quadrature detection")
  1254. thread.start_new_thread(self.RAWDataProc.quadDet, \
  1255. (self.ui.trimSpin.value(), method, loss, self.ui.mplwidget))
  1256. self.ui.plotQD.setEnabled(True)
  1257. def plotQD(self):
  1258. self.lock("plot QD")
  1259. thread.start_new_thread(self.RAWDataProc.plotQuadDet, \
  1260. (self.ui.trimSpin.value(), int(self.ui.QDType.currentIndex()), self.ui.mplwidget))
  1261. def gateIntegrate(self):
  1262. if "Gate integrate" not in self.YamlNode.Stacking.keys():
  1263. self.YamlNode.Stacking["Gate integrate"] = {}
  1264. self.YamlNode.Stacking["Gate integrate"]["gpd"] = str(self.ui.GPDspinBox.value( ) )
  1265. self.Log()
  1266. self.lock("gate integration")
  1267. thread.start_new_thread(self.RAWDataProc.gateIntegrate, \
  1268. (self.ui.GPDspinBox.value(), self.ui.trimSpin.value(), self.ui.mplwidget))
  1269. self.ui.actionExport_Preprocessed_Dataset.setEnabled(True)
  1270. self.ui.plotGI.setEnabled(True)
  1271. def plotGI(self):
  1272. self.lock("plot gate integrate")
  1273. thread.start_new_thread(self.RAWDataProc.plotGateIntegrate, \
  1274. (self.ui.GPDspinBox.value(), self.ui.trimSpin.value(), \
  1275. self.ui.QDType_2.currentIndex(), self.ui.mplwidget))
  1276. def designFilter(self):
  1277. [bord, fe] = self.RAWDataProc.designFilter( \
  1278. self.ui.CentralVSpinBox.value(), \
  1279. self.ui.passBandSpinBox.value(), \
  1280. self.ui.stopBandSpinBox.value(), \
  1281. self.ui.gpassSpinBox.value(), \
  1282. self.ui.gstopSpinBox.value(), \
  1283. str(self.ui.fTypeComboBox.currentText()),
  1284. self.ui.mplwidget
  1285. )
  1286. self.ui.lcdNumberFilterOrder.display(bord)
  1287. self.ui.lcdNumberFTauDead.display(1e3*fe)
  1288. self.ui.bandPassGO.setEnabled(1)
  1289. ################################################################
  1290. # Hack for MacOS to force refresh of group box and plot
  1291. # this has an undesirable effect that it causes the groupbox to 'jump' up
  1292. # TODO come up with a better solution
  1293. self.ui.mplwidget.hide()
  1294. self.ui.mplwidget.show()
  1295. self.ui.BandPassBox.hide()
  1296. self.ui.BandPassBox.show()
  1297. def windowFilter(self):
  1298. self.lock("window filter")
  1299. # Log processing
  1300. Window = OrderedDict()
  1301. Window["STEP"] = "Window filter"
  1302. Window["type"] = str(self.ui.windowTypeComboBox.currentText())
  1303. Window["width"] = str(self.ui.windowBandwidthSpinBox.value())
  1304. Window["centre"] = str(self.ui.CentralVSpinBox.value() )
  1305. Window["trim"] = str(self.ui.windowTrim.isChecked())
  1306. self.YamlNode.Processing.append(Window)
  1307. self.Log( )
  1308. if self.ui.windowTrim.isChecked():
  1309. nv = self.ui.lcdTotalDeadTime.value( ) + self.ui.lcdWinDead.value()
  1310. self.ui.lcdTotalDeadTime.display( nv )
  1311. thread.start_new_thread(self.RAWDataProc.windowFilter, \
  1312. (str(self.ui.windowTypeComboBox.currentText()), \
  1313. self.ui.windowBandwidthSpinBox.value(), \
  1314. self.ui.CentralVSpinBox.value(), \
  1315. self.ui.windowTrim.isChecked(), \
  1316. self.ui.mplwidget))
  1317. def designFDFilter(self):
  1318. mPulse = "None"
  1319. if u"Pulse 1" in self.RAWDataProc.DATADICT.keys():
  1320. mPulse = u"Pulse 1"
  1321. elif u"Pulse 2" in self.RAWDataProc.DATADICT.keys():
  1322. mPulse = u"Pulse 2"
  1323. a,b,c,d,dead,ndead = self.RAWDataProc.computeWindow( \
  1324. mPulse,
  1325. self.ui.windowBandwidthSpinBox.value(), \
  1326. self.ui.CentralVSpinBox.value(), \
  1327. str(self.ui.windowTypeComboBox.currentText()), \
  1328. self.ui.mplwidget )
  1329. self.ui.lcdWinDead.display(dead)
  1330. ################################################################
  1331. # Hack for MacOS to force refresh of group box and plot
  1332. # this has an undesirable effect that it causes the groupbox to 'jump' up
  1333. # TODO come up with a better solution
  1334. self.ui.mplwidget.hide()
  1335. self.ui.mplwidget.show()
  1336. self.ui.windowFilterGroupBox.hide()
  1337. self.ui.windowFilterGroupBox.show()
  1338. def updateProgressBar(self, percent):
  1339. self.ui.barProgress.setValue(percent)
  1340. def updateProc(self):
  1341. if str(self.ui.FIDProcComboBox.currentText()) == "Pulse 1":
  1342. self.ui.lcdNumberFID1Length.display(self.RAWDataProc.DATADICT["Pulse 1"]["TIMES"][-1]- self.RAWDataProc.DATADICT["Pulse 1"]["TIMES"][0])
  1343. elif str(self.ui.FIDProcComboBox.currentText()) == "Pulse 2":
  1344. self.ui.lcdNumberFID2Length.display(self.RAWDataProc.DATADICT["Pulse 2"]["TIMES"][-1]- self.RAWDataProc.DATADICT["Pulse 2"]["TIMES"][0])
  1345. else:
  1346. self.ui.lcdNumberFID1Length.display(self.RAWDataProc.DATADICT["Pulse 1"]["TIMES"][-1]- self.RAWDataProc.DATADICT["Pulse 1"]["TIMES"][0])
  1347. self.ui.lcdNumberFID2Length.display(self.RAWDataProc.DATADICT["Pulse 2"]["TIMES"][-1]- self.RAWDataProc.DATADICT["Pulse 2"]["TIMES"][0])
  1348. self.ui.lcdNumberResampFreq.display( self.RAWDataProc.samp )
  1349. def doneStatus(self): # unlocks GUI
  1350. self.ui.statusbar.clearMessage ( )
  1351. self.ui.barProgress.hide()
  1352. self.updateProc()
  1353. self.enableAll()
  1354. def lock(self, string):
  1355. self.ui.statusbar.showMessage ( string )
  1356. self.ui.barProgress.show()
  1357. self.ui.barProgress.setValue(0)
  1358. self.disable()
  1359. def unlock(self):
  1360. self.ui.statusbar.clearMessage ( )
  1361. self.ui.barProgress.hide()
  1362. self.enableAll()
  1363. def done(self):
  1364. self.ui.statusbar.showMessage ( "" )
  1365. ################################################################
  1366. ################################################################
  1367. # Boiler plate main function
  1368. import pkg_resources
  1369. from pkg_resources import resource_string
  1370. import matplotlib.image as mpimg
  1371. import matplotlib.pyplot as plt
  1372. from akvo.gui.logo import plotLogo
  1373. def main():
  1374. # splash screen logo
  1375. logo = pkg_resources.resource_filename(__name__, 'akvo.png')
  1376. logo2 = pkg_resources.resource_filename(__name__, 'akvo2.png')
  1377. qApp = QtWidgets.QApplication(sys.argv)
  1378. ssplash = True
  1379. if ssplash:
  1380. pixmap = QtGui.QPixmap(logo)
  1381. splash = QtWidgets.QSplashScreen(pixmap, QtCore.Qt.WindowStaysOnTopHint)
  1382. splash.show()
  1383. aw = ApplicationWindow()
  1384. #img=mpimg.imread(logo)
  1385. for ax in [ aw.ui.mplwidget ]:
  1386. ax.fig.clear()
  1387. subplot = ax.fig.add_subplot(211)
  1388. # old logo plot
  1389. ax.fig.patch.set_facecolor( None )
  1390. ax.fig.patch.set_alpha( .0 )
  1391. #subplot.imshow(img)
  1392. #ax.fig.patch.set_visible(False)
  1393. subplot.axis('off')
  1394. plotLogo(subplot)
  1395. subplot.xaxis.set_major_locator(plt.NullLocator())
  1396. subplot.yaxis.set_major_locator(plt.NullLocator())
  1397. subplot2 = ax.fig.add_subplot(212)
  1398. subplot2.text(0.5, 1.,'surface NMR workbench',
  1399. horizontalalignment='center',
  1400. verticalalignment='center',
  1401. size=22,
  1402. transform = subplot2.transAxes)
  1403. subplot2.xaxis.set_major_locator(plt.NullLocator())
  1404. subplot2.yaxis.set_major_locator(plt.NullLocator())
  1405. subplot2.axis('off')
  1406. ax.draw()
  1407. if ssplash:
  1408. splash.showMessage("Loading modules")
  1409. splash.finish(aw)
  1410. #time.sleep(1)
  1411. aw.setWindowTitle("Akvo v"+str(VERSION))
  1412. aw.show()
  1413. qApp.setWindowIcon(QtGui.QIcon(logo2))
  1414. sys.exit(qApp.exec_())
  1415. if __name__ == "__main__":
  1416. main()