allanplot-gui.py 3.17 KB
#!/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_()