2014-04-11 15:30:48 +00:00
|
|
|
# -*- encoding: utf8 -*-
|
2014-02-25 13:55:29 +00:00
|
|
|
from PyQt4.QtGui import QColor
|
2014-04-07 11:41:39 +00:00
|
|
|
import numpy as np
|
2014-04-11 07:29:32 +00:00
|
|
|
import pyqtgraph as pg
|
2014-03-19 18:51:06 +00:00
|
|
|
|
2014-04-15 13:44:15 +00:00
|
|
|
from Mathlib import FitFunctionCreator
|
|
|
|
|
2014-04-11 07:29:32 +00:00
|
|
|
|
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))
|
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-11 07:29:32 +00:00
|
|
|
|