Blame view
allanplot-gui.py
4.21 KB
b62959916 Add files via upload |
1 2 3 4 |
#!/usr/bin/python # -*- coding: utf-8 -*- from PyQt4 import QtGui, QtCore |
216c27103 Add files via upload |
5 |
import sys, csv, numpy, allantools, pyqtgraph |
b62959916 Add files via upload |
6 7 8 9 10 11 12 |
import allanplotUI class allanplot(QtGui.QMainWindow, allanplotUI.Ui_MainWindow): def __init__(self, parent=None): super(allanplot, self).__init__(parent) self.setupUi(self) self.connectActions() |
216c27103 Add files via upload |
13 14 15 16 17 18 19 20 21 22 23 |
self.pqg_widget(self.frame) def pqg_widget(self, frame): pyqtgraph.setConfigOption('background', 'w') pyqtgraph.setConfigOption('foreground', 'k') self.plot_widget = pyqtgraph.PlotWidget() self.layout_pqg = QtGui.QVBoxLayout(frame) self.layout_pqg.addWidget(self.plot_widget) self.plot_widget.showGrid(True, True, 0.5) self.plot_widget.addLegend() self.plot_widget.getViewBox().setMouseMode(pyqtgraph.ViewBox.RectMode) |
b62959916 Add files via upload |
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
def connectActions(self): self.pushQuit.clicked.connect(QtGui.qApp.quit) self.pushOpen.clicked.connect(self.openDat) self.pushTimePlot.clicked.connect(self.timePlot) self.pushAdevPlot.clicked.connect(self.adevPlot) self.pushRelativeTimePlot.clicked.connect(self.relativeTimePlot) self.pushRelativeAdevPlot.clicked.connect(self.relativeAdevPlot) def openDat(self): fileNames = QtGui.QFileDialog.getOpenFileNames(self, "Open datafile", QtCore.QDir.homePath(), "data files (*.dat)") if fileNames: fileList = sorted([str(f) for f in fileNames]) self.data = [] textList = '' for f in fileList: if textList=='': textList = str(f) else: textList = textList+' '+str(f) with open(f, 'r') as dest_f: data_iter = csv.reader(dest_f, delimiter = '\t', quotechar = '"') |
5ad56d313 resolve bug with ... |
47 |
temp_data = [filter(None, value) for value in data_iter] |
b62959916 Add files via upload |
48 49 50 51 52 53 |
self.data.extend(temp_data) self.data = numpy.asarray(self.data, dtype = float) self.textFileList.setText(textList) self.textValue.setText(str(self.data[:])) def timePlot(self): |
216c27103 Add files via upload |
54 55 56 57 58 |
self.plot_widget.clear() self.plot_widget.setTitle('time plot') self.plot_widget.setLabel('bottom', "Time", "s") self.plot_widget.setLabel('left', "y") self.plot_widget.setLogMode(False, False) |
b62959916 Add files via upload |
59 |
for i in range(2, self.data.shape[1]): |
216c27103 Add files via upload |
60 61 |
self.curve = self.plot_widget.plot() self.curve.setData(self.data[:,0], self.data[:,i], pen=5*i, name='#%s'%i) |
b62959916 Add files via upload |
62 63 |
def relativeTimePlot(self): |
216c27103 Add files via upload |
64 65 66 67 68 |
self.plot_widget.clear() self.plot_widget.setTitle('relative time plot') self.plot_widget.setLabel('bottom', "Time", "s") self.plot_widget.setLabel('left', "y") self.plot_widget.setLogMode(False, False) |
b62959916 Add files via upload |
69 |
for i in range(2, self.data.shape[1]): |
216c27103 Add files via upload |
70 71 |
self.curve = self.plot_widget.plot() self.curve.setData(self.data[:,0], self.data[:,i]/self.data[:,i].mean(), pen=5*i, name='#%s'%i) |
b62959916 Add files via upload |
72 73 |
def adevPlot(self): |
216c27103 Add files via upload |
74 75 76 77 78 |
self.plot_widget.clear() self.plot_widget.setTitle('adev plot') self.plot_widget.setLabel('bottom', "Tau", "s") self.plot_widget.setLabel('left', "adev") self.plot_widget.setLogMode(True, True) |
b62959916 Add files via upload |
79 80 |
for i in range(2, self.data.shape[1]): (tau2, ad, ade, adn) = allantools.adev(self.data[:,i], rate=1, data_type="freq", taus='decade') |
216c27103 Add files via upload |
81 82 |
self.curve = self.plot_widget.plot() self.curve.setData(tau2, ad, pen=5*i, name='#%s'%i) |
b62959916 Add files via upload |
83 84 |
def relativeAdevPlot(self): |
216c27103 Add files via upload |
85 86 87 88 89 |
self.plot_widget.clear() self.plot_widget.setTitle('relative adev plot') self.plot_widget.setLabel('bottom', "Tau", "s") self.plot_widget.setLabel('left', "relative adev") self.plot_widget.setLogMode(True, True) |
b62959916 Add files via upload |
90 91 |
for i in range(2, self.data.shape[1]): (tau2, ad, ade, adn) = allantools.adev(self.data[:,i]/self.data[:,i].mean(), rate=1, data_type="freq", taus='decade') |
216c27103 Add files via upload |
92 93 |
self.curve = self.plot_widget.plot() self.curve.setData(tau2, ad, pen=5*i, name='#%s'%i) |
b62959916 Add files via upload |
94 95 96 97 98 99 100 101 102 |
def main(self): self.show() if __name__=='__main__': app = QtGui.QApplication(sys.argv) allanplot = allanplot() allanplot.main() app.exec_() |