Blame view
allanplot-gui.py
3.65 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 |
import allanplotUI class allanplot(QtGui.QMainWindow, allanplotUI.Ui_MainWindow): |
4097f3a0c replace 4 spaces ... |
9 10 11 12 13 |
def __init__(self, parent=None): super(allanplot, self).__init__(parent) self.setupUi(self) self.connectActions() self.pqg_widget(self.frame) |
216c27103 Add files via upload |
14 |
|
4097f3a0c replace 4 spaces ... |
15 16 17 18 19 20 21 22 23 |
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 |
|
4097f3a0c replace 4 spaces ... |
25 26 27 28 29 30 31 |
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) |
b62959916 Add files via upload |
32 |
|
4097f3a0c replace 4 spaces ... |
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
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 = '"') 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[:])) |
b62959916 Add files via upload |
52 |
|
4097f3a0c replace 4 spaces ... |
53 54 55 56 57 58 59 60 61 |
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) |
b62959916 Add files via upload |
62 |
|
4097f3a0c replace 4 spaces ... |
63 64 65 66 67 68 69 70 71 |
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) |
b62959916 Add files via upload |
72 |
|
4097f3a0c replace 4 spaces ... |
73 74 75 76 77 78 79 80 81 82 |
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) |
b62959916 Add files via upload |
83 |
|
4097f3a0c replace 4 spaces ... |
84 85 86 87 88 89 90 91 92 93 |
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) |
b62959916 Add files via upload |
94 |
|
4097f3a0c replace 4 spaces ... |
95 96 |
def main(self): self.show() |
b62959916 Add files via upload |
97 98 |
if __name__=='__main__': |
4097f3a0c replace 4 spaces ... |
99 100 101 102 |
app = QtGui.QApplication(sys.argv) allanplot = allanplot() allanplot.main() app.exec_() |