Commit b629599168558697aaec5b5ebc77591d15ed5d65
Committed by
GitHub
1 parent
bf48715bbc
Exists in
master
Add files via upload
Showing 3 changed files with 307 additions and 0 deletions Inline Diff
allanplot-gui.py
| File was created | 1 | #!/usr/bin/python | ||
| 2 | # -*- coding: utf-8 -*- | |||
| 3 | ||||
| 4 | from PyQt4 import QtGui, QtCore | |||
| 5 | import sys, Gnuplot, csv, numpy, allantools | |||
| 6 | ||||
| 7 | import allanplotUI | |||
| 8 | ||||
| 9 | class allanplot(QtGui.QMainWindow, allanplotUI.Ui_MainWindow): | |||
| 10 | def __init__(self, parent=None): | |||
| 11 | super(allanplot, self).__init__(parent) | |||
| 12 | self.setupUi(self) | |||
| 13 | self.connectActions() | |||
| 14 | ||||
| 15 | def connectActions(self): | |||
| 16 | self.pushQuit.clicked.connect(QtGui.qApp.quit) | |||
| 17 | self.pushOpen.clicked.connect(self.openDat) | |||
| 18 | self.pushTimePlot.clicked.connect(self.timePlot) | |||
| 19 | self.pushAdevPlot.clicked.connect(self.adevPlot) | |||
| 20 | self.pushRelativeTimePlot.clicked.connect(self.relativeTimePlot) | |||
| 21 | self.pushRelativeAdevPlot.clicked.connect(self.relativeAdevPlot) | |||
| 22 | ||||
| 23 | def openDat(self): | |||
| 24 | fileNames = QtGui.QFileDialog.getOpenFileNames(self, "Open datafile", QtCore.QDir.homePath(), "data files (*.dat)") | |||
| 25 | if fileNames: | |||
| 26 | fileList = sorted([str(f) for f in fileNames]) | |||
| 27 | self.data = [] | |||
| 28 | textList = '' | |||
| 29 | for f in fileList: | |||
| 30 | if textList=='': | |||
| 31 | textList = str(f) | |||
| 32 | else: | |||
| 33 | textList = textList+'\n'+str(f) | |||
| 34 | with open(f, 'r') as dest_f: | |||
| 35 | data_iter = csv.reader(dest_f, delimiter = '\t', quotechar = '"') | |||
| 36 | temp_data = [value for value in data_iter] | |||
| 37 | self.data.extend(temp_data) | |||
| 38 | self.data = numpy.asarray(self.data, dtype = float) | |||
| 39 | self.textFileList.setText(textList) | |||
| 40 | self.textValue.setText(str(self.data[:])) | |||
| 41 | ||||
| 42 | def timePlot(self): | |||
| 43 | g = Gnuplot.Gnuplot(persist = 1) | |||
| 44 | g('set grid') | |||
| 45 | g.xlabel('t (s)') | |||
| 46 | g.ylabel('y (unit)') | |||
| 47 | for i in range(2, self.data.shape[1]): | |||
| 48 | g.replot(Gnuplot.Data(self.data[:,0], self.data[:,i], with_='l', title='#%s'%str(i))) | |||
| 49 | ||||
| 50 | def relativeTimePlot(self): | |||
| 51 | g = Gnuplot.Gnuplot(persist = 1) | |||
| 52 | g('set grid') | |||
| 53 | g.xlabel('t (s)') | |||
| 54 | g.ylabel('y (unit)') | |||
| 55 | for i in range(2, self.data.shape[1]): | |||
| 56 | g.replot(Gnuplot.Data(self.data[:,0], self.data[:,i]/self.data[:,i].mean(), with_='l', title='#%s'%str(i))) | |||
| 57 | ||||
| 58 | def adevPlot(self): | |||
| 59 | g = Gnuplot.Gnuplot(persist = 1) | |||
| 60 | g('set logscale xy') | |||
| 61 | g('set grid') | |||
| 62 | g.xlabel('Tau (s)') | |||
| 63 | g.ylabel('Adev') | |||
| 64 | for i in range(2, self.data.shape[1]): | |||
| 65 | (tau2, ad, ade, adn) = allantools.adev(self.data[:,i], rate=1, data_type="freq", taus='decade') | |||
| 66 | g.replot(Gnuplot.Data(tau2, ad, ade, with_='yerrorbars', title='#%s'%str(i))) | |||
| 67 | ||||
| 68 | def relativeAdevPlot(self): | |||
| 69 | g = Gnuplot.Gnuplot(persist = 1) | |||
| 70 | g('set logscale xy') | |||
| 71 | g('set grid') | |||
| 72 | g.xlabel('Tau (s)') | |||
| 73 | g.ylabel('Adev') | |||
| 74 | for i in range(2, self.data.shape[1]): |
allanplotUI.py
| File was created | 1 | # -*- coding: utf-8 -*- | ||
| 2 | ||||
| 3 | # Form implementation generated from reading ui file 'allanplotUI.ui' | |||
| 4 | # | |||
| 5 | # Created: Wed Jul 6 15:05:06 2016 | |||
| 6 | # by: PyQt4 UI code generator 4.11.2 | |||
| 7 | # | |||
| 8 | # WARNING! All changes made in this file will be lost! | |||
| 9 | ||||
| 10 | from PyQt4 import QtCore, QtGui | |||
| 11 | ||||
| 12 | try: | |||
| 13 | _fromUtf8 = QtCore.QString.fromUtf8 | |||
| 14 | except AttributeError: | |||
| 15 | def _fromUtf8(s): | |||
| 16 | return s | |||
| 17 | ||||
| 18 | try: | |||
| 19 | _encoding = QtGui.QApplication.UnicodeUTF8 | |||
| 20 | def _translate(context, text, disambig): | |||
| 21 | return QtGui.QApplication.translate(context, text, disambig, _encoding) | |||
| 22 | except AttributeError: | |||
| 23 | def _translate(context, text, disambig): | |||
| 24 | return QtGui.QApplication.translate(context, text, disambig) | |||
| 25 | ||||
| 26 | class Ui_MainWindow(object): | |||
| 27 | def setupUi(self, MainWindow): | |||
| 28 | MainWindow.setObjectName(_fromUtf8("MainWindow")) | |||
| 29 | MainWindow.resize(903, 240) | |||
| 30 | self.centralwidget = QtGui.QWidget(MainWindow) | |||
| 31 | self.centralwidget.setObjectName(_fromUtf8("centralwidget")) | |||
| 32 | self.gridLayout = QtGui.QGridLayout(self.centralwidget) | |||
| 33 | self.gridLayout.setObjectName(_fromUtf8("gridLayout")) | |||
| 34 | self.textFileList = QtGui.QTextBrowser(self.centralwidget) | |||
| 35 | self.textFileList.setObjectName(_fromUtf8("textFileList")) | |||
| 36 | self.gridLayout.addWidget(self.textFileList, 1, 3, 4, 1) | |||
| 37 | self.pushOpen = QtGui.QPushButton(self.centralwidget) | |||
| 38 | self.pushOpen.setObjectName(_fromUtf8("pushOpen")) | |||
| 39 | self.gridLayout.addWidget(self.pushOpen, 1, 1, 1, 1) | |||
| 40 | self.groupBox = QtGui.QGroupBox(self.centralwidget) | |||
| 41 | self.groupBox.setObjectName(_fromUtf8("groupBox")) | |||
| 42 | self.verticalLayout_2 = QtGui.QVBoxLayout(self.groupBox) | |||
| 43 | self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2")) | |||
| 44 | self.pushTimePlot = QtGui.QPushButton(self.groupBox) | |||
| 45 | self.pushTimePlot.setObjectName(_fromUtf8("pushTimePlot")) | |||
| 46 | self.verticalLayout_2.addWidget(self.pushTimePlot) | |||
| 47 | self.pushRelativeTimePlot = QtGui.QPushButton(self.groupBox) | |||
| 48 | self.pushRelativeTimePlot.setObjectName(_fromUtf8("pushRelativeTimePlot")) | |||
| 49 | self.verticalLayout_2.addWidget(self.pushRelativeTimePlot) | |||
| 50 | self.pushAdevPlot = QtGui.QPushButton(self.groupBox) | |||
| 51 | self.pushAdevPlot.setObjectName(_fromUtf8("pushAdevPlot")) | |||
| 52 | self.verticalLayout_2.addWidget(self.pushAdevPlot) | |||
| 53 | self.pushRelativeAdevPlot = QtGui.QPushButton(self.groupBox) | |||
| 54 | self.pushRelativeAdevPlot.setObjectName(_fromUtf8("pushRelativeAdevPlot")) | |||
| 55 | self.verticalLayout_2.addWidget(self.pushRelativeAdevPlot) | |||
| 56 | self.gridLayout.addWidget(self.groupBox, 5, 1, 1, 1) | |||
| 57 | spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) | |||
| 58 | self.gridLayout.addItem(spacerItem, 3, 1, 1, 1) | |||
| 59 | self.pushQuit = QtGui.QPushButton(self.centralwidget) | |||
| 60 | self.pushQuit.setObjectName(_fromUtf8("pushQuit")) | |||
| 61 | self.gridLayout.addWidget(self.pushQuit, 2, 1, 1, 1) | |||
| 62 | self.textValue = QtGui.QTextBrowser(self.centralwidget) | |||
| 63 | self.textValue.setObjectName(_fromUtf8("textValue")) | |||
| 64 | self.gridLayout.addWidget(self.textValue, 5, 3, 1, 1) | |||
| 65 | MainWindow.setCentralWidget(self.centralwidget) | |||
| 66 | self.actionOpen = QtGui.QAction(MainWindow) | |||
| 67 | self.actionOpen.setObjectName(_fromUtf8("actionOpen")) | |||
| 68 | self.actionPlot = QtGui.QAction(MainWindow) | |||
| 69 | self.actionPlot.setObjectName(_fromUtf8("actionPlot")) | |||
| 70 | self.actionQuit = QtGui.QAction(MainWindow) | |||
| 71 | self.actionQuit.setObjectName(_fromUtf8("actionQuit")) | |||
| 72 | ||||
| 73 | self.retranslateUi(MainWindow) | |||
| 74 | QtCore.QMetaObject.connectSlotsByName(MainWindow) | |||
| 75 | ||||
| 76 | def retranslateUi(self, MainWindow): | |||
| 77 | MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None)) | |||
| 78 | self.textFileList.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" | |||
| 79 | "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" | |||
| 80 | "p, li { white-space: pre-wrap; }\n" | |||
| 81 | "</style></head><body style=\" font-family:\'DejaVu Sans\'; font-size:9pt; font-weight:400; font-style:normal;\">\n" | |||
| 82 | "<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>", None)) | |||
| 83 | self.pushOpen.setText(_translate("MainWindow", "Open", None)) | |||
| 84 | self.groupBox.setTitle(_translate("MainWindow", "Plotting tools", None)) | |||
| 85 | self.pushTimePlot.setText(_translate("MainWindow", "Time Plot", None)) | |||
| 86 | self.pushRelativeTimePlot.setText(_translate("MainWindow", "Relative Time Plot", None)) | |||
| 87 | self.pushAdevPlot.setText(_translate("MainWindow", "Adev Plot", None)) | |||
| 88 | self.pushRelativeAdevPlot.setText(_translate("MainWindow", "Relative Adev Plot", None)) | |||
| 89 | self.pushQuit.setText(_translate("MainWindow", "Quit", None)) | |||
| 90 | self.textValue.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" |
allanplotUI.ui
| File was created | 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <ui version="4.0"> | |||
| 3 | <class>MainWindow</class> | |||
| 4 | <widget class="QMainWindow" name="MainWindow"> | |||
| 5 | <property name="geometry"> | |||
| 6 | <rect> | |||
| 7 | <x>0</x> | |||
| 8 | <y>0</y> | |||
| 9 | <width>903</width> | |||
| 10 | <height>240</height> | |||
| 11 | </rect> | |||
| 12 | </property> | |||
| 13 | <property name="windowTitle"> | |||
| 14 | <string>MainWindow</string> | |||
| 15 | </property> | |||
| 16 | <widget class="QWidget" name="centralwidget"> | |||
| 17 | <layout class="QGridLayout" name="gridLayout"> | |||
| 18 | <item row="1" column="3" rowspan="4"> | |||
| 19 | <widget class="QTextBrowser" name="textFileList"> | |||
| 20 | <property name="html"> | |||
| 21 | <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> | |||
| 22 | <html><head><meta name="qrichtext" content="1" /><style type="text/css"> | |||
| 23 | p, li { white-space: pre-wrap; } | |||
| 24 | </style></head><body style=" font-family:'DejaVu Sans'; font-size:9pt; font-weight:400; font-style:normal;"> | |||
| 25 | <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></string> | |||
| 26 | </property> | |||
| 27 | </widget> | |||
| 28 | </item> | |||
| 29 | <item row="1" column="1"> | |||
| 30 | <widget class="QPushButton" name="pushOpen"> | |||
| 31 | <property name="text"> | |||
| 32 | <string>Open</string> | |||
| 33 | </property> | |||
| 34 | </widget> | |||
| 35 | </item> | |||
| 36 | <item row="5" column="1"> | |||
| 37 | <widget class="QGroupBox" name="groupBox"> | |||
| 38 | <property name="title"> | |||
| 39 | <string>Plotting tools</string> | |||
| 40 | </property> | |||
| 41 | <layout class="QVBoxLayout" name="verticalLayout_2"> | |||
| 42 | <item> | |||
| 43 | <widget class="QPushButton" name="pushTimePlot"> | |||
| 44 | <property name="text"> | |||
| 45 | <string>Time Plot</string> | |||
| 46 | </property> | |||
| 47 | </widget> | |||
| 48 | </item> | |||
| 49 | <item> | |||
| 50 | <widget class="QPushButton" name="pushRelativeTimePlot"> | |||
| 51 | <property name="text"> | |||
| 52 | <string>Relative Time Plot</string> | |||
| 53 | </property> | |||
| 54 | </widget> | |||
| 55 | </item> | |||
| 56 | <item> | |||
| 57 | <widget class="QPushButton" name="pushAdevPlot"> | |||
| 58 | <property name="text"> | |||
| 59 | <string>Adev Plot</string> | |||
| 60 | </property> | |||
| 61 | </widget> | |||
| 62 | </item> | |||
| 63 | <item> | |||
| 64 | <widget class="QPushButton" name="pushRelativeAdevPlot"> | |||
| 65 | <property name="text"> | |||
| 66 | <string>Relative Adev Plot</string> | |||
| 67 | </property> | |||
| 68 | </widget> | |||
| 69 | </item> | |||
| 70 | </layout> | |||
| 71 | </widget> | |||
| 72 | </item> | |||
| 73 | <item row="3" column="1"> | |||
| 74 | <spacer name="verticalSpacer"> | |||
| 75 | <property name="orientation"> | |||
| 76 | <enum>Qt::Vertical</enum> | |||
| 77 | </property> | |||
| 78 | <property name="sizeHint" stdset="0"> | |||
| 79 | <size> | |||
| 80 | <width>20</width> | |||
| 81 | <height>40</height> | |||
| 82 | </size> | |||
| 83 | </property> | |||
| 84 | </spacer> | |||
| 85 | </item> | |||
| 86 | <item row="2" column="1"> | |||
| 87 | <widget class="QPushButton" name="pushQuit"> | |||
| 88 | <property name="text"> | |||
| 89 | <string>Quit</string> | |||
| 90 | </property> | |||
| 91 | </widget> | |||
| 92 | </item> | |||
| 93 | <item row="5" column="3"> | |||
| 94 | <widget class="QTextBrowser" name="textValue"> | |||
| 95 | <property name="html"> | |||
| 96 | <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> | |||
| 97 | <html><head><meta name="qrichtext" content="1" /><style type="text/css"> | |||
| 98 | p, li { white-space: pre-wrap; } | |||
| 99 | </style></head><body style=" font-family:'DejaVu Sans'; font-size:9pt; font-weight:400; font-style:normal;"> | |||
| 100 | <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></string> | |||
| 101 | </property> | |||
| 102 | </widget> | |||
| 103 | </item> | |||
| 104 | </layout> | |||
| 105 | </widget> | |||
| 106 | <action name="actionOpen"> | |||
| 107 | <property name="text"> | |||
| 108 | <string>Open</string> | |||
| 109 | </property> | |||
| 110 | </action> | |||
| 111 | <action name="actionPlot"> | |||
| 112 | <property name="text"> | |||
| 113 | <string>Plot</string> | |||
| 114 | </property> | |||
| 115 | </action> | |||
| 116 | <action name="actionQuit"> | |||
| 117 | <property name="text"> | |||
| 118 | <string>Quit</string> | |||
| 119 | </property> | |||
| 120 | </action> | |||
| 121 | </widget> | |||
| 122 | <resources/> | |||
| 123 | <connections/> | |||
| 124 | </ui> |