2014-02-25 13:55:29 +00:00
|
|
|
from PyQt4.QtCore import QObject, pyqtSignal, Qt
|
|
|
|
from PyQt4.QtGui import QColor
|
2014-04-07 11:41:39 +00:00
|
|
|
import numpy as np
|
2014-03-19 18:51:06 +00:00
|
|
|
|
2014-03-19 18:48:15 +00:00
|
|
|
import CustomWidgets
|
2014-03-19 18:51:06 +00:00
|
|
|
|
2014-02-25 13:55:29 +00:00
|
|
|
import pyqtgraph as pg
|
|
|
|
from PyQt4.QtCore import *
|
2014-03-19 21:02:26 +00:00
|
|
|
from mathlib import id_to_color, hn, FitFunctionCreator, Functions
|
2013-07-10 16:36:07 +00:00
|
|
|
|
2013-06-14 06:44:34 +00:00
|
|
|
class Data:
|
2014-04-07 11:41:39 +00:00
|
|
|
def __init__(self, frequency=np.zeros(1), die_real=np.zeros(1), die_imag=np.zeros(1)):
|
2013-06-14 06:44:34 +00:00
|
|
|
self.frequency = frequency
|
2013-07-10 16:36:07 +00:00
|
|
|
self.epsilon = die_real + 1j * die_imag
|
2014-03-20 14:15:40 +00:00
|
|
|
self.frequency_fit = frequency
|
2014-02-25 13:55:29 +00:00
|
|
|
self.epsilon_fit = die_real*0 + 1j * die_imag*0
|
2014-03-05 17:30:00 +00:00
|
|
|
myPen_imag = pg.mkPen(width=3, color=(255,255,127))
|
2014-03-20 13:30:19 +00:00
|
|
|
myPen_real = pg.mkPen(width=3, color=(51,255,127))
|
|
|
|
#33FF00
|
2014-02-25 13:55:29 +00:00
|
|
|
|
2014-04-07 11:41:39 +00:00
|
|
|
self.data_curve_imag = pg.PlotDataItem(x=[np.nan], y=[np.nan],pen=QColor(0,0,0,0), symbol='o',
|
2014-03-05 15:59:35 +00:00
|
|
|
symbolBrush=(255,127,0,127))
|
2014-04-07 11:41:39 +00:00
|
|
|
self.data_curve_real = pg.PlotDataItem(x=[np.nan], y=[np.nan],pen=QColor(0,0,0,0), symbol='s',
|
2014-03-18 18:48:39 +00:00
|
|
|
symbolBrush=(119,202,92,127))
|
2014-04-07 11:41:39 +00:00
|
|
|
self.fitted_curve_imag = pg.PlotDataItem(np.array([np.nan]), np.array([np.nan]), pen=myPen_imag)
|
|
|
|
self.fitted_curve_real = pg.PlotDataItem(np.array([np.nan]), np.array([np.nan]), pen=myPen_real)
|
2013-06-14 06:44:34 +00:00
|
|
|
self.length = len(frequency)
|
|
|
|
self.meta = dict()
|
2014-03-05 15:59:35 +00:00
|
|
|
self.fit_limits = [frequency.min(), frequency.max(), die_imag.min(), die_imag.max()]
|
2013-06-14 06:44:34 +00:00
|
|
|
|
2014-03-05 17:30:00 +00:00
|
|
|
self.fit_param = None
|
2014-04-03 18:56:50 +00:00
|
|
|
self.fit_funcs = None # list of fit functions
|
|
|
|
self.hide_funcs = None # remove these func from the data
|
2014-03-05 17:30:00 +00:00
|
|
|
|
|
|
|
def set_fit(self, param, funcs):
|
|
|
|
self.fit_funcs = funcs
|
2014-04-03 18:56:50 +00:00
|
|
|
self.hide_funcs = []
|
2014-03-05 17:30:00 +00:00
|
|
|
self.fit_param = param
|
2014-03-20 14:15:40 +00:00
|
|
|
fit_real, fit_imag = FitFunctionCreator().fitfcn(param, self.frequency_fit, *funcs)
|
2014-03-05 17:30:00 +00:00
|
|
|
self.epsilon_fit = fit_real + 1j*fit_imag
|
|
|
|
|
2014-02-25 13:55:29 +00:00
|
|
|
def set_data(self,f,e_real,e_imag):
|
|
|
|
self.frequency = f
|
|
|
|
self.epsilon = e_real + 1j*e_imag
|
|
|
|
self.epsilon_fit = 0*e_real + 1j*e_imag*0
|
2014-03-05 15:59:35 +00:00
|
|
|
self.fit_limits = [f.min(), f.max(), e_imag.min(), e_imag.max()]
|
|
|
|
self.data_curve_imag.setData(f,e_imag)
|
|
|
|
self.data_curve_real.setData(f,e_real)
|
|
|
|
|
|
|
|
def set_fit_xlimits(self, xmin, xmax):
|
|
|
|
self.fit_limits[0] = xmin
|
|
|
|
self.fit_limits[1] = xmax
|
2014-03-20 14:15:40 +00:00
|
|
|
self.frequency_fit = self.frequency[(self.frequency <= xmax) & (self.frequency >= xmin)]
|
2014-03-05 15:59:35 +00:00
|
|
|
|
|
|
|
def set_fit_ylimits(self, ymin, ymax):
|
|
|
|
self.fit_limits[2] = ymin
|
|
|
|
self.fit_limits[3] = ymax
|
|
|
|
|
2013-06-14 06:44:34 +00:00
|
|
|
def get_data(self):
|
2014-04-07 11:41:39 +00:00
|
|
|
#mask = np.ones(len(self.frequency), dtype='bool')
|
2013-06-14 06:44:34 +00:00
|
|
|
mask = (self.frequency > self.fit_limits[0]) & (self.frequency < self.fit_limits[1])
|
2014-03-18 18:48:39 +00:00
|
|
|
#mask &= (self.epsilon.imag > self.fit_limits[2]) & (self.epsilon.imag < self.fit_limits[3])
|
2013-06-14 06:44:34 +00:00
|
|
|
return self.frequency[mask], self.epsilon[mask]
|
|
|
|
|
|
|
|
def remove_curves(self):
|
2013-07-12 14:11:29 +00:00
|
|
|
print "remove data_curve"
|
2014-02-25 13:55:29 +00:00
|
|
|
#if self.data_curve is not None: self.data_curve.remove()
|
2013-07-12 14:11:29 +00:00
|
|
|
print "remove fitted_curve"
|
2014-02-25 13:55:29 +00:00
|
|
|
#if self.fitted_curve is not None: self.fitted_curve.remove()
|
2013-07-10 16:36:07 +00:00
|
|
|
|
2014-04-03 18:56:50 +00:00
|
|
|
class BaseObject(QObject):
|
2013-07-10 16:36:07 +00:00
|
|
|
changedData = pyqtSignal()
|
2014-03-19 23:35:07 +00:00
|
|
|
removeObj = pyqtSignal(QObject)
|
2014-03-20 13:30:19 +00:00
|
|
|
|
2014-04-03 18:56:50 +00:00
|
|
|
def __init__(self, plt_real=None, plt_imag=None, limits=None):
|
|
|
|
super(BaseObject, self).__init__()
|
2013-07-10 16:36:07 +00:00
|
|
|
|
2014-04-03 18:56:50 +00:00
|
|
|
myPen = pg.mkPen( style=Qt.DotLine,
|
|
|
|
width=2.5)
|
2014-03-19 21:02:26 +00:00
|
|
|
|
2014-04-07 11:41:39 +00:00
|
|
|
self.data_curve_real = pg.PlotDataItem(x=np.array([np.nan]),y=np.array([np.nan]), pen=myPen)
|
2014-03-20 13:30:19 +00:00
|
|
|
self.plt_real = plt_real
|
2014-04-03 18:56:50 +00:00
|
|
|
self.plt_real.addItem(self.data_curve_real)
|
2014-02-25 13:55:29 +00:00
|
|
|
|
2014-04-07 11:41:39 +00:00
|
|
|
self.data_curve_imag = pg.PlotDataItem(x=np.array([np.nan]),y=np.array([np.nan]), pen=myPen)
|
2014-04-03 18:56:50 +00:00
|
|
|
self.plt_imag = plt_imag
|
2014-03-20 13:30:19 +00:00
|
|
|
self.plt_imag.addItem(self.data_curve_imag)
|
2014-04-03 18:56:50 +00:00
|
|
|
|
2014-02-25 13:55:29 +00:00
|
|
|
self.limits = limits
|
|
|
|
|
2014-04-07 11:41:39 +00:00
|
|
|
# private varaibles
|
|
|
|
self.functions = Functions()
|
|
|
|
#self.functions.step_signal.connect(self.test) # TODO
|
2014-04-03 18:56:50 +00:00
|
|
|
self._color = QColor("white")
|
2014-04-07 11:41:39 +00:00
|
|
|
self._id = None
|
|
|
|
self._widget = None
|
|
|
|
self._frequency = np.logspace(np.log10(limits[0]), np.log10(limits[1]), 256)
|
|
|
|
self._data = None
|
|
|
|
self._func = None
|
|
|
|
|
|
|
|
def test(self,p):
|
|
|
|
print "found:",p
|
|
|
|
|
|
|
|
@property
|
|
|
|
def id_string(self):
|
|
|
|
return self._id
|
|
|
|
|
|
|
|
@id_string.setter
|
|
|
|
def id_string(self, id):
|
|
|
|
self._func = self.functions.get_function(id)
|
|
|
|
self._id = id
|
2014-04-03 18:56:50 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def color(self):
|
|
|
|
return self._color
|
|
|
|
|
|
|
|
@color.setter
|
|
|
|
def color(self, c):
|
|
|
|
self._color = c
|
|
|
|
self.data_curve_real.setPen(c)
|
|
|
|
self.data_curve_imag.setPen(c)
|
2013-07-10 16:36:07 +00:00
|
|
|
|
2014-04-07 11:41:39 +00:00
|
|
|
@property
|
|
|
|
def widget(self):
|
|
|
|
return self._widget
|
|
|
|
|
|
|
|
@widget.setter
|
|
|
|
def widget(self, wdgt):
|
|
|
|
self._widget = wdgt
|
|
|
|
self._widget.changedTable.connect(self.updateData)
|
|
|
|
self._widget.removeMe.connect(self.removeMe)
|
2013-07-10 16:36:07 +00:00
|
|
|
|
|
|
|
def getParameter(self):
|
|
|
|
p = self.widget.getTable()
|
|
|
|
return p
|
|
|
|
|
|
|
|
def getFixed(self):
|
|
|
|
p = self.widget.fixedParameter()
|
|
|
|
return p
|
|
|
|
|
2014-03-19 18:48:15 +00:00
|
|
|
def setParameter(self, beta, sd_beta=None):
|
|
|
|
self.widget.updateTable(beta, sd_beta)
|
2013-07-10 16:36:07 +00:00
|
|
|
self.updateData()
|
|
|
|
|
2014-03-19 21:02:26 +00:00
|
|
|
def get_data(self):
|
2014-04-07 11:41:39 +00:00
|
|
|
return self._frequency, self._data
|
2014-02-25 13:55:29 +00:00
|
|
|
|
2014-03-19 21:02:26 +00:00
|
|
|
def removeMe(self):
|
2014-03-20 13:30:19 +00:00
|
|
|
self.plt_imag.removeItem(self.data_curve_imag)
|
|
|
|
self.plt_real.removeItem(self.data_curve_real)
|
2014-03-19 23:35:07 +00:00
|
|
|
self.removeObj.emit(self)
|
|
|
|
self.changedData.emit()
|
2014-03-19 21:02:26 +00:00
|
|
|
|
2014-04-07 11:41:39 +00:00
|
|
|
def updateData(self):
|
|
|
|
self._data = self._func(self.getParameter(), 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()
|
2014-03-19 21:02:26 +00:00
|
|
|
|
2014-04-03 18:56:50 +00:00
|
|
|
class Conductivity(BaseObject):
|
|
|
|
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 = CustomWidgets.ConductivityWidget()
|
|
|
|
self.color = QColor("blue")
|
|
|
|
self.id_string = "conductivity"
|
2014-03-19 21:02:26 +00:00
|
|
|
|
2014-04-03 18:56:50 +00:00
|
|
|
class PowerComplex(BaseObject):
|
|
|
|
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 = CustomWidgets.PowerLawWidget()
|
|
|
|
self.color = QColor("#ff44c4")
|
|
|
|
self.id_string = 'power'
|
2014-03-19 21:02:26 +00:00
|
|
|
|
2014-04-03 18:56:50 +00:00
|
|
|
class Static(BaseObject):
|
2014-03-20 13:30:19 +00:00
|
|
|
def __init__( self, plt_real=None, plt_imag=None, limits=None ):
|
2014-04-03 18:56:50 +00:00
|
|
|
super(Static, self).__init__(plt_real=plt_real, plt_imag=plt_imag, limits=limits)
|
2014-03-19 23:35:07 +00:00
|
|
|
self.widget = CustomWidgets.StaticWidget()
|
2014-04-03 18:56:50 +00:00
|
|
|
self.color = QColor('#FF0F13')
|
2014-03-19 23:35:07 +00:00
|
|
|
self.id_string = 'static'
|
|
|
|
|
2014-04-03 18:56:50 +00:00
|
|
|
class Peak(BaseObject):
|
2014-03-20 13:30:19 +00:00
|
|
|
def __init__( self, id_num=None, plt_real=None, plt_imag=None, limits=None ):
|
2014-04-03 18:56:50 +00:00
|
|
|
super(Peak, self).__init__(plt_real=plt_real, plt_imag=plt_imag, limits=limits)
|
2014-03-19 18:48:15 +00:00
|
|
|
self.widget = CustomWidgets.PeakWidget()
|
2014-04-07 11:41:39 +00:00
|
|
|
self.widget.setColor(self.color)
|
2014-03-20 13:30:19 +00:00
|
|
|
self.widget.setId(id_num)
|
|
|
|
self.color = id_to_color(id_num)
|
|
|
|
self.id_num = id_num
|
2014-03-19 21:02:26 +00:00
|
|
|
self.id_string = "hn"
|
2014-02-25 13:55:29 +00:00
|
|
|
|
2014-04-03 18:56:50 +00:00
|
|
|
class YAFF(BaseObject):
|
|
|
|
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 = CustomWidgets.YaffWidget()
|
|
|
|
self.id_string = "yaff"
|
2014-03-19 23:35:07 +00:00
|
|
|
|