Commit 5ad56d3131ed866b5c83789163f0217d3e5d8c7a
1 parent
216c27103e
Exists in
master
resolve bug with empty value
Showing 1 changed file with 1 additions and 1 deletions Inline Diff
allanplot-gui.py
#!/usr/bin/python | 1 | 1 | #!/usr/bin/python | |
# -*- coding: utf-8 -*- | 2 | 2 | # -*- coding: utf-8 -*- | |
3 | 3 | |||
from PyQt4 import QtGui, QtCore | 4 | 4 | from PyQt4 import QtGui, QtCore | |
import sys, csv, numpy, allantools, pyqtgraph | 5 | 5 | import sys, csv, numpy, allantools, pyqtgraph | |
import allanplotUI | 6 | 6 | import allanplotUI | |
7 | 7 | |||
class allanplot(QtGui.QMainWindow, allanplotUI.Ui_MainWindow): | 8 | 8 | class allanplot(QtGui.QMainWindow, allanplotUI.Ui_MainWindow): | |
def __init__(self, parent=None): | 9 | 9 | def __init__(self, parent=None): | |
super(allanplot, self).__init__(parent) | 10 | 10 | super(allanplot, self).__init__(parent) | |
self.setupUi(self) | 11 | 11 | self.setupUi(self) | |
self.connectActions() | 12 | 12 | self.connectActions() | |
self.pqg_widget(self.frame) | 13 | 13 | self.pqg_widget(self.frame) | |
14 | 14 | |||
def pqg_widget(self, frame): | 15 | 15 | def pqg_widget(self, frame): | |
pyqtgraph.setConfigOption('background', 'w') | 16 | 16 | pyqtgraph.setConfigOption('background', 'w') | |
pyqtgraph.setConfigOption('foreground', 'k') | 17 | 17 | pyqtgraph.setConfigOption('foreground', 'k') | |
self.plot_widget = pyqtgraph.PlotWidget() | 18 | 18 | self.plot_widget = pyqtgraph.PlotWidget() | |
self.layout_pqg = QtGui.QVBoxLayout(frame) | 19 | 19 | self.layout_pqg = QtGui.QVBoxLayout(frame) | |
self.layout_pqg.addWidget(self.plot_widget) | 20 | 20 | self.layout_pqg.addWidget(self.plot_widget) | |
self.plot_widget.showGrid(True, True, 0.5) | 21 | 21 | self.plot_widget.showGrid(True, True, 0.5) | |
self.plot_widget.addLegend() | 22 | 22 | self.plot_widget.addLegend() | |
self.plot_widget.getViewBox().setMouseMode(pyqtgraph.ViewBox.RectMode) | 23 | 23 | self.plot_widget.getViewBox().setMouseMode(pyqtgraph.ViewBox.RectMode) | |
24 | 24 | |||
def connectActions(self): | 25 | 25 | def connectActions(self): | |
self.pushQuit.clicked.connect(QtGui.qApp.quit) | 26 | 26 | self.pushQuit.clicked.connect(QtGui.qApp.quit) | |
self.pushOpen.clicked.connect(self.openDat) | 27 | 27 | self.pushOpen.clicked.connect(self.openDat) | |
self.pushTimePlot.clicked.connect(self.timePlot) | 28 | 28 | self.pushTimePlot.clicked.connect(self.timePlot) | |
self.pushAdevPlot.clicked.connect(self.adevPlot) | 29 | 29 | self.pushAdevPlot.clicked.connect(self.adevPlot) | |
self.pushRelativeTimePlot.clicked.connect(self.relativeTimePlot) | 30 | 30 | self.pushRelativeTimePlot.clicked.connect(self.relativeTimePlot) | |
self.pushRelativeAdevPlot.clicked.connect(self.relativeAdevPlot) | 31 | 31 | self.pushRelativeAdevPlot.clicked.connect(self.relativeAdevPlot) | |
32 | 32 | |||
def openDat(self): | 33 | 33 | def openDat(self): | |
fileNames = QtGui.QFileDialog.getOpenFileNames(self, "Open datafile", QtCore.QDir.homePath(), "data files (*.dat)") | 34 | 34 | fileNames = QtGui.QFileDialog.getOpenFileNames(self, "Open datafile", QtCore.QDir.homePath(), "data files (*.dat)") | |
if fileNames: | 35 | 35 | if fileNames: | |
fileList = sorted([str(f) for f in fileNames]) | 36 | 36 | fileList = sorted([str(f) for f in fileNames]) | |
self.data = [] | 37 | 37 | self.data = [] | |
textList = '' | 38 | 38 | textList = '' | |
for f in fileList: | 39 | 39 | for f in fileList: | |
if textList=='': | 40 | 40 | if textList=='': | |
textList = str(f) | 41 | 41 | textList = str(f) | |
else: | 42 | 42 | else: | |
textList = textList+'\n'+str(f) | 43 | 43 | textList = textList+'\n'+str(f) | |
with open(f, 'r') as dest_f: | 44 | 44 | with open(f, 'r') as dest_f: | |
data_iter = csv.reader(dest_f, delimiter = '\t', quotechar = '"') | 45 | 45 | data_iter = csv.reader(dest_f, delimiter = '\t', quotechar = '"') | |
temp_data = [value for value in data_iter] | 46 | 46 | temp_data = [filter(None, value) for value in data_iter] | |
self.data.extend(temp_data) | 47 | 47 | self.data.extend(temp_data) | |
self.data = numpy.asarray(self.data, dtype = float) | 48 | 48 | self.data = numpy.asarray(self.data, dtype = float) | |
self.textFileList.setText(textList) | 49 | 49 | self.textFileList.setText(textList) | |
self.textValue.setText(str(self.data[:])) | 50 | 50 | self.textValue.setText(str(self.data[:])) | |
51 | 51 | |||
def timePlot(self): | 52 | 52 | def timePlot(self): | |
self.plot_widget.clear() | 53 | 53 | self.plot_widget.clear() | |
self.plot_widget.setTitle('time plot') | 54 | 54 | self.plot_widget.setTitle('time plot') | |
self.plot_widget.setLabel('bottom', "Time", "s") | 55 | 55 | self.plot_widget.setLabel('bottom', "Time", "s") | |
self.plot_widget.setLabel('left', "y") | 56 | 56 | self.plot_widget.setLabel('left', "y") | |
self.plot_widget.setLogMode(False, False) | 57 | 57 | self.plot_widget.setLogMode(False, False) | |
for i in range(2, self.data.shape[1]): | 58 | 58 | for i in range(2, self.data.shape[1]): | |
self.curve = self.plot_widget.plot() | 59 | 59 | self.curve = self.plot_widget.plot() | |
self.curve.setData(self.data[:,0], self.data[:,i], pen=5*i, name='#%s'%i) | 60 | 60 | self.curve.setData(self.data[:,0], self.data[:,i], pen=5*i, name='#%s'%i) | |
61 | 61 | |||
def relativeTimePlot(self): | 62 | 62 | def relativeTimePlot(self): | |
self.plot_widget.clear() | 63 | 63 | self.plot_widget.clear() | |
self.plot_widget.setTitle('relative time plot') | 64 | 64 | self.plot_widget.setTitle('relative time plot') | |
self.plot_widget.setLabel('bottom', "Time", "s") | 65 | 65 | self.plot_widget.setLabel('bottom', "Time", "s") | |
self.plot_widget.setLabel('left', "y") | 66 | 66 | self.plot_widget.setLabel('left', "y") | |
self.plot_widget.setLogMode(False, False) | 67 | 67 | self.plot_widget.setLogMode(False, False) | |
for i in range(2, self.data.shape[1]): | 68 | 68 | for i in range(2, self.data.shape[1]): | |
self.curve = self.plot_widget.plot() | 69 | 69 | 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) | 70 | 70 | self.curve.setData(self.data[:,0], self.data[:,i]/self.data[:,i].mean(), pen=5*i, name='#%s'%i) | |
71 | 71 | |||
def adevPlot(self): | 72 | 72 | def adevPlot(self): | |
self.plot_widget.clear() | 73 | 73 | self.plot_widget.clear() | |
self.plot_widget.setTitle('adev plot') | 74 | 74 | self.plot_widget.setTitle('adev plot') | |
self.plot_widget.setLabel('bottom', "Tau", "s") | 75 | 75 | self.plot_widget.setLabel('bottom', "Tau", "s") | |
self.plot_widget.setLabel('left', "adev") | 76 | 76 | self.plot_widget.setLabel('left', "adev") | |
self.plot_widget.setLogMode(True, True) | 77 | 77 | self.plot_widget.setLogMode(True, True) | |
for i in range(2, self.data.shape[1]): | 78 | 78 | 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') | 79 | 79 | (tau2, ad, ade, adn) = allantools.adev(self.data[:,i], rate=1, data_type="freq", taus='decade') | |
self.curve = self.plot_widget.plot() | 80 | 80 | self.curve = self.plot_widget.plot() | |
self.curve.setData(tau2, ad, pen=5*i, name='#%s'%i) | 81 | 81 | self.curve.setData(tau2, ad, pen=5*i, name='#%s'%i) | |
82 | 82 | |||
def relativeAdevPlot(self): | 83 | 83 | def relativeAdevPlot(self): | |
self.plot_widget.clear() | 84 | 84 | self.plot_widget.clear() | |
self.plot_widget.setTitle('relative adev plot') | 85 | 85 | self.plot_widget.setTitle('relative adev plot') | |
self.plot_widget.setLabel('bottom', "Tau", "s") | 86 | 86 | self.plot_widget.setLabel('bottom', "Tau", "s") | |
self.plot_widget.setLabel('left', "relative adev") | 87 | 87 | self.plot_widget.setLabel('left', "relative adev") | |
self.plot_widget.setLogMode(True, True) | 88 | 88 | self.plot_widget.setLogMode(True, True) | |
for i in range(2, self.data.shape[1]): | 89 | 89 | 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') | 90 | 90 | (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() | 91 | 91 | self.curve = self.plot_widget.plot() |