Ignore:
File:
1 edited

Legend:

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

    rdee9e5f r2b8286c  
    1414# pr inversion calculation elements 
    1515from sas.sascalc.pr.invertor import Invertor 
    16 from sas.qtgui.Plotting.PlotterData import Data1D 
    1716# Batch calculation display 
    1817from sas.qtgui.Utilities.GridPanel import BatchInversionOutputPanel 
     
    4443    estimateSignal = QtCore.pyqtSignal(tuple) 
    4544    estimateNTSignal = QtCore.pyqtSignal(tuple) 
    46     estimateDynamicNTSignal = QtCore.pyqtSignal(tuple) 
    47     estimateDynamicSignal = QtCore.pyqtSignal(tuple) 
    4845    calculateSignal = QtCore.pyqtSignal(tuple) 
    4946 
     
    5552 
    5653        self._manager = parent 
    57         #Needed for Batch fitting 
    58         self._parent = parent 
    5954        self.communicate = parent.communicator() 
    6055        self.communicate.dataDeletedSignal.connect(self.removeData) 
     
    114109        # Set up the Widget Map 
    115110        self.setupMapper() 
    116  
    117         #Hidding calculate all buton 
    118         self.calculateAllButton.setVisible(False) 
    119111        # Set base window state 
    120112        self.setupWindow() 
     
    127119 
    128120    def allowBatch(self): 
    129         return False 
     121        return True 
    130122 
    131123    def setClosable(self, value=True): 
     
    202194        self.model.itemChanged.connect(self.model_changed) 
    203195        self.estimateNTSignal.connect(self._estimateNTUpdate) 
    204         self.estimateDynamicNTSignal.connect(self._estimateDynamicNTUpdate) 
    205         self.estimateDynamicSignal.connect(self._estimateDynamicUpdate) 
    206196        self.estimateSignal.connect(self._estimateUpdate) 
    207197        self.calculateSignal.connect(self._calculateUpdate) 
    208  
    209         self.maxDistanceInput.textEdited.connect(self.performEstimateDynamic) 
    210198 
    211199    def setupMapper(self): 
     
    321309                                            and not self.isCalculating) 
    322310        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)) 
    324313        self.stopButton.setVisible(self.isCalculating) 
    325314        self.regConstantSuggestionButton.setEnabled( 
     
    464453            # Create initial internal mappings 
    465454            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 
    470455            # Estimate q range 
    471456            qmin, qmax = self.logic.computeDataRange() 
    472457            self._calculator.set_qmin(qmin) 
    473458            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) 
    476459            self.updateDataList(data) 
    477460            self.populateDataComboBox(self.logic.data.filename, data) 
    478461        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) 
    482463 
    483464    def updateDataList(self, dataRef): 
     
    520501        self.dataPlot = self._dataList[data_ref].get(DICT_KEYS[2]) 
    521502        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() 
    533503 
    534504    def updateGuiValues(self): 
     
    550520        self.model.setItem(WIDGETS.W_MAX_DIST, 
    551521                           QtGui.QStandardItem("{:.4g}".format(pr.get_dmax()))) 
     522        self.regConstantSuggestionButton.setText("{:-3.2g}".format(alpha)) 
     523        self.noOfTermsSuggestionButton.setText( 
     524            "{:n}".format(self.nTermsSuggested)) 
    552525 
    553526        if isinstance(pr.chi2, np.ndarray): 
     
    571544        if self.prPlot is not None: 
    572545            title = self.prPlot.name 
    573             self.prPlot.plot_role = Data1D.ROLE_RESIDUAL 
    574546            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) 
    576548        if self.dataPlot is not None: 
    577549            title = self.dataPlot.name 
    578             self.dataPlot.plot_role = Data1D.ROLE_DEFAULT 
    579             self.dataPlot.symbol = "Line" 
    580             self.dataPlot.show_errors = False 
    581550            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) 
    583552        self.enableButtons() 
    584553 
     
    664633 
    665634        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, 
    669637                                 error_func=self._threadError, 
    670638                                 completefn=self._calculateCompleted, 
     
    699667                                             error_func=self._threadError, 
    700668                                             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, 
    726669                                             updatefn=None) 
    727670        self.estimationThreadNT.queue() 
     
    750693        self.estimationThread.ready(2.5) 
    751694 
    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  
    769695    def stopEstimationThread(self): 
    770696        """ Stop the estimation thread if it exists and is running """ 
     
    779705        ''' Send a signal to the main thread for model update''' 
    780706        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)) 
    785707 
    786708    def _estimateUpdate(self, output_tuple): 
     
    798720            logger.info(message) 
    799721        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() 
    816722 
    817723    def _estimateNTCompleted(self, nterms, alpha, message, elapsed): 
    818724        ''' Send a signal to the main thread for model update''' 
    819725        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)) 
    824726 
    825727    def _estimateNTUpdate(self, output_tuple): 
     
    845747            self.startThread() 
    846748 
    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  
    869749    def _calculateCompleted(self, out, cov, pr, elapsed): 
    870750        ''' Send a signal to the main thread for model update''' 
Note: See TracChangeset for help on using the changeset viewer.