diff --git a/allanplot-gui.py b/allanplot-gui.py new file mode 100644 index 0000000..6b133b5 --- /dev/null +++ b/allanplot-gui.py @@ -0,0 +1,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_() diff --git a/allanplotUI.py b/allanplotUI.py new file mode 100644 index 0000000..59de803 --- /dev/null +++ b/allanplotUI.py @@ -0,0 +1,98 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'allanplotUI.ui' +# +# Created: Wed Jul 6 15:05:06 2016 +# by: PyQt4 UI code generator 4.11.2 +# +# WARNING! All changes made in this file will be lost! + +from PyQt4 import QtCore, QtGui + +try: + _fromUtf8 = QtCore.QString.fromUtf8 +except AttributeError: + def _fromUtf8(s): + return s + +try: + _encoding = QtGui.QApplication.UnicodeUTF8 + def _translate(context, text, disambig): + return QtGui.QApplication.translate(context, text, disambig, _encoding) +except AttributeError: + def _translate(context, text, disambig): + return QtGui.QApplication.translate(context, text, disambig) + +class Ui_MainWindow(object): + def setupUi(self, MainWindow): + MainWindow.setObjectName(_fromUtf8("MainWindow")) + MainWindow.resize(903, 240) + self.centralwidget = QtGui.QWidget(MainWindow) + self.centralwidget.setObjectName(_fromUtf8("centralwidget")) + self.gridLayout = QtGui.QGridLayout(self.centralwidget) + self.gridLayout.setObjectName(_fromUtf8("gridLayout")) + self.textFileList = QtGui.QTextBrowser(self.centralwidget) + self.textFileList.setObjectName(_fromUtf8("textFileList")) + self.gridLayout.addWidget(self.textFileList, 1, 3, 4, 1) + self.pushOpen = QtGui.QPushButton(self.centralwidget) + self.pushOpen.setObjectName(_fromUtf8("pushOpen")) + self.gridLayout.addWidget(self.pushOpen, 1, 1, 1, 1) + self.groupBox = QtGui.QGroupBox(self.centralwidget) + self.groupBox.setObjectName(_fromUtf8("groupBox")) + self.verticalLayout_2 = QtGui.QVBoxLayout(self.groupBox) + self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2")) + self.pushTimePlot = QtGui.QPushButton(self.groupBox) + self.pushTimePlot.setObjectName(_fromUtf8("pushTimePlot")) + self.verticalLayout_2.addWidget(self.pushTimePlot) + self.pushRelativeTimePlot = QtGui.QPushButton(self.groupBox) + self.pushRelativeTimePlot.setObjectName(_fromUtf8("pushRelativeTimePlot")) + self.verticalLayout_2.addWidget(self.pushRelativeTimePlot) + self.pushAdevPlot = QtGui.QPushButton(self.groupBox) + self.pushAdevPlot.setObjectName(_fromUtf8("pushAdevPlot")) + self.verticalLayout_2.addWidget(self.pushAdevPlot) + self.pushRelativeAdevPlot = QtGui.QPushButton(self.groupBox) + self.pushRelativeAdevPlot.setObjectName(_fromUtf8("pushRelativeAdevPlot")) + self.verticalLayout_2.addWidget(self.pushRelativeAdevPlot) + self.gridLayout.addWidget(self.groupBox, 5, 1, 1, 1) + spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) + self.gridLayout.addItem(spacerItem, 3, 1, 1, 1) + self.pushQuit = QtGui.QPushButton(self.centralwidget) + self.pushQuit.setObjectName(_fromUtf8("pushQuit")) + self.gridLayout.addWidget(self.pushQuit, 2, 1, 1, 1) + self.textValue = QtGui.QTextBrowser(self.centralwidget) + self.textValue.setObjectName(_fromUtf8("textValue")) + self.gridLayout.addWidget(self.textValue, 5, 3, 1, 1) + MainWindow.setCentralWidget(self.centralwidget) + self.actionOpen = QtGui.QAction(MainWindow) + self.actionOpen.setObjectName(_fromUtf8("actionOpen")) + self.actionPlot = QtGui.QAction(MainWindow) + self.actionPlot.setObjectName(_fromUtf8("actionPlot")) + self.actionQuit = QtGui.QAction(MainWindow) + self.actionQuit.setObjectName(_fromUtf8("actionQuit")) + + self.retranslateUi(MainWindow) + QtCore.QMetaObject.connectSlotsByName(MainWindow) + + def retranslateUi(self, MainWindow): + MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None)) + self.textFileList.setHtml(_translate("MainWindow", "\n" +"\n" +"

.dat files

", None)) + self.pushOpen.setText(_translate("MainWindow", "Open", None)) + self.groupBox.setTitle(_translate("MainWindow", "Plotting tools", None)) + self.pushTimePlot.setText(_translate("MainWindow", "Time Plot", None)) + self.pushRelativeTimePlot.setText(_translate("MainWindow", "Relative Time Plot", None)) + self.pushAdevPlot.setText(_translate("MainWindow", "Adev Plot", None)) + self.pushRelativeAdevPlot.setText(_translate("MainWindow", "Relative Adev Plot", None)) + self.pushQuit.setText(_translate("MainWindow", "Quit", None)) + self.textValue.setHtml(_translate("MainWindow", "\n" +"\n" +"


", None)) + self.actionOpen.setText(_translate("MainWindow", "Open", None)) + self.actionPlot.setText(_translate("MainWindow", "Plot", None)) + self.actionQuit.setText(_translate("MainWindow", "Quit", None)) + diff --git a/allanplotUI.ui b/allanplotUI.ui new file mode 100644 index 0000000..9b17df9 --- /dev/null +++ b/allanplotUI.ui @@ -0,0 +1,124 @@ + + + MainWindow + + + + 0 + 0 + 903 + 240 + + + + MainWindow + + + + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'DejaVu Sans'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">.dat files</p></body></html> + + + + + + + Open + + + + + + + Plotting tools + + + + + + Time Plot + + + + + + + Relative Time Plot + + + + + + + Adev Plot + + + + + + + Relative Adev Plot + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Quit + + + + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'DejaVu Sans'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> + + + + + + + + Open + + + + + Plot + + + + + Quit + + + + + +