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:
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()