From 737be85ee128769bd4d1708706a7cece356adb23 Mon Sep 17 00:00:00 2001 From: Markus Rosenstihl Date: Wed, 24 Sep 2014 21:42:06 +0200 Subject: [PATCH] more cleanup --- QDS.py | 9 +- Container.py => data/Container.py | 145 +----------------- data/container_base.py | 143 +++++++++++++++++ .../ContainerWidgets.py | 0 {ui => gui}/ExtraDifferentialWidget.py | 0 {assets => gui}/__init__.py | 0 libmath/{BDSMathlib.py => BDSlib.py} | 0 libmath/{libyaff.py => yafflib.py} | 0 8 files changed, 152 insertions(+), 145 deletions(-) rename Container.py => data/Container.py (50%) create mode 100644 data/container_base.py rename ContainerWidgets.py => gui/ContainerWidgets.py (100%) rename {ui => gui}/ExtraDifferentialWidget.py (100%) rename {assets => gui}/__init__.py (100%) rename libmath/{BDSMathlib.py => BDSlib.py} (100%) rename libmath/{libyaff.py => yafflib.py} (100%) diff --git a/QDS.py b/QDS.py index c907f36..18fbbe0 100755 --- a/QDS.py +++ b/QDS.py @@ -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 diff --git a/Container.py b/data/Container.py similarity index 50% rename from Container.py rename to data/Container.py index c97db88..643a70b 100644 --- a/Container.py +++ b/data/Container.py @@ -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) diff --git a/data/container_base.py b/data/container_base.py new file mode 100644 index 0000000..995de38 --- /dev/null +++ b/data/container_base.py @@ -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" \ No newline at end of file diff --git a/ContainerWidgets.py b/gui/ContainerWidgets.py similarity index 100% rename from ContainerWidgets.py rename to gui/ContainerWidgets.py diff --git a/ui/ExtraDifferentialWidget.py b/gui/ExtraDifferentialWidget.py similarity index 100% rename from ui/ExtraDifferentialWidget.py rename to gui/ExtraDifferentialWidget.py diff --git a/assets/__init__.py b/gui/__init__.py similarity index 100% rename from assets/__init__.py rename to gui/__init__.py diff --git a/libmath/BDSMathlib.py b/libmath/BDSlib.py similarity index 100% rename from libmath/BDSMathlib.py rename to libmath/BDSlib.py diff --git a/libmath/libyaff.py b/libmath/yafflib.py similarity index 100% rename from libmath/libyaff.py rename to libmath/yafflib.py