def __init__(self, parent=None): qt.QGroupBox.__init__(self, parent) self.setTitle("Fit Control") self.mainLayout = qt.QGridLayout(self) self.mainLayout.setMargin(2) self.mainLayout.setSpacing(2) row = 0 #linear fit self.fitAlgorithmLabel = qt.QLabel(self) self.fitAlgorithmLabel.setText("Fit algorithm") self.fitAlgorithmCombo = qt.QComboBox(self) self.fitAlgorithmCombo.addItem(str("Levenberg-Marquardt")) self.fitAlgorithmCombo.addItem(str("Linear Fit")) self.mainLayout.addWidget(self.fitAlgorithmLabel, row, 0) self.mainLayout.addWidget(qt.HorizontalSpacer(self), row, 1) self.mainLayout.addWidget(self.fitAlgorithmCombo, row, 3) row += 1 #weighting self.weightLabel = qt.QLabel(self) self.weightLabel.setText("Statistical weighting of data") self.weightCombo = qt.QComboBox(self) self.weightCombo.addItem(str("NO Weight")) self.weightCombo.addItem(str("Poisson (1/Y)")) self.mainLayout.addWidget(self.weightLabel, row, 0) self.mainLayout.addWidget(qt.HorizontalSpacer(self), row, 1) self.mainLayout.addWidget(self.weightCombo, row, 3) row += 1 #function estimation policy self.functionEstimationLabel = qt.QLabel(self) self.functionEstimationLabel.setText("Function estimation policy") self.functionEstimationCombo = qt.QComboBox(self) self.functionEstimationCombo.addItem(str("Use configuration")) self.functionEstimationCombo.addItem(str("Estimate once")) self.functionEstimationCombo.addItem(str("Estimate always")) self.functionEstimationCombo.setCurrentIndex(2) self.mainLayout.addWidget(self.functionEstimationLabel, row, 0) self.mainLayout.addWidget(self.functionEstimationCombo, row, 3) row += 1 #background estimation policy self.backgroundEstimationLabel = qt.QLabel(self) text = "Background estimation policy" self.backgroundEstimationLabel.setText(text) self.backgroundEstimationCombo = qt.QComboBox(self) self.backgroundEstimationCombo.addItem(str("Use configuration")) self.backgroundEstimationCombo.addItem(str("Estimate once")) self.backgroundEstimationCombo.addItem(str("Estimate always")) self.backgroundEstimationCombo.setCurrentIndex(2) self.mainLayout.addWidget(self.backgroundEstimationLabel, row, 0) self.mainLayout.addWidget(self.backgroundEstimationCombo, row, 3) row += 1 #number of iterations self.iterLabel = qt.QLabel(self) self.iterLabel.setText(str("Maximum number of fit iterations")) self.iterSpin = qt.QSpinBox(self) self.iterSpin.setMinimum(1) self.iterSpin.setMaximum(10000) self.iterSpin.setValue(10) self.mainLayout.addWidget(self.iterLabel, row, 0) self.mainLayout.addWidget(qt.HorizontalSpacer(self), row, 1) self.mainLayout.addWidget(self.iterSpin, row, 3) row += 1 #chi square handling self.chi2Label = qt.QLabel(self) self.chi2Label.setText(str("Minimum chi^2 difference (%)")) if 0: self.chi2Value = qt.QLineEdit(self) self.chi2Value._v = qt.QDoubleValidator(self.chi2Value) self.chi2Value.setValidator(self.chi2Value._v) self.chi2Value.setText(str("0.001")) else: self.chi2Value = qt.QDoubleSpinBox(self) self.chi2Value.setDecimals(4) self.chi2Value.setMinimum(0.0001) self.chi2Value.setMaximum(100.) self.chi2Value.setSingleStep(0.0001) self.chi2Value.setValue(0.001) self.mainLayout.addWidget(self.chi2Label, row, 0) self.mainLayout.addWidget(qt.HorizontalSpacer(self), row, 1) self.mainLayout.addWidget(self.chi2Value, row, 3) row += 1 #fitting region self.regionTopLine = qt.QFrame(self) self.regionTopLine.setFrameShape(qt.QFrame.HLine) self.regionTopLine.setFrameShadow(qt.QFrame.Sunken) self.regionTopLine.setFrameShape(qt.QFrame.HLine) self.regionCheckBox = qt.QCheckBox(self) self.regionCheckBox.setText(str("Limit fitting region to :")) self.firstLabel = qt.QLabel(self) firstLabel_font = qt.QFont(self.firstLabel.font()) firstLabel_font.setItalic(1) self.firstLabel.setFont(firstLabel_font) self.firstLabel.setText(str("First X Value ")) self.firstLabel.setAlignment(qt.Qt.AlignVCenter | qt.Qt.AlignRight) self.firstValue = qt.QLineEdit(self) self.firstValue._v = qt.QDoubleValidator(self.firstValue) self.firstValue.setValidator(self.firstValue._v) self.firstValue.setText(str("0.")) self.lastLabel = qt.QLabel(self) lastLabel_font = qt.QFont(self.lastLabel.font()) lastLabel_font.setItalic(1) self.lastLabel.setFont(lastLabel_font) self.lastLabel.setText(str("Last X Value ")) self.lastLabel.setAlignment(qt.Qt.AlignVCenter | qt.Qt.AlignRight) self.lastValue = qt.QLineEdit(self) self.lastValue._v = qt.QDoubleValidator(self.lastValue) self.lastValue.setValidator(self.lastValue._v) self.lastValue.setText(str("1000.")) self.regionBottomLine = qt.QFrame(self) self.regionBottomLine.setFrameShape(qt.QFrame.HLine) self.regionBottomLine.setFrameShadow(qt.QFrame.Sunken) self.regionBottomLine.setFrameShape(qt.QFrame.HLine) self.mainLayout.addWidget(self.regionTopLine, row, 0, 1, 4) row += 1 self.mainLayout.addWidget(self.regionCheckBox, row, 0) self.mainLayout.addWidget(self.firstLabel, row, 1) self.mainLayout.addWidget(self.firstValue, row, 3) row += 1 self.mainLayout.addWidget(self.lastLabel, row, 1) self.mainLayout.addWidget(self.lastValue, row, 3) row += 1 self.mainLayout.addWidget(self.regionBottomLine, row, 0, 1, 4) row += 1
def build(self): self.__text = ["Photon beam polarisation degree:", "Source horizontal size FWHM (cm):", "Source vertical size FWHM (cm):", "Source horizontal divergence (rad):", "Source vertical divergence (rad):", "Distance beam source to slits (cm):", "Distance beam source to sample (cm):", "Slit width (cm):", "Slit height (cm):", # "Detector acceptance angle (rad):", "Maximum number of sample interactions: ", "Sample layer to be adjusted:"] i = 0 for t in self.__text: label = qt.QLabel(self) label.setText(t) self.mainLayout.addWidget(label, i, 0) i += 1 self.__widgetList = [] #polarisation i = 0 self.polarisationSB = qt.QDoubleSpinBox(self) self.polarisationSB.setRange(0.0, 1.0) self.polarisationSB.setDecimals(5) self.__widgetList.append(self.polarisationSB) self.mainLayout.addWidget(self.polarisationSB, i, 1) i += 1 #source horizontal size self.sourceHSize = qt.QDoubleSpinBox(self) self.sourceHSize.setRange(0.0, 1.0) self.sourceHSize.setDecimals(5) self.__widgetList.append(self.sourceHSize) self.mainLayout.addWidget(self.sourceHSize, i, 1) i += 1 #source vertical size self.sourceVSize = qt.QDoubleSpinBox(self) self.sourceVSize.setRange(0.0, 1.0) self.sourceVSize.setDecimals(5) self.__widgetList.append(self.sourceVSize) self.mainLayout.addWidget(self.sourceVSize, i, 1) i += 1 # Source horizontal divergence self.sourceHDivergence = qt.QDoubleSpinBox(self) self.sourceHDivergence.setDecimals(5) self.sourceHDivergence.setRange(0.0, 3.1415926) self.__widgetList.append(self.sourceHDivergence) self.mainLayout.addWidget(self.sourceHDivergence, i, 1) i += 1 # Source vertical divergence self.sourceVDivergence = qt.QDoubleSpinBox(self) self.sourceVDivergence.setDecimals(5) self.sourceVDivergence.setRange(0.0, 3.14159) self.__widgetList.append(self.sourceVDivergence) self.mainLayout.addWidget(self.sourceVDivergence, i, 1) i += 1 # Distance source sample self.sourceSampleDistance = qt.QDoubleSpinBox(self) self.sourceSampleDistance.setDecimals(5) self.sourceSampleDistance.setRange(0.0001, 100000.0) self.__widgetList.append(self.sourceSampleDistance) self.mainLayout.addWidget(self.sourceSampleDistance, i, 1) i += 1 # Distance source slits self.sourceSlitsDistance = qt.QDoubleSpinBox(self) self.sourceSlitsDistance.setDecimals(5) self.sourceSlitsDistance.setRange(0.0001, 100000.0) self.__widgetList.append(self.sourceSlitsDistance) self.mainLayout.addWidget(self.sourceSlitsDistance, i, 1) i += 1 # Slit H size self.slitsHWidth = qt.QDoubleSpinBox(self) self.slitsHWidth.setDecimals(5) self.slitsHWidth.setRange(0.0001, 100.0) self.__widgetList.append(self.slitsHWidth) self.mainLayout.addWidget(self.slitsHWidth, i, 1) i += 1 # Slit V size self.slitsVWidth = qt.QDoubleSpinBox(self) self.slitsVWidth.setDecimals(5) self.slitsVWidth.setRange(0.0001, 100.0) self.__widgetList.append(self.slitsVWidth) self.mainLayout.addWidget(self.slitsVWidth, i, 1) i += 1 # Detector acceptance angle if 0: # this was used in previous versions of the code self.acceptanceAngle = qt.QDoubleSpinBox(self) self.acceptanceAngle.setDecimals(5) self.acceptanceAngle.setRange(0.0001, 3.14159) self.__widgetList.append(self.acceptanceAngle) self.mainLayout.addWidget(self.acceptanceAngle, i, 1) i += 1 # Maximum number of interactions self.maxInteractions = qt.QSpinBox(self) self.maxInteractions.setMinimum(1) self.__widgetList.append(self.maxInteractions) self.mainLayout.addWidget(self.maxInteractions, i, 1) i += 1 # Layer to be adjusted self.fitLayer = qt.QSpinBox(self) self.fitLayer.setMinimum(0) self.fitLayer.setValue(0) self.__widgetList.append(self.fitLayer) self.mainLayout.addWidget(self.fitLayer, i, 1) i += 1
def configureFilter(self): msg = qt.QDialog() msgLayout = qt.QGridLayout() buttonLayout = qt.QHBoxLayout() inpThreshold = qt.QDoubleSpinBox() inpThreshold.setRange(0., 10.) inpThreshold.setSingleStep(.1) inpThreshold.setValue(2.0) inpThreshold.setToolTip('Increase width for broad spikes') inpWidth = qt.QSpinBox() inpWidth.setRange(1, 101) inpWidth.setSingleStep(2) inpWidth.setValue(self.width) inpWidth.setToolTip( 'Set low threshold for multiple spikes of different markedness') labelWidth = qt.QLabel('Width (must be odd)') labelThreshold = qt.QLabel('Threshold (multiple of deviation)') buttonOK = qt.QPushButton('Ok') buttonOK.clicked.connect(msg.accept) buttonCancel = qt.QPushButton('Cancel') buttonCancel.clicked.connect(msg.reject) allActiveBG = qt.QButtonGroup() buttonAll = qt.QCheckBox('Apply to All') buttonActive = qt.QCheckBox('Apply to Active') allActiveBG.addButton(buttonAll, 0) allActiveBG.addButton(buttonActive, 1) buttonLayout.addWidget(qt.HorizontalSpacer()) buttonLayout.addWidget(buttonOK) buttonLayout.addWidget(buttonCancel) msgLayout.addWidget(labelWidth, 0, 0) msgLayout.addWidget(inpWidth, 0, 1) msgLayout.addWidget(labelThreshold, 1, 0) msgLayout.addWidget(inpThreshold, 1, 1) msgLayout.addWidget(buttonActive, 2, 0) msgLayout.addWidget(buttonAll, 2, 1) msgLayout.addLayout(buttonLayout, 3, 0, 1, 2) msg.setLayout(msgLayout) if msg.exec_(): try: self.threshold = float(inpThreshold.value()) / 100. self.threshold = float(inpThreshold.value()) self.width = int(inpWidth.value()) except: self.threshold = 0.66 self.width = 9 if not (self.width % 2): self.width += 1 if buttonActive.isChecked(): if DEBUG: print('ActiveChecked') self.removeSpikesActive() if buttonAll.isChecked(): if DEBUG: print('AllChecked') self.removeSpikesAll()