generalized addPeak, addYAFF, addCond, etc.

to addContainer(container,data_pos)

fixed action group
This commit is contained in:
Markus Rosenstihl 2015-01-08 18:17:43 +01:00
parent 8f538174d9
commit ae30438737
3 changed files with 57 additions and 93 deletions

View File

@ -24,6 +24,8 @@ class Conductivity(BaseContainer):
def function(self, p ,x):
if self._abort:
raise StopIteration
return functions.cond_cmplx(p,x)
def start_parameter(self, pos):
@ -41,6 +43,8 @@ class PowerComplex(BaseContainer):
self.param_number = 2
def function( self, p, x ):
if self._abort:
raise StopIteration
return functions.power_cmplx(p, x)
def start_parameter(self, pos):
@ -58,6 +62,8 @@ class Static(BaseContainer):
self.param_number = 1
def function( self, p, x ):
if self._abort:
raise StopIteration
return functions.static_cmplx(p, x)
def start_parameter(self, position):
@ -65,18 +71,22 @@ class Static(BaseContainer):
self.set_parameter(beta=cond_par)
class Peak(BaseContainer):
def __init__( self, id_num=None, plt_real=None, plt_imag=None, limits=None ):
def __init__( self, 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.container_widgets.PeakWidget()
self.widget.setId(id_num)
self.color = id_to_color(id_num)
self.widget.setColor(self.color)
self.id_num = id_num
self.id_label = "Hav-Neg"
self.id_string = "hn"
self.param_number = 4
def set_id(self, id_num):
self.widget.setId(id_num)
self.color = id_to_color(id_num)
self.widget.setColor(self.color)
self.id_num = id_num
def function( self, p, x ):
if self._abort:
raise StopIteration
return functions.hn(p, x)
def start_parameter(self, pos):
@ -117,6 +127,8 @@ class YAFF(BaseContainer):
self.update_data()
def function( self, p, x ):
if self._abort:
raise StopIteration
ya = self._libyaff.loss(p, x)
cplx = np.array([ya.imag, ya.real])
return cplx

View File

@ -8,10 +8,18 @@ __author__ = 'markusro'
class QABCMeta(abc.ABCMeta, QObject.__class__):
"""
Allows us to use ABCMeta
Allows us to use abstract base class module to fixate the container API.
The metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases.
This means the BaseContainer's metaclass must also be a subclass of QObject, as
the BaseContainer is itself a subclass of QObject.
This class provides a suitable metaclass.
"""
pass
class BaseContainer(QObject):
"""
This class provides placeholders (or default) methods for "container" objects.
@ -155,12 +163,12 @@ class BaseContainer(QObject):
@abc.abstractmethod
def start_parameter(self, position):
raise NotImplementedError("This needs to be implemented in your subclass")
raise NotImplementedError("This needs to be implemented in your container subclass")
@abc.abstractmethod
def function( self, p, x ):
if self._abort:
raise StopIteration
raise NotImplementedError("This needs to be implemented in your subclass")
raise NotImplementedError("This needs to be implemented in your container subclass")

114
qds.py
View File

@ -41,12 +41,13 @@ class AppWindow(QMainWindow):
self._file_paths = self._sortInputFiles(files)
self._last_written_header = None
# create action group
actions = {
self.ui.actionAdd_Peak: self.addPeak,
self.ui.actionAdd_Cond: self.addCond,
self.ui.actionAdd_PowerLaw: self.addPowerComplex,
self.ui.actionAdd_Eps_Infty: self.addEpsInfty,
self.ui.actionYAFF: self.addYaff,
self.ui.actionAdd_Peak: True,
self.ui.actionAdd_Cond: True,
self.ui.actionAdd_PowerLaw: True,
self.ui.actionAdd_Eps_Infty: True,
self.ui.actionYAFF: True,
}
self.myActionGroup = QActionGroup(self)
@ -196,7 +197,15 @@ class AppWindow(QMainWindow):
if self.ui.actionAdd_Peak.isChecked():
if mouse_in_imag:
self.addPeak(data_pos)
id_list = [key.id_num for key in
self.function_registry.get_registered_functions()
if key.id_string == 'hn']
self.peakId = 1
while self.peakId in id_list:
self.peakId += 1
_pk = self.addContainer(Peak, data_pos)
_pk.set_id(self.peakId)
# self.addPeak(data_pos)
self.ui.actionAdd_Peak.setChecked(False)
else:
msgBox.setText("Click in imaginary part")
@ -204,7 +213,7 @@ class AppWindow(QMainWindow):
if self.ui.actionAdd_Cond.isChecked():
if mouse_in_imag:
self.addCond(data_pos)
self.addContainer(Conductivity, data_pos)
self.ui.actionAdd_Cond.setChecked(False)
else:
msgBox.setText("Click in imaginary part")
@ -212,7 +221,7 @@ class AppWindow(QMainWindow):
if self.ui.actionYAFF.isChecked():
if mouse_in_imag:
self.addYaff(data_pos)
self.addContainer(YAFF, data_pos)
self.ui.actionYAFF.setChecked(False)
else:
msgBox.setText("Click in imaginary part")
@ -220,7 +229,7 @@ class AppWindow(QMainWindow):
if self.ui.actionAdd_PowerLaw.isChecked():
if mouse_in_imag:
self.addPowerComplex(data_pos)
self.addContainer(PowerComplex, data_pos)
self.ui.actionAdd_PowerLaw.setChecked(False)
else:
msgBox.setText("Click in imaginary part")
@ -228,7 +237,7 @@ class AppWindow(QMainWindow):
if self.ui.actionAdd_Eps_Infty.isChecked():
if mouse_in_real:
self.addEpsInfty(data_pos)
self.addContainer(Static, data_pos)
self.ui.actionAdd_Eps_Infty.setChecked(False)
else:
msgBox.setText("Click in real part")
@ -346,89 +355,24 @@ class AppWindow(QMainWindow):
"""
#TODO: need interface/method for adding function blocks, this is too repetitive
#TODO: start parameters have to be factored out for the above
def addYaff( self, pos ):
_yaff = YAFF(plt_real=self.ui.pgPlotWidget_real,
def addContainer(self, selected_container, pos):
_cont = selected_container(plt_real=self.ui.pgPlotWidget_real,
plt_imag=self.ui.pgPlotWidget_imag,
limits=self.data.fit_limits)
_yaff.blockSignals(True)
_yaff.changedData.connect(self.update_plot)
_yaff.removeObj.connect(self.delParamterObject)
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.set_parameter(beta=yaff_par)
self.parameterWidget.add(_yaff.widget)
self.function_registry.register_function(_yaff)
self.update_plot()
_yaff.blockSignals(False)
def addCond( self, pos ):
_conductivity = Conductivity(plt_real=self.ui.pgPlotWidget_real,
plt_imag=self.ui.pgPlotWidget_imag,
limits=self.data.fit_limits)
_conductivity.blockSignals(True)
_conductivity.changedData.connect(self.update_plot)
_conductivity.removeObj.connect(self.delParamterObject)
cond_par = [0.0, 10**(pos.y()+pos.x())*2*np.pi, 1.0]
_conductivity.set_parameter(beta=cond_par)
self.parameterWidget.add(_conductivity.widget)
self.function_registry.register_function(_conductivity)
self.update_plot()
_conductivity.blockSignals(False)
def addPowerComplex( self, pos ):
_power_complex = PowerComplex(plt_imag=self.ui.pgPlotWidget_imag,
plt_real=self.ui.pgPlotWidget_real,
limits=self.data.fit_limits)
_power_complex.changedData.connect(self.update_plot)
_power_complex.removeObj.connect(self.delParamterObject)
cond_par = [10**(pos.y()+pos.x())*2*np.pi, 1.0]
_power_complex.set_parameter(beta=cond_par)
self.parameterWidget.add(_power_complex.widget)
self.function_registry.register_function(_power_complex)
self.update_plot()
def addEpsInfty( self, pos ):
_eps_infty = Static(plt_imag=self.ui.pgPlotWidget_imag,
plt_real=self.ui.pgPlotWidget_real,
limits=self.data.fit_limits)
_eps_infty.changedData.connect(self.update_plot)
_eps_infty.removeObj.connect(self.delParamterObject)
cond_par = [10**pos.y()]
_eps_infty.set_parameter(beta=cond_par)
self.parameterWidget.add(_eps_infty.widget)
self.function_registry.register_function(_eps_infty)
_cont.blockSignals(True)
_cont.changedData.connect(self.update_plot)
_cont.removeObj.connect(self.delParamterObject)
_cont.start_parameter(pos)
self.parameterWidget.add(_cont.widget)
self.function_registry.register_function(_cont)
self.update_plot()
_cont.blockSignals(False)
return _cont
def delParamterObject( self, obj ):
self.function_registry.unregister_function(obj)
self.update_plot()
def addPeak( self, pos ):
id_list = [key.id_num for key in
self.function_registry.get_registered_functions()
if key.id_string == 'hn']
self.peakId = 1
while self.peakId in id_list:
self.peakId += 1
_peak = Peak(id_num=self.peakId,
plt_real=self.ui.pgPlotWidget_real,
plt_imag=self.ui.pgPlotWidget_imag,
limits=self.data.fit_limits)
self.function_registry.register_function(_peak)
_peak.changedData.connect(self.update_plot)
_peak.removeObj.connect(self.delParamterObject)
new_peak_beta0 = [2*10**pos.y(), 1/(2*np.pi*10**pos.x()), 1, 1]
_peak.set_parameter(beta=new_peak_beta0)
self.parameterWidget.add(_peak.widget)
self.update_plot()
def fitData_start( self, method ):
#fit_methods = [fit_odr_cmplx, fit_odr_imag, fit_lbfgsb, fit_anneal]
self.fit_boundary_real.hide()