2014-04-14 12:01:45 +00:00
|
|
|
# -*- encoding: utf8 -*-
|
|
|
|
|
|
|
|
from PyQt4.QtGui import QColor
|
|
|
|
import numpy as np
|
2014-09-24 18:46:23 +00:00
|
|
|
|
2015-01-08 15:47:13 +00:00
|
|
|
from libmath import yafflib, functions
|
2014-09-25 15:14:50 +00:00
|
|
|
|
2014-09-24 20:07:14 +00:00
|
|
|
from libmath.BDSlib import id_to_color
|
2014-09-25 15:14:50 +00:00
|
|
|
from container_base import BaseContainer
|
|
|
|
|
2014-09-28 19:16:06 +00:00
|
|
|
import gui.container_widgets
|
2014-09-25 15:14:50 +00:00
|
|
|
|
|
|
|
|
2014-04-14 12:01:45 +00:00
|
|
|
__author__ = 'markusro'
|
|
|
|
|
2015-01-08 15:47:13 +00:00
|
|
|
# FIXME: why are the functions implemented again? Better to use function_library!!
|
2014-09-25 15:14:50 +00:00
|
|
|
class Conductivity(BaseContainer):
|
2014-04-14 12:01:45 +00:00
|
|
|
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)
|
2014-09-28 19:16:06 +00:00
|
|
|
self.widget = gui.container_widgets.ConductivityWidget()
|
2014-04-14 12:01:45 +00:00
|
|
|
self.color = QColor("blue")
|
|
|
|
self.id_label = "Cond."
|
|
|
|
self.id_string = "cond"
|
|
|
|
|
|
|
|
self.param_number = 3
|
2015-01-08 15:47:13 +00:00
|
|
|
def function(self, p ,x):
|
|
|
|
return functions.cond_cmplx(p,x)
|
|
|
|
|
|
|
|
# def function( self, p, x ):
|
|
|
|
# om = 2*np.pi*x
|
|
|
|
# sgma, isgma, n = p
|
|
|
|
# cond = sgma/(om**n)+isgma/(1j*om**n) # Jonscher (Universal Dielectric Response: e",e' prop sigma/omega**n
|
|
|
|
# cplx = np.array([cond.real, -cond.imag])
|
|
|
|
# return cplx
|
2014-04-14 12:01:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-25 15:14:50 +00:00
|
|
|
class PowerComplex(BaseContainer):
|
2014-04-14 12:01:45 +00:00
|
|
|
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)
|
2014-09-28 19:16:06 +00:00
|
|
|
self.widget = gui.container_widgets.PowerLawWidget()
|
2014-04-14 12:01:45 +00:00
|
|
|
self.color = QColor("#ff44c4")
|
|
|
|
self.id_label = 'Power Law'
|
|
|
|
self.id_string = "pwr"
|
|
|
|
self.param_number = 2
|
|
|
|
|
|
|
|
def function( self, p, x ):
|
|
|
|
om = 2*np.pi*x
|
2014-09-25 15:14:50 +00:00
|
|
|
sgma, n = p
|
2014-04-14 12:01:45 +00:00
|
|
|
power = sgma/(om*1j)**n
|
|
|
|
cplx = np.array([power.real, -power.imag])
|
|
|
|
return cplx
|
|
|
|
|
|
|
|
|
2014-09-25 15:14:50 +00:00
|
|
|
class Static(BaseContainer):
|
2014-04-14 12:01:45 +00:00
|
|
|
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)
|
2014-09-28 19:16:06 +00:00
|
|
|
self.widget = gui.container_widgets.StaticWidget()
|
2014-04-14 12:01:45 +00:00
|
|
|
self.color = QColor('#FF0F13')
|
|
|
|
self.id_label = u'ε(∞)'
|
|
|
|
self.id_string = "eps_infty"
|
|
|
|
self.param_number = 1
|
|
|
|
|
|
|
|
def function( self, p, x ):
|
|
|
|
eps_inf = p[0]
|
2014-09-25 15:14:50 +00:00
|
|
|
static = np.ones((2, x.size))*eps_inf
|
|
|
|
static[1, :] *= 0 # set imag part zero
|
2014-04-14 12:01:45 +00:00
|
|
|
return static
|
|
|
|
|
|
|
|
|
2014-09-25 15:14:50 +00:00
|
|
|
class Peak(BaseContainer):
|
2014-04-14 12:01:45 +00:00
|
|
|
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)
|
2014-09-28 19:16:06 +00:00
|
|
|
self.widget = gui.container_widgets.PeakWidget()
|
2014-04-14 12:01:45 +00:00
|
|
|
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 function( self, p, x ):
|
2014-09-25 15:14:50 +00:00
|
|
|
eps, t, a, b = p
|
2014-04-14 12:01:45 +00:00
|
|
|
om = 2*np.pi*x
|
|
|
|
hn = eps/(1+(1j*om*t)**a)**b
|
|
|
|
cplx = np.array([hn.real, -hn.imag])
|
|
|
|
return cplx
|
|
|
|
|
|
|
|
|
2014-09-25 15:14:50 +00:00
|
|
|
class YAFF(BaseContainer):
|
2014-04-14 12:01:45 +00:00
|
|
|
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)
|
2014-09-28 19:16:06 +00:00
|
|
|
self.widget = gui.container_widgets.YaffWidget()
|
2014-04-14 12:01:45 +00:00
|
|
|
self.widget.on_model_changed.connect(self.change_model)
|
2014-04-15 13:44:15 +00:00
|
|
|
self.widget.configuration_changed.connect(self.change_configuration)
|
2014-04-14 12:01:45 +00:00
|
|
|
self.color = QColor(32, 120, 29, int(255*0.82))
|
2014-09-24 20:07:14 +00:00
|
|
|
self._libyaff = yafflib.Yaff(self.widget.getYaffType())
|
2014-04-14 12:01:45 +00:00
|
|
|
self.id_label = self._libyaff.label
|
|
|
|
self.id_string = "yaff"
|
|
|
|
self._param_number = self._libyaff.params
|
|
|
|
self._selector_mask = self.widget.selector_mask
|
|
|
|
|
|
|
|
@property
|
2014-09-25 15:14:50 +00:00
|
|
|
def param_number( self ):
|
2014-04-14 12:01:45 +00:00
|
|
|
return self._param_number
|
|
|
|
|
|
|
|
@param_number.setter
|
2014-09-25 15:14:50 +00:00
|
|
|
def param_number( self, num=None ):
|
2014-04-14 12:01:45 +00:00
|
|
|
self._param_number = self._libyaff.params
|
|
|
|
|
2014-09-25 15:14:50 +00:00
|
|
|
def change_configuration( self, t_list, tau_list ):
|
2014-04-15 13:44:15 +00:00
|
|
|
self._libyaff.dist_tau = tau_list
|
|
|
|
self._libyaff.time_points = t_list
|
2014-09-28 19:16:06 +00:00
|
|
|
self.update_data()
|
2014-04-15 13:44:15 +00:00
|
|
|
|
2014-09-25 15:14:50 +00:00
|
|
|
def change_model( self ):
|
2014-09-24 20:07:14 +00:00
|
|
|
self._libyaff = yafflib.Yaff(self.widget.getYaffType())
|
2014-04-14 12:01:45 +00:00
|
|
|
self._selector_mask = self.widget.selector_mask
|
|
|
|
self.id_label = self._libyaff.label
|
|
|
|
self.param_number = self._libyaff.params
|
2014-09-28 19:16:06 +00:00
|
|
|
self.update_data()
|
2014-04-14 12:01:45 +00:00
|
|
|
|
|
|
|
def function( self, p, x ):
|
2014-09-25 15:14:50 +00:00
|
|
|
ya = self._libyaff.loss(p, x)
|
2014-04-14 12:01:45 +00:00
|
|
|
cplx = np.array([ya.imag, ya.real])
|
|
|
|
return cplx
|