further reorganization
This commit is contained in:
@ -11,8 +11,6 @@ from container_base import BaseContainer
|
||||
import gui.container_widgets
|
||||
|
||||
|
||||
|
||||
|
||||
__author__ = 'markusro'
|
||||
|
||||
|
||||
@ -44,7 +42,6 @@ class PowerComplex(BaseContainer):
|
||||
self.param_number = 2
|
||||
|
||||
def function( self, p, x ):
|
||||
BaseContainer.function(self, p, x)
|
||||
om = 2*np.pi*x
|
||||
sgma, n = p
|
||||
power = sgma/(om*1j)**n
|
||||
@ -62,7 +59,6 @@ class Static(BaseContainer):
|
||||
self.param_number = 1
|
||||
|
||||
def function( self, p, x ):
|
||||
BaseContainer.function(self, p, x)
|
||||
eps_inf = p[0]
|
||||
static = np.ones((2, x.size))*eps_inf
|
||||
static[1, :] *= 0 # set imag part zero
|
||||
@ -82,7 +78,6 @@ class Peak(BaseContainer):
|
||||
self.param_number = 4
|
||||
|
||||
def function( self, p, x ):
|
||||
BaseContainer.function(self, p, x)
|
||||
eps, t, a, b = p
|
||||
om = 2*np.pi*x
|
||||
hn = eps/(1+(1j*om*t)**a)**b
|
||||
@ -124,7 +119,6 @@ class YAFF(BaseContainer):
|
||||
self.update_data()
|
||||
|
||||
def function( self, p, x ):
|
||||
BaseContainer.function(self, p, x)
|
||||
ya = self._libyaff.loss(p, x)
|
||||
cplx = np.array([ya.imag, ya.real])
|
||||
return cplx
|
@ -3,24 +3,30 @@ from PyQt4.QtGui import QColor
|
||||
import numpy as np
|
||||
import pyqtgraph as pg
|
||||
|
||||
|
||||
__author__ = 'markusro'
|
||||
|
||||
|
||||
class BaseContainer(QObject):
|
||||
"""
|
||||
This class provides placeholders (or default) methods for "container" objects.
|
||||
These objects are basically the different fit elements for dielectric spectroscopy.
|
||||
"""
|
||||
# TODO generalize the base class so that we can use plugins (self-contained fit functions)
|
||||
changedData = pyqtSignal()
|
||||
removeObj = pyqtSignal(QObject)
|
||||
|
||||
def __init__(self, plt_real=None, plt_imag=None, limits=None):
|
||||
def __init__( self, plt_real=None, plt_imag=None, limits=None ):
|
||||
super(BaseContainer, self).__init__()
|
||||
|
||||
myPen = pg.mkPen( style=Qt.DotLine,
|
||||
width=2.5)
|
||||
myPen = pg.mkPen(style=Qt.DotLine,
|
||||
width=2.5)
|
||||
|
||||
self.data_curve_real = pg.PlotDataItem(x=np.array([np.nan]),y=np.array([np.nan]), pen=myPen)
|
||||
self.data_curve_real = pg.PlotDataItem(x=np.array([np.nan]), y=np.array([np.nan]), pen=myPen)
|
||||
self.plt_real = plt_real
|
||||
self.plt_real.addItem(self.data_curve_real)
|
||||
|
||||
self.data_curve_imag = pg.PlotDataItem(x=np.array([np.nan]),y=np.array([np.nan]), pen=myPen)
|
||||
self.data_curve_imag = pg.PlotDataItem(x=np.array([np.nan]), y=np.array([np.nan]), pen=myPen)
|
||||
self.plt_imag = plt_imag
|
||||
self.plt_imag.addItem(self.data_curve_imag)
|
||||
|
||||
@ -41,65 +47,63 @@ class BaseContainer(QObject):
|
||||
self._param_number = 0
|
||||
self._abort = False
|
||||
|
||||
def set_limits(self, limits):
|
||||
def set_limits( self, limits ):
|
||||
self.limits = limits
|
||||
self.update_data()
|
||||
|
||||
@pyqtSlot(bool)
|
||||
def abort(self, abort=False):
|
||||
def abort( self, abort=False ):
|
||||
self._abort = abort
|
||||
|
||||
@property
|
||||
def param_number(self):
|
||||
def param_number( self ):
|
||||
return self._param_number
|
||||
|
||||
@param_number.setter
|
||||
def param_number(self, num):
|
||||
def param_number( self, num ):
|
||||
self._param_number = num
|
||||
|
||||
@property
|
||||
def id_string(self):
|
||||
def id_string( self ):
|
||||
return self._id_string
|
||||
|
||||
@id_string.setter
|
||||
def id_string(self, id):
|
||||
#self._func = self.functions.get_function(id)
|
||||
self._id_string = id
|
||||
def id_string( self, id ):
|
||||
# self._func = self.functions.get_function(id)
|
||||
self._id_string = id
|
||||
|
||||
|
||||
@property
|
||||
def id_label(self):
|
||||
def id_label( self ):
|
||||
return self._id_label
|
||||
|
||||
@id_label.setter
|
||||
def id_label(self, id):
|
||||
#self._func = self.functions.get_function(id)
|
||||
self._func = self.function
|
||||
self._id_label = id
|
||||
def id_label( self, id ):
|
||||
self._id_label = id
|
||||
|
||||
@property
|
||||
def color(self):
|
||||
def color( self ):
|
||||
return self._color
|
||||
|
||||
@color.setter
|
||||
def color(self, c):
|
||||
def color( self, c ):
|
||||
self._color = c
|
||||
self.data_curve_real.setPen(color=c, style=Qt.DotLine, width=2.5)
|
||||
self.data_curve_imag.setPen(color=c, style=Qt.DotLine, width=2.5)
|
||||
|
||||
@property
|
||||
def widget(self):
|
||||
def widget( self ):
|
||||
return self._widget
|
||||
|
||||
@widget.setter
|
||||
def widget(self, wdgt):
|
||||
def widget( self, wdgt ):
|
||||
self._widget = wdgt
|
||||
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 get_parameter( self ):
|
||||
p = self.widget.getTable() # TODO ugly ... should return self._beta etc ...?
|
||||
p = self.widget.getTable() # TODO ugly ... should return self._beta etc ...?
|
||||
return p
|
||||
|
||||
def get_fixed( self ):
|
||||
@ -107,15 +111,15 @@ class BaseContainer(QObject):
|
||||
return p
|
||||
|
||||
def set_parameter( self, beta, sd_beta=None ):
|
||||
self._beta = beta
|
||||
self._beta = beta
|
||||
self._sd_beta = sd_beta
|
||||
self.widget.update_table(beta, sd_beta)
|
||||
self.update_data()
|
||||
|
||||
def get_data(self):
|
||||
def get_data( self ):
|
||||
return self._frequency, self._data
|
||||
|
||||
def removeMe(self):
|
||||
def removeMe( self ):
|
||||
self.plt_imag.removeItem(self.data_curve_imag)
|
||||
self.plt_real.removeItem(self.data_curve_real)
|
||||
self.removeObj.emit(self)
|
||||
@ -123,20 +127,27 @@ class BaseContainer(QObject):
|
||||
|
||||
def update_data( self ):
|
||||
self._frequency = np.logspace(np.log10(self.limits[0]), np.log10(self.limits[1]), 256)
|
||||
self._data = self._func(self.get_parameter(), self._frequency)
|
||||
self._data = self.function(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.get_parameter(), x)
|
||||
return np.array([x,data[0],data[1]]).T
|
||||
def resampleData( self, x ):
|
||||
data = self.function(self.get_parameter(), x)
|
||||
return np.array([x, data[0], data[1]]).T
|
||||
|
||||
def subtractMe(self, flag):
|
||||
print "subtract"
|
||||
self._data = -self._data
|
||||
self.changedData.emit()
|
||||
|
||||
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])
|
||||
|
||||
def function(self,p,x):
|
||||
if self._abort: raise StopIteration
|
||||
#raise NotImplementedError, "This needs to be implemented in your subclass"
|
||||
def function( self, p, x ):
|
||||
if self._abort:
|
||||
raise StopIteration
|
||||
raise NotImplementedError, "This needs to be implemented in your subclass"
|
||||
|
||||
|
||||
|
21
data/data.py
Normal file
21
data/data.py
Normal file
@ -0,0 +1,21 @@
|
||||
from PyQt4.QtCore import QObject, pyqtSignal
|
||||
|
||||
__author__ = 'markusro'
|
||||
|
||||
|
||||
class Daten(QObject):
|
||||
data_changed_signal = pyqtSignal(list, list, list)
|
||||
|
||||
def __init__(self, x=None, y_real=None, y_imag=None):
|
||||
super(Daten, self).__init__(None)
|
||||
self._data = (x, y_real, y_imag)
|
||||
|
||||
def get_data(self):
|
||||
return self._data
|
||||
|
||||
def set_data(self, x, y_real, y_imag):
|
||||
if len(x) == len(y_real) == len(y_imag):
|
||||
self._data = (x, y_real, y_imag)
|
||||
self.data_changed_signal.emit(list(x), list(y_real), list(y_imag))
|
||||
else:
|
||||
raise AttributeError("Inhomogeneous data size x,real,imag: %i,%i,%i"(len(x), len(y_real), len(y_imag)))
|
@ -16,7 +16,7 @@ class Data:
|
||||
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),
|
||||
pen=None,
|
||||
symbol='o',
|
||||
symbolBrush=(255, 127, 0, 127))
|
||||
self.experimental_curve_real = pg.PlotDataItem(x=[np.nan], y=[np.nan],
|
||||
|
Reference in New Issue
Block a user