Changeset 6040cd7 in sasview


Ignore:
Timestamp:
Oct 18, 2018 1:08:33 AM (5 years ago)
Author:
Piotr Rozyczko <piotr.rozyczko@…>
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:
9a42ea1
Parents:
dd545d1
Message:

Refactored getFitParameters slightly to allow use for both parameter
copy, analysis save and project save

Location:
src/sas/qtgui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/MainWindow/GuiManager.py

    refaf022 r6040cd7  
    444444        """ 
    445445        # disable not yet fully implemented actions 
    446         self._workspace.actionOpen_Analysis.setVisible(False) 
     446        #self._workspace.actionOpen_Analysis.setVisible(False) 
    447447        self._workspace.actionUndo.setVisible(False) 
    448448        self._workspace.actionRedo.setVisible(False) 
  • src/sas/qtgui/Perspectives/Fitting/FittingWidget.py

    rdd545d1 r6040cd7  
    33693369        Create and serialize local PageState 
    33703370        """ 
    3371         from sas.sascalc.fit.pagestate import Reader 
    3372         model = self.kernel_module 
    3373  
    3374         # Old style PageState object 
    3375         state = PageState(model=model, data=self.data) 
    3376  
    3377         # Add parameter data to the state 
    3378         self.getCurrentFitState(state) 
    3379  
    3380         # Create the filewriter, aptly named 'Reader' 
    3381         state_reader = Reader(self.loadPageStateCallback) 
    33823371        filepath = self.saveAsAnalysisFile() 
    33833372        if filepath is None or filepath == "": 
    33843373            return 
    3385         state_reader.write(filename=filepath, fitstate=state) 
    3386         pass 
     3374 
     3375        fitpage_state = self.getFitPage() 
     3376        fitpage_state += self.getFitModel() 
     3377 
     3378        with open(filepath, 'w') as statefile: 
     3379            for line in fitpage_state: 
     3380                statefile.write(str(line)) 
     3381 
     3382        self.communicate.statusBarUpdateSignal.emit('Analysis saved.') 
    33873383 
    33883384    def saveAsAnalysisFile(self): 
     
    34173413        Load the PageState object and update the current widget 
    34183414        """ 
    3419         pass 
    3420  
    3421     def getCurrentFitState(self, state=None): 
    3422         """ 
    3423         Store current state for fit_page 
    3424         """ 
    3425         # save model option 
    3426         #if self.model is not None: 
    3427         #    self.disp_list = self.getDispParamList() 
    3428         #    state.disp_list = copy.deepcopy(self.disp_list) 
    3429         #    #state.model = self.model.clone() 
    3430  
    3431         # Comboboxes 
    3432         state.categorycombobox = self.cbCategory.currentText() 
    3433         state.formfactorcombobox = self.cbModel.currentText() 
    3434         if self.cbStructureFactor.isEnabled(): 
    3435             state.structurecombobox = self.cbStructureFactor.currentText() 
    3436         state.tcChi = self.chi2 
    3437  
    3438         state.enable2D = self.is2D 
    3439  
    3440         #state.weights = copy.deepcopy(self.weights) 
    3441         # save data 
    3442         state.data = copy.deepcopy(self.data) 
    3443  
    3444         # save plotting range 
    3445         state.qmin = self.q_range_min 
    3446         state.qmax = self.q_range_max 
    3447         state.npts = self.npts 
    3448  
    3449         #    self.state.enable_disp = self.enable_disp.GetValue() 
    3450         #    self.state.disable_disp = self.disable_disp.GetValue() 
    3451  
    3452         #    self.state.enable_smearer = \ 
    3453         #                        copy.deepcopy(self.enable_smearer.GetValue()) 
    3454         #    self.state.disable_smearer = \ 
    3455         #                        copy.deepcopy(self.disable_smearer.GetValue()) 
    3456  
    3457         #self.state.pinhole_smearer = \ 
    3458         #                        copy.deepcopy(self.pinhole_smearer.GetValue()) 
    3459         #self.state.slit_smearer = copy.deepcopy(self.slit_smearer.GetValue()) 
    3460         #self.state.dI_noweight = copy.deepcopy(self.dI_noweight.GetValue()) 
    3461         #self.state.dI_didata = copy.deepcopy(self.dI_didata.GetValue()) 
    3462         #self.state.dI_sqrdata = copy.deepcopy(self.dI_sqrdata.GetValue()) 
    3463         #self.state.dI_idata = copy.deepcopy(self.dI_idata.GetValue()) 
    3464  
    3465         p = self.model_parameters 
    3466         # save checkbutton state and txtcrtl values 
    3467         state.parameters = FittingUtilities.getStandardParam(self._model_model) 
    3468         state.orientation_params_disp = FittingUtilities.getOrientationParam(self.kernel_module) 
    3469  
    3470         #self._copy_parameters_state(self.orientation_params_disp, self.state.orientation_params_disp) 
    3471         #self._copy_parameters_state(self.parameters, self.state.parameters) 
    3472         #self._copy_parameters_state(self.fittable_param, self.state.fittable_param) 
    3473         #self._copy_parameters_state(self.fixed_param, self.state.fixed_param) 
     3415        filepath = self.loadAnalysisFile() 
     3416        if filepath is None or filepath == "": 
     3417            return 
     3418 
     3419        with open(filepath, 'r') as statefile: 
     3420            statefile.read(lines) 
     3421 
     3422        # convert into list of lists 
     3423 
     3424    def loadAnalysisFile(self): 
     3425        """ 
     3426        Called when the "Open Project" menu item chosen. 
     3427        """ 
     3428        default_name = "FitPage"+str(self.tab_id)+".fitv" 
     3429        wildcard = "fitv files (*.fitv)" 
     3430        kwargs = { 
     3431            'caption'   : 'Open Analysis', 
     3432            'directory' : default_name, 
     3433            'filter'    : wildcard, 
     3434            'parent'    : self, 
     3435        } 
     3436        filename = QtWidgets.QFileDialog.getOpenFileName(**kwargs)[0] 
     3437        return filename 
    34743438 
    34753439    def onCopyToClipboard(self, format=None): 
     
    34933457        cb.setText(formatted_output) 
    34943458 
    3495     def getFitParameters(self, format=None): 
    3496         """ 
    3497         Copy current parameters into the clipboard 
     3459    def getFitModel(self): 
     3460        """ 
     3461        serializes model combos state 
     3462        """ 
     3463        param_list = [] 
     3464        model = str(self.cbModel.currentText()) 
     3465        category = str(self.cbCategory.currentText()) 
     3466        structure = str(self.cbStructureFactor.currentText()) 
     3467        param_list.append(['fitpage_category', category]) 
     3468        param_list.append(['fitpage_model', model]) 
     3469        param_list.append(['fitpage_structure', structure]) 
     3470        return param_list 
     3471 
     3472    def getFitPage(self): 
     3473        """ 
     3474        serializes full state of this fit page 
    34983475        """ 
    34993476        # run a loop over all parameters and pull out 
    35003477        # first - regular params 
     3478        param_list = self.getFitParameters() 
     3479 
     3480        # option tab 
     3481        param_list.append(['q_range_min', str(self.q_range_min)]) 
     3482        param_list.append(['q_range_max', str(self.q_range_max)]) 
     3483        param_list.append(['q_weighting', str(self.weighting)]) 
     3484 
     3485        # resolution 
     3486        smearing, accuracy, smearing_min, smearing_max = self.smearing_widget.state() 
     3487        index = self.smearing_widget.cbSmearing.currentIndex() 
     3488        param_list.append(['smearing', str(index)]) 
     3489        param_list.append(['smearing_min', str(smearing_min)]) 
     3490        param_list.append(['smearing_max', str(smearing_max)]) 
     3491 
     3492        # checkboxes, if required 
     3493        has_polydisp = self.chkPolydispersity.isChecked() 
     3494        has_magnetism = self.chkMagnetism.isChecked() 
     3495        has_chain = self.chkChainFit.isChecked() 
     3496        has_2D = self.chk2DView.isChecked() 
     3497        param_list.append(['polydisperse_params', str(has_polydisp)]) 
     3498        param_list.append(['magnetic_params', str(has_magnetism)]) 
     3499        param_list.append(['chainfit_params', str(has_chain)]) 
     3500        param_list.append(['2D_params', str(has_2D)]) 
     3501 
     3502        return param_list 
     3503 
     3504    def getFitParameters(self): 
     3505        """ 
     3506        serializes current parameters 
     3507        """ 
    35013508        param_list = [] 
    35023509        param_list.append(['model_name', str(self.cbModel.currentText())]) 
     
    35333540            if self.has_error_column: 
    35343541                column_offset = 1 
     3542                param_error = str(self._model_model.item(row, 1+column_offset).text()) 
    35353543            try: 
    35363544                param_min = str(self._model_model.item(row, 2+column_offset).text()) 
     
    35393547                pass 
    35403548 
    3541             param_list.append([param_name, param_checked, param_value, param_min, param_max]) 
     3549            param_list.append([param_name, param_checked, param_value, param_error, param_min, param_max]) 
    35423550 
    35433551        def gatherPolyParams(row): 
     
    35523560            if self.has_poly_error_column: 
    35533561                column_offset = 1 
     3562                param_error = str(self._poly_model.item(row, 1+column_offset).text()) 
    35543563            param_min   = str(self._poly_model.item(row, 2+column_offset).text()) 
    35553564            param_max   = str(self._poly_model.item(row, 3+column_offset).text()) 
     
    35633572            # width 
    35643573            name = param_name+".width" 
    3565             param_list.append([name, param_checked, param_value, param_min, param_max, 
    3566                                 param_npts, param_nsigs, param_fun]) 
     3574            param_list.append([name, param_checked, param_value, param_error, 
     3575                               param_min, param_max, param_npts, param_nsigs, param_fun]) 
    35673576 
    35683577        def gatherMagnetParams(row): 
     
    35773586            if self.has_magnet_error_column: 
    35783587                column_offset = 1 
     3588                param_error = str(self._magnet_model.item(row, 1+column_offset).text()) 
    35793589            param_min = str(self._magnet_model.item(row, 2+column_offset).text()) 
    35803590            param_max = str(self._magnet_model.item(row, 3+column_offset).text()) 
    3581             param_list.append([param_name, param_checked, param_value, param_min, param_max]) 
     3591            param_list.append([param_name, param_checked, param_value, 
     3592                               param_error, param_min, param_max]) 
    35823593 
    35833594        self.iterateOverModel(gatherParams) 
     
    35893600        if self.kernel_module.is_multiplicity_model: 
    35903601            param_list.append(['multiplicity', str(self.kernel_module.multiplicity)]) 
    3591  
    3592         # option tab 
    3593         param_list.append(['q_range_min', str(self.q_range_min)]) 
    3594         param_list.append(['q_range_max', str(self.q_range_max)]) 
    3595         param_list.append(['q_weighting', str(self.weighting)]) 
    3596  
    3597         # resolution 
    3598         smearing, accuracy, smearing_min, smearing_max = self.smearing_widget.state() 
    3599         index = self.smearing_widget.cbSmearing.currentIndex() 
    3600         param_list.append(['smearing', str(index)]) 
    3601         param_list.append(['smearing_min', str(smearing_min)]) 
    3602         param_list.append(['smearing_max', str(smearing_max)]) 
    3603  
    3604         # checkboxes, if required 
    3605         has_polydisp = self.chkPolydispersity.isChecked() 
    3606         has_magnetism = self.chkMagnetism.isChecked() 
    3607         has_chain = self.chkChainFit.isChecked() 
    3608         has_2D = self.chk2DView.isChecked() 
    3609         param_list.append(['polydisperse_params', str(has_polydisp)]) 
    3610         param_list.append(['magnetic_params', str(has_magnetism)]) 
    3611         param_list.append(['chainfit_params', str(has_chain)]) 
    3612         param_list.append(['2D_params', str(has_2D)]) 
    36133602 
    36143603        return param_list 
     
    37593748            # Potentially the error column 
    37603749            ioffset = 0 
    3761             if len(param_dict[param_name])>4 and self.has_error_column: 
     3750            joffset = 0 
     3751            if len(param_dict[param_name])>3: 
    37623752                # error values are not editable - no need to update 
    37633753                ioffset = 1 
     3754            if self.has_error_column: 
     3755                joffset = 1 
    37643756            # min/max 
    37653757            try: 
    37663758                param_repr = GuiUtils.formatNumber(param_dict[param_name][2+ioffset], high=True) 
    3767                 self._model_model.item(row, 2+ioffset).setText(param_repr) 
     3759                self._model_model.item(row, 2+joffset).setText(param_repr) 
    37683760                param_repr = GuiUtils.formatNumber(param_dict[param_name][3+ioffset], high=True) 
    3769                 self._model_model.item(row, 3+ioffset).setText(param_repr) 
     3761                self._model_model.item(row, 3+joffset).setText(param_repr) 
    37703762            except: 
    37713763                pass 
     
    38013793            # Potentially the error column 
    38023794            ioffset = 0 
    3803             if len(param_dict[param_name])>4 and self.has_poly_error_column: 
     3795            joffset = 0 
     3796            if len(param_dict[param_name])>3: 
    38043797                ioffset = 1 
     3798            if self.has_poly_error_column: 
     3799                joffset = 1 
    38053800            # min 
    38063801            param_repr = GuiUtils.formatNumber(param_dict[param_name][2+ioffset], high=True) 
    3807             self._poly_model.item(row, 2+ioffset).setText(param_repr) 
     3802            self._poly_model.item(row, 2+joffset).setText(param_repr) 
    38083803            # max 
    38093804            param_repr = GuiUtils.formatNumber(param_dict[param_name][3+ioffset], high=True) 
    3810             self._poly_model.item(row, 3+ioffset).setText(param_repr) 
     3805            self._poly_model.item(row, 3+joffset).setText(param_repr) 
    38113806            # Npts 
    38123807            param_repr = GuiUtils.formatNumber(param_dict[param_name][4+ioffset], high=True) 
    3813             self._poly_model.item(row, 4+ioffset).setText(param_repr) 
     3808            self._poly_model.item(row, 4+joffset).setText(param_repr) 
    38143809            # Nsigs 
    38153810            param_repr = GuiUtils.formatNumber(param_dict[param_name][5+ioffset], high=True) 
    3816             self._poly_model.item(row, 5+ioffset).setText(param_repr) 
    3817  
    3818             param_repr = GuiUtils.formatNumber(param_dict[param_name][5+ioffset], high=True) 
    3819             self._poly_model.item(row, 5+ioffset).setText(param_repr) 
     3811            self._poly_model.item(row, 5+joffset).setText(param_repr) 
     3812 
    38203813            self.setFocus() 
    38213814 
     
    38483841            # Potentially the error column 
    38493842            ioffset = 0 
    3850             if len(param_dict[param_name])>4 and self.has_magnet_error_column: 
     3843            joffset = 0 
     3844            if len(param_dict[param_name])>3: 
    38513845                ioffset = 1 
     3846            if self.has_magnet_error_column: 
     3847                joffset = 1 
    38523848            # min 
    38533849            param_repr = GuiUtils.formatNumber(param_dict[param_name][2+ioffset], high=True) 
    3854             self._magnet_model.item(row, 2+ioffset).setText(param_repr) 
     3850            self._magnet_model.item(row, 2+joffset).setText(param_repr) 
    38553851            # max 
    38563852            param_repr = GuiUtils.formatNumber(param_dict[param_name][3+ioffset], high=True) 
    3857             self._magnet_model.item(row, 3+ioffset).setText(param_repr) 
     3853            self._magnet_model.item(row, 3+joffset).setText(param_repr) 
    38583854 
    38593855        self.iterateOverMagnetModel(updateFittedValues) 
     3856 
     3857    def getCurrentFitState(self, state=None): 
     3858        """ 
     3859        Store current state for fit_page 
     3860        """ 
     3861        # save model option 
     3862        #if self.model is not None: 
     3863        #    self.disp_list = self.getDispParamList() 
     3864        #    state.disp_list = copy.deepcopy(self.disp_list) 
     3865        #    #state.model = self.model.clone() 
     3866 
     3867        # Comboboxes 
     3868        state.categorycombobox = self.cbCategory.currentText() 
     3869        state.formfactorcombobox = self.cbModel.currentText() 
     3870        if self.cbStructureFactor.isEnabled(): 
     3871            state.structurecombobox = self.cbStructureFactor.currentText() 
     3872        state.tcChi = self.chi2 
     3873 
     3874        state.enable2D = self.is2D 
     3875 
     3876        #state.weights = copy.deepcopy(self.weights) 
     3877        # save data 
     3878        state.data = copy.deepcopy(self.data) 
     3879 
     3880        # save plotting range 
     3881        state.qmin = self.q_range_min 
     3882        state.qmax = self.q_range_max 
     3883        state.npts = self.npts 
     3884 
     3885        #    self.state.enable_disp = self.enable_disp.GetValue() 
     3886        #    self.state.disable_disp = self.disable_disp.GetValue() 
     3887 
     3888        #    self.state.enable_smearer = \ 
     3889        #                        copy.deepcopy(self.enable_smearer.GetValue()) 
     3890        #    self.state.disable_smearer = \ 
     3891        #                        copy.deepcopy(self.disable_smearer.GetValue()) 
     3892 
     3893        #self.state.pinhole_smearer = \ 
     3894        #                        copy.deepcopy(self.pinhole_smearer.GetValue()) 
     3895        #self.state.slit_smearer = copy.deepcopy(self.slit_smearer.GetValue()) 
     3896        #self.state.dI_noweight = copy.deepcopy(self.dI_noweight.GetValue()) 
     3897        #self.state.dI_didata = copy.deepcopy(self.dI_didata.GetValue()) 
     3898        #self.state.dI_sqrdata = copy.deepcopy(self.dI_sqrdata.GetValue()) 
     3899        #self.state.dI_idata = copy.deepcopy(self.dI_idata.GetValue()) 
     3900 
     3901        p = self.model_parameters 
     3902        # save checkbutton state and txtcrtl values 
     3903        state.parameters = FittingUtilities.getStandardParam(self._model_model) 
     3904        state.orientation_params_disp = FittingUtilities.getOrientationParam(self.kernel_module) 
     3905 
     3906        #self._copy_parameters_state(self.orientation_params_disp, self.state.orientation_params_disp) 
     3907        #self._copy_parameters_state(self.parameters, self.state.parameters) 
     3908        #self._copy_parameters_state(self.fittable_param, self.state.fittable_param) 
     3909        #self._copy_parameters_state(self.fixed_param, self.state.fixed_param) 
     3910 
Note: See TracChangeset for help on using the changeset viewer.