Changes in src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py [2b8286c:dee9e5f] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py
r2b8286c rdee9e5f 14 14 # pr inversion calculation elements 15 15 from sas.sascalc.pr.invertor import Invertor 16 from sas.qtgui.Plotting.PlotterData import Data1D 16 17 # Batch calculation display 17 18 from sas.qtgui.Utilities.GridPanel import BatchInversionOutputPanel … … 43 44 estimateSignal = QtCore.pyqtSignal(tuple) 44 45 estimateNTSignal = QtCore.pyqtSignal(tuple) 46 estimateDynamicNTSignal = QtCore.pyqtSignal(tuple) 47 estimateDynamicSignal = QtCore.pyqtSignal(tuple) 45 48 calculateSignal = QtCore.pyqtSignal(tuple) 46 49 … … 52 55 53 56 self._manager = parent 57 #Needed for Batch fitting 58 self._parent = parent 54 59 self.communicate = parent.communicator() 55 60 self.communicate.dataDeletedSignal.connect(self.removeData) … … 109 114 # Set up the Widget Map 110 115 self.setupMapper() 116 117 #Hidding calculate all buton 118 self.calculateAllButton.setVisible(False) 111 119 # Set base window state 112 120 self.setupWindow() … … 119 127 120 128 def allowBatch(self): 121 return True129 return False 122 130 123 131 def setClosable(self, value=True): … … 194 202 self.model.itemChanged.connect(self.model_changed) 195 203 self.estimateNTSignal.connect(self._estimateNTUpdate) 204 self.estimateDynamicNTSignal.connect(self._estimateDynamicNTUpdate) 205 self.estimateDynamicSignal.connect(self._estimateDynamicUpdate) 196 206 self.estimateSignal.connect(self._estimateUpdate) 197 207 self.calculateSignal.connect(self._calculateUpdate) 208 209 self.maxDistanceInput.textEdited.connect(self.performEstimateDynamic) 198 210 199 211 def setupMapper(self): … … 309 321 and not self.isCalculating) 310 322 self.removeButton.setEnabled(self.logic.data_is_loaded) 311 self.explorerButton.setEnabled(self.logic.data_is_loaded 312 and np.all(self.logic.data.dy != 0)) 323 self.explorerButton.setEnabled(self.logic.data_is_loaded) 313 324 self.stopButton.setVisible(self.isCalculating) 314 325 self.regConstantSuggestionButton.setEnabled( … … 453 464 # Create initial internal mappings 454 465 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 continue 455 470 # Estimate q range 456 471 qmin, qmax = self.logic.computeDataRange() 457 472 self._calculator.set_qmin(qmin) 458 473 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) 459 476 self.updateDataList(data) 460 477 self.populateDataComboBox(self.logic.data.filename, data) 461 478 self.dataList.setCurrentIndex(len(self.dataList) - 1) 462 self.setCurrentData(data) 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) 463 482 464 483 def updateDataList(self, dataRef): … … 501 520 self.dataPlot = self._dataList[data_ref].get(DICT_KEYS[2]) 502 521 self.performEstimate() 522 523 def updateDynamicGuiValues(self): 524 pr = self._calculator 525 alpha = self._calculator.suggested_alpha 526 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() 503 533 504 534 def updateGuiValues(self): … … 520 550 self.model.setItem(WIDGETS.W_MAX_DIST, 521 551 QtGui.QStandardItem("{:.4g}".format(pr.get_dmax()))) 522 self.regConstantSuggestionButton.setText("{:-3.2g}".format(alpha))523 self.noOfTermsSuggestionButton.setText(524 "{:n}".format(self.nTermsSuggested))525 552 526 553 if isinstance(pr.chi2, np.ndarray): … … 544 571 if self.prPlot is not None: 545 572 title = self.prPlot.name 573 self.prPlot.plot_role = Data1D.ROLE_RESIDUAL 546 574 GuiUtils.updateModelItemWithPlot(self._data, self.prPlot, title) 547 self.communicate.plotRequestedSignal.emit([self. prPlot], None)575 self.communicate.plotRequestedSignal.emit([self._data,self.prPlot], None) 548 576 if self.dataPlot is not None: 549 577 title = self.dataPlot.name 578 self.dataPlot.plot_role = Data1D.ROLE_DEFAULT 579 self.dataPlot.symbol = "Line" 580 self.dataPlot.show_errors = False 550 581 GuiUtils.updateModelItemWithPlot(self._data, self.dataPlot, title) 551 self.communicate.plotRequestedSignal.emit([self. dataPlot], None)582 self.communicate.plotRequestedSignal.emit([self._data,self.dataPlot], None) 552 583 self.enableButtons() 553 584 … … 633 664 634 665 pr = self._calculator.clone() 635 nfunc = self.getNFunc() 636 self.calcThread = CalcPr(pr, nfunc, 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, 637 669 error_func=self._threadError, 638 670 completefn=self._calculateCompleted, … … 667 699 error_func=self._threadError, 668 700 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 estimation 708 """ 709 from .Thread import EstimateNT 710 711 self.updateCalculator() 712 713 # If a thread is already started, stop it 714 self.stopEstimateNTThread() 715 716 pr = self._calculator.clone() 717 # Skip the slit settings for the estimation 718 # It slows down the application and it doesn't change the estimates 719 pr.slit_height = 0.0 720 pr.slit_width = 0.0 721 nfunc = self.getNFunc() 722 723 self.estimationThreadNT = EstimateNT(pr, nfunc, 724 error_func=self._threadError, 725 completefn=self._estimateDynamicNTCompleted, 669 726 updatefn=None) 670 727 self.estimationThreadNT.queue() … … 693 750 self.estimationThread.ready(2.5) 694 751 752 def performEstimateDynamic(self): 753 """ 754 Perform parameter estimation 755 """ 756 from .Thread import EstimatePr 757 758 # If a thread is already started, stop it 759 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 695 769 def stopEstimationThread(self): 696 770 """ Stop the estimation thread if it exists and is running """ … … 705 779 ''' Send a signal to the main thread for model update''' 706 780 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)) 707 785 708 786 def _estimateUpdate(self, output_tuple): … … 720 798 logger.info(message) 721 799 self.performEstimateNT() 800 self.performEstimateDynamicNT() 801 802 def _estimateDynamicUpdate(self, output_tuple): 803 """ 804 Parameter estimation completed, 805 display the results to the user 806 807 :param alpha: estimated best alpha 808 :param elapsed: computation time 809 """ 810 alpha, message, elapsed = output_tuple 811 self._calculator.alpha = alpha 812 self._calculator.elapsed += self._calculator.elapsed 813 if message: 814 logger.info(message) 815 self.performEstimateDynamicNT() 722 816 723 817 def _estimateNTCompleted(self, nterms, alpha, message, elapsed): 724 818 ''' Send a signal to the main thread for model update''' 725 819 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)) 726 824 727 825 def _estimateNTUpdate(self, output_tuple): … … 747 845 self.startThread() 748 846 847 def _estimateDynamicNTUpdate(self, output_tuple): 848 """ 849 Parameter estimation completed, 850 display the results to the user 851 852 :param alpha: estimated best alpha 853 :param nterms: estimated number of terms 854 :param elapsed: computation time 855 """ 856 nterms, alpha, message, elapsed = output_tuple 857 self._calculator.elapsed += elapsed 858 self._calculator.suggested_alpha = alpha 859 self.nTermsSuggested = nterms 860 # Save useful info 861 self.updateDynamicGuiValues() 862 if message: 863 logger.info(message) 864 if self.isBatch: 865 self.acceptAlpha() 866 self.acceptNoTerms() 867 self.startThread() 868 749 869 def _calculateCompleted(self, out, cov, pr, elapsed): 750 870 ''' Send a signal to the main thread for model update'''
Note: See TracChangeset
for help on using the changeset viewer.