Changes in src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py [dee9e5f:2b8286c] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py
rdee9e5f r2b8286c 14 14 # pr inversion calculation elements 15 15 from sas.sascalc.pr.invertor import Invertor 16 from sas.qtgui.Plotting.PlotterData import Data1D17 16 # Batch calculation display 18 17 from sas.qtgui.Utilities.GridPanel import BatchInversionOutputPanel … … 44 43 estimateSignal = QtCore.pyqtSignal(tuple) 45 44 estimateNTSignal = QtCore.pyqtSignal(tuple) 46 estimateDynamicNTSignal = QtCore.pyqtSignal(tuple)47 estimateDynamicSignal = QtCore.pyqtSignal(tuple)48 45 calculateSignal = QtCore.pyqtSignal(tuple) 49 46 … … 55 52 56 53 self._manager = parent 57 #Needed for Batch fitting58 self._parent = parent59 54 self.communicate = parent.communicator() 60 55 self.communicate.dataDeletedSignal.connect(self.removeData) … … 114 109 # Set up the Widget Map 115 110 self.setupMapper() 116 117 #Hidding calculate all buton118 self.calculateAllButton.setVisible(False)119 111 # Set base window state 120 112 self.setupWindow() … … 127 119 128 120 def allowBatch(self): 129 return False121 return True 130 122 131 123 def setClosable(self, value=True): … … 202 194 self.model.itemChanged.connect(self.model_changed) 203 195 self.estimateNTSignal.connect(self._estimateNTUpdate) 204 self.estimateDynamicNTSignal.connect(self._estimateDynamicNTUpdate)205 self.estimateDynamicSignal.connect(self._estimateDynamicUpdate)206 196 self.estimateSignal.connect(self._estimateUpdate) 207 197 self.calculateSignal.connect(self._calculateUpdate) 208 209 self.maxDistanceInput.textEdited.connect(self.performEstimateDynamic)210 198 211 199 def setupMapper(self): … … 321 309 and not self.isCalculating) 322 310 self.removeButton.setEnabled(self.logic.data_is_loaded) 323 self.explorerButton.setEnabled(self.logic.data_is_loaded) 311 self.explorerButton.setEnabled(self.logic.data_is_loaded 312 and np.all(self.logic.data.dy != 0)) 324 313 self.stopButton.setVisible(self.isCalculating) 325 314 self.regConstantSuggestionButton.setEnabled( … … 464 453 # Create initial internal mappings 465 454 self.logic.data = GuiUtils.dataFromItem(data) 466 if not isinstance(self.logic.data, Data1D):467 msg = "P(r) perspective works for 1D data only"468 logger.warning(msg)469 continue470 455 # Estimate q range 471 456 qmin, qmax = self.logic.computeDataRange() 472 457 self._calculator.set_qmin(qmin) 473 458 self._calculator.set_qmax(qmax) 474 if np.size(self.logic.data.dy) == 0 or np.all(self.logic.data.dy) == 0:475 self.logic.data.dy = self._calculator.add_errors(self.logic.data.y)476 459 self.updateDataList(data) 477 460 self.populateDataComboBox(self.logic.data.filename, data) 478 461 self.dataList.setCurrentIndex(len(self.dataList) - 1) 479 #Checking for 1D again to mitigate the case when 2D data is last on the data list 480 if isinstance(self.logic.data, Data1D): 481 self.setCurrentData(data) 462 self.setCurrentData(data) 482 463 483 464 def updateDataList(self, dataRef): … … 520 501 self.dataPlot = self._dataList[data_ref].get(DICT_KEYS[2]) 521 502 self.performEstimate() 522 523 def updateDynamicGuiValues(self):524 pr = self._calculator525 alpha = self._calculator.suggested_alpha526 self.model.setItem(WIDGETS.W_MAX_DIST,527 QtGui.QStandardItem("{:.4g}".format(pr.get_dmax())))528 self.regConstantSuggestionButton.setText("{:-3.2g}".format(alpha))529 self.noOfTermsSuggestionButton.setText(530 "{:n}".format(self.nTermsSuggested))531 532 self.enableButtons()533 503 534 504 def updateGuiValues(self): … … 550 520 self.model.setItem(WIDGETS.W_MAX_DIST, 551 521 QtGui.QStandardItem("{:.4g}".format(pr.get_dmax()))) 522 self.regConstantSuggestionButton.setText("{:-3.2g}".format(alpha)) 523 self.noOfTermsSuggestionButton.setText( 524 "{:n}".format(self.nTermsSuggested)) 552 525 553 526 if isinstance(pr.chi2, np.ndarray): … … 571 544 if self.prPlot is not None: 572 545 title = self.prPlot.name 573 self.prPlot.plot_role = Data1D.ROLE_RESIDUAL574 546 GuiUtils.updateModelItemWithPlot(self._data, self.prPlot, title) 575 self.communicate.plotRequestedSignal.emit([self. _data,self.prPlot], None)547 self.communicate.plotRequestedSignal.emit([self.prPlot], None) 576 548 if self.dataPlot is not None: 577 549 title = self.dataPlot.name 578 self.dataPlot.plot_role = Data1D.ROLE_DEFAULT579 self.dataPlot.symbol = "Line"580 self.dataPlot.show_errors = False581 550 GuiUtils.updateModelItemWithPlot(self._data, self.dataPlot, title) 582 self.communicate.plotRequestedSignal.emit([self. _data,self.dataPlot], None)551 self.communicate.plotRequestedSignal.emit([self.dataPlot], None) 583 552 self.enableButtons() 584 553 … … 664 633 665 634 pr = self._calculator.clone() 666 #Making sure that nfunc and alpha parameters are correctly initialized 667 pr.suggested_alpha = self._calculator.alpha 668 self.calcThread = CalcPr(pr, self.nTermsSuggested, 635 nfunc = self.getNFunc() 636 self.calcThread = CalcPr(pr, nfunc, 669 637 error_func=self._threadError, 670 638 completefn=self._calculateCompleted, … … 699 667 error_func=self._threadError, 700 668 completefn=self._estimateNTCompleted, 701 updatefn=None)702 self.estimationThreadNT.queue()703 self.estimationThreadNT.ready(2.5)704 705 def performEstimateDynamicNT(self):706 """707 Perform parameter estimation708 """709 from .Thread import EstimateNT710 711 self.updateCalculator()712 713 # If a thread is already started, stop it714 self.stopEstimateNTThread()715 716 pr = self._calculator.clone()717 # Skip the slit settings for the estimation718 # It slows down the application and it doesn't change the estimates719 pr.slit_height = 0.0720 pr.slit_width = 0.0721 nfunc = self.getNFunc()722 723 self.estimationThreadNT = EstimateNT(pr, nfunc,724 error_func=self._threadError,725 completefn=self._estimateDynamicNTCompleted,726 669 updatefn=None) 727 670 self.estimationThreadNT.queue() … … 750 693 self.estimationThread.ready(2.5) 751 694 752 def performEstimateDynamic(self):753 """754 Perform parameter estimation755 """756 from .Thread import EstimatePr757 758 # If a thread is already started, stop it759 self.stopEstimationThread()760 761 self.estimationThread = EstimatePr(self._calculator.clone(),762 self.getNFunc(),763 error_func=self._threadError,764 completefn=self._estimateDynamicCompleted,765 updatefn=None)766 self.estimationThread.queue()767 self.estimationThread.ready(2.5)768 769 695 def stopEstimationThread(self): 770 696 """ Stop the estimation thread if it exists and is running """ … … 779 705 ''' Send a signal to the main thread for model update''' 780 706 self.estimateSignal.emit((alpha, message, elapsed)) 781 782 def _estimateDynamicCompleted(self, alpha, message, elapsed):783 ''' Send a signal to the main thread for model update'''784 self.estimateDynamicSignal.emit((alpha, message, elapsed))785 707 786 708 def _estimateUpdate(self, output_tuple): … … 798 720 logger.info(message) 799 721 self.performEstimateNT() 800 self.performEstimateDynamicNT()801 802 def _estimateDynamicUpdate(self, output_tuple):803 """804 Parameter estimation completed,805 display the results to the user806 807 :param alpha: estimated best alpha808 :param elapsed: computation time809 """810 alpha, message, elapsed = output_tuple811 self._calculator.alpha = alpha812 self._calculator.elapsed += self._calculator.elapsed813 if message:814 logger.info(message)815 self.performEstimateDynamicNT()816 722 817 723 def _estimateNTCompleted(self, nterms, alpha, message, elapsed): 818 724 ''' Send a signal to the main thread for model update''' 819 725 self.estimateNTSignal.emit((nterms, alpha, message, elapsed)) 820 821 def _estimateDynamicNTCompleted(self, nterms, alpha, message, elapsed):822 ''' Send a signal to the main thread for model update'''823 self.estimateDynamicNTSignal.emit((nterms, alpha, message, elapsed))824 726 825 727 def _estimateNTUpdate(self, output_tuple): … … 845 747 self.startThread() 846 748 847 def _estimateDynamicNTUpdate(self, output_tuple):848 """849 Parameter estimation completed,850 display the results to the user851 852 :param alpha: estimated best alpha853 :param nterms: estimated number of terms854 :param elapsed: computation time855 """856 nterms, alpha, message, elapsed = output_tuple857 self._calculator.elapsed += elapsed858 self._calculator.suggested_alpha = alpha859 self.nTermsSuggested = nterms860 # Save useful info861 self.updateDynamicGuiValues()862 if message:863 logger.info(message)864 if self.isBatch:865 self.acceptAlpha()866 self.acceptNoTerms()867 self.startThread()868 869 749 def _calculateCompleted(self, out, cov, pr, elapsed): 870 750 ''' Send a signal to the main thread for model update'''
Note: See TracChangeset
for help on using the changeset viewer.