Changeset c1bc9de in sasview for src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py
- Timestamp:
- Sep 19, 2018 7:33:59 AM (6 years ago)
- Branches:
- ESS_GUI, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
- Children:
- bdfe0be
- Parents:
- dee9e5f (diff), d1e4689 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py
r9ce69ec rdee9e5f 44 44 estimateSignal = QtCore.pyqtSignal(tuple) 45 45 estimateNTSignal = QtCore.pyqtSignal(tuple) 46 estimateDynamicNTSignal = QtCore.pyqtSignal(tuple) 47 estimateDynamicSignal = QtCore.pyqtSignal(tuple) 46 48 calculateSignal = QtCore.pyqtSignal(tuple) 47 49 … … 53 55 54 56 self._manager = parent 57 #Needed for Batch fitting 58 self._parent = parent 55 59 self.communicate = parent.communicator() 56 60 self.communicate.dataDeletedSignal.connect(self.removeData) … … 110 114 # Set up the Widget Map 111 115 self.setupMapper() 116 117 #Hidding calculate all buton 118 self.calculateAllButton.setVisible(False) 112 119 # Set base window state 113 120 self.setupWindow() … … 120 127 121 128 def allowBatch(self): 122 return True129 return False 123 130 124 131 def setClosable(self, value=True): … … 195 202 self.model.itemChanged.connect(self.model_changed) 196 203 self.estimateNTSignal.connect(self._estimateNTUpdate) 204 self.estimateDynamicNTSignal.connect(self._estimateDynamicNTUpdate) 205 self.estimateDynamicSignal.connect(self._estimateDynamicUpdate) 197 206 self.estimateSignal.connect(self._estimateUpdate) 198 207 self.calculateSignal.connect(self._calculateUpdate) 208 209 self.maxDistanceInput.textEdited.connect(self.performEstimateDynamic) 199 210 200 211 def setupMapper(self): … … 310 321 and not self.isCalculating) 311 322 self.removeButton.setEnabled(self.logic.data_is_loaded) 312 self.explorerButton.setEnabled(self.logic.data_is_loaded 313 and np.all(self.logic.data.dy != 0)) 323 self.explorerButton.setEnabled(self.logic.data_is_loaded) 314 324 self.stopButton.setVisible(self.isCalculating) 315 325 self.regConstantSuggestionButton.setEnabled( … … 454 464 # Create initial internal mappings 455 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 456 470 # Estimate q range 457 471 qmin, qmax = self.logic.computeDataRange() 458 472 self._calculator.set_qmin(qmin) 459 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) 460 476 self.updateDataList(data) 461 477 self.populateDataComboBox(self.logic.data.filename, data) 462 478 self.dataList.setCurrentIndex(len(self.dataList) - 1) 463 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) 464 482 465 483 def updateDataList(self, dataRef): … … 502 520 self.dataPlot = self._dataList[data_ref].get(DICT_KEYS[2]) 503 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() 504 533 505 534 def updateGuiValues(self): … … 521 550 self.model.setItem(WIDGETS.W_MAX_DIST, 522 551 QtGui.QStandardItem("{:.4g}".format(pr.get_dmax()))) 523 self.regConstantSuggestionButton.setText("{:-3.2g}".format(alpha))524 self.noOfTermsSuggestionButton.setText(525 "{:n}".format(self.nTermsSuggested))526 552 527 553 if isinstance(pr.chi2, np.ndarray): … … 638 664 639 665 pr = self._calculator.clone() 640 nfunc = self.getNFunc() 641 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, 642 669 error_func=self._threadError, 643 670 completefn=self._calculateCompleted, … … 672 699 error_func=self._threadError, 673 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, 674 726 updatefn=None) 675 727 self.estimationThreadNT.queue() … … 698 750 self.estimationThread.ready(2.5) 699 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 700 769 def stopEstimationThread(self): 701 770 """ Stop the estimation thread if it exists and is running """ … … 710 779 ''' Send a signal to the main thread for model update''' 711 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)) 712 785 713 786 def _estimateUpdate(self, output_tuple): … … 725 798 logger.info(message) 726 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() 727 816 728 817 def _estimateNTCompleted(self, nterms, alpha, message, elapsed): 729 818 ''' Send a signal to the main thread for model update''' 730 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)) 731 824 732 825 def _estimateNTUpdate(self, output_tuple): … … 752 845 self.startThread() 753 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 754 869 def _calculateCompleted(self, out, cov, pr, elapsed): 755 870 ''' Send a signal to the main thread for model update'''
Note: See TracChangeset
for help on using the changeset viewer.