qdsfit/data.py

69 lines
2.8 KiB
Python
Raw Normal View History

# -*- encoding: utf8 -*-
from PyQt4.QtGui import QColor
import numpy as np
import pyqtgraph as pg
2014-03-19 18:51:06 +00:00
from BDSMathlib import FitFunctionCreator
2013-06-14 06:44:34 +00:00
class Data:
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
self.epsilon = die_real + 1j * die_imag
self.frequency_fit = frequency[:]
self.epsilon_fit = die_real[:]*0 + 1j * die_imag[:]*0
myPen_imag = pg.mkPen(width=3, color=(255,255,127))
myPen_real = pg.mkPen(width=3, color=(51,255,127))
self.data_curve_imag = pg.PlotDataItem(x=[np.nan], y=[np.nan],pen=QColor(0,0,0,0), symbol='o',
symbolBrush=(255,127,0,127))
self.data_curve_real = pg.PlotDataItem(x=[np.nan], y=[np.nan],pen=QColor(0,0,0,0), symbol='s',
symbolBrush=(119,202,92,127))
self.fitted_curve_imag = pg.PlotDataItem(x=[np.nan], y=[np.nan], pen=myPen_imag)
self.fitted_curve_real = pg.PlotDataItem(x=[np.nan], y=[np.nan], pen=myPen_real)
2013-06-14 06:44:34 +00:00
self.length = len(frequency)
self.meta = dict()
self.fit_limits = [frequency.min(), frequency.max(), die_imag.min(), die_imag.max()]
2013-06-14 06:44:34 +00:00
self.fit_param = None
self.fit_funcs = None # list of fit functions
self.hide_funcs = None # remove these func from the data
def set_fit(self, param, funcs):
self.fit_funcs = funcs
self.hide_funcs = []
self.fit_param = param
fit_real, fit_imag = FitFunctionCreator().fitfcn(param, self.frequency_fit, *funcs)
self.epsilon_fit = fit_real+1j*fit_imag
def set_data(self,f,e_real,e_imag):
self.frequency = f
self.frequency_fit = f[:]
self.epsilon = e_real + 1j*e_imag
self.epsilon_fit = 0*e_real + 1j*e_imag*0
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
self.frequency_fit = self.frequency[(self.frequency <= xmax) & (self.frequency >= xmin)]
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):
#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])
#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):
print "remove data_curve"
#if self.data_curve is not None: self.data_curve.remove()
print "remove fitted_curve"
#if self.fitted_curve is not None: self.fitted_curve.remove()