Surface NMR processing and inversion GUI
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

akvoGUI.py 66KB

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