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

akvoGUI.py 81KB

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