Fixed Bug in PeaKWidget: change from CD,cc or Debye to HN did not reset the parameters to be fixed

This commit is contained in:
Markus Rosenstihl 2014-09-28 21:16:06 +02:00
parent 1a1066a07e
commit 21a93d6d09
6 changed files with 138 additions and 132 deletions

View File

@ -8,7 +8,7 @@ from libmath import yafflib
from libmath.BDSlib import id_to_color
from container_base import BaseContainer
import gui.ContainerWidgets
import gui.container_widgets
@ -19,7 +19,7 @@ __author__ = 'markusro'
class Conductivity(BaseContainer):
def __init__( self, plt_imag=None, plt_real=None, limits=None ):
super(Conductivity, self).__init__(plt_real=plt_real, plt_imag=plt_imag, limits=limits)
self.widget = gui.ContainerWidgets.ConductivityWidget()
self.widget = gui.container_widgets.ConductivityWidget()
self.color = QColor("blue")
self.id_label = "Cond."
self.id_string = "cond"
@ -37,7 +37,7 @@ class Conductivity(BaseContainer):
class PowerComplex(BaseContainer):
def __init__( self, plt_real=None, plt_imag=None, limits=None ):
super(PowerComplex, self).__init__(plt_real=plt_real, plt_imag=plt_imag, limits=limits)
self.widget = gui.ContainerWidgets.PowerLawWidget()
self.widget = gui.container_widgets.PowerLawWidget()
self.color = QColor("#ff44c4")
self.id_label = 'Power Law'
self.id_string = "pwr"
@ -55,7 +55,7 @@ class PowerComplex(BaseContainer):
class Static(BaseContainer):
def __init__( self, plt_real=None, plt_imag=None, limits=None ):
super(Static, self).__init__(plt_real=plt_real, plt_imag=plt_imag, limits=limits)
self.widget = gui.ContainerWidgets.StaticWidget()
self.widget = gui.container_widgets.StaticWidget()
self.color = QColor('#FF0F13')
self.id_label = u'ε(∞)'
self.id_string = "eps_infty"
@ -72,7 +72,7 @@ class Static(BaseContainer):
class Peak(BaseContainer):
def __init__( self, id_num=None, plt_real=None, plt_imag=None, limits=None ):
super(Peak, self).__init__(plt_real=plt_real, plt_imag=plt_imag, limits=limits)
self.widget = gui.ContainerWidgets.PeakWidget()
self.widget = gui.container_widgets.PeakWidget()
self.widget.setId(id_num)
self.color = id_to_color(id_num)
self.widget.setColor(self.color)
@ -93,7 +93,7 @@ class Peak(BaseContainer):
class YAFF(BaseContainer):
def __init__( self, plt_real=None, plt_imag=None, limits=None ):
super(YAFF, self).__init__(plt_real=plt_real, plt_imag=plt_imag, limits=limits)
self.widget = gui.ContainerWidgets.YaffWidget()
self.widget = gui.container_widgets.YaffWidget()
self.widget.on_model_changed.connect(self.change_model)
self.widget.configuration_changed.connect(self.change_configuration)
self.color = QColor(32, 120, 29, int(255*0.82))
@ -114,14 +114,14 @@ class YAFF(BaseContainer):
def change_configuration( self, t_list, tau_list ):
self._libyaff.dist_tau = tau_list
self._libyaff.time_points = t_list
self.updateData()
self.update_data()
def change_model( self ):
self._libyaff = yafflib.Yaff(self.widget.getYaffType())
self._selector_mask = self.widget.selector_mask
self.id_label = self._libyaff.label
self.param_number = self._libyaff.params
self.updateData()
self.update_data()
def function( self, p, x ):
BaseContainer.function(self, p, x)

View File

@ -43,7 +43,7 @@ class BaseContainer(QObject):
def set_limits(self, limits):
self.limits = limits
self.updateData()
self.update_data()
@pyqtSlot(bool)
def abort(self, abort=False):
@ -94,23 +94,23 @@ class BaseContainer(QObject):
@widget.setter
def widget(self, wdgt):
self._widget = wdgt
self._widget.changedTable.connect(self.updateData) # TODO better to use self.setParameter
self._widget.changedTable.connect(self.update_data) # TODO better to use self.setParameter
self.removeObj.connect(self._widget.deleteLater)
self._widget.removeMe.connect(self.removeMe)
def getParameter(self):
def get_parameter( self ):
p = self.widget.getTable() # TODO ugly ... should return self._beta etc ...?
return p
def getFixed(self):
def get_fixed( self ):
p = self.widget.fixedParameter()
return p
def setParameter(self, beta, sd_beta=None):
def set_parameter( self, beta, sd_beta=None ):
self._beta = beta
self._sd_beta = sd_beta
self.widget.updateTable(beta, sd_beta)
self.updateData()
self.widget.update_table(beta, sd_beta)
self.update_data()
def get_data(self):
return self._frequency, self._data
@ -121,19 +121,19 @@ class BaseContainer(QObject):
self.removeObj.emit(self)
self.changedData.emit()
def updateData(self):
def update_data( self ):
self._frequency = np.logspace(np.log10(self.limits[0]), np.log10(self.limits[1]), 256)
self._data = self._func(self.getParameter(), self._frequency)
self._data = self._func(self.get_parameter(), self._frequency)
self.data_curve_real.setData(x=self._frequency, y=self._data[0])
self.data_curve_imag.setData(x=self._frequency, y=self._data[1])
self.changedData.emit()
def resampleData(self, x):
data = self._func(self.getParameter(), x)
data = self._func(self.get_parameter(), x)
return np.array([x,data[0],data[1]]).T
def clearData(self):
def clear_data( self ):
self.data_curve_real.setData(x=[np.nan], y=[np.nan])
self.data_curve_imag.setData(x=[np.nan], y=[np.nan])

View File

@ -1,69 +0,0 @@
# -*- encoding: utf8 -*-
from PyQt4.QtGui import QColor
import numpy as np
import pyqtgraph as pg
from libmath.BDSlib import FitFunctionCreator
class Data:
def __init__(self, frequency=np.zeros(1), die_real=np.zeros(1), die_imag=np.zeros(1)):
self.frequency = frequency
self.epsilon = die_real + 1j * die_imag
self.frequency_fit = frequency[:]
self.epsilon_fit = die_real[:]*0 + 1j * die_imag[:]*0
myPen_imag = pg.mkPen(width=3, color=(255,255,127))
myPen_real = pg.mkPen(width=3, color=(51,255,127))
self.data_curve_imag = pg.PlotDataItem(x=[np.nan], y=[np.nan],pen=QColor(0,0,0,0), symbol='o',
symbolBrush=(255,127,0,127))
self.data_curve_real = pg.PlotDataItem(x=[np.nan], y=[np.nan],pen=QColor(0,0,0,0), symbol='s',
symbolBrush=(119,202,92,127))
self.fitted_curve_imag = pg.PlotDataItem(x=[np.nan], y=[np.nan], pen=myPen_imag)
self.fitted_curve_real = pg.PlotDataItem(x=[np.nan], y=[np.nan], pen=myPen_real)
self.length = len(frequency)
self.meta = dict()
self.fit_limits = [frequency.min(), frequency.max(), die_imag.min(), die_imag.max()]
self.fit_param = None
self.fit_funcs = None # list of fit functions
self.hide_funcs = None # remove these func from the data
def set_fit(self, param, funcs):
self.fit_funcs = funcs
self.hide_funcs = []
self.fit_param = param
fit_real, fit_imag = FitFunctionCreator().fitfcn(param, self.frequency_fit, *funcs)
self.epsilon_fit = fit_real+1j*fit_imag
def set_data(self,f,e_real,e_imag):
self.frequency = f
self.frequency_fit = f[:]
self.epsilon = e_real + 1j*e_imag
self.epsilon_fit = 0*e_real + 1j*e_imag*0
self.fit_limits = [f.min(), f.max(), e_imag.min(), e_imag.max()]
self.data_curve_imag.setData(f,e_imag)
self.data_curve_real.setData(f,e_real)
def set_fit_xlimits(self, xmin, xmax):
self.fit_limits[0] = xmin
self.fit_limits[1] = xmax
self.frequency_fit = self.frequency[(self.frequency <= xmax) & (self.frequency >= xmin)]
def set_fit_ylimits(self, ymin, ymax):
self.fit_limits[2] = ymin
self.fit_limits[3] = ymax
def get_data(self):
#mask = np.ones(len(self.frequency), dtype='bool')
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[3])
return self.frequency[mask], self.epsilon[mask]
def remove_curves(self):
print "remove data_curve"
#if self.data_curve is not None: self.data_curve.remove()
print "remove fitted_curve"
#if self.fitted_curve is not None: self.fitted_curve.remove()

73
data/experimental.py Normal file
View File

@ -0,0 +1,73 @@
# -*- encoding: utf8 -*-
from PyQt4.QtGui import QColor
import numpy as np
import pyqtgraph as pg
from libmath.BDSlib import FitFunctionCreator
class Data:
def __init__( self, frequency=np.zeros(1), die_real=np.zeros(1), die_imag=np.zeros(1) ):
self.frequency = frequency
self.epsilon = die_real+1j*die_imag
self.frequency_fit = frequency[:]
self.epsilon_fit = die_real[:]*0+1j*die_imag[:]*0
myPen_imag = pg.mkPen(width=2.5, color=(255, 255, 127))
myPen_real = pg.mkPen(width=2.5, color=(51, 255, 127))
self.experimental_curve_imag = pg.PlotDataItem(x=[np.nan], y=[np.nan],
pen=QColor(0, 0, 0, 0),
symbol='o',
symbolBrush=(255, 127, 0, 127))
self.experimental_curve_real = pg.PlotDataItem(x=[np.nan], y=[np.nan],
pen=QColor(0, 0, 0, 0),
symbol='o',
symbolBrush=(119, 202, 92, 127))
self.model_curve_imag = pg.PlotDataItem(x=[np.nan], y=[np.nan], pen=myPen_imag)
self.model_curve_real = pg.PlotDataItem(x=[np.nan], y=[np.nan], pen=myPen_real)
self.length = len(frequency)
self.meta = dict()
self.fit_limits = [frequency.min(), frequency.max(), die_imag.min(), die_imag.max()]
self.fit_param = None
self.fit_funcs = None # list of fit functions
self.hide_funcs = None # remove these func from the data
def set_fit( self, param, funcs ):
self.fit_funcs = funcs
self.hide_funcs = []
self.fit_param = param
fit_real, fit_imag = FitFunctionCreator().fitfcn(param, self.frequency_fit, *funcs)
self.epsilon_fit = fit_real+1j*fit_imag
def set_data( self, f, e_real, e_imag ):
self.frequency = f
self.frequency_fit = f[:]
self.epsilon = e_real+1j*e_imag
self.epsilon_fit = 0*e_real+1j*e_imag*0
self.fit_limits = [f.min(), f.max(), e_imag.min(), e_imag.max()]
self.experimental_curve_imag.setData(f, e_imag)
self.experimental_curve_real.setData(f, e_real)
def set_fit_xlimits( self, xmin, xmax ):
self.fit_limits[0] = xmin
self.fit_limits[1] = xmax
self.frequency_fit = self.frequency[(self.frequency <= xmax) & (self.frequency >= xmin)]
def set_fit_ylimits( self, ymin, ymax ):
self.fit_limits[2] = ymin
self.fit_limits[3] = ymax
def get_data( self ):
# mask = np.ones(len(self.frequency), dtype='bool')
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[3])
return self.frequency[mask], self.epsilon[mask]
def remove_curves( self ):
print "remove data_curve"
# if self.data_curve is not None: self.data_curve.remove()
print "remove fitted_curve"
#if self.fitted_curve is not None: self.fitted_curve.remove()

View File

@ -65,7 +65,7 @@ class BaseWidget(QGroupBox):
def subtract(self):
self.subtract.emit()
def changeValues(self, num):
def change_values( self, num ):
self.changedTable.emit()
def fixedParameter(self):
@ -86,7 +86,7 @@ class BaseWidget(QGroupBox):
def update(self):
self.changedTable.emit()
def updateTable(self, beta, sd_beta=None):
def update_table( self, beta, sd_beta=None ):
for i, arg in enumerate(beta):
self.inputs[i].setValue(arg)
sd_style=""
@ -161,26 +161,19 @@ class PeakWidget(BaseWidget,QGroupBox):
]
for dsb in self.inputs:
dsb.valueChanged.connect(self.changeValues)
dsb.valueChanged.connect(self.change_values)
self.fixedCheckBoxes = [self.ui.checkBox_1,
self.ui.checkBox_2,
self.ui.checkBox_3,
self.ui.checkBox_4]
# self.ui.checkBox_3.stateChanged.connect(self._distrib_cc)
# self.ui.checkBox_4.stateChanged.connect(self._distrib_cd)
self.ui.comboBox.currentIndexChanged.connect(self._distrib_select)
def _distrib_select(self, dist):
self._distrib_hn(1)
if dist == 0: # hav-neg:
self.ui.checkBox_3.setChecked(False)
self.ui.checkBox_3.setDisabled(False)
self.ui.checkBox_4.setChecked(False)
self.ui.checkBox_4.setDisabled(False)
self.ui.doubleSpinBox_3.setDisabled(False)
self.ui.doubleSpinBox_4.setDisabled(False)
self._distrib_hn(1)
if dist == 1: # Cole-Cole:
self._distrib_cc(1)
if dist == 2: # Cole-Davidson
@ -188,6 +181,14 @@ class PeakWidget(BaseWidget,QGroupBox):
if dist == 3: # Cole-Davidson
self._distrib_debye(1)
def _distrib_hn( self, state ):
self.ui.checkBox_3.setChecked(False)
self.ui.checkBox_3.setDisabled(False)
self.ui.checkBox_4.setChecked(False)
self.ui.checkBox_4.setDisabled(False)
self.ui.doubleSpinBox_3.setDisabled(False)
self.ui.doubleSpinBox_4.setDisabled(False)
def _distrib_cd(self, state):
if state:
self.ui.doubleSpinBox_3.setValue(1.0)
@ -290,7 +291,7 @@ class StaticWidget(BaseWidget, QGroupBox):
self.fixedCheckBoxes = [ self.ui.checkBox_1]
for dsb in self.inputs:
dsb.valueChanged.connect(self.changeValues)
dsb.valueChanged.connect(self.change_values)
self.ui.removeButton.clicked.connect(self.remove)
self.func_type=r"$\epsilon_\infty$"
@ -336,7 +337,7 @@ class ConductivityWidget(BaseWidget, QGroupBox):
self.ui.checkBox_2,
self.ui.checkBox_3]
for dsb in self.inputs:
dsb.valueChanged.connect(self.changeValues)
dsb.valueChanged.connect(self.change_values)
@ -366,7 +367,7 @@ class PowerLawWidget(BaseWidget):
self.fixedCheckBoxes = [ self.ui.checkBox_2,
self.ui.checkBox_3]
for dsb in self.inputs:
dsb.valueChanged.connect(self.changeValues)
dsb.valueChanged.connect(self.change_values)
class YaffWidget(BaseWidget):
@ -460,7 +461,7 @@ class YaffWidget(BaseWidget):
self.ui.checkBox_10,
]
for dsb in self.inputs:
dsb.valueChanged.connect(self.changeValues)
dsb.valueChanged.connect(self.change_values)
self.change_model(0)
self._t_list, self._tau_list = None, None

View File

@ -1,6 +1,5 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
from gui import ExtraDifferentialWidget
_author_ = "Markus Rosenstihl"
@ -24,11 +23,13 @@ import numpy as np
import pyqtgraph as pg
from data.container import Conductivity, PowerComplex, Static, Peak, YAFF
from gui.ContainerWidgets import ParameterWidget
from gui.container_widgets import ParameterWidget
from ui import QDSMain
from libmath.BDSlib import FunctionRegister, FitRoutine
from data.data import Data
from data.experimental import Data
from gui import ExtraDifferentialWidget
from bds_io import bds_file_reader
@ -65,10 +66,10 @@ class AppWindow(QMainWindow):
self.fit_boundary_imag = pg.LinearRegionItem(brush=QColor(0, 127, 254, 15))
self.fit_boundary_real = pg.LinearRegionItem(brush=QColor(0, 127, 254, 15))
self.ui.pgPlotWidget_imag.addItem(self.data.data_curve_imag)
self.ui.pgPlotWidget_real.addItem(self.data.data_curve_real)
self.ui.pgPlotWidget_imag.addItem(self.data.fitted_curve_imag)
self.ui.pgPlotWidget_real.addItem(self.data.fitted_curve_real)
self.ui.pgPlotWidget_imag.addItem(self.data.experimental_curve_imag)
self.ui.pgPlotWidget_real.addItem(self.data.experimental_curve_real)
self.ui.pgPlotWidget_imag.addItem(self.data.model_curve_imag)
self.ui.pgPlotWidget_real.addItem(self.data.model_curve_real)
self.ui.pgPlotWidget_imag.addItem(self.fit_boundary_imag)
self.ui.pgPlotWidget_real.addItem(self.fit_boundary_real)
@ -353,7 +354,7 @@ class AppWindow(QMainWindow):
gg_y = 10**pos.y()*2
gg_x = 1/(10**pos.x()*2*np.pi)
yaff_par = [gg_y, gg_x, 20.0, 1.0, 0.5, gg_x/100, 1.0, 1.0]
_yaff.setParameter(beta=yaff_par)
_yaff.set_parameter(beta=yaff_par)
self.parameterWidget.add(_yaff.widget)
self.function_registry.register_function(_yaff)
self.updatePlot()
@ -368,7 +369,7 @@ class AppWindow(QMainWindow):
_conductivity.changedData.connect(self.updatePlot)
_conductivity.removeObj.connect(self.delParamterObject)
cond_par = [0.0, 10**(pos.y()+pos.x())*2*np.pi, 1.0]
_conductivity.setParameter(beta=cond_par)
_conductivity.set_parameter(beta=cond_par)
self.parameterWidget.add(_conductivity.widget)
self.function_registry.register_function(_conductivity)
self.updatePlot()
@ -382,7 +383,7 @@ class AppWindow(QMainWindow):
_power_complex.changedData.connect(self.updatePlot)
_power_complex.removeObj.connect(self.delParamterObject)
cond_par = [10**(pos.y()+pos.x())*2*np.pi, 1.0]
_power_complex.setParameter(beta=cond_par)
_power_complex.set_parameter(beta=cond_par)
self.parameterWidget.add(_power_complex.widget)
self.function_registry.register_function(_power_complex)
self.updatePlot()
@ -394,7 +395,7 @@ class AppWindow(QMainWindow):
_eps_infty.changedData.connect(self.updatePlot)
_eps_infty.removeObj.connect(self.delParamterObject)
cond_par = [10**pos.y()]
_eps_infty.setParameter(beta=cond_par)
_eps_infty.set_parameter(beta=cond_par)
self.parameterWidget.add(_eps_infty.widget)
self.function_registry.register_function(_eps_infty)
self.updatePlot()
@ -419,7 +420,7 @@ class AppWindow(QMainWindow):
_peak.changedData.connect(self.updatePlot)
_peak.removeObj.connect(self.delParamterObject)
new_peak_beta0 = [2*10**pos.y(), 1/(2*np.pi*10**pos.x()), 1, 1]
_peak.setParameter(beta=new_peak_beta0)
_peak.set_parameter(beta=new_peak_beta0)
self.parameterWidget.add(_peak.widget)
self.updatePlot()
@ -435,10 +436,10 @@ class AppWindow(QMainWindow):
# build function list
p0, funcs, fixed_params = [], [], []
for fcn in self.function_registry.get_registered_functions():
p0.extend(fcn.getParameter())
p0.extend(fcn.get_parameter())
funcs.append(fcn)
fixed_params.extend(fcn.getFixed())
fcn.clearData()
fixed_params.extend(fcn.get_fixed())
fcn.clear_data()
_freq, _fit = self.data.get_data()
if not self._fit_thread.isRunning():
@ -454,9 +455,9 @@ class AppWindow(QMainWindow):
odr_result = self._fit_method.result()
p0, funcs, fixed_params = [], [], []
for fcn in self.function_registry.get_registered_functions():
p0.extend(fcn.getParameter())
p0.extend(fcn.get_parameter())
funcs.append(fcn)
fixed_params.extend(fcn.getFixed())
fixed_params.extend(fcn.get_fixed())
for container in self.function_registry.get_registered_functions():
container.abort(False)
@ -465,13 +466,13 @@ class AppWindow(QMainWindow):
self.ui.statusbar.showMessage(" ".join(odr_result.stopreason))
ndx = 0
for i, fcn in enumerate(self.function_registry.get_registered_functions()):
num_p = len(fcn.getParameter())
num_p = len(fcn.get_parameter())
beta = odr_result.beta[ndx:num_p+ndx]
if odr_result.sd_beta is not None:
sd_beta = odr_result.sd_beta[ndx:num_p+ndx]
else:
sd_beta = None
fcn.setParameter(beta, sd_beta)
fcn.set_parameter(beta, sd_beta)
ndx += num_p
self.fit_boundary_real.show()
@ -540,7 +541,7 @@ class AppWindow(QMainWindow):
p0, funcs = [], []
for fcn in self.function_registry.get_registered_functions():
p0.extend(fcn.getParameter())
p0.extend(fcn.get_parameter())
funcs.append(fcn)
@ -549,21 +550,21 @@ class AppWindow(QMainWindow):
# replot data and fit, TODO: replot only if measurement data changed
self.data.data_curve_real.setData(self.data.frequency, self.data.epsilon.real)
self.data.data_curve_imag.setData(self.data.frequency, self.data.epsilon.imag)
self.data.experimental_curve_real.setData(self.data.frequency, self.data.epsilon.real)
self.data.experimental_curve_imag.setData(self.data.frequency, self.data.epsilon.imag)
#print "updatePlot: ",self.data.frequency_fit, self.data.epsilon_fit
if len(funcs) > 0:
#print "funcs > 0:",self.data.frequency_fit, self.data.epsilon_fit
self.data.fitted_curve_real.setData(x=self.data.frequency_fit, y=self.data.epsilon_fit.real)
self.data.fitted_curve_imag.setData(x=self.data.frequency_fit, y=self.data.epsilon_fit.imag)
self.data.model_curve_real.setData(x=self.data.frequency_fit, y=self.data.epsilon_fit.real)
self.data.model_curve_imag.setData(x=self.data.frequency_fit, y=self.data.epsilon_fit.imag)
else:
self.data.fitted_curve_real.setData(x=np.array([np.nan]), y=np.array([np.nan]))
self.data.fitted_curve_imag.setData(x=np.array([np.nan]), y=np.array([np.nan]))
self.data.model_curve_real.setData(x=np.array([np.nan]), y=np.array([np.nan]))
self.data.model_curve_imag.setData(x=np.array([np.nan]), y=np.array([np.nan]))
def updateIntermediatePlot( self, freq, intermediate_data ):
self.data.fitted_curve_real.setData(freq, intermediate_data[0])
self.data.fitted_curve_imag.setData(freq, intermediate_data[1])
self.data.model_curve_real.setData(freq, intermediate_data[0])
self.data.model_curve_imag.setData(freq, intermediate_data[1])
def _update_fit_boundary_imag( self ):
"""