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

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