Fit limits are shown and labeles

Size of PeakBox elements are now OK
Conductivity moved to data
This commit is contained in:
Markus Rosenstihl 2013-07-10 18:36:07 +02:00
parent 4f6421ae22
commit 805a726346
11 changed files with 464 additions and 420 deletions

View File

@ -2,8 +2,8 @@
# Form implementation generated from reading ui file 'ConductivityGroupBox.ui' # Form implementation generated from reading ui file 'ConductivityGroupBox.ui'
# #
# Created: Fri Jun 14 08:45:33 2013 # Created: Wed Jul 10 18:32:01 2013
# by: PyQt4 UI code generator 4.10.1 # by: PyQt4 UI code generator 4.10.2
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!

View File

@ -6,6 +6,7 @@ import ConductivityGroupBox
class ConductivityWidget(QGroupBox): class ConductivityWidget(QGroupBox):
changedTable = pyqtSignal() changedTable = pyqtSignal()
def __init__(self, parent=None): def __init__(self, parent=None):
QGroupBox.__init__(self) QGroupBox.__init__(self)
super(ConductivityWidget, self).__init__(parent) super(ConductivityWidget, self).__init__(parent)
@ -28,7 +29,7 @@ class ConductivityWidget(QGroupBox):
self.ui.pushButton_5, self.ui.pushButton_5,
self.ui.pushButton_6, self.ui.pushButton_6,
]): ]):
self.signalMapper.setMapping(button,i) self.signalMapper.setMapping(button, i)
button.clicked.connect(self.signalMapper.map) button.clicked.connect(self.signalMapper.map)
self.signalMapper.mapped.connect(self.changeValues) self.signalMapper.mapped.connect(self.changeValues)
@ -38,38 +39,38 @@ class ConductivityWidget(QGroupBox):
# 0-3 down/up for d_eps and tau, respectively # 0-3 down/up for d_eps and tau, respectively
# 4-7 down, up for a, b # 4-7 down, up for a, b
if num == 0: if num == 0:
self.ui.lineEdit_1.setText("%.2e"%(self.ui.lineEdit_1.text().toDouble()[0]/logstep)) self.ui.lineEdit_1.setText("%.2e" % (self.ui.lineEdit_1.text().toDouble()[0] / logstep))
if num == 1: if num == 1:
self.ui.lineEdit_1.setText("%.2e"%(self.ui.lineEdit_1.text().toDouble()[0]*logstep)) self.ui.lineEdit_1.setText("%.2e" % (self.ui.lineEdit_1.text().toDouble()[0] * logstep))
if num == 2: if num == 2:
self.ui.lineEdit_2.setText("%.2e"%(self.ui.lineEdit_2.text().toDouble()[0]/logstep)) self.ui.lineEdit_2.setText("%.2e" % (self.ui.lineEdit_2.text().toDouble()[0] / logstep))
if num == 3: if num == 3:
self.ui.lineEdit_2.setText("%.2e"%(self.ui.lineEdit_2.text().toDouble()[0]*logstep)) self.ui.lineEdit_2.setText("%.2e" % (self.ui.lineEdit_2.text().toDouble()[0] * logstep))
if num == 4: if num == 4:
self.ui.lineEdit_3.setText("%.2e"%(self.ui.lineEdit_3.text().toDouble()[0]-linstep)) self.ui.lineEdit_3.setText("%.2e" % (self.ui.lineEdit_3.text().toDouble()[0] - linstep))
if num == 5: if num == 5:
self.ui.lineEdit_3.setText("%.2e"%(self.ui.lineEdit_3.text().toDouble()[0]+linstep)) self.ui.lineEdit_3.setText("%.2e" % (self.ui.lineEdit_3.text().toDouble()[0] + linstep))
self.changedTable.emit() self.changedTable.emit()
def fixedParameter(self): def fixedParameter(self):
return [0 if cb.isChecked() else 1 for cb in self.fixedCheckBoxes] return [0 if cb.isChecked() else 1 for cb in self.fixedCheckBoxes]
def setColor(self, color): def setColor(self, color):
r,g,b = color r, g, b = color
palette = self.palette() palette = self.palette()
palette.setColor(QPalette.Foreground, QColor(r,g,b)) palette.setColor(QPalette.Foreground, QColor(r, g, b))
self.setPalette(palette) self.setPalette(palette)
def getTable(self): def getTable(self):
tmp = [i.text().toDouble()[0] # selects the number, ignores the status tmp = [i.text().toDouble()[0] # selects the number, ignores the status
for i in self.lineEdits ] for i in self.lineEdits]
print "peakParams:",tmp print "peakParams:", tmp
return tmp return tmp
def update(self): def update(self):
self.changedTable.emit() self.changedTable.emit()
def updateTable(self, *args): def updateTable(self, *args):
for i,arg in enumerate(args): for i, arg in enumerate(args):
self.lineEdits[i].setText("%g"%(args[i])) self.lineEdits[i].setText("%g" % (args[i]))

View File

@ -25,6 +25,7 @@ from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as Canvas
from matplotlib.figure import Figure from matplotlib.figure import Figure
from matplotlib import rcParams from matplotlib import rcParams
rcParams['font.size'] = 9 rcParams['font.size'] = 9
@ -61,6 +62,7 @@ class MatplotlibWidget(Canvas):
self.widget.axes.plot(x, x**2) self.widget.axes.plot(x, x**2)
self.wdiget.axes.plot(x, x**3) self.wdiget.axes.plot(x, x**3)
""" """
def __init__(self, parent=None, title='', xlabel='', ylabel='', def __init__(self, parent=None, title='', xlabel='', ylabel='',
xlim=None, ylim=None, xscale='linear', yscale='linear', xlim=None, ylim=None, xscale='linear', yscale='linear',
width=6, height=4, dpi=100, hold=False): width=6, height=4, dpi=100, hold=False):
@ -93,7 +95,6 @@ class MatplotlibWidget(Canvas):
return QSize(10, 10) return QSize(10, 10)
#=============================================================================== #===============================================================================
# Example # Example
#=============================================================================== #===============================================================================
@ -115,8 +116,8 @@ if __name__ == '__main__':
def plot(self, axes): def plot(self, axes):
x = linspace(-10, 10) x = linspace(-10, 10)
axes.plot(x, x**2) axes.plot(x, x ** 2)
axes.plot(x, x**3) axes.plot(x, x ** 3)
app = QApplication(sys.argv) app = QApplication(sys.argv)
win = ApplicationWindow() win = ApplicationWindow()

View File

@ -2,8 +2,8 @@
# Form implementation generated from reading ui file 'PeakGroupBox.ui' # Form implementation generated from reading ui file 'PeakGroupBox.ui'
# #
# Created: Fri Jun 14 08:45:33 2013 # Created: Wed Jul 10 18:32:01 2013
# by: PyQt4 UI code generator 4.10.1 # by: PyQt4 UI code generator 4.10.2
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!
@ -27,16 +27,18 @@ class Ui_PeakGroupBox(object):
def setupUi(self, PeakGroupBox): def setupUi(self, PeakGroupBox):
PeakGroupBox.setObjectName(_fromUtf8("PeakGroupBox")) PeakGroupBox.setObjectName(_fromUtf8("PeakGroupBox"))
PeakGroupBox.setEnabled(True) PeakGroupBox.setEnabled(True)
PeakGroupBox.resize(385, 230) PeakGroupBox.resize(320, 210)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.MinimumExpanding) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0) sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0) sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(PeakGroupBox.sizePolicy().hasHeightForWidth()) sizePolicy.setHeightForWidth(PeakGroupBox.sizePolicy().hasHeightForWidth())
PeakGroupBox.setSizePolicy(sizePolicy) PeakGroupBox.setSizePolicy(sizePolicy)
PeakGroupBox.setMinimumSize(QtCore.QSize(275, 210)) PeakGroupBox.setMinimumSize(QtCore.QSize(308, 210))
PeakGroupBox.setAutoFillBackground(False)
PeakGroupBox.setFlat(False) PeakGroupBox.setFlat(False)
PeakGroupBox.setCheckable(False) PeakGroupBox.setCheckable(False)
self.gridLayout_2 = QtGui.QGridLayout(PeakGroupBox) self.gridLayout_2 = QtGui.QGridLayout(PeakGroupBox)
self.gridLayout_2.setMargin(10)
self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2")) self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2"))
self.gridLayout = QtGui.QGridLayout() self.gridLayout = QtGui.QGridLayout()
self.gridLayout.setSizeConstraint(QtGui.QLayout.SetDefaultConstraint) self.gridLayout.setSizeConstraint(QtGui.QLayout.SetDefaultConstraint)
@ -48,13 +50,12 @@ class Ui_PeakGroupBox(object):
self.checkBox_2.setObjectName(_fromUtf8("checkBox_2")) self.checkBox_2.setObjectName(_fromUtf8("checkBox_2"))
self.gridLayout.addWidget(self.checkBox_2, 2, 4, 1, 1) self.gridLayout.addWidget(self.checkBox_2, 2, 4, 1, 1)
self.lineEdit_3 = QtGui.QLineEdit(PeakGroupBox) self.lineEdit_3 = QtGui.QLineEdit(PeakGroupBox)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.Fixed) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0) sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0) sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.lineEdit_3.sizePolicy().hasHeightForWidth()) sizePolicy.setHeightForWidth(self.lineEdit_3.sizePolicy().hasHeightForWidth())
self.lineEdit_3.setSizePolicy(sizePolicy) self.lineEdit_3.setSizePolicy(sizePolicy)
self.lineEdit_3.setMinimumSize(QtCore.QSize(128, 0)) self.lineEdit_3.setMinimumSize(QtCore.QSize(96, 0))
self.lineEdit_3.setMaximumSize(QtCore.QSize(90, 16777215))
self.lineEdit_3.setObjectName(_fromUtf8("lineEdit_3")) self.lineEdit_3.setObjectName(_fromUtf8("lineEdit_3"))
self.gridLayout.addWidget(self.lineEdit_3, 3, 1, 1, 1) self.gridLayout.addWidget(self.lineEdit_3, 3, 1, 1, 1)
self.checkBox_3 = QtGui.QCheckBox(PeakGroupBox) self.checkBox_3 = QtGui.QCheckBox(PeakGroupBox)
@ -66,7 +67,7 @@ class Ui_PeakGroupBox(object):
sizePolicy.setVerticalStretch(0) sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_7.sizePolicy().hasHeightForWidth()) sizePolicy.setHeightForWidth(self.pushButton_7.sizePolicy().hasHeightForWidth())
self.pushButton_7.setSizePolicy(sizePolicy) self.pushButton_7.setSizePolicy(sizePolicy)
self.pushButton_7.setMinimumSize(QtCore.QSize(64, 0)) self.pushButton_7.setMinimumSize(QtCore.QSize(56, 0))
self.pushButton_7.setObjectName(_fromUtf8("pushButton_7")) self.pushButton_7.setObjectName(_fromUtf8("pushButton_7"))
self.gridLayout.addWidget(self.pushButton_7, 4, 2, 1, 1) self.gridLayout.addWidget(self.pushButton_7, 4, 2, 1, 1)
self.label_2 = QtGui.QLabel(PeakGroupBox) self.label_2 = QtGui.QLabel(PeakGroupBox)
@ -79,13 +80,12 @@ class Ui_PeakGroupBox(object):
self.label_2.setObjectName(_fromUtf8("label_2")) self.label_2.setObjectName(_fromUtf8("label_2"))
self.gridLayout.addWidget(self.label_2, 2, 0, 1, 1) self.gridLayout.addWidget(self.label_2, 2, 0, 1, 1)
self.lineEdit_4 = QtGui.QLineEdit(PeakGroupBox) self.lineEdit_4 = QtGui.QLineEdit(PeakGroupBox)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.Fixed) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0) sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0) sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.lineEdit_4.sizePolicy().hasHeightForWidth()) sizePolicy.setHeightForWidth(self.lineEdit_4.sizePolicy().hasHeightForWidth())
self.lineEdit_4.setSizePolicy(sizePolicy) self.lineEdit_4.setSizePolicy(sizePolicy)
self.lineEdit_4.setMinimumSize(QtCore.QSize(128, 0)) self.lineEdit_4.setMinimumSize(QtCore.QSize(96, 0))
self.lineEdit_4.setMaximumSize(QtCore.QSize(90, 16777215))
self.lineEdit_4.setObjectName(_fromUtf8("lineEdit_4")) self.lineEdit_4.setObjectName(_fromUtf8("lineEdit_4"))
self.gridLayout.addWidget(self.lineEdit_4, 4, 1, 1, 1) self.gridLayout.addWidget(self.lineEdit_4, 4, 1, 1, 1)
self.pushButton_1 = QtGui.QPushButton(PeakGroupBox) self.pushButton_1 = QtGui.QPushButton(PeakGroupBox)
@ -94,7 +94,8 @@ class Ui_PeakGroupBox(object):
sizePolicy.setVerticalStretch(0) sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_1.sizePolicy().hasHeightForWidth()) sizePolicy.setHeightForWidth(self.pushButton_1.sizePolicy().hasHeightForWidth())
self.pushButton_1.setSizePolicy(sizePolicy) self.pushButton_1.setSizePolicy(sizePolicy)
self.pushButton_1.setMinimumSize(QtCore.QSize(64, 0)) self.pushButton_1.setMinimumSize(QtCore.QSize(56, 0))
self.pushButton_1.setBaseSize(QtCore.QSize(0, 0))
self.pushButton_1.setAutoDefault(False) self.pushButton_1.setAutoDefault(False)
self.pushButton_1.setDefault(False) self.pushButton_1.setDefault(False)
self.pushButton_1.setFlat(False) self.pushButton_1.setFlat(False)
@ -107,7 +108,7 @@ class Ui_PeakGroupBox(object):
sizePolicy.setVerticalStretch(0) sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_6.sizePolicy().hasHeightForWidth()) sizePolicy.setHeightForWidth(self.pushButton_6.sizePolicy().hasHeightForWidth())
self.pushButton_6.setSizePolicy(sizePolicy) self.pushButton_6.setSizePolicy(sizePolicy)
self.pushButton_6.setMinimumSize(QtCore.QSize(64, 0)) self.pushButton_6.setMinimumSize(QtCore.QSize(56, 0))
self.pushButton_6.setObjectName(_fromUtf8("pushButton_6")) self.pushButton_6.setObjectName(_fromUtf8("pushButton_6"))
self.gridLayout.addWidget(self.pushButton_6, 3, 3, 1, 1) self.gridLayout.addWidget(self.pushButton_6, 3, 3, 1, 1)
self.label = QtGui.QLabel(PeakGroupBox) self.label = QtGui.QLabel(PeakGroupBox)
@ -125,7 +126,7 @@ class Ui_PeakGroupBox(object):
sizePolicy.setVerticalStretch(0) sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_5.sizePolicy().hasHeightForWidth()) sizePolicy.setHeightForWidth(self.pushButton_5.sizePolicy().hasHeightForWidth())
self.pushButton_5.setSizePolicy(sizePolicy) self.pushButton_5.setSizePolicy(sizePolicy)
self.pushButton_5.setMinimumSize(QtCore.QSize(64, 0)) self.pushButton_5.setMinimumSize(QtCore.QSize(56, 0))
self.pushButton_5.setObjectName(_fromUtf8("pushButton_5")) self.pushButton_5.setObjectName(_fromUtf8("pushButton_5"))
self.gridLayout.addWidget(self.pushButton_5, 3, 2, 1, 1) self.gridLayout.addWidget(self.pushButton_5, 3, 2, 1, 1)
self.removeButton = QtGui.QPushButton(PeakGroupBox) self.removeButton = QtGui.QPushButton(PeakGroupBox)
@ -144,7 +145,7 @@ class Ui_PeakGroupBox(object):
sizePolicy.setVerticalStretch(0) sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_8.sizePolicy().hasHeightForWidth()) sizePolicy.setHeightForWidth(self.pushButton_8.sizePolicy().hasHeightForWidth())
self.pushButton_8.setSizePolicy(sizePolicy) self.pushButton_8.setSizePolicy(sizePolicy)
self.pushButton_8.setMinimumSize(QtCore.QSize(64, 0)) self.pushButton_8.setMinimumSize(QtCore.QSize(56, 0))
self.pushButton_8.setObjectName(_fromUtf8("pushButton_8")) self.pushButton_8.setObjectName(_fromUtf8("pushButton_8"))
self.gridLayout.addWidget(self.pushButton_8, 4, 3, 1, 1) self.gridLayout.addWidget(self.pushButton_8, 4, 3, 1, 1)
self.label_3 = QtGui.QLabel(PeakGroupBox) self.label_3 = QtGui.QLabel(PeakGroupBox)
@ -163,7 +164,7 @@ class Ui_PeakGroupBox(object):
sizePolicy.setVerticalStretch(0) sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_4.sizePolicy().hasHeightForWidth()) sizePolicy.setHeightForWidth(self.pushButton_4.sizePolicy().hasHeightForWidth())
self.pushButton_4.setSizePolicy(sizePolicy) self.pushButton_4.setSizePolicy(sizePolicy)
self.pushButton_4.setMinimumSize(QtCore.QSize(64, 0)) self.pushButton_4.setMinimumSize(QtCore.QSize(56, 0))
self.pushButton_4.setObjectName(_fromUtf8("pushButton_4")) self.pushButton_4.setObjectName(_fromUtf8("pushButton_4"))
self.gridLayout.addWidget(self.pushButton_4, 2, 3, 1, 1) self.gridLayout.addWidget(self.pushButton_4, 2, 3, 1, 1)
self.label_1 = QtGui.QLabel(PeakGroupBox) self.label_1 = QtGui.QLabel(PeakGroupBox)
@ -176,13 +177,12 @@ class Ui_PeakGroupBox(object):
self.label_1.setObjectName(_fromUtf8("label_1")) self.label_1.setObjectName(_fromUtf8("label_1"))
self.gridLayout.addWidget(self.label_1, 1, 0, 1, 1) self.gridLayout.addWidget(self.label_1, 1, 0, 1, 1)
self.lineEdit_2 = QtGui.QLineEdit(PeakGroupBox) self.lineEdit_2 = QtGui.QLineEdit(PeakGroupBox)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.Fixed) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0) sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0) sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.lineEdit_2.sizePolicy().hasHeightForWidth()) sizePolicy.setHeightForWidth(self.lineEdit_2.sizePolicy().hasHeightForWidth())
self.lineEdit_2.setSizePolicy(sizePolicy) self.lineEdit_2.setSizePolicy(sizePolicy)
self.lineEdit_2.setMinimumSize(QtCore.QSize(128, 0)) self.lineEdit_2.setMinimumSize(QtCore.QSize(96, 0))
self.lineEdit_2.setMaximumSize(QtCore.QSize(90, 16777215))
self.lineEdit_2.setObjectName(_fromUtf8("lineEdit_2")) self.lineEdit_2.setObjectName(_fromUtf8("lineEdit_2"))
self.gridLayout.addWidget(self.lineEdit_2, 2, 1, 1, 1) self.gridLayout.addWidget(self.lineEdit_2, 2, 1, 1, 1)
self.checkBox_1 = QtGui.QCheckBox(PeakGroupBox) self.checkBox_1 = QtGui.QCheckBox(PeakGroupBox)
@ -191,13 +191,13 @@ class Ui_PeakGroupBox(object):
self.checkBox_1.setObjectName(_fromUtf8("checkBox_1")) self.checkBox_1.setObjectName(_fromUtf8("checkBox_1"))
self.gridLayout.addWidget(self.checkBox_1, 1, 4, 1, 1) self.gridLayout.addWidget(self.checkBox_1, 1, 4, 1, 1)
self.lineEdit_1 = QtGui.QLineEdit(PeakGroupBox) self.lineEdit_1 = QtGui.QLineEdit(PeakGroupBox)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.Fixed) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0) sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0) sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.lineEdit_1.sizePolicy().hasHeightForWidth()) sizePolicy.setHeightForWidth(self.lineEdit_1.sizePolicy().hasHeightForWidth())
self.lineEdit_1.setSizePolicy(sizePolicy) self.lineEdit_1.setSizePolicy(sizePolicy)
self.lineEdit_1.setMinimumSize(QtCore.QSize(128, 0)) self.lineEdit_1.setMinimumSize(QtCore.QSize(96, 0))
self.lineEdit_1.setMaximumSize(QtCore.QSize(90, 16777215)) self.lineEdit_1.setBaseSize(QtCore.QSize(0, 0))
self.lineEdit_1.setObjectName(_fromUtf8("lineEdit_1")) self.lineEdit_1.setObjectName(_fromUtf8("lineEdit_1"))
self.gridLayout.addWidget(self.lineEdit_1, 1, 1, 1, 1) self.gridLayout.addWidget(self.lineEdit_1, 1, 1, 1, 1)
self.pushButton_3 = QtGui.QPushButton(PeakGroupBox) self.pushButton_3 = QtGui.QPushButton(PeakGroupBox)
@ -206,7 +206,7 @@ class Ui_PeakGroupBox(object):
sizePolicy.setVerticalStretch(0) sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_3.sizePolicy().hasHeightForWidth()) sizePolicy.setHeightForWidth(self.pushButton_3.sizePolicy().hasHeightForWidth())
self.pushButton_3.setSizePolicy(sizePolicy) self.pushButton_3.setSizePolicy(sizePolicy)
self.pushButton_3.setMinimumSize(QtCore.QSize(64, 0)) self.pushButton_3.setMinimumSize(QtCore.QSize(56, 0))
self.pushButton_3.setObjectName(_fromUtf8("pushButton_3")) self.pushButton_3.setObjectName(_fromUtf8("pushButton_3"))
self.gridLayout.addWidget(self.pushButton_3, 2, 2, 1, 1) self.gridLayout.addWidget(self.pushButton_3, 2, 2, 1, 1)
self.label_4 = QtGui.QLabel(PeakGroupBox) self.label_4 = QtGui.QLabel(PeakGroupBox)
@ -228,9 +228,10 @@ class Ui_PeakGroupBox(object):
sizePolicy.setVerticalStretch(0) sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_2.sizePolicy().hasHeightForWidth()) sizePolicy.setHeightForWidth(self.pushButton_2.sizePolicy().hasHeightForWidth())
self.pushButton_2.setSizePolicy(sizePolicy) self.pushButton_2.setSizePolicy(sizePolicy)
self.pushButton_2.setMinimumSize(QtCore.QSize(64, 0)) self.pushButton_2.setMinimumSize(QtCore.QSize(56, 0))
self.pushButton_2.setObjectName(_fromUtf8("pushButton_2")) self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
self.gridLayout.addWidget(self.pushButton_2, 1, 3, 1, 1) self.gridLayout.addWidget(self.pushButton_2, 1, 3, 1, 1)
self.gridLayout.setColumnStretch(1, 1)
self.gridLayout_2.addLayout(self.gridLayout, 0, 0, 1, 1) self.gridLayout_2.addLayout(self.gridLayout, 0, 0, 1, 1)
self.retranslateUi(PeakGroupBox) self.retranslateUi(PeakGroupBox)

View File

@ -9,25 +9,28 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>385</width> <width>320</width>
<height>230</height> <height>210</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>275</width> <width>308</width>
<height>210</height> <height>210</height>
</size> </size>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>GroupBox</string> <string>GroupBox</string>
</property> </property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="title"> <property name="title">
<string>GroupBox</string> <string>GroupBox</string>
</property> </property>
@ -37,9 +40,12 @@
<property name="checkable"> <property name="checkable">
<bool>false</bool> <bool>false</bool>
</property> </property>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2" rowstretch="0">
<property name="margin">
<number>10</number>
</property>
<item row="0" column="0"> <item row="0" column="0">
<layout class="QGridLayout" name="gridLayout" rowstretch="0,0,0,0,0" columnstretch="0,0,0,0,0"> <layout class="QGridLayout" name="gridLayout" rowstretch="0,0,0,0,0" columnstretch="0,1,0,0,0" rowminimumheight="0,0,0,0,0" columnminimumwidth="0,0,0,0,0">
<property name="sizeConstraint"> <property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum> <enum>QLayout::SetDefaultConstraint</enum>
</property> </property>
@ -62,23 +68,17 @@
<item row="3" column="1"> <item row="3" column="1">
<widget class="QLineEdit" name="lineEdit_3"> <widget class="QLineEdit" name="lineEdit_3">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>128</width> <width>96</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
<property name="maximumSize">
<size>
<width>90</width>
<height>16777215</height>
</size>
</property>
<property name="text"> <property name="text">
<string>0.0</string> <string>0.0</string>
</property> </property>
@ -101,7 +101,7 @@
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>64</width> <width>56</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
@ -129,23 +129,17 @@
<item row="4" column="1"> <item row="4" column="1">
<widget class="QLineEdit" name="lineEdit_4"> <widget class="QLineEdit" name="lineEdit_4">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>128</width> <width>96</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
<property name="maximumSize">
<size>
<width>90</width>
<height>16777215</height>
</size>
</property>
<property name="text"> <property name="text">
<string>0.0</string> <string>0.0</string>
</property> </property>
@ -161,7 +155,13 @@
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>64</width> <width>56</width>
<height>0</height>
</size>
</property>
<property name="baseSize">
<size>
<width>0</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
@ -192,7 +192,7 @@
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>64</width> <width>56</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
@ -227,7 +227,7 @@
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>64</width> <width>56</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
@ -268,7 +268,7 @@
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>64</width> <width>56</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
@ -306,7 +306,7 @@
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>64</width> <width>56</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
@ -334,23 +334,17 @@
<item row="2" column="1"> <item row="2" column="1">
<widget class="QLineEdit" name="lineEdit_2"> <widget class="QLineEdit" name="lineEdit_2">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>128</width> <width>96</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
<property name="maximumSize">
<size>
<width>90</width>
<height>16777215</height>
</size>
</property>
<property name="text"> <property name="text">
<string>0.00e+00</string> <string>0.00e+00</string>
</property> </property>
@ -369,21 +363,21 @@
<item row="1" column="1"> <item row="1" column="1">
<widget class="QLineEdit" name="lineEdit_1"> <widget class="QLineEdit" name="lineEdit_1">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> <sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>128</width> <width>96</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
<property name="maximumSize"> <property name="baseSize">
<size> <size>
<width>90</width> <width>0</width>
<height>16777215</height> <height>0</height>
</size> </size>
</property> </property>
<property name="text"> <property name="text">
@ -401,7 +395,7 @@
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>64</width> <width>56</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
@ -446,7 +440,7 @@
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>64</width> <width>56</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>

View File

@ -5,6 +5,7 @@ import PeakGroupBox
class PeakWidget(QGroupBox): class PeakWidget(QGroupBox):
changedTable = pyqtSignal() changedTable = pyqtSignal()
def __init__(self, parent=None): def __init__(self, parent=None):
QGroupBox.__init__(self) QGroupBox.__init__(self)
super(PeakWidget, self).__init__(parent) super(PeakWidget, self).__init__(parent)
@ -30,7 +31,7 @@ class PeakWidget(QGroupBox):
self.ui.pushButton_7, self.ui.pushButton_7,
self.ui.pushButton_8, self.ui.pushButton_8,
]): ]):
self.signalMapper.setMapping(button,i) self.signalMapper.setMapping(button, i)
button.clicked.connect(self.signalMapper.map) button.clicked.connect(self.signalMapper.map)
self.signalMapper.mapped.connect(self.changeValues) self.signalMapper.mapped.connect(self.changeValues)
@ -40,41 +41,41 @@ class PeakWidget(QGroupBox):
# 0-3 down/up for d_eps and tau, respectively # 0-3 down/up for d_eps and tau, respectively
# 4-7 down, up for a, b # 4-7 down, up for a, b
if num == 0: if num == 0:
self.ui.lineEdit_1.setText("%.2e"%(self.ui.lineEdit_1.text().toDouble()[0]/logstep)) self.ui.lineEdit_1.setText("%.2e" % (self.ui.lineEdit_1.text().toDouble()[0] / logstep))
if num == 1: if num == 1:
self.ui.lineEdit_1.setText("%.2e"%(self.ui.lineEdit_1.text().toDouble()[0]*logstep)) self.ui.lineEdit_1.setText("%.2e" % (self.ui.lineEdit_1.text().toDouble()[0] * logstep))
if num == 2: if num == 2:
self.ui.lineEdit_2.setText("%.2e"%(self.ui.lineEdit_2.text().toDouble()[0]/logstep)) self.ui.lineEdit_2.setText("%.2e" % (self.ui.lineEdit_2.text().toDouble()[0] / logstep))
if num == 3: if num == 3:
self.ui.lineEdit_2.setText("%.2e"%(self.ui.lineEdit_2.text().toDouble()[0]*logstep)) self.ui.lineEdit_2.setText("%.2e" % (self.ui.lineEdit_2.text().toDouble()[0] * logstep))
if num == 4: if num == 4:
self.ui.lineEdit_3.setText("%.2e"%(self.ui.lineEdit_3.text().toDouble()[0]-linstep)) self.ui.lineEdit_3.setText("%.2e" % (self.ui.lineEdit_3.text().toDouble()[0] - linstep))
if num == 5: if num == 5:
self.ui.lineEdit_3.setText("%.2e"%(self.ui.lineEdit_3.text().toDouble()[0]+linstep)) self.ui.lineEdit_3.setText("%.2e" % (self.ui.lineEdit_3.text().toDouble()[0] + linstep))
if num == 6: if num == 6:
self.ui.lineEdit_4.setText("%.2e"%(self.ui.lineEdit_4.text().toDouble()[0]-linstep)) self.ui.lineEdit_4.setText("%.2e" % (self.ui.lineEdit_4.text().toDouble()[0] - linstep))
if num == 7: if num == 7:
self.ui.lineEdit_4.setText("%.2e"%(self.ui.lineEdit_4.text().toDouble()[0]+linstep)) self.ui.lineEdit_4.setText("%.2e" % (self.ui.lineEdit_4.text().toDouble()[0] + linstep))
self.changedTable.emit() self.changedTable.emit()
def fixedParameter(self): def fixedParameter(self):
return [0 if cb.isChecked() else 1 for cb in self.fixedCheckBoxes] return [0 if cb.isChecked() else 1 for cb in self.fixedCheckBoxes]
def setId(self,id): def setId(self, id):
self.id=id self.id = id
self.setTitle("Peak %i"%id) self.setTitle("Peak %i" % id)
def setColor(self, color): def setColor(self, color):
r,g,b = color r, g, b = color
palette = self.palette() palette = self.palette()
palette.setColor(QPalette.Foreground, QColor(r,g,b)) palette.setColor(QPalette.Foreground, QColor(r, g, b))
self.setPalette(palette) self.setPalette(palette)
def peakParameter(self): def peakParameter(self):
tmp = [i.text().toDouble()[0] # selects the number, ignores the status tmp = [i.text().toDouble()[0] # selects the number, ignores the status
for i in self.lineEdits ] for i in self.lineEdits]
print "peakParams:",tmp print "peakParams:", tmp
return tmp return tmp
def update(self): def update(self):
@ -82,6 +83,6 @@ class PeakWidget(QGroupBox):
def updateTable(self, *args): def updateTable(self, *args):
print "updateTable", args print "updateTable", args
for i,arg in enumerate(args): for i, arg in enumerate(args):
self.lineEdits[i].setText("%g"%(args[i])) self.lineEdits[i].setText("%g" % (args[i]))

440
QDS.py
View File

@ -1,17 +1,17 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-
import os,sys import os
import sys
import re import re
import signal import signal
from PyQt4.QtCore import * from PyQt4.QtCore import *
from PyQt4.QtGui import * from PyQt4.QtGui import *
from PyQt4.uic import *
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
#from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
import matplotlib.pyplot as plt #import matplotlib.pyplot as plt
import matplotlib.colors import matplotlib.colors
import numpy as N import numpy as N
@ -21,14 +21,14 @@ import scipy.optimize as opt
import MatplotlibWidget import MatplotlibWidget
import QDSMain import QDSMain
import PeakWidget import PeakWidget
import ConductivityWidget from data import Data, Conductivity, conductivity
from data import Data
#import yaff #import yaff
def sigint_handler(*args): def sigint_handler(*args):
"""Handler for the SIGINT signal.""" """Handler for the SIGINT signal (CTRL + C).
"""
sys.stderr.write('\r') sys.stderr.write('\r')
if QMessageBox.question(None, '', "Are you sure you want to quit?", if QMessageBox.question(None, '', "Are you sure you want to quit?",
QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes | QMessageBox.No,
@ -37,81 +37,81 @@ def sigint_handler(*args):
def id_to_color(id): def id_to_color(id):
colors = ['b', 'r','g','c','m','y','k'] """
"""
colors = ['b', 'r', 'g', 'c', 'm', 'y', 'k']
conv = matplotlib.colors.ColorConverter() conv = matplotlib.colors.ColorConverter()
return conv.to_rgb(colors[id%len(colors)]) return conv.to_rgb(colors[id % len(colors)])
def tau_peak(f,a,b): def tau_peak(f, a, b):
tau = (N.sin( N.pi*a/2./(b+1) )/N.sin( N.pi*a*b/2./(b+1) ))**(1/a) tau = (N.sin(N.pi * a / 2. / (b + 1)) / N.sin(N.pi * a * b / 2. / (b + 1))) ** (1 / a)
tau /= 2*N.pi*f tau /= 2 * N.pi * f
return tau return tau
def hn(p,nu):
delta_eps,tau,a,b = p
om = 2*N.pi*nu
Phi = N.arctan( (om*tau)**a*N.sin(N.pi*a/2.)/(1.+(om*tau)**a*N.cos(N.pi*a/2.)) )
e_loss = delta_eps * (1+ 2*(om*tau)**a * N.cos(N.pi*a/2.) + (om*tau)**(2.*a) )**(-b/2.)*N.sin(b*Phi)
e_stor = delta_eps * (1+ 2*(om*tau)**a * N.cos(N.pi*a/2.) + (om*tau)**(2.*a) )**(-b/2.)*N.cos(b*Phi)
return 2*e_loss
def multi_hn(p,nu): def hn(p, nu):
delta_eps, tau, a, b = p
om = 2 * N.pi * nu
Phi = N.arctan((om * tau) ** a * N.sin(N.pi * a / 2.) / (1. + (om * tau) ** a * N.cos(N.pi * a / 2.)))
e_loss = delta_eps * (1 + 2 * (om * tau) ** a * N.cos(N.pi * a / 2.) + (om * tau) ** (2. * a) ) ** (
-b / 2.) * N.sin(b * Phi)
e_stor = delta_eps * (1 + 2 * (om * tau) ** a * N.cos(N.pi * a / 2.) + (om * tau) ** (2. * a) ) ** (
-b / 2.) * N.cos(b * Phi)
return 2 * e_loss
def multi_hn(p, nu):
conductivity = p[1] conductivity = p[1]
cond_beta = p[2] cond_beta = p[2]
om = 2*N.pi*nu om = 2 * N.pi * nu
e_loss = conductivity/om**cond_beta e_loss = conductivity / om ** cond_beta
e_loss += p[0] e_loss += p[0]
#for key, igroup in groupby(p[3:], lambda x: x//4): #for key, igroup in groupby(p[3:], lambda x: x//4):
for i in xrange(len(p[3:])/4): for i in xrange(len(p[3:]) / 4):
delta_eps, tau, a, b = p[3+i*4:3+(i+1)*4] delta_eps, tau, a, b = p[3 + i * 4:3 + (i + 1) * 4]
#delta_eps, tau, a, b = list(igroup) #delta_eps, tau, a, b = list(igroup)
#print delta_eps,tau,a,b #print delta_eps,tau,a,b
#a = 0.5 *(1 + N.tanh(a)) #a = 0.5 *(1 + N.tanh(a))
#b = 0.5 *(1 + N.tanh(b)) #b = 0.5 *(1 + N.tanh(b))
Phi = N.arctan( (om*tau)**a*N.sin(N.pi*a/2.)/(1.+(om*tau)**a*N.cos(N.pi*a/2.)) ) Phi = N.arctan((om * tau) ** a * N.sin(N.pi * a / 2.) / (1. + (om * tau) ** a * N.cos(N.pi * a / 2.)))
e_loss += 2*delta_eps * (1+ 2*(om*tau)**a * N.cos(N.pi*a/2.) + (om*tau)**(2.*a) )**(-b/2.)*N.sin(b*Phi) e_loss += 2 * delta_eps * (1 + 2 * (om * tau) ** a * N.cos(N.pi * a / 2.) + (om * tau) ** (2. * a) ) ** (
-b / 2.) * N.sin(b * Phi)
#e_stor = delta_eps * (1+ 2*(om*tau)**a * N.cos(N.pi*a/2.) + (om*tau)**(2.*a) )**(-b/2.)*N.cos(b*Phi) #e_stor = delta_eps * (1+ 2*(om*tau)**a * N.cos(N.pi*a/2.) + (om*tau)**(2.*a) )**(-b/2.)*N.cos(b*Phi)
return e_loss return e_loss
def mini_func(p,x, y):
res = y - multi_hn(p,x) def mini_func(p, x, y):
res = y - multi_hn(p, x)
# apply weights # apply weights
res /= 1/y res /= 1 / y
return N.sqrt(N.dot(res,res)) return N.sqrt(N.dot(res, res))
def conductivity(p, nu):
c = p[0]/(2*N.pi*nu)**p[1]
return c
def hnfit(delta_eps, tau, points):
x = [point[0] for point in points]
y = [point[1] for point in points]
dat = O.Data(x,y)
mod = O.Model(hn)
odr = O.ODR(dat,mod, [delta_eps, tau, 1, 1], ifixb=(0,0,1,1), ifixx=(0,), maxit=1000)
odr.run()
odr.output.pprint()
return odr.output.beta
def fit_odr(x,y,p0, fixed):
dat = O.Data(x,y, 1.0/y)
def fit_odr(x, y, p0, fixed):
dat = O.Data(x, y, 1.0 / y)
mod = O.Model(multi_hn) mod = O.Model(multi_hn)
odr = O.ODR(dat, mod, p0, ifixx=(0,), ifixb=fixed, maxit=2000) odr = O.ODR(dat, mod, p0, ifixx=(0,), ifixb=fixed, maxit=2000)
odr.run() odr.run()
return odr.output.beta return odr.output.beta
def fit_lbfgsb(x,y,p0, fixed):
# TODO fixed parameters…
bounds = [(0,None), (0,1)]
for i in xrange(len(p0[3:])/4):
bounds.append((1e-4,1e12)) # delta_eps
bounds.append((1e-12,1e3)) # tau
bounds.append((0.1,1)) # a
bounds.append((0.1,1)) # b
x,f_minvalue, info_dict = opt.fmin_l_bfgs_b(mini_func, p0, def fit_lbfgsb(x, y, p0, fixed):
# TODO fixed parameters…
bounds = [(0, None), (0, 1)]
for i in xrange(len(p0[3:]) / 4):
bounds.append((1e-4, 1e12)) # delta_eps
bounds.append((1e-12, 1e3)) # tau
bounds.append((0.1, 1)) # a
bounds.append((0.1, 1)) # b
x, f_minvalue, info_dict = opt.fmin_l_bfgs_b(mini_func, p0,
fprime=None, fprime=None,
args=(x,y), args=(x, y),
approx_grad=True, approx_grad=True,
bounds=bounds, bounds=bounds,
iprint=0, iprint=0,
@ -120,15 +120,16 @@ def fit_lbfgsb(x,y,p0, fixed):
print info_dict["task"] print info_dict["task"]
return x return x
def fit_anneal(x,y,p0,fixed):
bounds = [(0,1e14), (0,1)] def fit_anneal(x, y, p0, fixed):
for i in xrange(len(p0[2:])/4): bounds = [(0, 1e14), (0, 1)]
bounds.append((1e-4,1e12)) # delta_eps for i in xrange(len(p0[2:]) / 4):
bounds.append((1e-12,1e3)) # tau bounds.append((1e-4, 1e12)) # delta_eps
bounds.append((0.1,1)) # a bounds.append((1e-12, 1e3)) # tau
bounds.append((0.1,1)) # b bounds.append((0.1, 1)) # a
bounds.append((0.1, 1)) # b
ret = opt.anneal(mini_func, p0, ret = opt.anneal(mini_func, p0,
args=(x,y), args=(x, y),
maxeval=20000, maxeval=20000,
maxiter=30000, maxiter=30000,
lower=[b[0] for b in bounds], lower=[b[0] for b in bounds],
@ -150,68 +151,9 @@ def fit_anneal(x,y,p0,fixed):
return ret[0] return ret[0]
class Conductivity(QObject):
changedData = pyqtSignal()
def __init__(self, mpl=None):
QObject.__init__(self)
super(Conductivity, self)
self.widget = ConductivityWidget.ConductivityWidget()
self.widget.changedTable.connect(self.updateData)
self.mpl_line = None
self.mpl_line_static = None
self.mpl = mpl
def getParameter(self):
p = self.widget.getTable()
return p
def getFixed(self):
p = self.widget.fixedParameter()
return p
def setParameter(self, eps_static=None, sigma=None, sigma_N=None):
self.widget.updateTable(eps_static, sigma, sigma_N)
self.updateData()
def updateData(self):
# get current axis limits
x_min, x_max = self.mpl.canvas.axes.get_xlim()
y_min, y_max = self.mpl.canvas.axes.get_ylim()
nu = N.logspace(N.log10(x_min), N.log10(x_max), 1024)
eps_static, sigma, sigma_N = self.getParameter()
y = conductivity([sigma, sigma_N],nu)
y_static = N.ones(len(nu))*eps_static
# clip data to axes limits
mask_static = (y_static < y_max) & (y_static > y_min)
# clip data to axes limits
mask = (y < y_max) & (y > y_min)
#mask = mask_static = N.ones(1024, dtype='bool')
if self.mpl_line == None:
self.mpl_line, = self.mpl.canvas.axes.loglog(nu[mask],y[mask],'k--',label="Cond.", animated=True) # peak
else:
self.mpl_line.set_xdata(nu[mask])
self.mpl_line.set_ydata(y[mask])
if self.mpl_line_static == None:
self.mpl_line_static, = self.mpl.canvas.axes.loglog(nu[mask_static],
y_static[mask_static],
'k:',
label=r"$\epsilon_S$",
animated=True) # peak
else:
self.mpl_line_static.set_xdata(nu[mask_static])
self.mpl_line_static.set_ydata(y_static[mask_static])
self.changedData.emit()
class Peak(QObject): class Peak(QObject):
changedData = pyqtSignal() changedData = pyqtSignal()
def __init__(self, id=None, mpl=None): def __init__(self, id=None, mpl=None):
QObject.__init__(self) QObject.__init__(self)
super(Peak, self).__init__() super(Peak, self).__init__()
@ -219,7 +161,7 @@ class Peak(QObject):
self.color = id_to_color(id) self.color = id_to_color(id)
self.widget = PeakWidget.PeakWidget() self.widget = PeakWidget.PeakWidget()
self.widget.setId(id) self.widget.setId(id)
self.widget.setColor(map(int, [255*i for i in self.color])) self.widget.setColor(map(int, [255 * i for i in self.color]))
self.widget.changedTable.connect(self.updatePeak) self.widget.changedTable.connect(self.updatePeak)
self.mpl = mpl self.mpl = mpl
self.mpl_line = None self.mpl_line = None
@ -243,13 +185,14 @@ class Peak(QObject):
y_min, y_max = self.mpl.canvas.axes.get_ylim() y_min, y_max = self.mpl.canvas.axes.get_ylim()
nu = N.logspace(N.log10(x_min), N.log10(x_max), 2048) nu = N.logspace(N.log10(x_min), N.log10(x_max), 2048)
y = hn(self.getParameter(),nu) y = hn(self.getParameter(), nu)
# clip data to axes limits # clip data to axes limits
mask = (y < y_max) & (y > y_min) mask = (y < y_max) & (y > y_min)
y = y[mask] y = y[mask]
nu = nu[mask] nu = nu[mask]
if self.mpl_line == None: if self.mpl_line == None:
self.mpl_line, = self.mpl.canvas.axes.loglog(nu,y,'--',label="Peak %i"%(self.widget.id), animated=True) # peak self.mpl_line, = self.mpl.canvas.axes.loglog(nu, y, '--', label="Peak %i" % (self.widget.id),
animated=True) # peak
self.mpl_line.set_color(self.color) self.mpl_line.set_color(self.color)
else: else:
self.mpl_line.set_xdata(nu) self.mpl_line.set_xdata(nu)
@ -257,7 +200,6 @@ class Peak(QObject):
self.changedData.emit() self.changedData.emit()
class AppWindow(QMainWindow): class AppWindow(QMainWindow):
def __init__(self, parent=None): def __init__(self, parent=None):
super(AppWindow, self).__init__(parent) super(AppWindow, self).__init__(parent)
@ -266,7 +208,6 @@ class AppWindow(QMainWindow):
self.picked_artist = None self.picked_artist = None
self.data = None self.data = None
self.Conductivity = None self.Conductivity = None
self._lines = dict() self._lines = dict()
@ -276,44 +217,57 @@ class AppWindow(QMainWindow):
## menubar ## menubar
fileMenu = self.menuBar().addMenu("File") fileMenu = self.menuBar().addMenu("File")
openFile = QAction("&Open",self) openFile = QAction("&Open", self)
openFile.setShortcut(QKeySequence.Open) openFile.setShortcut(QKeySequence.Open)
openFile.triggered.connect(self.openFile) openFile.triggered.connect(self.openFile)
fileMenu.addAction(openFile) fileMenu.addAction(openFile)
# fitting methods # fitting methods
fitMenu = self.menuBar().addMenu("Fit") fitMenu = self.menuBar().addMenu("Standard Fits")
# lm # lm
fit_lmAction = QAction("&Levenberg-Marquardt",self) fit_lmAction = QAction("&Levenberg-Marquardt", self)
fit_lmAction.setShortcut(QKeySequence("Ctrl+F"))
fitMenu.addAction(fit_lmAction) fitMenu.addAction(fit_lmAction)
# lbfgsb # lbfgsb
fit_lbfgsbAction = QAction("&L-BFGS-B",self) fit_lbfgsbAction = QAction("&L-BFGS-B", self)
fitMenu.addAction(fit_lbfgsbAction) fitMenu.addAction(fit_lbfgsbAction)
# Simulated Annealing # Simulated Annealing
fit_annealAction = QAction("&Simulated Annealing",self) fit_annealAction = QAction("&Simulated Annealing", self)
fitMenu.addAction(fit_annealAction) fitMenu.addAction(fit_annealAction)
# YAFF
yaffMenu = self.menuBar().addMenu("YAFF")
start_yaff = QAction("&Startparam.", self)
yaffMenu.addAction(start_yaff)
fit_yaff = QAction("&Fit", self)
yaffMenu.addAction(fit_yaff)
self.signalMapper = QSignalMapper(self) self.signalMapper = QSignalMapper(self)
for i, fit_action in enumerate([fit_lmAction, fit_lbfgsbAction, fit_annealAction for i, fit_action in enumerate([fit_lmAction, fit_lbfgsbAction, fit_annealAction
]): ]):
self.signalMapper.setMapping(fit_action,i) self.signalMapper.setMapping(fit_action, i)
fit_action.triggered.connect(self.signalMapper.map) fit_action.triggered.connect(self.signalMapper.map)
self.signalMapper.mapped.connect(self.fitData) self.signalMapper.mapped.connect(self.fitData)
# save fitted values # save fitted values
self.ui.actionSave_FitResult.triggered.connect(self.saveFit) self.ui.actionSave_FitResult.triggered.connect(self.saveFit)
# he plot area, a matplotlib widget # the plot area, a matplotlib widget
self.mplWidget = PlotWidget(self.ui.mplWidget) self.mplWidget = PlotWidget(self.ui.mplWidget)
self.mplWidget.canvas.draw() self.mplWidget.canvas.draw()
self.mplWidget.updateGeometry() self.mplWidget.updateGeometry()
# what to do with CIDs? # what to do with CIDs?
self.cid = [] self.cid = []
self.cid.append( self.mplWidget.canvas.mpl_connect("button_press_event", self.onclick) ) self.cid.append(self.mplWidget.canvas.mpl_connect("button_press_event", self.mpl_button_press))
self.cid.append( self.mplWidget.canvas.mpl_connect("pick_event", self.pick) ) self.cid.append(self.mplWidget.canvas.mpl_connect("pick_event", self.mpl_button_pick))
self.cid.append( self.mplWidget.canvas.mpl_connect("button_release_event", self.mpl_button_release) ) self.cid.append(self.mplWidget.canvas.mpl_connect("button_release_event", self.mpl_button_release))
#self.cid.append(self.mplWidget.canvas.mpl_connect("resize_event", self.myresizeEvent))
self.mplWidget.toolbar.spanSelectedTrigger.connect(self.set_fit_xlimits) self.mplWidget.toolbar.spanSelectedTrigger.connect(self.set_fit_xlimits)
def resizeEvent(self,evt): def resizeEvent(self, evt):
"""resizing the main window executes this method
TODO: FIX RESIZEING keeping mainwindow maximised for now
:param evt:
"""
self.mplWidget.canvas.draw() self.mplWidget.canvas.draw()
self.mplWidget._bg_cache = self.mplWidget.canvas.copy_from_bbox(self.mplWidget.canvas.axes.bbox) self.mplWidget._bg_cache = self.mplWidget.canvas.copy_from_bbox(self.mplWidget.canvas.axes.bbox)
for line in self.mplWidget.canvas.axes.get_lines(): for line in self.mplWidget.canvas.axes.get_lines():
@ -324,42 +278,49 @@ class AppWindow(QMainWindow):
def saveFit(self): def saveFit(self):
"""
Saving fit parameters to fitresults.log
including temperature
"""
if not os.path.exists("fitresults.log"): if not os.path.exists("fitresults.log"):
f = open("fitresults.log","w") f = open("fitresults.log", "w")
# write header # write header
f.write('# T ') f.write('# T ')
if self.Conductivity != None: if self.Conductivity != None:
f.write("e_s sig pow_sig ") f.write("%8s %8s %8s " % ("e_s", "sig", "pow_sig"))
for i,pb in enumerate(self.peakBoxes): for i, pb in enumerate(self.peakBoxes):
f.write("e_inf_%i tau_%i alpha_%i beta_%i"%(i,i,i,i)) enum_peak = ("e_inf_%i" % i, "tau_%i" % i, "alpha_%i" % i, "beta_%i" % i)
f.write("%8s %8s %8s %8s " % enum_peak)
f.write("high_lim lower_lim")
f.write('\n') f.write('\n')
f.flush() f.flush()
else: else:
f = open("fitresults.log","a") f = open("fitresults.log", "a")
#f.write("%3.2f "%(self.data.meta["T"])) #f.write("%3.2f "%(self.data.meta["T"]))
pars = list(self.fitresult) pars = list(self.fitresult)
pars.insert(0,self.data.meta["T"] ) pars.insert(0, self.data.meta["T"])
print pars N.savetxt(f, N.array([pars, ]), fmt="%8.5g", delimiter=" ")
N.savetxt(f,N.array([pars,]),fmt="%.5g", delimiter=" ")
f.close() f.close()
def set_fit_xlimits(self,xmin,xmax): def set_fit_xlimits(self, xmin, xmax):
self.data.fit_limits = (xmin, xmax, None,None) self.data.fit_limits = (xmin, xmax, None, None)
self.updatePlot()
def mpl_button_release(self,event): def mpl_button_release(self, event):
ax = self.mplWidget.canvas.axes
if self.picked_artist: if self.picked_artist:
if not event.inaxes: # moved outside the plot, add back to original position if not event.inaxes: # moved outside the plot, add back to original position
self.mplWidget.canvas.axes.add_artist(self.picked_artist) ax.add_artist(self.picked_artist)
else: # we move one of the three points determinig the peak else: # we move one of the three points determinig the peak
self.picked_artist.set_xdata(event.xdata) self.picked_artist.set_xdata(event.xdata)
self.picked_artist.set_ydata(event.ydata) self.picked_artist.set_ydata(event.ydata)
self.mplWidget.canvas.axes.add_artist(self.picked_artist) ax.add_artist(self.picked_artist)
for peak in self.peakBoxes.keys(): for peak in self.peakBoxes.keys():
peak.updatePeak() peak.updatePeak()
self.picked_artist = None self.picked_artist = None
self.mplWidget.canvas.draw_idle() self.mplWidget.canvas.draw_idle()
def pick(self,event): def mpl_button_pick(self, event):
self.picked_artist = event.artist self.picked_artist = event.artist
event.artist.remove() event.artist.remove()
self.mplWidget.canvas.draw_idle() self.mplWidget.canvas.draw_idle()
@ -370,7 +331,7 @@ class AppWindow(QMainWindow):
self.statusBar().showMessage("Click on graph") self.statusBar().showMessage("Click on graph")
self.Conductivity = Conductivity(mpl=self.mplWidget) self.Conductivity = Conductivity(mpl=self.mplWidget)
self.Conductivity.changedData.connect(self.updatePlot) self.Conductivity.changedData.connect(self.updatePlot)
self.Conductivity.setParameter(0, 1/(pos[0]/pos[1]/2/N.pi), 1.0) self.Conductivity.setParameter(0, 1 / (pos[0] / pos[1] / 2 / N.pi), 1.0)
self.ui.scrollAreaWidgetContents.layout().addWidget(self.Conductivity.widget) self.ui.scrollAreaWidgetContents.layout().addWidget(self.Conductivity.widget)
self.Conductivity.widget.ui.removeButton.clicked.connect(self.delCond) self.Conductivity.widget.ui.removeButton.clicked.connect(self.delCond)
@ -392,11 +353,11 @@ class AppWindow(QMainWindow):
# connect to delPeak # connect to delPeak
peak.widget.ui.removeButton.clicked.connect(self.delPeak) peak.widget.ui.removeButton.clicked.connect(self.delPeak)
peak.setParameter(delta_eps=pos[1], tau=1/(2.*N.pi*pos[0]), a=1, b=1) peak.setParameter(delta_eps=pos[1], tau=1 / (2. * N.pi * pos[0]), a=1, b=1)
peak.changedData.connect(self.updatePlot) peak.changedData.connect(self.updatePlot)
self.peakBoxes[peak]=None self.peakBoxes[peak] = None
for pb in self.peakBoxes.keys(): for pb in self.peakBoxes.keys():
self.ui.scrollAreaWidgetContents.layout().addWidget(pb.widget) self.ui.scrollAreaWidgetContents.layout().addWidget(pb.widget)
self.updatePlot() self.updatePlot()
@ -406,7 +367,7 @@ class AppWindow(QMainWindow):
for i in xrange(self.ui.scrollAreaWidgetContents.layout().count()): for i in xrange(self.ui.scrollAreaWidgetContents.layout().count()):
print i print i
for i,peak in enumerate(self.peakBoxes.keys()): for i, peak in enumerate(self.peakBoxes.keys()):
if peak.widget.isHidden(): if peak.widget.isHidden():
peak.mpl_line.remove() peak.mpl_line.remove()
deletePeaks.append(peak) deletePeaks.append(peak)
@ -417,116 +378,120 @@ class AppWindow(QMainWindow):
def fitData(self, method): def fitData(self, method):
if self.Conductivity != None: if self.Conductivity != None:
start_parameter = list(self.Conductivity.getParameter()) start_parameter = list(self.Conductivity.getParameter())
fixed_params = [ i for i in self.Conductivity.getFixed() ] fixed_params = [i for i in self.Conductivity.getFixed()]
else: else:
start_parameter = [0,0,1] start_parameter = [0, 0, 1]
fixed_params = [0,0,0] fixed_params = [0, 0, 0]
for pb in self.peakBoxes.keys(): for pb in self.peakBoxes.keys():
[ start_parameter.append(i) for i in pb.getParameter() ] [start_parameter.append(i) for i in pb.getParameter()]
[ fixed_params.append(i) for i in pb.getFixed() ] [fixed_params.append(i) for i in pb.getFixed()]
fit_methods = [fit_odr, fit_lbfgsb, fit_anneal] fit_methods = [fit_odr, fit_lbfgsb, fit_anneal]
print "StartParameter",start_parameter print "StartParameter", start_parameter
print "FixedParameter",fixed_params print "FixedParameter", fixed_params
print "Limits (xmin, xmax, ymin, ymax)", self.data.fit_limits print "Limits (xmin, xmax, ymin, ymax)", self.data.fit_limits
_freq, _fit = self.data.get_data() _freq, _fit = self.data.get_data()
result = fit_methods[method](_freq, _fit.imag, start_parameter, fixed_params) result = fit_methods[method](_freq, _fit.imag, start_parameter, fixed_params)
self.fitresult = result self.fitresult = result
for i,pb in enumerate(self.peakBoxes.keys()): for i, pb in enumerate(self.peakBoxes.keys()):
delta_eps, tau, a, b = result[3+i*4:3+(i+1)*4] delta_eps, tau, a, b = result[3 + i * 4:3 + (i + 1) * 4]
pb.setParameter(delta_eps, tau, a, b ) pb.setParameter(delta_eps, tau, a, b)
e_static,sigma, sigma_N = result[:3] e_static, sigma, sigma_N = result[:3]
if self.Conductivity != None: if self.Conductivity != None:
self.Conductivity.setParameter(e_static,sigma,sigma_N) self.Conductivity.setParameter(e_static, sigma, sigma_N)
print "*** FIT RESULTS ***" #print "*** FIT RESULTS ***"
print u"\u03c3" #print u"\u03c3"
print u"\u0394\u03b5" #print u"\u0394\u03b5"
self.updatePlot() self.updatePlot()
def onclick(self, event): def mpl_button_press(self, event):
""" """
Handles the clicks on the matplotlib figure canvas Handles the clicks on the matplotlib figure canvas
""" """
if self.ui.actionAdd_Peak.isChecked(): if self.ui.actionAdd_Peak.isChecked() and event.inaxes:
x,y = event.xdata,event.ydata x, y = event.xdata, event.ydata
self.addPeak((x,y)) self.addPeak((x, y))
self.ui.actionAdd_Peak.setChecked(False) self.ui.actionAdd_Peak.setChecked(False)
self.statusBar().clear() self.statusBar().clear()
if self.ui.actionAdd_Cond.isChecked(): if self.ui.actionAdd_Cond.isChecked() and event.inaxes:
x,y = event.xdata,event.ydata x, y = event.xdata, event.ydata
self.addCond((x,y)) self.addCond((x, y))
self.ui.actionAdd_Cond.setChecked(False) self.ui.actionAdd_Cond.setChecked(False)
self.statusBar().clear() self.statusBar().clear()
def openFile(self): def openFile(self):
ax = self.mplWidget.canvas.axes
path = unicode(QFileDialog.getOpenFileName(self, "Open file")) path = unicode(QFileDialog.getOpenFileName(self, "Open file"))
# TODO anaylize file (LF,MF, HF) and act accordingly # TODO anaylize file (LF,MF, HF) and act accordingly
data = N.loadtxt(path, skiprows=4) data = N.loadtxt(path, skiprows=4)
numpat = re.compile('\d+\.\d+') numpat = re.compile('\d+\.\d+')
try: try:
Temp = None
for line in open(path).readlines(): for line in open(path).readlines():
if re.search("Fixed", line) or re.search("Temp", line): if re.search("Fixed", line) or re.search("Temp", line):
print "Found line with Fixed or Temp"
Temp = float(re.search(numpat, line).group()) Temp = float(re.search(numpat, line).group())
print "Temperature found in file:",Temp print "Temperature found in file:", Temp
break break
else: if Temp == None: raise ValueError
print "No Temperature found in file"
raise
#Temp = QInputDialog.getDouble(self, "No temperature found in data set","Temperature/K:", value=Temp)[0]
except: except:
Temp = QInputDialog.getDouble(self, "No temperature found in data set","Temperature/K:", value=0.0)[0] Temp = QInputDialog.getDouble(self, "No temperature found in data set", "Temperature/K:", value=0.00)[0]
# mask the data to values > 0 (loglog plot) # mask the data to values > 0 (loglog plot)
mask = (data[:,1]>0) & (data[:,2]>0) #& (data[:,2]>1e-3) & (data[:,0] > 1e-2) mask = (data[:, 1] > 0) & (data[:, 2] > 0) #& (data[:,2]>1e-3) & (data[:,0] > 1e-2)
_freq = data[mask,0] _freq = data[mask, 0]
_die_stor = data[mask,1] _die_stor = data[mask, 1]
_die_loss = data[mask,2] _die_loss = data[mask, 2]
# clear the figure # clear the figure
self.mplWidget.canvas.axes.clear() ax.clear()
#if self.data != None: #if self.data != None:
# self.data.remove_curves() # self.data.remove_curves()
self.data = Data(_freq, _die_stor, _die_loss) self.data = Data(_freq, _die_stor, _die_loss)
self.data.meta["T"]=Temp self.data.meta["T"] = Temp
self.data.data_curve, = self.mplWidget.canvas.axes.loglog(self.data.frequency, self.data.data_curve, = ax.loglog(self.data.frequency,
self.data.epsilon.imag, self.data.epsilon.imag,
'b.', 'b.',
markersize=4, markersize=4,
label="Data", label="Data",
animated=True) animated=True)
self.mplWidget.canvas.axes.set_xlim(_freq.min(), _freq.max()) ax.set_xlabel("Frequency/Hz", fontsize=16)
self.mplWidget.canvas.axes.set_xlabel("frequency/Hz", fontsize=16) #ax.set_ylabel(u'\u03B5"', fontsize=16)
self.mplWidget.canvas.axes.set_ylabel(u'\u03B5"', fontsize=16) ax.set_ylabel(u'e"', fontsize=16)
self.mplWidget.canvas.axes.autoscale(True)
self.legend = self.mplWidget.canvas.axes.legend(title="T=%.2f"%Temp) ax.autoscale(True)
for line in self.mplWidget.canvas.axes.get_lines(): ax.set_xlim(_freq.min()/3, _freq.max()*3)
self.legend = ax.legend(title="T=%.2f" % Temp)
for line in ax.get_lines():
line.set_animated(False) line.set_animated(False)
self.mplWidget.canvas.axes.grid() ax.grid()
self.mplWidget.canvas.draw() self.mplWidget.canvas.draw()
for line in self.mplWidget.canvas.axes.get_lines(): # weird behaviour need to draw all first, then set_animated the redraw
for line in ax.get_lines():
line.set_animated(True) line.set_animated(True)
self.legend.set_animated(True) self.legend.set_animated(True)
self.mplWidget.canvas.axes.autoscale(False) ax.autoscale(False)
self.mplWidget._bg_cache = self.mplWidget.canvas.copy_from_bbox(self.mplWidget.canvas.axes.bbox) self.mplWidget._bg_cache = self.mplWidget.canvas.copy_from_bbox(ax.bbox)
self.updatePlot() self.updatePlot()
def updatePlot(self): def updatePlot(self):
ax = self.mplWidget.canvas.axes
nu = self.data.frequency nu = self.data.frequency
fit = N.zeros(len(nu)) fit = N.zeros(len(nu))
for peak in self.peakBoxes.keys(): for peak in self.peakBoxes.keys():
params = peak.getParameter() params = peak.getParameter()
fit += hn(params,nu) fit += hn(params, nu)
if self.Conductivity != None: if self.Conductivity != None:
print "Cond. given" print "Cond. given"
params = self.Conductivity.getParameter()[1:] params = self.Conductivity.getParameter()[1:]
fit += conductivity(params, nu) fit += conductivity(params, nu)
fit += self.Conductivity.getParameter()[0] # eps static fit += self.Conductivity.getParameter()[0] # eps static
# clip data to axes limits # clip data to axes limits
y_min, y_max = self.mplWidget.canvas.axes.get_ylim() y_min, y_max = ax.get_ylim()
mask = (fit < y_max) & (fit > y_min) mask = (fit < y_max) & (fit > y_min)
#mask = N.ones(len(fit), dtype="bool") #mask = N.ones(len(fit), dtype="bool")
if self.data.fitted_curve == None: if self.data.fitted_curve == None:
self.data.fitted_curve, = self.mplWidget.canvas.axes.loglog(nu[mask],fit[mask], self.data.fitted_curve, = ax.loglog(nu[mask], fit[mask],
'k-', 'k-',
alpha=0.5, alpha=0.5,
label="Sum", label="Sum",
@ -534,14 +499,27 @@ class AppWindow(QMainWindow):
else: else:
self.data.fitted_curve.set_xdata(nu[mask]) self.data.fitted_curve.set_xdata(nu[mask])
self.data.fitted_curve.set_ydata(fit[mask]) self.data.fitted_curve.set_ydata(fit[mask])
# update lines
if self.mplWidget._axvlims != []:
[axv.remove() for axv in self.mplWidget._axvlims]
self.mplWidget._axvlims = []
if self.mplWidget._axvname != []:
[axvname.remove() for axvname in self.mplWidget._axvname]
self.mplWidget._axvname = []
for xlim in self.data.fit_limits[:2]:
self.mplWidget._axvlims.append(ax.axvline(xlim, color="k", ls="--", alpha=0.5, animated=True))
self.mplWidget._axvname.append(ax.text(xlim, y_min*3. , "%.3g"%xlim,
horizontalalignment='center',
verticalalignment='center',
animated=True) )
self.mplWidget.canvas.restore_region(self.mplWidget._bg_cache) self.mplWidget.canvas.restore_region(self.mplWidget._bg_cache)
self.legend = self.mplWidget.canvas.axes.legend(title = "T=%.2f"%(self.data.meta["T"]) ) self.legend = ax.legend(title="T=%.2f" % (self.data.meta["T"]))
self.legend.set_animated(True) self.legend.set_animated(True)
for animated_artist in self.mplWidget.canvas.axes.findobj(match=lambda x: x.get_animated()): for animated_artist in ax.findobj(match=lambda x: x.get_animated()):
#print "updatePlot: animated artist:",animated_artist #print "updatePlot: animated artist:",animated_artist
self.mplWidget.canvas.axes.draw_artist(animated_artist) ax.draw_artist(animated_artist)
self.mplWidget.canvas.blit( self.mplWidget.canvas.axes.bbox ) self.mplWidget.canvas.blit(ax.bbox)
class PlotWidget(QWidget): class PlotWidget(QWidget):
@ -549,32 +527,35 @@ class PlotWidget(QWidget):
QWidget.__init__(self) QWidget.__init__(self)
super(PlotWidget, self).__init__(parent) super(PlotWidget, self).__init__(parent)
self.mplwidget = MatplotlibWidget.MatplotlibWidget(hold=True, self.mplwidget = MatplotlibWidget.MatplotlibWidget(hold=True,
xlim=(1e-2,1e7), xlim=(1e-2, 1e7),
xscale='log', xscale='log',
yscale='log') yscale='log')
self.canvas = self.mplwidget.figure.canvas # shortcut self.canvas = self.mplwidget.figure.canvas # shortcut
self.canvas.axes.grid(True) self.canvas.axes.grid(True)
self.bbox_size = self.canvas.axes.bbox.size #self.bbox_size = self.canvas.axes.bbox.size
print "PlotWidget",self.bbox_size
#self.toolbar = NavigationToolbar(self.mplwidget, parent)
self.toolbar = CustomToolbar(self.canvas, self.mplwidget, parent) self.toolbar = CustomToolbar(self.canvas, self.mplwidget, parent)
self.toolbar.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
layout = QVBoxLayout(parent) layout = QVBoxLayout(parent)
#self.mplwidget.setLayout(layout)
layout.addWidget(self.canvas) layout.addWidget(self.canvas)
layout.addWidget(self.mplwidget) layout.addWidget(self.mplwidget)
layout.addWidget(self.toolbar) layout.addWidget(self.toolbar)
self._bg_cache = None self._bg_cache = None
self._axvlims = []
self._axvname = []
class CustomToolbar(NavigationToolbar): class CustomToolbar(NavigationToolbar):
# our spanChanged signal # our spanChanged signal
spanSelectedTrigger = pyqtSignal(float, float, name='spanChanged') spanSelectedTrigger = pyqtSignal(float, float, name='spanChanged')
def __init__(self, plotCanvas, plotWidget, parent=None): def __init__(self, plotCanvas, plotWidget, parent=None):
NavigationToolbar.__init__(self, plotCanvas, plotWidget, coordinates=True) NavigationToolbar.__init__(self, plotCanvas, plotWidget, coordinates=True)
self.canvas = plotCanvas self.canvas = plotCanvas
# Span select Button # Span select Button
#self.span_button = QAction(QIcon("border-1d-right-icon.png" ), "Span", self) #self.span_button = QAction(QIcon("border-1d-right-icon.png" ), "Span", self)
self.span_button = QAction( QIcon(QPixmap(":/icons/fit_limits.png")), "Span", self) self.span_button = QAction(QIcon(QPixmap(":/icons/fit_limits.png")), "Fit Limits", self)
self.span_button.setCheckable(True) self.span_button.setCheckable(True)
self.cids = [] self.cids = []
@ -588,7 +569,7 @@ class CustomToolbar(NavigationToolbar):
# add actions before the coordinates widget # add actions before the coordinates widget
self.insertAction(self.actions()[-1], self.span_button) self.insertAction(self.actions()[-1], self.span_button)
self.buttons={} self.buttons = {}
self._pressed = False self._pressed = False
self.background = None self.background = None
self.span = None self.span = None
@ -597,18 +578,18 @@ class CustomToolbar(NavigationToolbar):
self.xstart = 0 self.xstart = 0
self.xend = 0 self.xend = 0
def set_span(self,x1,x2): def set_span(self, x1, x2):
#trans = blended_transform_factory(self.axes.transData, self.axes.transAxes) #trans = blended_transform_factory(self.axes.transData, self.axes.transAxes)
cur = self.span.get_xy() cur = self.span.get_xy()
cur[0,0] = x1 cur[0, 0] = x1
cur[1,0] = x1 cur[1, 0] = x1
cur[2,0] = x2 cur[2, 0] = x2
cur[3,0] = x2 cur[3, 0] = x2
self.span.set_xy(cur) self.span.set_xy(cur)
def ignore(self, event): def ignore(self, event):
# 'return ``True`` if *event* should be ignored' # 'return ``True`` if *event* should be ignored'
return event.inaxes!=self.canvas.axes or event.button !=1 return event.inaxes != self.canvas.axes or event.button != 1
def update_background(self, event): def update_background(self, event):
#if self.canvas.axes is None: #if self.canvas.axes is None:
@ -624,12 +605,12 @@ class CustomToolbar(NavigationToolbar):
self.xstart = event.xdata self.xstart = event.xdata
self.istart = event.x self.istart = event.x
if self.span is None: if self.span is None:
self.span = self.canvas.axes.axvspan(event.xdata, event.xdata, alpha = 0.10, color = "k", animated=False) self.span = self.canvas.axes.axvspan(event.xdata, event.xdata, alpha=0.10, color="k", animated=False)
else: else:
self.set_span(event.xdata, event.xdata) self.set_span(event.xdata, event.xdata)
self._pressed = True self._pressed = True
def onmove(self,event): def onmove(self, event):
if self.span_button.isChecked() and self._pressed and not self.ignore(event): if self.span_button.isChecked() and self._pressed and not self.ignore(event):
self.set_span(self.xstart, event.xdata) self.set_span(self.xstart, event.xdata)
self.update() self.update()
@ -641,21 +622,20 @@ class CustomToolbar(NavigationToolbar):
self.canvas.axes.draw_artist(line) self.canvas.axes.draw_artist(line)
self.canvas.blit(self.canvas.axes.bbox) self.canvas.blit(self.canvas.axes.bbox)
def release(self,event): def release(self, event):
self.span_button.setChecked(False) self.span_button.setChecked(False)
self.xend = event.xdata self.xend = event.xdata
self.iend = event.x self.iend = event.x
if self.iend < self.istart: if self.iend < self.istart:
self.iend,self.istart = self.istart,self.iend self.iend, self.istart = self.istart, self.iend
print "released",self.xstart,self.xend print "released", self.xstart, self.xend
if self._pressed: if self._pressed:
if self.ignore(event): if self.ignore(event):
self.istart = 0 self.istart = 0
self.spanSelectedTrigger.emit(self.xstart,self.xend) self.spanSelectedTrigger.emit(self.xstart, self.xend)
self._pressed = False self._pressed = False
if __name__ == '__main__': if __name__ == '__main__':
signal.signal(signal.SIGINT, sigint_handler) signal.signal(signal.SIGINT, sigint_handler)
app = QApplication(sys.argv) app = QApplication(sys.argv)

View File

@ -2,8 +2,8 @@
# Form implementation generated from reading ui file 'QDSMain.ui' # Form implementation generated from reading ui file 'QDSMain.ui'
# #
# Created: Fri Jun 14 08:45:33 2013 # Created: Wed Jul 10 18:32:01 2013
# by: PyQt4 UI code generator 4.10.1 # by: PyQt4 UI code generator 4.10.2
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!

72
data.py
View File

@ -1,13 +1,17 @@
from PyQt4.QtCore import QObject, pyqtSignal
import numpy as N import numpy as N
import ConductivityWidget
class Data: class Data:
def __init__(self, frequency, die_real, die_imag): def __init__(self, frequency, die_real, die_imag):
self.frequency = frequency self.frequency = frequency
self.epsilon = die_real +1j *die_imag self.epsilon = die_real + 1j * die_imag
self.data_curve = None # mpl object self.data_curve = None # mpl object
self.fitted_curve = None # mpl object self.fitted_curve = None # mpl object
self.length = len(frequency) self.length = len(frequency)
self.meta = dict() self.meta = dict()
self.fit_limits = (frequency.min(),frequency.max(),die_imag.min(),die_imag.max()) self.fit_limits = (frequency.min(), frequency.max(), die_imag.min(), die_imag.max())
def __del__(self): def __del__(self):
self.remove_curves() self.remove_curves()
@ -17,7 +21,7 @@ class Data:
""" """
""" """
mask = N.ones(len(self.frequency),dtype = 'bool') mask = N.ones(len(self.frequency), dtype='bool')
mask = (self.frequency > self.fit_limits[0]) & (self.frequency < self.fit_limits[1]) mask = (self.frequency > self.fit_limits[0]) & (self.frequency < self.fit_limits[1])
mask &= (self.epsilon.imag > self.fit_limits[2]) & (self.epsilon.imag < self.fit_limits[1]) mask &= (self.epsilon.imag > self.fit_limits[2]) & (self.epsilon.imag < self.fit_limits[1])
return self.frequency[mask], self.epsilon[mask] return self.frequency[mask], self.epsilon[mask]
@ -26,3 +30,65 @@ class Data:
if self.data_curve is not None: self.data_curve.remove() if self.data_curve is not None: self.data_curve.remove()
if self.fitted_curve is not None: self.fitted_curve.remove() if self.fitted_curve is not None: self.fitted_curve.remove()
class Conductivity(QObject):
changedData = pyqtSignal()
def __init__(self, mpl=None):
QObject.__init__(self)
super(Conductivity, self)
self.widget = ConductivityWidget.ConductivityWidget()
self.widget.changedTable.connect(self.updateData)
self.mpl_line = None
self.mpl_line_static = None
self.mpl = mpl
def getParameter(self):
p = self.widget.getTable()
return p
def getFixed(self):
p = self.widget.fixedParameter()
return p
def setParameter(self, eps_static=None, sigma=None, sigma_N=None):
self.widget.updateTable(eps_static, sigma, sigma_N)
self.updateData()
def updateData(self):
# get current axis limits
x_min, x_max = self.mpl.canvas.axes.get_xlim()
y_min, y_max = self.mpl.canvas.axes.get_ylim()
nu = N.logspace(N.log10(x_min), N.log10(x_max), 1024)
eps_static, sigma, sigma_N = self.getParameter()
y = conductivity([sigma, sigma_N], nu)
y_static = N.ones(len(nu)) * eps_static
# clip data to axes limits
mask_static = (y_static < y_max) & (y_static > y_min)
# clip data to axes limits
mask = (y < y_max) & (y > y_min)
#mask = mask_static = N.ones(1024, dtype='bool')
if self.mpl_line == None:
self.mpl_line, = self.mpl.canvas.axes.loglog(nu[mask], y[mask], 'k--', label="Cond.", animated=True) # peak
else:
self.mpl_line.set_xdata(nu[mask])
self.mpl_line.set_ydata(y[mask])
if self.mpl_line_static == None:
self.mpl_line_static, = self.mpl.canvas.axes.loglog(nu[mask_static],
y_static[mask_static],
'k:',
label=r"$\epsilon_S$",
animated=True) # peak
else:
self.mpl_line_static.set_xdata(nu[mask_static])
self.mpl_line_static.set_ydata(y_static[mask_static])
self.changedData.emit()
def conductivity(p, nu):
c = p[0] / (2 * N.pi * nu) ** p[1]
return c

View File

@ -2,7 +2,7 @@
# Resource object code # Resource object code
# #
# Created: Fr. Jun 14 08:45:33 2013 # Created: Mi. Jul 10 18:32:00 2013
# by: The Resource Compiler for PyQt (Qt v4.8.4) # by: The Resource Compiler for PyQt (Qt v4.8.4)
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!