diff --git a/allanplot-gui.py b/allanplot-gui.py index 17f6ae3..148630e 100755 --- a/allanplot-gui.py +++ b/allanplot-gui.py @@ -6,96 +6,96 @@ 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 __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 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 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 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 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 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 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 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() + def main(self): + self.show() if __name__=='__main__': - app = QtGui.QApplication(sys.argv) - allanplot = allanplot() - allanplot.main() - app.exec_() + app = QtGui.QApplication(sys.argv) + allanplot = allanplot() + allanplot.main() + app.exec_() diff --git a/allanplotUI.py b/allanplotUI.py index d02a591..aad1875 100644 --- a/allanplotUI.py +++ b/allanplotUI.py @@ -3,123 +3,123 @@ # Form implementation generated from reading ui file 'allanplotUI.ui' # # Created: Thu Jul 7 17:46:05 2016 -# by: PyQt4 UI code generator 4.11.2 +# 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 + _fromUtf8 = QtCore.QString.fromUtf8 except AttributeError: - def _fromUtf8(s): - return s + def _fromUtf8(s): + return s try: - _encoding = QtGui.QApplication.UnicodeUTF8 - def _translate(context, text, disambig): - return QtGui.QApplication.translate(context, text, disambig, _encoding) + _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) + 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(766, 780) - self.centralwidget = QtGui.QWidget(MainWindow) - self.centralwidget.setObjectName(_fromUtf8("centralwidget")) - self.gridLayout = QtGui.QGridLayout(self.centralwidget) - self.gridLayout.setObjectName(_fromUtf8("gridLayout")) - 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) - sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Minimum) - sizePolicy.setHorizontalStretch(0) - sizePolicy.setVerticalStretch(0) - sizePolicy.setHeightForWidth(self.groupBox.sizePolicy().hasHeightForWidth()) - self.groupBox.setSizePolicy(sizePolicy) - 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, 4, 1, 1, 1) - self.textValue = QtGui.QTextBrowser(self.centralwidget) - sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum) - sizePolicy.setHorizontalStretch(0) - sizePolicy.setVerticalStretch(0) - sizePolicy.setHeightForWidth(self.textValue.sizePolicy().hasHeightForWidth()) - self.textValue.setSizePolicy(sizePolicy) - self.textValue.setMinimumSize(QtCore.QSize(600, 150)) - self.textValue.setMaximumSize(QtCore.QSize(16777215, 150)) - self.textValue.setObjectName(_fromUtf8("textValue")) - self.gridLayout.addWidget(self.textValue, 4, 2, 1, 1) - self.pushQuit = QtGui.QPushButton(self.centralwidget) - self.pushQuit.setObjectName(_fromUtf8("pushQuit")) - self.gridLayout.addWidget(self.pushQuit, 2, 1, 1, 1) - self.textFileList = QtGui.QTextBrowser(self.centralwidget) - self.textFileList.setEnabled(True) - sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Maximum) - sizePolicy.setHorizontalStretch(0) - sizePolicy.setVerticalStretch(0) - sizePolicy.setHeightForWidth(self.textFileList.sizePolicy().hasHeightForWidth()) - self.textFileList.setSizePolicy(sizePolicy) - self.textFileList.setMinimumSize(QtCore.QSize(600, 100)) - self.textFileList.setMaximumSize(QtCore.QSize(16777215, 100)) - self.textFileList.setObjectName(_fromUtf8("textFileList")) - self.gridLayout.addWidget(self.textFileList, 1, 2, 3, 1) - self.frame = QtGui.QFrame(self.centralwidget) - sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Expanding) - sizePolicy.setHorizontalStretch(0) - sizePolicy.setVerticalStretch(0) - sizePolicy.setHeightForWidth(self.frame.sizePolicy().hasHeightForWidth()) - self.frame.setSizePolicy(sizePolicy) - self.frame.setMinimumSize(QtCore.QSize(700, 500)) - self.frame.setObjectName(_fromUtf8("frame")) - self.gridLayout.addWidget(self.frame, 5, 1, 1, 2) - 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")) + def setupUi(self, MainWindow): + MainWindow.setObjectName(_fromUtf8("MainWindow")) + MainWindow.resize(766, 780) + self.centralwidget = QtGui.QWidget(MainWindow) + self.centralwidget.setObjectName(_fromUtf8("centralwidget")) + self.gridLayout = QtGui.QGridLayout(self.centralwidget) + self.gridLayout.setObjectName(_fromUtf8("gridLayout")) + 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) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Minimum) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.groupBox.sizePolicy().hasHeightForWidth()) + self.groupBox.setSizePolicy(sizePolicy) + 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, 4, 1, 1, 1) + self.textValue = QtGui.QTextBrowser(self.centralwidget) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.textValue.sizePolicy().hasHeightForWidth()) + self.textValue.setSizePolicy(sizePolicy) + self.textValue.setMinimumSize(QtCore.QSize(600, 150)) + self.textValue.setMaximumSize(QtCore.QSize(16777215, 150)) + self.textValue.setObjectName(_fromUtf8("textValue")) + self.gridLayout.addWidget(self.textValue, 4, 2, 1, 1) + self.pushQuit = QtGui.QPushButton(self.centralwidget) + self.pushQuit.setObjectName(_fromUtf8("pushQuit")) + self.gridLayout.addWidget(self.pushQuit, 2, 1, 1, 1) + self.textFileList = QtGui.QTextBrowser(self.centralwidget) + self.textFileList.setEnabled(True) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Maximum) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.textFileList.sizePolicy().hasHeightForWidth()) + self.textFileList.setSizePolicy(sizePolicy) + self.textFileList.setMinimumSize(QtCore.QSize(600, 100)) + self.textFileList.setMaximumSize(QtCore.QSize(16777215, 100)) + self.textFileList.setObjectName(_fromUtf8("textFileList")) + self.gridLayout.addWidget(self.textFileList, 1, 2, 3, 1) + self.frame = QtGui.QFrame(self.centralwidget) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Expanding) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.frame.sizePolicy().hasHeightForWidth()) + self.frame.setSizePolicy(sizePolicy) + self.frame.setMinimumSize(QtCore.QSize(700, 500)) + self.frame.setObjectName(_fromUtf8("frame")) + self.gridLayout.addWidget(self.frame, 5, 1, 1, 2) + 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) + self.retranslateUi(MainWindow) + QtCore.QMetaObject.connectSlotsByName(MainWindow) - def retranslateUi(self, MainWindow): - MainWindow.setWindowTitle(_translate("MainWindow", "allanplot-gui", 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.textValue.setHtml(_translate("MainWindow", "\n" + def retranslateUi(self, MainWindow): + MainWindow.setWindowTitle(_translate("MainWindow", "allanplot-gui", 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.textValue.setHtml(_translate("MainWindow", "\n" "
\n" ".dat files
", None)) - self.actionOpen.setText(_translate("MainWindow", "Open", None)) - self.actionPlot.setText(_translate("MainWindow", "Plot", None)) - self.actionQuit.setText(_translate("MainWindow", "Quit", None)) + self.actionOpen.setText(_translate("MainWindow", "Open", None)) + self.actionPlot.setText(_translate("MainWindow", "Plot", None)) + self.actionQuit.setText(_translate("MainWindow", "Quit", None))