From a8ad4b68cb98d1fd404ad8fa6fedadfeba5ffec1 Mon Sep 17 00:00:00 2001 From: Markus Rosenstihl Date: Thu, 20 Mar 2014 17:02:58 +0100 Subject: [PATCH] BaseWidget for parameters gerneralized, YAFF implementation started --- ConductivityGroupBox.py | 2 +- CustomWidgets.py | 135 +++++++++---- Makefile | 1 + PeakGroupBox.py | 2 +- PowerLawGroupBox.py | 2 +- QDSMain.py | 2 +- StaticGroupBox.py | 2 +- YAFFparameters.py | 281 ++++++++++++++++++++++++++ YAFFparameters.ui | 425 ++++++++++++++++++++++++++++++++++++++++ images_rc.py | 2 +- libyaff.py | 156 +++++++++++++++ mathlib.py | 2 + 12 files changed, 963 insertions(+), 49 deletions(-) create mode 100644 YAFFparameters.py create mode 100644 YAFFparameters.ui create mode 100644 libyaff.py diff --git a/ConductivityGroupBox.py b/ConductivityGroupBox.py index c3d4139..6f75c09 100644 --- a/ConductivityGroupBox.py +++ b/ConductivityGroupBox.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'ConductivityGroupBox.ui' # -# Created: Thu Mar 20 14:46:49 2014 +# Created: Thu Mar 20 16:44:40 2014 # by: PyQt4 UI code generator 4.10.3 # # WARNING! All changes made in this file will be lost! diff --git a/CustomWidgets.py b/CustomWidgets.py index b0813fd..dc3f887 100644 --- a/CustomWidgets.py +++ b/CustomWidgets.py @@ -5,6 +5,7 @@ import ConductivityGroupBox import PeakGroupBox import PowerLawGroupBox import StaticGroupBox +import YAFFparameters __author__ = 'markusro' @@ -49,6 +50,7 @@ class ParameterWidget(QWidget): def add(self, wdgt): self.vlayout.insertWidget(self.vlayout.count()-1, wdgt) self.vlayout.update() + if __name__ == "__main__": app = QApplication([]) @@ -90,9 +92,12 @@ class BaseWidget(QGroupBox): for i, arg in enumerate(beta): self.inputs[i].setValue(arg) sd_style="" - if i in (0,) and sd_beta is not None: + + if isinstance(self.inputs[i], LogFSpinBox) and sd_beta is not None: + #if i in (0,) and sd_beta is not None: sd = "+/- %.3e"%(sd_beta[i]) - elif i in (1,) and sd_beta is not None: + elif isinstance(self.inputs[i], QDoubleSpinBox) and sd_beta is not None: + #elif i in (1,) and sd_beta is not None: sd = "+/- %.2f"%(sd_beta[i]) if sd_beta is not None: if 0.0 < sd_beta[i]/arg < 0.2: @@ -222,29 +227,29 @@ class PeakWidget(BaseWidget,QGroupBox): self.setPalette(palette) - - def updateTable(self, beta=None, sd_beta = None): - - - for i, arg in enumerate(beta): - self.inputs[i].setValue(arg) - sd_style="" - if i in (0,1) and sd_beta is not None: - sd = "+/- %.3e"%(sd_beta[i]) - elif i in (2,3) and sd_beta is not None: - sd = "+/- %.2f"%(sd_beta[i]) - if sd_beta is not None: - if 0.0 < sd_beta[i]/arg < 0.2: - sd_style="background-color: rgba(0, 255, 0, 64);" - if 0.2 < sd_beta[i]/arg < 1.0: - sd_style="background-color: rgba(255,255, 0, 64);" - elif sd_beta[i]/arg > 1.0: - sd_style="background-color: rgba(255, 0, 0, 64);" - - else: - sd = "( --- )" - self.errors[i].setStyleSheet(sd_style) - self.errors[i].setText(sd) + # + # def updateTable(self, beta=None, sd_beta = None): + # + # + # for i, arg in enumerate(beta): + # self.inputs[i].setValue(arg) + # sd_style="" + # if i in (0,1) and sd_beta is not None: + # sd = "+/- %.3e"%(sd_beta[i]) + # elif i in (2,3) and sd_beta is not None: + # sd = "+/- %.2f"%(sd_beta[i]) + # if sd_beta is not None: + # if 0.0 < sd_beta[i]/arg < 0.2: + # sd_style="background-color: rgba(0, 255, 0, 64);" + # if 0.2 < sd_beta[i]/arg < 1.0: + # sd_style="background-color: rgba(255,255, 0, 64);" + # elif sd_beta[i]/arg > 1.0: + # sd_style="background-color: rgba(255, 0, 0, 64);" + # + # else: + # sd = "( --- )" + # self.errors[i].setStyleSheet(sd_style) + # self.errors[i].setText(sd) class StaticWidget(BaseWidget, QGroupBox): @@ -271,24 +276,6 @@ class StaticWidget(BaseWidget, QGroupBox): self.ui.removeButton.clicked.connect(self.remove) - def updateTable(self, beta, sd_beta=None): - for i, arg in enumerate(beta): - self.inputs[i].setValue(arg) - sd_style="" - if sd_beta is not None: - sd = "+/- %.2f"%(sd_beta[i]) - if 0.0 < sd_beta[i]/arg < 0.2: - sd_style="background-color: rgba(0, 255, 0, 64);" - if 0.2 < sd_beta[i]/arg < 1.0: - sd_style="background-color: rgba(255,255, 0, 64);" - elif sd_beta[i]/arg > 1.0: - sd_style="background-color: rgba(255, 0, 0, 64);" - - else: - sd = "( --- )" - self.errors[i].setStyleSheet(sd_style) - self.errors[i].setText(sd) - class ConductivityWidget(BaseWidget, QGroupBox): @@ -345,3 +332,65 @@ class PowerLawWidget(BaseWidget, QGroupBox): for dsb in self.inputs: dsb.valueChanged.connect(self.changeValues) + +class YaffWidget(BaseWidget, QGroupBox): + + def __init__(self, parent=None): + QGroupBox.__init__(self) + BaseWidget.__init__(self) + + super(YaffWidget, self).__init__(parent) + self.ui = YAFFparameters.Ui_Form() + self.ui.setupUi(self) + + self.ui.doubleSpinBox_1.setParent(None) + self.ui.doubleSpinBox_1 = LogFSpinBox(self) + self.ui.gridLayout.addWidget(self.ui.doubleSpinBox_1, 1, 1) + + self.ui.doubleSpinBox_2.setParent(None) + self.ui.doubleSpinBox_2 = LogFSpinBox(self) + self.ui.gridLayout.addWidget(self.ui.doubleSpinBox_2, 2, 1) + + self.ui.doubleSpinBox_6.setParent(None) + self.ui.doubleSpinBox_6 = LogFSpinBox(self) + self.ui.gridLayout.addWidget(self.ui.doubleSpinBox_6, 6, 1) + + self.ui.removeButton.clicked.connect(self.remove) + + self.errors = [self.ui.label_1, + self.ui.label_2, + self.ui.label_3, + self.ui.label_4, + self.ui.label_5, + self.ui.label_6, + self.ui.label_7, + self.ui.label_8, + self.ui.label_9, + self.ui.label_10, + ] + + self.inputs = [self.ui.doubleSpinBox_1, + self.ui.doubleSpinBox_2, + self.ui.doubleSpinBox_3, + self.ui.doubleSpinBox_4, + self.ui.doubleSpinBox_5, + self.ui.doubleSpinBox_6, + self.ui.doubleSpinBox_7, + self.ui.doubleSpinBox_8, + self.ui.doubleSpinBox_9, + self.ui.doubleSpinBox_10, + ] + + self.fixedCheckBoxes = [ self.ui.checkBox_1, + self.ui.checkBox_2, + self.ui.checkBox_3, + self.ui.checkBox_4, + self.ui.checkBox_5, + self.ui.checkBox_6, + self.ui.checkBox_7, + self.ui.checkBox_8, + self.ui.checkBox_9, + self.ui.checkBox_10, + ] + for dsb in self.inputs: + dsb.valueChanged.connect(self.changeValues) diff --git a/Makefile b/Makefile index 8441ca1..13b262a 100644 --- a/Makefile +++ b/Makefile @@ -5,3 +5,4 @@ all: pyuic4 ConductivityGroupBox.ui -o ConductivityGroupBox.py pyuic4 PowerLawGroupBox.ui -o PowerLawGroupBox.py pyuic4 StaticGroupBox.ui -o StaticGroupBox.py + pyuic4 YAFFparameters.ui -o YAFFparameters.py diff --git a/PeakGroupBox.py b/PeakGroupBox.py index 93b0e47..93e1e71 100644 --- a/PeakGroupBox.py +++ b/PeakGroupBox.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'PeakGroupBox.ui' # -# Created: Thu Mar 20 14:46:49 2014 +# Created: Thu Mar 20 16:44:40 2014 # by: PyQt4 UI code generator 4.10.3 # # WARNING! All changes made in this file will be lost! diff --git a/PowerLawGroupBox.py b/PowerLawGroupBox.py index 43fa9e5..3a1ae3d 100644 --- a/PowerLawGroupBox.py +++ b/PowerLawGroupBox.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'PowerLawGroupBox.ui' # -# Created: Thu Mar 20 14:46:49 2014 +# Created: Thu Mar 20 16:44:40 2014 # by: PyQt4 UI code generator 4.10.3 # # WARNING! All changes made in this file will be lost! diff --git a/QDSMain.py b/QDSMain.py index 6cf811e..d5ea6e5 100644 --- a/QDSMain.py +++ b/QDSMain.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'QDSMain.ui' # -# Created: Thu Mar 20 14:46:49 2014 +# Created: Thu Mar 20 16:44:40 2014 # by: PyQt4 UI code generator 4.10.3 # # WARNING! All changes made in this file will be lost! diff --git a/StaticGroupBox.py b/StaticGroupBox.py index 67e054f..364f153 100644 --- a/StaticGroupBox.py +++ b/StaticGroupBox.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'StaticGroupBox.ui' # -# Created: Thu Mar 20 14:46:49 2014 +# Created: Thu Mar 20 16:44:40 2014 # by: PyQt4 UI code generator 4.10.3 # # WARNING! All changes made in this file will be lost! diff --git a/YAFFparameters.py b/YAFFparameters.py new file mode 100644 index 0000000..0362011 --- /dev/null +++ b/YAFFparameters.py @@ -0,0 +1,281 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'YAFFparameters.ui' +# +# Created: Thu Mar 20 16:44:40 2014 +# by: PyQt4 UI code generator 4.10.3 +# +# WARNING! All changes made in this file will be lost! + +from PyQt4 import QtCore, QtGui + +try: + _fromUtf8 = QtCore.QString.fromUtf8 +except AttributeError: + def _fromUtf8(s): + return s + +try: + _encoding = QtGui.QApplication.UnicodeUTF8 + def _translate(context, text, disambig): + return QtGui.QApplication.translate(context, text, disambig, _encoding) +except AttributeError: + def _translate(context, text, disambig): + return QtGui.QApplication.translate(context, text, disambig) + +class Ui_Form(object): + def setupUi(self, Form): + Form.setObjectName(_fromUtf8("Form")) + Form.resize(270, 396) + self.gridLayout = QtGui.QGridLayout(Form) + self.gridLayout.setMargin(1) + self.gridLayout.setObjectName(_fromUtf8("gridLayout")) + self.checkBox_2 = QtGui.QCheckBox(Form) + self.checkBox_2.setText(_fromUtf8("")) + self.checkBox_2.setObjectName(_fromUtf8("checkBox_2")) + self.gridLayout.addWidget(self.checkBox_2, 3, 3, 1, 1) + self.checkBox_1 = QtGui.QCheckBox(Form) + self.checkBox_1.setText(_fromUtf8("")) + self.checkBox_1.setObjectName(_fromUtf8("checkBox_1")) + self.gridLayout.addWidget(self.checkBox_1, 2, 3, 1, 1) + self.label_4 = QtGui.QLabel(Form) + self.label_4.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) + self.label_4.setObjectName(_fromUtf8("label_4")) + self.gridLayout.addWidget(self.label_4, 7, 0, 1, 1) + self.label_21 = QtGui.QLabel(Form) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.label_21.sizePolicy().hasHeightForWidth()) + self.label_21.setSizePolicy(sizePolicy) + self.label_21.setObjectName(_fromUtf8("label_21")) + self.gridLayout.addWidget(self.label_21, 13, 2, 1, 1) + self.doubleSpinBox_1 = QtGui.QDoubleSpinBox(Form) + self.doubleSpinBox_1.setObjectName(_fromUtf8("doubleSpinBox_1")) + self.gridLayout.addWidget(self.doubleSpinBox_1, 2, 1, 1, 1) + self.doubleSpinBox_4 = QtGui.QDoubleSpinBox(Form) + self.doubleSpinBox_4.setSingleStep(0.05) + self.doubleSpinBox_4.setObjectName(_fromUtf8("doubleSpinBox_4")) + self.gridLayout.addWidget(self.doubleSpinBox_4, 7, 1, 1, 1) + self.label_1 = QtGui.QLabel(Form) + self.label_1.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) + self.label_1.setObjectName(_fromUtf8("label_1")) + self.gridLayout.addWidget(self.label_1, 2, 0, 1, 1) + self.label_16 = QtGui.QLabel(Form) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.label_16.sizePolicy().hasHeightForWidth()) + self.label_16.setSizePolicy(sizePolicy) + self.label_16.setObjectName(_fromUtf8("label_16")) + self.gridLayout.addWidget(self.label_16, 7, 2, 1, 1) + self.doubleSpinBox_6 = QtGui.QDoubleSpinBox(Form) + self.doubleSpinBox_6.setObjectName(_fromUtf8("doubleSpinBox_6")) + self.gridLayout.addWidget(self.doubleSpinBox_6, 9, 1, 1, 1) + self.label_18 = QtGui.QLabel(Form) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.label_18.sizePolicy().hasHeightForWidth()) + self.label_18.setSizePolicy(sizePolicy) + self.label_18.setObjectName(_fromUtf8("label_18")) + self.gridLayout.addWidget(self.label_18, 8, 2, 1, 1) + self.label_5 = QtGui.QLabel(Form) + self.label_5.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) + self.label_5.setObjectName(_fromUtf8("label_5")) + self.gridLayout.addWidget(self.label_5, 8, 0, 1, 1) + self.label_11 = QtGui.QLabel(Form) + self.label_11.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) + self.label_11.setObjectName(_fromUtf8("label_11")) + self.gridLayout.addWidget(self.label_11, 12, 0, 1, 1) + self.label_14 = QtGui.QLabel(Form) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.label_14.sizePolicy().hasHeightForWidth()) + self.label_14.setSizePolicy(sizePolicy) + self.label_14.setObjectName(_fromUtf8("label_14")) + self.gridLayout.addWidget(self.label_14, 12, 2, 1, 1) + self.label_17 = QtGui.QLabel(Form) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.label_17.sizePolicy().hasHeightForWidth()) + self.label_17.setSizePolicy(sizePolicy) + self.label_17.setObjectName(_fromUtf8("label_17")) + self.gridLayout.addWidget(self.label_17, 9, 2, 1, 1) + self.label_type = QtGui.QLabel(Form) + self.label_type.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) + self.label_type.setObjectName(_fromUtf8("label_type")) + self.gridLayout.addWidget(self.label_type, 0, 0, 1, 1) + self.doubleSpinBox_3 = QtGui.QDoubleSpinBox(Form) + self.doubleSpinBox_3.setSingleStep(0.05) + self.doubleSpinBox_3.setObjectName(_fromUtf8("doubleSpinBox_3")) + self.gridLayout.addWidget(self.doubleSpinBox_3, 5, 1, 1, 1) + self.label_huh = QtGui.QLabel(Form) + self.label_huh.setObjectName(_fromUtf8("label_huh")) + self.gridLayout.addWidget(self.label_huh, 1, 0, 1, 1) + self.label_19 = QtGui.QLabel(Form) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.label_19.sizePolicy().hasHeightForWidth()) + self.label_19.setSizePolicy(sizePolicy) + self.label_19.setObjectName(_fromUtf8("label_19")) + self.gridLayout.addWidget(self.label_19, 3, 2, 1, 1) + self.label_10 = QtGui.QLabel(Form) + self.label_10.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) + self.label_10.setObjectName(_fromUtf8("label_10")) + self.gridLayout.addWidget(self.label_10, 13, 0, 1, 1) + self.label_2 = QtGui.QLabel(Form) + self.label_2.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) + self.label_2.setObjectName(_fromUtf8("label_2")) + self.gridLayout.addWidget(self.label_2, 3, 0, 1, 1) + self.label_3 = QtGui.QLabel(Form) + self.label_3.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) + self.label_3.setObjectName(_fromUtf8("label_3")) + self.gridLayout.addWidget(self.label_3, 5, 0, 1, 1) + self.doubleSpinBox_9 = QtGui.QDoubleSpinBox(Form) + self.doubleSpinBox_9.setObjectName(_fromUtf8("doubleSpinBox_9")) + self.gridLayout.addWidget(self.doubleSpinBox_9, 12, 1, 1, 1) + self.label_13 = QtGui.QLabel(Form) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.label_13.sizePolicy().hasHeightForWidth()) + self.label_13.setSizePolicy(sizePolicy) + self.label_13.setObjectName(_fromUtf8("label_13")) + self.gridLayout.addWidget(self.label_13, 11, 2, 1, 1) + self.label_22 = QtGui.QLabel(Form) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.label_22.sizePolicy().hasHeightForWidth()) + self.label_22.setSizePolicy(sizePolicy) + self.label_22.setObjectName(_fromUtf8("label_22")) + self.gridLayout.addWidget(self.label_22, 2, 2, 1, 1) + self.label_15 = QtGui.QLabel(Form) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.label_15.sizePolicy().hasHeightForWidth()) + self.label_15.setSizePolicy(sizePolicy) + self.label_15.setObjectName(_fromUtf8("label_15")) + self.gridLayout.addWidget(self.label_15, 5, 2, 1, 1) + self.label_8 = QtGui.QLabel(Form) + self.label_8.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) + self.label_8.setObjectName(_fromUtf8("label_8")) + self.gridLayout.addWidget(self.label_8, 11, 0, 1, 1) + self.label_6 = QtGui.QLabel(Form) + self.label_6.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) + self.label_6.setObjectName(_fromUtf8("label_6")) + self.gridLayout.addWidget(self.label_6, 9, 0, 1, 1) + self.doubleSpinBox_7 = QtGui.QDoubleSpinBox(Form) + self.doubleSpinBox_7.setSingleStep(0.05) + self.doubleSpinBox_7.setObjectName(_fromUtf8("doubleSpinBox_7")) + self.gridLayout.addWidget(self.doubleSpinBox_7, 10, 1, 1, 1) + self.label_20 = QtGui.QLabel(Form) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.label_20.sizePolicy().hasHeightForWidth()) + self.label_20.setSizePolicy(sizePolicy) + self.label_20.setObjectName(_fromUtf8("label_20")) + self.gridLayout.addWidget(self.label_20, 10, 2, 1, 1) + self.label_7 = QtGui.QLabel(Form) + self.label_7.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) + self.label_7.setObjectName(_fromUtf8("label_7")) + self.gridLayout.addWidget(self.label_7, 10, 0, 1, 1) + self.doubleSpinBox_8 = QtGui.QDoubleSpinBox(Form) + self.doubleSpinBox_8.setSingleStep(0.05) + self.doubleSpinBox_8.setObjectName(_fromUtf8("doubleSpinBox_8")) + self.gridLayout.addWidget(self.doubleSpinBox_8, 11, 1, 1, 1) + self.doubleSpinBox_10 = QtGui.QDoubleSpinBox(Form) + self.doubleSpinBox_10.setObjectName(_fromUtf8("doubleSpinBox_10")) + self.gridLayout.addWidget(self.doubleSpinBox_10, 13, 1, 1, 1) + self.doubleSpinBox_5 = QtGui.QDoubleSpinBox(Form) + self.doubleSpinBox_5.setSingleStep(0.05) + self.doubleSpinBox_5.setObjectName(_fromUtf8("doubleSpinBox_5")) + self.gridLayout.addWidget(self.doubleSpinBox_5, 8, 1, 1, 1) + self.doubleSpinBox_2 = QtGui.QDoubleSpinBox(Form) + self.doubleSpinBox_2.setObjectName(_fromUtf8("doubleSpinBox_2")) + self.gridLayout.addWidget(self.doubleSpinBox_2, 3, 1, 1, 1) + self.checkBox_4 = QtGui.QCheckBox(Form) + self.checkBox_4.setText(_fromUtf8("")) + self.checkBox_4.setObjectName(_fromUtf8("checkBox_4")) + self.gridLayout.addWidget(self.checkBox_4, 7, 3, 1, 1) + self.checkBox_3 = QtGui.QCheckBox(Form) + self.checkBox_3.setText(_fromUtf8("")) + self.checkBox_3.setObjectName(_fromUtf8("checkBox_3")) + self.gridLayout.addWidget(self.checkBox_3, 5, 3, 1, 1) + self.checkBox_5 = QtGui.QCheckBox(Form) + self.checkBox_5.setText(_fromUtf8("")) + self.checkBox_5.setObjectName(_fromUtf8("checkBox_5")) + self.gridLayout.addWidget(self.checkBox_5, 8, 3, 1, 1) + self.checkBox_6 = QtGui.QCheckBox(Form) + self.checkBox_6.setText(_fromUtf8("")) + self.checkBox_6.setObjectName(_fromUtf8("checkBox_6")) + self.gridLayout.addWidget(self.checkBox_6, 9, 3, 1, 1) + self.checkBox_7 = QtGui.QCheckBox(Form) + self.checkBox_7.setText(_fromUtf8("")) + self.checkBox_7.setObjectName(_fromUtf8("checkBox_7")) + self.gridLayout.addWidget(self.checkBox_7, 10, 3, 1, 1) + self.checkBox_8 = QtGui.QCheckBox(Form) + self.checkBox_8.setText(_fromUtf8("")) + self.checkBox_8.setObjectName(_fromUtf8("checkBox_8")) + self.gridLayout.addWidget(self.checkBox_8, 11, 3, 1, 1) + self.checkBox_9 = QtGui.QCheckBox(Form) + self.checkBox_9.setText(_fromUtf8("")) + self.checkBox_9.setObjectName(_fromUtf8("checkBox_9")) + self.gridLayout.addWidget(self.checkBox_9, 12, 3, 1, 1) + self.checkBox_10 = QtGui.QCheckBox(Form) + self.checkBox_10.setText(_fromUtf8("")) + self.checkBox_10.setObjectName(_fromUtf8("checkBox_10")) + self.gridLayout.addWidget(self.checkBox_10, 13, 3, 1, 1) + self.label_23 = QtGui.QLabel(Form) + self.label_23.setObjectName(_fromUtf8("label_23")) + self.gridLayout.addWidget(self.label_23, 1, 3, 1, 1) + self.comboBox = QtGui.QComboBox(Form) + self.comboBox.setObjectName(_fromUtf8("comboBox")) + self.comboBox.addItem(_fromUtf8("")) + self.comboBox.addItem(_fromUtf8("")) + self.comboBox.addItem(_fromUtf8("")) + self.comboBox.addItem(_fromUtf8("")) + self.gridLayout.addWidget(self.comboBox, 0, 1, 1, 2) + self.comboBox_2 = QtGui.QComboBox(Form) + self.comboBox_2.setObjectName(_fromUtf8("comboBox_2")) + self.gridLayout.addWidget(self.comboBox_2, 1, 1, 1, 1) + + self.retranslateUi(Form) + QtCore.QMetaObject.connectSlotsByName(Form) + + def retranslateUi(self, Form): + Form.setWindowTitle(_translate("Form", "Form", None)) + self.label_4.setText(_translate("Form", "b", None)) + self.label_21.setText(_translate("Form", "TextLabel", None)) + self.label_1.setText(_translate("Form", "eps", None)) + self.label_16.setText(_translate("Form", "TextLabel", None)) + self.label_18.setText(_translate("Form", "TextLabel", None)) + self.label_5.setText(_translate("Form", "lambda", None)) + self.label_11.setText(_translate("Form", "TextLabel", None)) + self.label_14.setText(_translate("Form", "TextLabel", None)) + self.label_17.setText(_translate("Form", "TextLabel", None)) + self.label_type.setText(_translate("Form", "Type", None)) + self.label_huh.setText(_translate("Form", "TextLabel", None)) + self.label_19.setText(_translate("Form", "TextLabel", None)) + self.label_10.setText(_translate("Form", "TextLabel", None)) + self.label_2.setText(_translate("Form", "tau_a", None)) + self.label_3.setText(_translate("Form", "a", None)) + self.label_13.setText(_translate("Form", "TextLabel", None)) + self.label_22.setText(_translate("Form", "TextLabel", None)) + self.label_15.setText(_translate("Form", "TextLabel", None)) + self.label_8.setText(_translate("Form", "b", None)) + self.label_6.setText(_translate("Form", "tau_b", None)) + self.label_20.setText(_translate("Form", "TextLabel", None)) + self.label_7.setText(_translate("Form", "a", None)) + self.label_23.setText(_translate("Form", "Fix", None)) + self.comboBox.setItemText(0, _translate("Form", "GG", None)) + self.comboBox.setItemText(1, _translate("Form", "GGe", None)) + self.comboBox.setItemText(2, _translate("Form", "GG + b", None)) + self.comboBox.setItemText(3, _translate("Form", "GGe + b", None)) + diff --git a/YAFFparameters.ui b/YAFFparameters.ui new file mode 100644 index 0000000..2127707 --- /dev/null +++ b/YAFFparameters.ui @@ -0,0 +1,425 @@ + + + Form + + + + 0 + 0 + 270 + 396 + + + + Form + + + + 1 + + + + + + + + + + + + + + + + + + + b + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + TextLabel + + + + + + + + + + 0.050000000000000 + + + + + + + eps + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + TextLabel + + + + + + + + + + + 0 + 0 + + + + TextLabel + + + + + + + lambda + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + TextLabel + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + TextLabel + + + + + + + + 0 + 0 + + + + TextLabel + + + + + + + Type + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 0.050000000000000 + + + + + + + TextLabel + + + + + + + + 0 + 0 + + + + TextLabel + + + + + + + TextLabel + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + tau_a + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + a + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + 0 + 0 + + + + TextLabel + + + + + + + + 0 + 0 + + + + TextLabel + + + + + + + + 0 + 0 + + + + TextLabel + + + + + + + b + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + tau_b + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 0.050000000000000 + + + + + + + + 0 + 0 + + + + TextLabel + + + + + + + a + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 0.050000000000000 + + + + + + + + + + 0.050000000000000 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Fix + + + + + + + + GG + + + + + GGe + + + + + GG + b + + + + + GGe + b + + + + + + + + + + + + diff --git a/images_rc.py b/images_rc.py index f1fd856..6975877 100644 --- a/images_rc.py +++ b/images_rc.py @@ -2,7 +2,7 @@ # Resource object code # -# Created: Do. Mär. 20 14:46:49 2014 +# Created: Do. Mär. 20 16:44:40 2014 # by: The Resource Compiler for PyQt (Qt v4.8.5) # # WARNING! All changes made in this file will be lost! diff --git a/libyaff.py b/libyaff.py new file mode 100644 index 0000000..e8313dd --- /dev/null +++ b/libyaff.py @@ -0,0 +1,156 @@ +__author__ = 'markusro' + +from numpy import * +import mathlib + +import scipy.special +import scipy.integrate + +numpat = re.compile('\d+\.\d+') +NUM_PROCESSES = 8 + +#define norm1(a,b) exp(gammln(b/a))/(a*pow(b/a,b/a)) + +#define glntau1(x,t,a,b) exp( -exp( (log(x)-log(t))*a )*b/a) * pow(x/t,b) + + +def filon(oms, x,y): + amps = N.zeros(len(oms), dtype='complex') + for i,om in enumerate(oms): + amps[i] = sum(diff(y)/diff(x)*(cos(om*x[1:])-cos(om*x[:-1])))/om**2 + amps[i] += 1j*(y[0]/om + N.sum(diff(y)/diff(x)*(sin(om*x[1:])-sin(om*x[:-1])))/om**2) + return amps + + +class Yaff: + def __init__(self, dist_type=0): + self.dist_x = N.logspace(-10,4,512) + self.dist_y = N.zeros(self.dist_x.size) + self.dist_type = [self.yaff, + self.yaff_gg, + ][dist_type] + + + + def gg(self, p, tau): + tau0, a, b = p + """ + Generalized Gamma function + """ + NGG = a * (b/a)**(b/a) / scipy.special.gamma(b/a) + #g = exp(-b/a*exp( (log(tau)-log(tau0))*a))*(tau/tau0)**b + g = exp(-b/a*exp( (log(tau)-log(tau0))*a))*(tau/tau0)**b + return g*NGG + + + def ggb(self, p, tau): + tau0,a,b = p + norm_ggb = a*(1+b)/pi *b**(b/(1+b)) * sin(pi*b/(1+b)) + g = (b*exp( (log(tau)-log(tau0)) *a) + exp( (log(tau)-log(tau0))*(-a*b)))**(-1) + return norm_ggb*g + + + def gg_hw(self, p ,tau): + tau0, a, b, g, s = p + """ + Generalized Gamma function with HF wing. + s gives the onset of the wing in units of tau0, i.e. 100 means 100*tau0 or two decades later + g is the slope of the wing, smaller than b; if not the slope will be b + """ + NGG = a * (b/a)**(b/a) / ( scipy.special.gamma(b/a) + s**(g-b)*(a/b)**((g-b)/a)* scipy.special.gamma(g/a) ) + g = exp(-b/a*exp((log(tau) - log(tau0))*a))*(tau/tau0)**b * (1 + (tau*s/tau0)**(g-b)) + return g*NGG + + + def dist_to_eps(omegas,dist_x,dist_y): + epp = zeros(len(omegas), dtype='complex') + for i,om in enumerate(omegas): + kern_imag = dist_y*om*dist_x/(1+(om*dist_x)**2) + kern_real = dist_y/(1+(om*dist_x)**2) + epp[i] = scipy.integrate.simps(kern_real,log(dist_x)) + epp[i] += 1j*scipy.integrate.simps(kern_imag,log(dist_x)) + return epp + + def dist_to_relax(self, ts,dist_x,dist_y): + phi = zeros(len(ts)) + for i,t in enumerate(ts): + phi[i] = phi_t(t,dist_x,dist_y) + return phi + + + def phi_t(self, t, dist_x, dist_y): + kern = dist_y*exp(-t/dist_x) + phi = scipy.integrate.simps(kern,log(dist_x)) + return phi + + + def williams_watts(self, phi_1, phi_2, lambd): + return phi_1 * ( (1-lambd) + lambd*phi_2) + + def yaff2(self, p, x): + """ + GGe+G b ---> GG+GB - lambda determined by p + """ + delta_eps, s_c, tau1,a1,b1, g,s, tau2, a2, b2 = p + p_ggb = tau2,a2,b2 + p_gghw=tau1,a1,b1,g,s + lambd = 2*g/pi*a1*(b1/a1)**(b1/a1) + lambd /= scipy.special.gamma(b1/a1)*s**(b1-g) + (a1/b1)**((g-b1)/a1)*scipy.special.gamma(g/a1) + print "LAMBDA:",lambd,a1,b1,g,s + dist_ggb = self.ggb(p_ggb, dist_t) + phi_beta = self.dist_to_relax(ts, dist_t, dist_ggb ).real + phi_alpha = self.dist_to_relax(ts, dist_t, self.gg_hw(p_gghw, dist_t)).real + phi_tot = (1-lambd) + lambd*phi_beta + phi_tot *= phi_alpha + epp = delta_eps*2*pi*x*filon(2*pi*x, ts, phi_tot ).real + epp += s_c/(2*pi*x) + return epp + + def yaff(self, p,x, cb=None): + """ + GG + GB + """ + delta_eps, tau1, a1, b1, lambd, tau2, a2, b2 = p + + dist_ggb = ggb(self.dist_x,tau2,a2,b2) + dist_gg = gg(self.dist_x,tau1,a1,b1) + + ts = logspace(-10,5,1024) + phi_beta = self.dist_to_relax(ts, self.dist_x, dist_ggb).real + phi_alpha = self.dist_to_relax(ts, self.dist_x, dist_gg).real + # William-Watts-Ansatz + phi_tot = (1-lambd) + lambd*phi_beta + phi_tot *= phi_alpha + epp = delta_eps*2*pi*x*filon(2*pi*x, ts, phi_tot ).real + + if cb != None: + cb.next(p,x,epp) + return epp + + def yaff_gg(self, p,x, cb=None): + """ + GG + """ + delta_eps, s_c, tau1,a1,b1 = p + + dist_gg = gg(dist_t,tau1,a1,b1) + + phi_alpha = dist_to_relax(ts, dist_t, dist_gg).real + epp = delta_eps*2*pi*x*filon(2*pi*x, ts, phi_alpha ).real + # epp = dist_to_eps(2*pi*x, dist_t, dist_gg ).real + epp += s_c/(2*pi*x) + if cb != None: + cb(p,x,epp) + return epp + + +def show_correlations(cov, ax): + cor = zeros(cov.shape) + for i in range(cor.shape[0]): + for j in range(cor.shape[1]): + if cov[i,i] == 0 or cov[j,j]==0: + cor[i,j] = 0 + else: + cor[i,j] = cov[i,j]/sqrt(cov[i,i]*cov[j,j]) + ax.matshow(abs(cor), cmap=cm.RdYlGn) + ax.colorbar() diff --git a/mathlib.py b/mathlib.py index f8fbc83..3f444b2 100644 --- a/mathlib.py +++ b/mathlib.py @@ -131,6 +131,8 @@ def tau_peak(f, a, b): return tau + + ### define funcs here class Functions: def __init__(self):