allanplot-gui.py
3.17 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
#!/usr/bin/python
# -*- coding: utf-8 -*-
from PyQt4 import QtGui, QtCore
import sys, Gnuplot, csv, numpy, allantools
import allanplotUI
class allanplot(QtGui.QMainWindow, allanplotUI.Ui_MainWindow):
def __init__(self, parent=None):
super(allanplot, self).__init__(parent)
self.setupUi(self)
self.connectActions()
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 = [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):
g = Gnuplot.Gnuplot(persist = 1)
g('set grid')
g.xlabel('t (s)')
g.ylabel('y (unit)')
for i in range(2, self.data.shape[1]):
g.replot(Gnuplot.Data(self.data[:,0], self.data[:,i], with_='l', title='#%s'%str(i)))
def relativeTimePlot(self):
g = Gnuplot.Gnuplot(persist = 1)
g('set grid')
g.xlabel('t (s)')
g.ylabel('y (unit)')
for i in range(2, self.data.shape[1]):
g.replot(Gnuplot.Data(self.data[:,0], self.data[:,i]/self.data[:,i].mean(), with_='l', title='#%s'%str(i)))
def adevPlot(self):
g = Gnuplot.Gnuplot(persist = 1)
g('set logscale xy')
g('set grid')
g.xlabel('Tau (s)')
g.ylabel('Adev')
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')
g.replot(Gnuplot.Data(tau2, ad, ade, with_='yerrorbars', title='#%s'%str(i)))
def relativeAdevPlot(self):
g = Gnuplot.Gnuplot(persist = 1)
g('set logscale xy')
g('set grid')
g.xlabel('Tau (s)')
g.ylabel('Adev')
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')
g.replot(Gnuplot.Data(tau2, ad, ade, with_='yerrorbars', title='#%s'%str(i)))
def main(self):
self.show()
if __name__=='__main__':
app = QtGui.QApplication(sys.argv)
allanplot = allanplot()
allanplot.main()
app.exec_()