Fit shown calculated only within the selected region

This commit is contained in:
Markus Rosenstihl 2014-03-20 15:15:40 +01:00
parent 62a8d0fb9d
commit 4f5cdc7103
14 changed files with 2031 additions and 1425 deletions

View File

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'ConductivityGroupBox.ui' # Form implementation generated from reading ui file 'ConductivityGroupBox.ui'
# #
# Created: Thu Mar 20 13:41:01 2014 # Created: Thu Mar 20 14:46:49 2014
# by: PyQt4 UI code generator 4.10.3 # by: PyQt4 UI code generator 4.10.3
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!

View File

@ -42,11 +42,13 @@ class ParameterWidget(QWidget):
def __init__(self, parent = None): def __init__(self, parent = None):
super(ParameterWidget, self).__init__(parent) super(ParameterWidget, self).__init__(parent)
self.vlayout = QVBoxLayout(self) self.vlayout = QVBoxLayout(self)
self.vlayout.addSpacerItem(QSpacerItem(10,10,QSizePolicy.Minimum, QSizePolicy.Expanding) ) #self.vlayout.addSpacerItem(QSpacerItem(10,10,QSizePolicy.Minimum, QSizePolicy.Expanding) )
self.vlayout.addSpacerItem(QSpacerItem(10,10,QSizePolicy.Minimum, QSizePolicy.Expanding) ) self.vlayout.addSpacerItem(QSpacerItem(10,10,QSizePolicy.Minimum, QSizePolicy.Expanding) )
#self.vlayout.addStretch(1) #self.vlayout.addStretch(1)
def add(self, wdgt):
self.vlayout.insertWidget(self.vlayout.count()-1, wdgt)
self.vlayout.update()
if __name__ == "__main__": if __name__ == "__main__":
app = QApplication([]) app = QApplication([])

View File

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'PeakGroupBox.ui' # Form implementation generated from reading ui file 'PeakGroupBox.ui'
# #
# Created: Thu Mar 20 13:41:01 2014 # Created: Thu Mar 20 14:46:49 2014
# by: PyQt4 UI code generator 4.10.3 # by: PyQt4 UI code generator 4.10.3
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!

View File

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'PowerLawGroupBox.ui' # Form implementation generated from reading ui file 'PowerLawGroupBox.ui'
# #
# Created: Thu Mar 20 13:41:01 2014 # Created: Thu Mar 20 14:46:49 2014
# by: PyQt4 UI code generator 4.10.3 # by: PyQt4 UI code generator 4.10.3
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!

51
QDS.py
View File

@ -36,8 +36,6 @@ class AppWindow(QMainWindow):
super(AppWindow, self).__init__(parent) super(AppWindow, self).__init__(parent)
self.ui = QDSMain.Ui_MainWindow() self.ui = QDSMain.Ui_MainWindow()
self.ui.setupUi(self) self.ui.setupUi(self)
self.picked_artist = None
self.data = None
actions = { actions = {
self.ui.actionAdd_Peak:self.addPeak, self.ui.actionAdd_Peak:self.addPeak,
@ -45,17 +43,13 @@ class AppWindow(QMainWindow):
self.ui.actionAdd_PowerLaw:self.addPowerComplex, self.ui.actionAdd_PowerLaw:self.addPowerComplex,
self.ui.actionAdd_Eps_Infty:self.addEpsInfty self.ui.actionAdd_Eps_Infty:self.addEpsInfty
} }
self.myActionGroup = QActionGroup(self) self.myActionGroup = QActionGroup(self)
for a in actions.keys(): self.myActionGroup.addAction(a) for a in actions.keys(): self.myActionGroup.addAction(a)
self.function_registry = FunctionRegister() self.function_registry = FunctionRegister()
self.Conductivity = None
self._lines = dict()
self.peakId = 0 self.peakId = 0
self.peakBoxes = {}
self.parameterWidget = ParameterWidget() self.parameterWidget = ParameterWidget()
self.ui.dockWidget_3.setWidget(self.parameterWidget) self.ui.dockWidget_3.setWidget(self.parameterWidget)
@ -128,22 +122,17 @@ class AppWindow(QMainWindow):
pltwidgt.setLogMode(x=True, y=True) pltwidgt.setLogMode(x=True, y=True)
pltwidgt.showGrid(x=True, y=True) pltwidgt.showGrid(x=True, y=True)
pltwidgt.disableAutoRange() pltwidgt.disableAutoRange()
pltwidgt.setLabel("bottom","Frequency",units="Hz") pltwidgt.setLabel("bottom", "Frequency", units="Hz")
self.ui.pgPlotWidget_imag.setLabel("left", "(I) Dielectric loss", units="Debye") self.ui.pgPlotWidget_imag.setLabel("left", "(I) Dielectric loss", units="Debye")
self.ui.pgPlotWidget_real.setLabel("left", "(R) Dielectric loss", units="Debye") self.ui.pgPlotWidget_real.setLabel("left", "(R) Dielectric loss", units="Debye")
#self.peak_box_layout = QGridLayout()
#self.ui.scrollAreaWidgetContents.setLayout(self.peak_box_layout)
##self.huh = pg.SignalProxy(, slot=self.mPE)
sc_real = self.ui.pgPlotWidget_real.scene() sc_real = self.ui.pgPlotWidget_real.scene()
sc_real.sigMouseClicked.connect(self.mousePress) sc_real.sigMouseClicked.connect(self.mousePress)
sc_real.sigMouseMoved.connect(self.updateCrosshair) sc_real.sigMouseMoved.connect(self.updateCrosshair)
sc_imag = self.ui.pgPlotWidget_imag.scene() sc_imag = self.ui.pgPlotWidget_imag.scene()
sc_imag.sigMouseClicked.connect(self.mousePress) sc_imag.sigMouseClicked.connect(self.mousePress)
sc_imag.sigMouseMoved.connect(self.updateCrosshair) sc_imag.sigMouseMoved.connect(self.updateCrosshair)
@ -158,7 +147,7 @@ class AppWindow(QMainWindow):
elif self.ui.pgPlotWidget_real.underMouse(): elif self.ui.pgPlotWidget_real.underMouse():
pos = vb_real.mapSceneToView(evt) pos = vb_real.mapSceneToView(evt)
else: else:
pos = QPointF(1.0,1.0) pos = QPointF(0.0, 0.0)
self.last_pos = pos self.last_pos = pos
@ -286,9 +275,8 @@ class AppWindow(QMainWindow):
cond_par = [10**(pos.y() + pos.x())*2*N.pi , 1.0] cond_par = [10**(pos.y() + pos.x())*2*N.pi , 1.0]
_conductivity.setParameter(beta=cond_par) _conductivity.setParameter(beta=cond_par)
self.parameterWidget.vlayout.insertWidget(1,_conductivity.widget) self.parameterWidget.add(_conductivity.widget)
self.function_registry.register_function(_conductivity) self.function_registry.register_function(_conductivity)
self.parameterWidget.vlayout.update()
self.updatePlot() self.updatePlot()
@ -302,9 +290,8 @@ class AppWindow(QMainWindow):
cond_par = [10**(pos.y() + pos.x())*2*N.pi , 1.0] cond_par = [10**(pos.y() + pos.x())*2*N.pi , 1.0]
_power_complex.setParameter(beta=cond_par) _power_complex.setParameter(beta=cond_par)
self.parameterWidget.vlayout.insertWidget(1,_power_complex.widget) self.parameterWidget.add(_power_complex.widget)
self.function_registry.register_function(_power_complex) self.function_registry.register_function(_power_complex)
self.parameterWidget.vlayout.update()
self.updatePlot() self.updatePlot()
def addEpsInfty(self, pos): def addEpsInfty(self, pos):
@ -317,21 +304,15 @@ class AppWindow(QMainWindow):
cond_par = [10**pos.y()] cond_par = [10**pos.y()]
_eps_infty.setParameter(beta=cond_par) _eps_infty.setParameter(beta=cond_par)
self.parameterWidget.vlayout.insertWidget(1,_eps_infty.widget) self.parameterWidget.add(_eps_infty.widget)
self.function_registry.register_function(_eps_infty) self.function_registry.register_function(_eps_infty)
self.parameterWidget.vlayout.update()
self.updatePlot() self.updatePlot()
def delParamterObject(self, obj): def delParamterObject(self, obj):
print "unregister",obj print "unregister",obj
self.function_registry.unregister_function(obj) self.function_registry.unregister_function(obj)
self.updatePlot() self.updatePlot()
def addPeak(self, pos): def addPeak(self, pos):
id_list = [ key.id_num for key in id_list = [ key.id_num for key in
self.function_registry.get_registered_functions().keys() self.function_registry.get_registered_functions().keys()
@ -341,8 +322,11 @@ class AppWindow(QMainWindow):
while self.peakId in id_list: while self.peakId in id_list:
self.peakId += 1 self.peakId += 1
_peak = Peak(id_num=self.peakId, plt_real=self.ui.pgPlotWidget_real, plt_imag=self.ui.pgPlotWidget_imag, _peak = Peak(id_num=self.peakId,
plt_real=self.ui.pgPlotWidget_real,
plt_imag=self.ui.pgPlotWidget_imag,
limits=self.data.fit_limits) limits=self.data.fit_limits)
_peak.changedData.connect(self.updatePlot) _peak.changedData.connect(self.updatePlot)
_peak.removeObj.connect(self.delParamterObject) _peak.removeObj.connect(self.delParamterObject)
@ -350,11 +334,7 @@ class AppWindow(QMainWindow):
_peak.setParameter(beta = new_peak) _peak.setParameter(beta = new_peak)
self.function_registry.register_function(_peak) self.function_registry.register_function(_peak)
self.peakBoxes[_peak] = self.peakId self.parameterWidget.add(_peak.widget)
for i,pb in enumerate(self.peakBoxes.keys()):
self.parameterWidget.vlayout.insertWidget(1,pb.widget)
self.parameterWidget.vlayout.update()
self.updatePlot() self.updatePlot()
@ -371,8 +351,6 @@ class AppWindow(QMainWindow):
self.updatePlot() self.updatePlot()
def fitData(self, method): def fitData(self, method):
log10fmin, log10fmax = self.fit_boundary.getRegion()
self.data.set_fit_xlimits(10**log10fmin, 10**log10fmax)
fit_methods = [fit_odr_cmplx, fit_lbfgsb, fit_anneal] fit_methods = [fit_odr_cmplx, fit_lbfgsb, fit_anneal]
# build function list # build function list
@ -433,6 +411,8 @@ class AppWindow(QMainWindow):
def updatePlot(self): def updatePlot(self):
log10fmin, log10fmax = self.fit_boundary.getRegion()
self.data.set_fit_xlimits(10**log10fmin, 10**log10fmax)
p0,funcs = [],[] p0,funcs = [],[]
for fcn in self.function_registry.get_registered_functions(): for fcn in self.function_registry.get_registered_functions():
p0.extend(fcn.getParameter()) p0.extend(fcn.getParameter())
@ -445,12 +425,13 @@ class AppWindow(QMainWindow):
self.data.data_curve_imag.setData(self.data.frequency, self.data.epsilon.imag) self.data.data_curve_imag.setData(self.data.frequency, self.data.epsilon.imag)
if len(funcs)> 0: if len(funcs)> 0:
self.data.fitted_curve_real.setData(self.data.frequency, self.data.epsilon_fit.real) self.data.fitted_curve_real.setData(self.data.frequency_fit, self.data.epsilon_fit.real)
self.data.fitted_curve_imag.setData(self.data.frequency, self.data.epsilon_fit.imag) self.data.fitted_curve_imag.setData(self.data.frequency_fit, self.data.epsilon_fit.imag)
else: else:
self.data.fitted_curve_real.setData([N.nan],[N.nan]) self.data.fitted_curve_real.setData([N.nan],[N.nan])
self.data.fitted_curve_imag.setData([N.nan],[N.nan]) self.data.fitted_curve_imag.setData([N.nan],[N.nan])
def sigint_handler(*args): def sigint_handler(*args):
"""Handler for the SIGINT signal (CTRL + C). """Handler for the SIGINT signal (CTRL + C).
""" """

View File

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'QDSMain.ui' # Form implementation generated from reading ui file 'QDSMain.ui'
# #
# Created: Thu Mar 20 13:41:01 2014 # Created: Thu Mar 20 14:46:49 2014
# by: PyQt4 UI code generator 4.10.3 # by: PyQt4 UI code generator 4.10.3
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!
@ -94,7 +94,7 @@ class Ui_MainWindow(object):
self.actionAdd_Cond.setObjectName(_fromUtf8("actionAdd_Cond")) self.actionAdd_Cond.setObjectName(_fromUtf8("actionAdd_Cond"))
self.actionSave_FitResult = QtGui.QAction(MainWindow) self.actionSave_FitResult = QtGui.QAction(MainWindow)
icon2 = QtGui.QIcon() icon2 = QtGui.QIcon()
icon2.addPixmap(QtGui.QPixmap(_fromUtf8(":/icons/save_fit.svg")), QtGui.QIcon.Normal, QtGui.QIcon.Off) icon2.addPixmap(QtGui.QPixmap(_fromUtf8(":/icons/save_fit.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.actionSave_FitResult.setIcon(icon2) self.actionSave_FitResult.setIcon(icon2)
self.actionSave_FitResult.setObjectName(_fromUtf8("actionSave_FitResult")) self.actionSave_FitResult.setObjectName(_fromUtf8("actionSave_FitResult"))
self.actionAdd_PowerLaw = QtGui.QAction(MainWindow) self.actionAdd_PowerLaw = QtGui.QAction(MainWindow)

View File

@ -127,7 +127,7 @@
<action name="actionSave_FitResult"> <action name="actionSave_FitResult">
<property name="icon"> <property name="icon">
<iconset resource="icons/images.qrc"> <iconset resource="icons/images.qrc">
<normaloff>:/icons/save_fit.svg</normaloff>:/icons/save_fit.svg</iconset> <normaloff>:/icons/save_fit.png</normaloff>:/icons/save_fit.png</iconset>
</property> </property>
<property name="text"> <property name="text">
<string>Save Fit</string> <string>Save Fit</string>

View File

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'StaticGroupBox.ui' # Form implementation generated from reading ui file 'StaticGroupBox.ui'
# #
# Created: Thu Mar 20 13:41:01 2014 # Created: Thu Mar 20 14:46:49 2014
# by: PyQt4 UI code generator 4.10.3 # by: PyQt4 UI code generator 4.10.3
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!

View File

@ -14,6 +14,7 @@ class Data:
def __init__(self, frequency=N.zeros(1), die_real=N.zeros(1), die_imag=N.zeros(1)): def __init__(self, frequency=N.zeros(1), die_real=N.zeros(1), die_imag=N.zeros(1)):
self.frequency = frequency self.frequency = frequency
self.epsilon = die_real + 1j * die_imag self.epsilon = die_real + 1j * die_imag
self.frequency_fit = frequency
self.epsilon_fit = die_real*0 + 1j * die_imag*0 self.epsilon_fit = die_real*0 + 1j * die_imag*0
myPen_imag = pg.mkPen(width=3, color=(255,255,127)) myPen_imag = pg.mkPen(width=3, color=(255,255,127))
myPen_real = pg.mkPen(width=3, color=(51,255,127)) myPen_real = pg.mkPen(width=3, color=(51,255,127))
@ -35,7 +36,7 @@ class Data:
def set_fit(self, param, funcs): def set_fit(self, param, funcs):
self.fit_funcs = funcs self.fit_funcs = funcs
self.fit_param = param self.fit_param = param
fit_real, fit_imag = FitFunctionCreator().fitfcn(param, self.frequency, *funcs) fit_real, fit_imag = FitFunctionCreator().fitfcn(param, self.frequency_fit, *funcs)
self.epsilon_fit = fit_real + 1j*fit_imag self.epsilon_fit = fit_real + 1j*fit_imag
def __del__(self): def __del__(self):
@ -54,6 +55,7 @@ class Data:
def set_fit_xlimits(self, xmin, xmax): def set_fit_xlimits(self, xmin, xmax):
self.fit_limits[0] = xmin self.fit_limits[0] = xmin
self.fit_limits[1] = xmax self.fit_limits[1] = xmax
self.frequency_fit = self.frequency[(self.frequency <= xmax) & (self.frequency >= xmin)]
def set_fit_ylimits(self, ymin, ymax): def set_fit_ylimits(self, ymin, ymax):
self.fit_limits[2] = ymin self.fit_limits[2] = ymin
@ -127,7 +129,6 @@ class Conductivity(QObject):
p = self.getParameter() p = self.getParameter()
y = self.f.cond_cmplx(p, self.frequency) y = self.f.cond_cmplx(p, self.frequency)
print p
self.conductivity = y # imaginary part self.conductivity = y # imaginary part
self.data_curve_real.setData(x=self.frequency, y=self.conductivity[0], label="Cond.") self.data_curve_real.setData(x=self.frequency, y=self.conductivity[0], label="Cond.")

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -1,9 +1,9 @@
<RCC> <RCC>
<qresource prefix="icons"> <qresource prefix="icons">
<file>add_eps_infty.png</file>
<file>add_cond.svg</file> <file>add_cond.svg</file>
<file>add_eps_infty.png</file>
<file>add_peak.svg</file> <file>add_peak.svg</file>
<file>save_fit.svg</file>
<file>fit_limits.png</file> <file>fit_limits.png</file>
<file>save_fit.png</file>
</qresource> </qresource>
</RCC> </RCC>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 18 KiB

File diff suppressed because it is too large Load Diff

View File

@ -219,20 +219,20 @@ class FunctionRegister:
self.registry = {} self.registry = {}
def register_function(self,obj): def register_function(self,obj):
print "FR: Registering:",obj #print "FR: Registering:",obj
id_string = obj.id_string id_string = obj.id_string
if self.registry.has_key(obj): if self.registry.has_key(obj):
raise AssertionError,"The object is already registered! This should NOT happen" raise AssertionError,"The object is already registered! This should NOT happen"
self.registry[obj]=id_string self.registry[obj]=id_string
print "FR: ",self.registry #print "FR: ",self.registry
def unregister_function(self, obj): def unregister_function(self, obj):
print "FR: UnRegistering:",obj #print "FR: UnRegistering:",obj
if self.registry.has_key(obj): if self.registry.has_key(obj):
self.registry.pop(obj) self.registry.pop(obj)
else: else:
raise AssertionError,"The object is not in the registry! This should NOT happen" raise AssertionError,"The object is not in the registry! This should NOT happen"
print "FR: ",self.registry #print "FR: ",self.registry
def get_registered_functions(self): def get_registered_functions(self):
return self.registry return self.registry