more cleanup

This commit is contained in:
Markus Rosenstihl 2014-09-24 21:42:06 +02:00
parent 97cdf4ecb2
commit 737be85ee1
8 changed files with 152 additions and 145 deletions

9
QDS.py
View File

@ -1,5 +1,6 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
from gui import ExtraDifferentialWidget
_author_ = "Markus Rosenstihl"
@ -21,11 +22,11 @@ from PyQt4.QtGui import *
import numpy as np
import pyqtgraph as pg
from Container import Conductivity, PowerComplex, Static, Peak, YAFF
from ContainerWidgets import ParameterWidget
from ui import QDSMain, ExtraDifferentialWidget
from data.container import Conductivity, PowerComplex, Static, Peak, YAFF
from gui.ContainerWidgets import ParameterWidget
from ui import QDSMain
from libmath.BDSMathlib import FunctionRegister, FitRoutine
from libmath.BDSlib import FunctionRegister, FitRoutine
from data.data import Data

View File

@ -1,155 +1,18 @@
# -*- encoding: utf8 -*-
from PyQt4.QtCore import QObject, Qt, pyqtSignal, pyqtSlot
from math import libyaff
from PyQt4.QtGui import QColor
import numpy as np
import pyqtgraph as pg
import ContainerWidgets
from math.BDSMathlib import id_to_color
from math import libyaff
from data.container_base import BaseObject
from gui import ContainerWidgets
__author__ = 'markusro'
class BaseObject(QObject):
changedData = pyqtSignal()
removeObj = pyqtSignal(QObject)
def __init__(self, plt_real=None, plt_imag=None, limits=None):
super(BaseObject, self).__init__()
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.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.plt_imag = plt_imag
self.plt_imag.addItem(self.data_curve_imag)
self.limits = limits
# private varaibles
self._color = QColor("white")
self._id_label = None
self._id_string = None
self._widget = None
self._frequency = np.logspace(np.log10(limits[0]), np.log10(limits[1]), 256)
self._data = None
self._func = None
self._beta = None
self._sd_beta = None
self._selector_mask = None
self._param_number = 0
self._abort = False
def set_limits(self, limits):
self.limits = limits
self.updateData()
@pyqtSlot(bool)
def abort(self, abort=False):
self._abort = abort
@property
def param_number(self):
return self._param_number
@param_number.setter
def param_number(self, num):
self._param_number = num
@property
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
@property
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
@property
def color(self):
return self._color
@color.setter
def color(self, c):
self._color = c
print 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):
return self._widget
@widget.setter
def widget(self, wdgt):
self._widget = wdgt
self._widget.changedTable.connect(self.updateData) # TODO better to use self.setParameter
self.removeObj.connect(self._widget.deleteLater)
self._widget.removeMe.connect(self.removeMe)
def getParameter(self):
p = self.widget.getTable() # TODO ugly ... should return self._beta etc ...?
return p
def getFixed(self):
p = self.widget.fixedParameter()
return p
def setParameter(self, beta, sd_beta=None):
self._beta = beta
self._sd_beta = sd_beta
self.widget.updateTable(beta, sd_beta)
self.updateData()
def get_data(self):
return self._frequency, self._data
def removeMe(self):
self.plt_imag.removeItem(self.data_curve_imag)
self.plt_real.removeItem(self.data_curve_real)
self.removeObj.emit(self)
self.changedData.emit()
def updateData(self):
self._frequency = np.logspace(np.log10(self.limits[0]), np.log10(self.limits[1]), 256)
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()
def resampleData(self, x):
data = self._func(self.getParameter(), x)
return np.array([x,data[0],data[1]]).T
def clearData(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"
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)

143
data/container_base.py Normal file
View File

@ -0,0 +1,143 @@
from PyQt4.QtCore import QObject, pyqtSignal, Qt, pyqtSlot
from PyQt4.QtGui import QColor
import numpy as np
import pyqtgraph as pg
__author__ = 'markusro'
class BaseObject(QObject):
changedData = pyqtSignal()
removeObj = pyqtSignal(QObject)
def __init__(self, plt_real=None, plt_imag=None, limits=None):
super(BaseObject, self).__init__()
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.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.plt_imag = plt_imag
self.plt_imag.addItem(self.data_curve_imag)
self.limits = limits
# private varaibles
self._color = QColor("white")
self._id_label = None
self._id_string = None
self._widget = None
self._frequency = np.logspace(np.log10(limits[0]), np.log10(limits[1]), 256)
self._data = None
self._func = None
self._beta = None
self._sd_beta = None
self._selector_mask = None
self._param_number = 0
self._abort = False
def set_limits(self, limits):
self.limits = limits
self.updateData()
@pyqtSlot(bool)
def abort(self, abort=False):
self._abort = abort
@property
def param_number(self):
return self._param_number
@param_number.setter
def param_number(self, num):
self._param_number = num
@property
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
@property
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
@property
def color(self):
return self._color
@color.setter
def color(self, c):
self._color = c
print 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):
return self._widget
@widget.setter
def widget(self, wdgt):
self._widget = wdgt
self._widget.changedTable.connect(self.updateData) # TODO better to use self.setParameter
self.removeObj.connect(self._widget.deleteLater)
self._widget.removeMe.connect(self.removeMe)
def getParameter(self):
p = self.widget.getTable() # TODO ugly ... should return self._beta etc ...?
return p
def getFixed(self):
p = self.widget.fixedParameter()
return p
def setParameter(self, beta, sd_beta=None):
self._beta = beta
self._sd_beta = sd_beta
self.widget.updateTable(beta, sd_beta)
self.updateData()
def get_data(self):
return self._frequency, self._data
def removeMe(self):
self.plt_imag.removeItem(self.data_curve_imag)
self.plt_real.removeItem(self.data_curve_real)
self.removeObj.emit(self)
self.changedData.emit()
def updateData(self):
self._frequency = np.logspace(np.log10(self.limits[0]), np.log10(self.limits[1]), 256)
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()
def resampleData(self, x):
data = self._func(self.getParameter(), x)
return np.array([x,data[0],data[1]]).T
def clearData(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"