Changeset cb39d66 in sasview for src/sas/qtgui/Perspectives/Fitting


Ignore:
Timestamp:
Sep 25, 2018 3:50:43 PM (6 years ago)
Author:
GitHub <noreply@…>
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:
49699a3
Parents:
34f13a83 (diff), d99b1a5 (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.
git-author:
Torin Cooper-Bennun <40573959+tcbennun@…> (09/25/18 15:50:43)
git-committer:
GitHub <noreply@…> (09/25/18 15:50:43)
Message:

Merge pull request #184 from SasView?/ESS_GUI_iss1052

SASVIEW-1052: Let user choose if radius_effective is computed from form factor, or free/fittable

Location:
src/sas/qtgui/Perspectives/Fitting
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Perspectives/Fitting/FittingLogic.py

    ra54bbf2b radf1c2a  
    223223        return plots 
    224224 
     225    def getScalarIntermediateResults(self, return_data): 
     226        """ 
     227        Returns a dict of scalar-only intermediate results from the return data. 
     228        """ 
     229        res = {} 
     230        for name, int_res in return_data["intermediate_results"].items(): 
     231            if isinstance(int_res, np.ndarray): 
     232                continue 
     233            res[name] = int_res 
     234        return res 
     235 
    225236    def computeDataRange(self): 
    226237        """ 
  • src/sas/qtgui/Perspectives/Fitting/FittingWidget.py

    r9b9ec10 rcb39d66  
    22972297        # TODO: multishell params in self.kernel_module.details[??] = value 
    22982298 
     2299        # handle display of effective radius parameter according to radius_effective_mode; pass ER into model if 
     2300        # necessary 
     2301        self.processEffectiveRadius() 
     2302 
    22992303        # Force the chart update when actual parameters changed 
    23002304        if model_column == 1: 
     
    23032307        # Update state stack 
    23042308        self.updateUndo() 
     2309 
     2310    def processEffectiveRadius(self): 
     2311        """ 
     2312        Checks the value of radius_effective_mode, if existent, and processes radius_effective as necessary. 
     2313        * mode == 0: This means 'unconstrained'; ensure use can specify ER. 
     2314        * mode > 0: This means it is constrained to a P(Q)-computed value in sasmodels; prevent user from editing ER. 
     2315 
     2316        Note: If ER has been computed, it is passed back to SasView as an intermediate result. That value must be 
     2317        displayed for the user; that is not dealt with here, but in complete1D. 
     2318        """ 
     2319        ER_row = self.getRowFromName("radius_effective") 
     2320        if ER_row is None: 
     2321            return 
     2322 
     2323        ER_mode_row = self.getRowFromName("radius_effective_mode") 
     2324        if ER_mode_row is None: 
     2325            return 
     2326 
     2327        try: 
     2328            ER_mode = int(self._model_model.item(ER_mode_row, 1).text()) 
     2329        except ValueError: 
     2330            logging.error("radius_effective_mode was set to an invalid value.") 
     2331            return 
     2332 
     2333        if ER_mode == 0: 
     2334            # ensure the ER value can be modified by user 
     2335            self.setParamEditableByRow(ER_row, True) 
     2336        elif ER_mode > 0: 
     2337            # ensure the ER value cannot be modified by user 
     2338            self.setParamEditableByRow(ER_row, False) 
     2339        else: 
     2340            logging.error("radius_effective_mode was set to an invalid value.") 
     2341 
     2342    def setParamEditableByRow(self, row, editable=True): 
     2343        """ 
     2344        Sets whether the user can edit a parameter in the table. If they cannot, the parameter name's font is changed, 
     2345        the value itself cannot be edited if clicked on, and the parameter may not be fitted. 
     2346        """ 
     2347        item_name = self._model_model.item(row, 0) 
     2348        item_value = self._model_model.item(row, 1) 
     2349 
     2350        item_value.setEditable(editable) 
     2351 
     2352        if editable: 
     2353            # reset font 
     2354            item_name.setFont(QtGui.QFont()) 
     2355            # reset colour 
     2356            item_name.setForeground(QtGui.QBrush()) 
     2357            # make checkable 
     2358            item_name.setCheckable(True) 
     2359        else: 
     2360            # change font 
     2361            font = QtGui.QFont() 
     2362            font.setItalic(True) 
     2363            item_name.setFont(font) 
     2364            # change colour 
     2365            item_name.setForeground(QtGui.QBrush(QtGui.QColor(50, 50, 50))) 
     2366            # make not checkable (and uncheck) 
     2367            item_name.setCheckState(QtCore.Qt.Unchecked) 
     2368            item_name.setCheckable(False) 
    23052369 
    23062370    def isCheckable(self, row): 
     
    25352599            self.communicate.plotUpdateSignal.emit([plot]) 
    25362600 
     2601        # Update radius_effective if relevant 
     2602        self.updateEffectiveRadius(return_data) 
     2603 
    25372604    def complete2D(self, return_data): 
    25382605        """ 
     
    25612628        for plot in new_plots: 
    25622629            self.communicate.plotUpdateSignal.emit([plot]) 
     2630 
     2631    def updateEffectiveRadius(self, return_data): 
     2632        """ 
     2633        Given return data from sasmodels, update the effective radius parameter in the GUI table with the new 
     2634        calculated value as returned by sasmodels (if the value was returned). 
     2635        """ 
     2636        ER_mode_row = self.getRowFromName("radius_effective_mode") 
     2637        if ER_mode_row is None: 
     2638            return 
     2639        try: 
     2640            ER_mode = int(self._model_model.item(ER_mode_row, 1).text()) 
     2641        except ValueError: 
     2642            logging.error("radius_effective_mode was set to an invalid value.") 
     2643            return 
     2644        if ER_mode < 1: 
     2645            # does not need updating if it is not being computed 
     2646            return 
     2647 
     2648        ER_row = self.getRowFromName("radius_effective") 
     2649        if ER_row is None: 
     2650            return 
     2651 
     2652        scalar_results = self.logic.getScalarIntermediateResults(return_data) 
     2653        ER_value = scalar_results.get("effective_radius") # note name of key 
     2654        if ER_value is None: 
     2655            return 
     2656        # ensure the model does not recompute when updating the value 
     2657        self._model_model.blockSignals(True) 
     2658        self._model_model.item(ER_row, 1).setText(str(ER_value)) 
     2659        self._model_model.blockSignals(False) 
     2660        # ensure the view is updated immediately 
     2661        self._model_model.layoutChanged.emit() 
    25632662 
    25642663    def calculateResiduals(self, fitted_data): 
  • src/sas/qtgui/Perspectives/Fitting/FittingPerspective.py

    r10fee37 r9b9ec10  
    6363        self.fittingStoppedSignal.connect(self.onFittingStopped) 
    6464 
     65        self.communicate.copyFitParamsSignal.connect(self.onParamCopy) 
     66        self.communicate.pasteFitParamsSignal.connect(self.onParamPaste) 
     67 
    6568        # Perspective window not allowed to close by default 
    6669        self._allow_close = False 
     
    9497 
    9598        self._allow_close = value 
     99 
     100    def onParamCopy(self): 
     101        self.currentTab.onParameterCopy("") 
     102 
     103    def onParamPaste(self): 
     104        self.currentTab.onParameterPaste() 
    96105 
    97106    def closeEvent(self, event): 
     
    298307            page_name = "Page%s"%tab_object.tab_id 
    299308            if any([page_name in tab for tab in tabs_for_fitting]): 
    300                 tab_object.setFittingStarted() 
     309                tab_object.disableInteractiveElements() 
    301310 
    302311        pass 
     
    315324            page_name = "Page%s"%tab_object.tab_id 
    316325            if any([page_name in tab for tab in tabs_for_fitting]): 
    317                 tab_object.setFittingStopped() 
     326                tab_object.enableInteractiveElements() 
    318327 
    319328        pass 
  • src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py

    r30bed93 r65759c7  
    484484                    endl = i 
    485485                    break 
    486             # make sure we have correct lengths 
    487             assert len(x_current) == len(x_reference[begin:end-endl]) 
    488486 
    489487            y = (fn - gn[begin:end-endl])/en 
     
    549547                      "Data2D": residualsData2D} 
    550548 
    551     residuals = residuals_dict[method_name](reference_data, data_copy) 
     549    try: 
     550        residuals = residuals_dict[method_name](reference_data, data_copy) 
     551    except ValueError: 
     552        return None 
    552553 
    553554    theory_name = str(current_data.name.split()[0]) 
  • src/sas/qtgui/Perspectives/Fitting/SmearingWidget.py

    r9a7c81c r8b6e4be  
    6161        self.data = None 
    6262        self.current_smearer = None 
     63        self.kernel_model = None 
    6364 
    6465        # Let only floats in the line edits 
     
    110111        if data is None: 
    111112            self.setElementsVisibility(False) 
    112         elif isinstance(data, Data1D): 
     113 
     114    def updateKernelModel(self, kernel_model=None): 
     115        """ 
     116        Update the model 
     117        """ 
     118        self.kernel_model = kernel_model 
     119        if self.data is None: 
     120            self.setElementsVisibility(False) 
     121            return 
     122        if self.kernel_model is None: 
     123            return 
     124        elif isinstance(self.data, Data1D): 
    113125            self.cbSmearing.addItems(SMEARING_1D) 
    114126        else: 
    115127            self.cbSmearing.addItems(SMEARING_2D) 
    116128        self.cbSmearing.setCurrentIndex(0) 
    117  
    118     def updateKernelModel(self, kernel_model=None): 
    119         """ 
    120         Update the model 
    121         """ 
    122         self.kernel_model = kernel_model 
    123129 
    124130    def smearer(self): 
  • src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingWidgetTest.py

    r8faac15 r712db9e  
    393393 
    394394        # Test tooltips 
    395         self.assertEqual(len(self.widget._poly_model.header_tooltips), 9) 
     395        self.assertEqual(len(self.widget._poly_model.header_tooltips), 8) 
    396396 
    397397        header_tooltips = ['Select parameter for fitting', 
     
    702702        # Force same data into logic 
    703703        self.widget.data = item 
     704 
    704705        category_index = self.widget.cbCategory.findText("Sphere") 
    705706        self.widget.cbCategory.setCurrentIndex(category_index) 
    706  
    707         self.widget.show() 
    708707 
    709708        # Test no fitting params 
Note: See TracChangeset for help on using the changeset viewer.