qdsfit/data/Container.py
Markus Rosenstihl ae30438737 generalized addPeak, addYAFF, addCond, etc.
to addContainer(container,data_pos)

fixed action group
2015-01-08 18:17:43 +01:00

140 lines
4.6 KiB
Python

# -*- encoding: utf8 -*-
from PyQt4.QtGui import QColor
import numpy as np
from libmath import yafflib, functions
from libmath.BDSlib import id_to_color
from container_base import BaseContainer
import gui.container_widgets
__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.container_widgets.ConductivityWidget()
self.color = QColor("blue")
self.id_label = "Cond."
self.id_string = "cond"
self.param_number = 3
def function(self, p ,x):
if self._abort:
raise StopIteration
return functions.cond_cmplx(p,x)
def start_parameter(self, pos):
cond_par = [0.0, 10**(pos.y()+pos.x())*2*np.pi, 1.0]
self.set_parameter(beta=cond_par)
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.container_widgets.PowerLawWidget()
self.color = QColor("#ff44c4")
self.id_label = 'Power Law'
self.id_string = "pwr"
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):
cond_par = [10**(pos.y()+pos.x())*2*np.pi, 1.0]
self.set_parameter(cond_par)
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.container_widgets.StaticWidget()
self.color = QColor('#FF0F13')
self.id_label = u'ε(∞)'
self.id_string = "eps_infty"
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):
cond_par = [10**position.y()]
self.set_parameter(beta=cond_par)
class Peak(BaseContainer):
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.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):
new_peak_beta0 = [2*10**pos.y(), 1/(2*np.pi*10**pos.x()), 1, 1]
self.set_parameter(beta=new_peak_beta0)
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.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))
self._libyaff = yafflib.Yaff(self.widget.getYaffType())
self.id_label = self._libyaff.label
self.id_string = "yaff"
self._param_number = self._libyaff.params
self._selector_mask = self.widget.selector_mask
@property
def param_number( self ):
return self._param_number
@param_number.setter
def param_number( self, num=None ):
self._param_number = self._libyaff.params
def change_configuration( self, t_list, tau_list ):
self._libyaff.dist_tau = tau_list
self._libyaff.time_points = t_list
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.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
def start_parameter(self, pos):
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]
self.set_parameter(yaff_par)