Surface NMR processing and inversion GUI
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

akvoGUI.py 56KB

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