generalized addPeak, addYAFF, addCond, etc.
to addContainer(container,data_pos) fixed action group
This commit is contained in:
parent
8f538174d9
commit
ae30438737
@ -24,6 +24,8 @@ class Conductivity(BaseContainer):
|
|||||||
|
|
||||||
|
|
||||||
def function(self, p ,x):
|
def function(self, p ,x):
|
||||||
|
if self._abort:
|
||||||
|
raise StopIteration
|
||||||
return functions.cond_cmplx(p,x)
|
return functions.cond_cmplx(p,x)
|
||||||
|
|
||||||
def start_parameter(self, pos):
|
def start_parameter(self, pos):
|
||||||
@ -41,6 +43,8 @@ class PowerComplex(BaseContainer):
|
|||||||
self.param_number = 2
|
self.param_number = 2
|
||||||
|
|
||||||
def function( self, p, x ):
|
def function( self, p, x ):
|
||||||
|
if self._abort:
|
||||||
|
raise StopIteration
|
||||||
return functions.power_cmplx(p, x)
|
return functions.power_cmplx(p, x)
|
||||||
|
|
||||||
def start_parameter(self, pos):
|
def start_parameter(self, pos):
|
||||||
@ -58,6 +62,8 @@ class Static(BaseContainer):
|
|||||||
self.param_number = 1
|
self.param_number = 1
|
||||||
|
|
||||||
def function( self, p, x ):
|
def function( self, p, x ):
|
||||||
|
if self._abort:
|
||||||
|
raise StopIteration
|
||||||
return functions.static_cmplx(p, x)
|
return functions.static_cmplx(p, x)
|
||||||
|
|
||||||
def start_parameter(self, position):
|
def start_parameter(self, position):
|
||||||
@ -65,18 +71,22 @@ class Static(BaseContainer):
|
|||||||
self.set_parameter(beta=cond_par)
|
self.set_parameter(beta=cond_par)
|
||||||
|
|
||||||
class Peak(BaseContainer):
|
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)
|
super(Peak, self).__init__(plt_real=plt_real, plt_imag=plt_imag, limits=limits)
|
||||||
self.widget = gui.container_widgets.PeakWidget()
|
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_label = "Hav-Neg"
|
||||||
self.id_string = "hn"
|
self.id_string = "hn"
|
||||||
self.param_number = 4
|
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 ):
|
def function( self, p, x ):
|
||||||
|
if self._abort:
|
||||||
|
raise StopIteration
|
||||||
return functions.hn(p, x)
|
return functions.hn(p, x)
|
||||||
|
|
||||||
def start_parameter(self, pos):
|
def start_parameter(self, pos):
|
||||||
@ -117,6 +127,8 @@ class YAFF(BaseContainer):
|
|||||||
self.update_data()
|
self.update_data()
|
||||||
|
|
||||||
def function( self, p, x ):
|
def function( self, p, x ):
|
||||||
|
if self._abort:
|
||||||
|
raise StopIteration
|
||||||
ya = self._libyaff.loss(p, x)
|
ya = self._libyaff.loss(p, x)
|
||||||
cplx = np.array([ya.imag, ya.real])
|
cplx = np.array([ya.imag, ya.real])
|
||||||
return cplx
|
return cplx
|
||||||
|
@ -8,10 +8,18 @@ __author__ = 'markusro'
|
|||||||
|
|
||||||
class QABCMeta(abc.ABCMeta, QObject.__class__):
|
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
|
pass
|
||||||
|
|
||||||
|
|
||||||
class BaseContainer(QObject):
|
class BaseContainer(QObject):
|
||||||
"""
|
"""
|
||||||
This class provides placeholders (or default) methods for "container" objects.
|
This class provides placeholders (or default) methods for "container" objects.
|
||||||
@ -155,12 +163,12 @@ class BaseContainer(QObject):
|
|||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def start_parameter(self, position):
|
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
|
@abc.abstractmethod
|
||||||
def function( self, p, x ):
|
def function( self, p, x ):
|
||||||
if self._abort:
|
if self._abort:
|
||||||
raise StopIteration
|
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
114
qds.py
@ -41,12 +41,13 @@ class AppWindow(QMainWindow):
|
|||||||
self._file_paths = self._sortInputFiles(files)
|
self._file_paths = self._sortInputFiles(files)
|
||||||
self._last_written_header = None
|
self._last_written_header = None
|
||||||
|
|
||||||
|
# create action group
|
||||||
actions = {
|
actions = {
|
||||||
self.ui.actionAdd_Peak: self.addPeak,
|
self.ui.actionAdd_Peak: True,
|
||||||
self.ui.actionAdd_Cond: self.addCond,
|
self.ui.actionAdd_Cond: True,
|
||||||
self.ui.actionAdd_PowerLaw: self.addPowerComplex,
|
self.ui.actionAdd_PowerLaw: True,
|
||||||
self.ui.actionAdd_Eps_Infty: self.addEpsInfty,
|
self.ui.actionAdd_Eps_Infty: True,
|
||||||
self.ui.actionYAFF: self.addYaff,
|
self.ui.actionYAFF: True,
|
||||||
}
|
}
|
||||||
|
|
||||||
self.myActionGroup = QActionGroup(self)
|
self.myActionGroup = QActionGroup(self)
|
||||||
@ -196,7 +197,15 @@ class AppWindow(QMainWindow):
|
|||||||
|
|
||||||
if self.ui.actionAdd_Peak.isChecked():
|
if self.ui.actionAdd_Peak.isChecked():
|
||||||
if mouse_in_imag:
|
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)
|
self.ui.actionAdd_Peak.setChecked(False)
|
||||||
else:
|
else:
|
||||||
msgBox.setText("Click in imaginary part")
|
msgBox.setText("Click in imaginary part")
|
||||||
@ -204,7 +213,7 @@ class AppWindow(QMainWindow):
|
|||||||
|
|
||||||
if self.ui.actionAdd_Cond.isChecked():
|
if self.ui.actionAdd_Cond.isChecked():
|
||||||
if mouse_in_imag:
|
if mouse_in_imag:
|
||||||
self.addCond(data_pos)
|
self.addContainer(Conductivity, data_pos)
|
||||||
self.ui.actionAdd_Cond.setChecked(False)
|
self.ui.actionAdd_Cond.setChecked(False)
|
||||||
else:
|
else:
|
||||||
msgBox.setText("Click in imaginary part")
|
msgBox.setText("Click in imaginary part")
|
||||||
@ -212,7 +221,7 @@ class AppWindow(QMainWindow):
|
|||||||
|
|
||||||
if self.ui.actionYAFF.isChecked():
|
if self.ui.actionYAFF.isChecked():
|
||||||
if mouse_in_imag:
|
if mouse_in_imag:
|
||||||
self.addYaff(data_pos)
|
self.addContainer(YAFF, data_pos)
|
||||||
self.ui.actionYAFF.setChecked(False)
|
self.ui.actionYAFF.setChecked(False)
|
||||||
else:
|
else:
|
||||||
msgBox.setText("Click in imaginary part")
|
msgBox.setText("Click in imaginary part")
|
||||||
@ -220,7 +229,7 @@ class AppWindow(QMainWindow):
|
|||||||
|
|
||||||
if self.ui.actionAdd_PowerLaw.isChecked():
|
if self.ui.actionAdd_PowerLaw.isChecked():
|
||||||
if mouse_in_imag:
|
if mouse_in_imag:
|
||||||
self.addPowerComplex(data_pos)
|
self.addContainer(PowerComplex, data_pos)
|
||||||
self.ui.actionAdd_PowerLaw.setChecked(False)
|
self.ui.actionAdd_PowerLaw.setChecked(False)
|
||||||
else:
|
else:
|
||||||
msgBox.setText("Click in imaginary part")
|
msgBox.setText("Click in imaginary part")
|
||||||
@ -228,7 +237,7 @@ class AppWindow(QMainWindow):
|
|||||||
|
|
||||||
if self.ui.actionAdd_Eps_Infty.isChecked():
|
if self.ui.actionAdd_Eps_Infty.isChecked():
|
||||||
if mouse_in_real:
|
if mouse_in_real:
|
||||||
self.addEpsInfty(data_pos)
|
self.addContainer(Static, data_pos)
|
||||||
self.ui.actionAdd_Eps_Infty.setChecked(False)
|
self.ui.actionAdd_Eps_Infty.setChecked(False)
|
||||||
else:
|
else:
|
||||||
msgBox.setText("Click in real part")
|
msgBox.setText("Click in real part")
|
||||||
@ -346,89 +355,24 @@ class AppWindow(QMainWindow):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def addContainer(self, selected_container, pos):
|
||||||
#TODO: need interface/method for adding function blocks, this is too repetitive
|
_cont = selected_container(plt_real=self.ui.pgPlotWidget_real,
|
||||||
#TODO: start parameters have to be factored out for the above
|
|
||||||
def addYaff( self, pos ):
|
|
||||||
_yaff = YAFF(plt_real=self.ui.pgPlotWidget_real,
|
|
||||||
plt_imag=self.ui.pgPlotWidget_imag,
|
plt_imag=self.ui.pgPlotWidget_imag,
|
||||||
limits=self.data.fit_limits)
|
limits=self.data.fit_limits)
|
||||||
_yaff.blockSignals(True)
|
_cont.blockSignals(True)
|
||||||
_yaff.changedData.connect(self.update_plot)
|
_cont.changedData.connect(self.update_plot)
|
||||||
_yaff.removeObj.connect(self.delParamterObject)
|
_cont.removeObj.connect(self.delParamterObject)
|
||||||
gg_y = 10**pos.y()*2
|
_cont.start_parameter(pos)
|
||||||
gg_x = 1/(10**pos.x()*2*np.pi)
|
self.parameterWidget.add(_cont.widget)
|
||||||
yaff_par = [gg_y, gg_x, 20.0, 1.0, 0.5, gg_x/100, 1.0, 1.0]
|
self.function_registry.register_function(_cont)
|
||||||
_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)
|
|
||||||
self.update_plot()
|
self.update_plot()
|
||||||
|
_cont.blockSignals(False)
|
||||||
|
return _cont
|
||||||
|
|
||||||
def delParamterObject( self, obj ):
|
def delParamterObject( self, obj ):
|
||||||
self.function_registry.unregister_function(obj)
|
self.function_registry.unregister_function(obj)
|
||||||
self.update_plot()
|
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 ):
|
def fitData_start( self, method ):
|
||||||
#fit_methods = [fit_odr_cmplx, fit_odr_imag, fit_lbfgsb, fit_anneal]
|
#fit_methods = [fit_odr_cmplx, fit_odr_imag, fit_lbfgsb, fit_anneal]
|
||||||
self.fit_boundary_real.hide()
|
self.fit_boundary_real.hide()
|
||||||
|
Loading…
Reference in New Issue
Block a user