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

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