allanplot-gui.py
4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/python
# -*- coding: utf-8 -*-
from PyQt4 import QtGui, QtCore
import sys, csv, numpy, allantools, pyqtgraph
import allanplotUI
class allanplot(QtGui.QMainWindow, allanplotUI.Ui_MainWindow):
def __init__(self, parent=None):
super(allanplot, self).__init__(parent)
self.setupUi(self)
self.connectActions()
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)
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+'\n'+str(f)
with open(f, 'r') as dest_f:
data_iter = csv.reader(dest_f, delimiter = '\t', quotechar = '"')
temp_data = [filter(None, value) for value in data_iter]
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):
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)
for i in range(2, self.data.shape[1]):
self.curve = self.plot_widget.plot()
self.curve.setData(self.data[:,0], self.data[:,i], pen=5*i, name='#%s'%i)
def relativeTimePlot(self):
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)
for i in range(2, self.data.shape[1]):
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)
def adevPlot(self):
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)
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')
self.curve = self.plot_widget.plot()
self.curve.setData(tau2, ad, pen=5*i, name='#%s'%i)
def relativeAdevPlot(self):
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)
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')
self.curve = self.plot_widget.plot()
self.curve.setData(tau2, ad, pen=5*i, name='#%s'%i)
def main(self):
self.show()
if __name__=='__main__':
app = QtGui.QApplication(sys.argv)
allanplot = allanplot()
allanplot.main()
app.exec_()