qdsfit/data/experimental.py

74 lines
3.1 KiB
Python

# -*- encoding: utf8 -*-
from PyQt4.QtGui import QColor
import numpy as np
import pyqtgraph as pg
from libmath.BDSlib import FitFunctionCreator
class Data:
def __init__( self, frequency=np.zeros(1), die_real=np.zeros(1), die_imag=np.zeros(1) ):
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=2.5, color=(255, 255, 127))
myPen_real = pg.mkPen(width=2.5, color=(51, 255, 127))
self.experimental_curve_imag = pg.PlotDataItem(x=[np.nan], y=[np.nan],
pen=None,
symbol='o',
symbolBrush=(255, 127, 0, 127))
self.experimental_curve_real = pg.PlotDataItem(x=[np.nan], y=[np.nan],
pen=QColor(0, 0, 0, 0),
symbol='o',
symbolBrush=(119, 202, 92, 127))
self.model_curve_imag = pg.PlotDataItem(x=[np.nan], y=[np.nan], pen=myPen_imag)
self.model_curve_real = pg.PlotDataItem(x=[np.nan], y=[np.nan], pen=myPen_real)
self.length = len(frequency)
self.meta = dict()
self.fit_limits = [frequency.min(), frequency.max(), die_imag.min(), die_imag.max()]
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.experimental_curve_imag.setData(f, e_imag)
self.experimental_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
def get_data( self ):
# mask = np.ones(len(self.frequency), dtype='bool')
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])
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()