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

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