Ignore:
Timestamp:
Sep 19, 2018 7:33:59 AM (6 years ago)
Author:
wojciech
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.
Message:

Merge branch 'ESS_GUI' of https://github.com/SasView/sasview into ESS_GUI_Pr_fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py

    r9ce69ec rdee9e5f  
    4444    estimateSignal = QtCore.pyqtSignal(tuple) 
    4545    estimateNTSignal = QtCore.pyqtSignal(tuple) 
     46    estimateDynamicNTSignal = QtCore.pyqtSignal(tuple) 
     47    estimateDynamicSignal = QtCore.pyqtSignal(tuple) 
    4648    calculateSignal = QtCore.pyqtSignal(tuple) 
    4749 
     
    5355 
    5456        self._manager = parent 
     57        #Needed for Batch fitting 
     58        self._parent = parent 
    5559        self.communicate = parent.communicator() 
    5660        self.communicate.dataDeletedSignal.connect(self.removeData) 
     
    110114        # Set up the Widget Map 
    111115        self.setupMapper() 
     116 
     117        #Hidding calculate all buton 
     118        self.calculateAllButton.setVisible(False) 
    112119        # Set base window state 
    113120        self.setupWindow() 
     
    120127 
    121128    def allowBatch(self): 
    122         return True 
     129        return False 
    123130 
    124131    def setClosable(self, value=True): 
     
    195202        self.model.itemChanged.connect(self.model_changed) 
    196203        self.estimateNTSignal.connect(self._estimateNTUpdate) 
     204        self.estimateDynamicNTSignal.connect(self._estimateDynamicNTUpdate) 
     205        self.estimateDynamicSignal.connect(self._estimateDynamicUpdate) 
    197206        self.estimateSignal.connect(self._estimateUpdate) 
    198207        self.calculateSignal.connect(self._calculateUpdate) 
     208 
     209        self.maxDistanceInput.textEdited.connect(self.performEstimateDynamic) 
    199210 
    200211    def setupMapper(self): 
     
    310321                                            and not self.isCalculating) 
    311322        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) 
    314324        self.stopButton.setVisible(self.isCalculating) 
    315325        self.regConstantSuggestionButton.setEnabled( 
     
    454464            # Create initial internal mappings 
    455465            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 
    456470            # Estimate q range 
    457471            qmin, qmax = self.logic.computeDataRange() 
    458472            self._calculator.set_qmin(qmin) 
    459473            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) 
    460476            self.updateDataList(data) 
    461477            self.populateDataComboBox(self.logic.data.filename, data) 
    462478        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) 
    464482 
    465483    def updateDataList(self, dataRef): 
     
    502520        self.dataPlot = self._dataList[data_ref].get(DICT_KEYS[2]) 
    503521        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() 
    504533 
    505534    def updateGuiValues(self): 
     
    521550        self.model.setItem(WIDGETS.W_MAX_DIST, 
    522551                           QtGui.QStandardItem("{:.4g}".format(pr.get_dmax()))) 
    523         self.regConstantSuggestionButton.setText("{:-3.2g}".format(alpha)) 
    524         self.noOfTermsSuggestionButton.setText( 
    525             "{:n}".format(self.nTermsSuggested)) 
    526552 
    527553        if isinstance(pr.chi2, np.ndarray): 
     
    638664 
    639665        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, 
    642669                                 error_func=self._threadError, 
    643670                                 completefn=self._calculateCompleted, 
     
    672699                                             error_func=self._threadError, 
    673700                                             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, 
    674726                                             updatefn=None) 
    675727        self.estimationThreadNT.queue() 
     
    698750        self.estimationThread.ready(2.5) 
    699751 
     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 
    700769    def stopEstimationThread(self): 
    701770        """ Stop the estimation thread if it exists and is running """ 
     
    710779        ''' Send a signal to the main thread for model update''' 
    711780        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)) 
    712785 
    713786    def _estimateUpdate(self, output_tuple): 
     
    725798            logger.info(message) 
    726799        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() 
    727816 
    728817    def _estimateNTCompleted(self, nterms, alpha, message, elapsed): 
    729818        ''' Send a signal to the main thread for model update''' 
    730819        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)) 
    731824 
    732825    def _estimateNTUpdate(self, output_tuple): 
     
    752845            self.startThread() 
    753846 
     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 
    754869    def _calculateCompleted(self, out, cov, pr, elapsed): 
    755870        ''' Send a signal to the main thread for model update''' 
Note: See TracChangeset for help on using the changeset viewer.