Changeset f1495ff in sasview for src/sas/sasgui


Ignore:
Timestamp:
Sep 1, 2017 4:48:55 AM (7 years ago)
Author:
lewis
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
57b48ab
Parents:
14fbdba
git-author:
Lewis O'Driscoll <lewis.o'driscoll@…> (09/01/17 04:47:45)
git-committer:
Lewis O'Driscoll <lewis.o'driscoll@…> (09/01/17 04:48:55)
Message:

Revert "Ensure sum/multiplication models behave correctly"

This reverts commit 14fbdba3d08cd73cbe9502e304cb92761e39253d.
This commit has been moved to a different branch (ticket-767)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/perspectives/calculator/model_editor.py

    r14fbdba rf1495ff  
    106106        self.model2_string = "cylinder" 
    107107        self.name = 'Sum' + M_NAME 
     108        self.factor = 'scale_factor' 
    108109        self._notes = '' 
    109110        self._operator = '+' 
     
    132133        self.model2_name = str(self.model2.GetValue()) 
    133134        self.good_name = True 
    134         self.fill_operator_combox() 
     135        self.fill_oprator_combox() 
    135136 
    136137    def _layout_name(self): 
     
    490491        a sum or multiply model then create the appropriate string 
    491492        """ 
     493 
    492494        name = '' 
     495 
    493496        if operator == '*': 
    494497            name = 'Multi' 
    495498            factor = 'background' 
     499            f_oper = '+' 
    496500        else: 
    497501            name = 'Sum' 
    498502            factor = 'scale_factor' 
    499  
     503            f_oper = '*' 
     504 
     505        self.factor = factor 
    500506        self._operator = operator 
    501         self.explanation = ("  Plugin_model = scale_factor * (model_1 {} " 
    502             "model_2) + background").format(operator) 
     507        self.explanation = "  Plugin Model = %s %s (model1 %s model2)\n" % \ 
     508                           (self.factor, f_oper, self._operator) 
    503509        self.explanationctr.SetLabel(self.explanation) 
    504510        self.name = name + M_NAME 
    505511 
    506512 
    507     def fill_operator_combox(self): 
     513    def fill_oprator_combox(self): 
    508514        """ 
    509515        fill the current combobox with the operator 
     
    530536            description = name1 + self._operator + name2 
    531537        operator_text = self._operator_choice.GetValue() 
    532         f_oper = '*' if '+' in operator_text else '+' 
     538        if '+' in operator_text: 
     539            factor = 'scale_factor' 
     540            f_oper = '*' 
     541            default_val = '1.0' 
     542        else: 
     543            factor = 'background' 
     544            f_oper = '+' 
     545            default_val = '0.0' 
    533546        path = self.fname 
     547        try: 
     548            out_f = open(path, 'w') 
     549        except: 
     550            raise 
    534551        output = SUM_TEMPLATE.format(model1=name1, model2=name2,  
    535             scale_factor_default=1.0, background_default=0.001, 
    536             factor_operator=f_oper, operator=self._operator, 
    537             description=description) 
    538         if self._operator == '*': 
    539             # Multiplication models only have 1 overall scale factor. Don't use 
    540             # sub-models' individual scales as fitting params 
    541             output = output.replace("if name == 'background'",  
    542                 "if name == 'background' or name == 'scale'") 
    543         with open(self.fname, 'w') as out_f: 
    544             out_f.write(output + "\n") 
     552            scale_factor_default=default_val, factor_operator=f_oper, 
     553            operator=self._operator, description=description) 
     554        output = output.replace("scale_factor", factor) 
     555        out_f.write(output + "\n") 
     556        out_f.close() 
    545557 
    546558    def compile_file(self, path): 
     
    12681280        ## New parameter:scaling_factor 
    12691281        self.params['scale_factor'] = {scale_factor_default} 
    1270         # Set each model's background to 0, and define our own background param 
    1271         if 'background' in self.p_model1.params: 
    1272             self.p_model1.setParam('background', 0.0) 
    1273         if 'background' in self.p_model2.params: 
    1274             self.p_model2.setParam('background', 0.0) 
    1275         self.params['background'] = {background_default} 
    12761282 
    12771283        ## Parameter details [units, min, max] 
    12781284        self._set_details() 
    12791285        self.details['scale_factor'] = ['', 0.0, numpy.inf] 
    1280         self.details['background'] = ['1/cm', 0.0, numpy.inf] 
     1286 
    12811287 
    12821288        #list of parameter that can be fitted 
     
    13791385    def _set_params(self): 
    13801386        for name , value in self.p_model1.params.iteritems(): 
    1381             # Don't use the model's background param - we've defined our own 
    1382             if name == 'background': 
    1383                 continue 
     1387            # No 2D-supported 
     1388            #if name not in self.p_model1.orientation_params: 
    13841389            new_name = "p1_" + name 
    1385             self.params[new_name] = value 
     1390            self.params[new_name]= value 
    13861391 
    13871392        for name , value in self.p_model2.params.iteritems(): 
    1388             # Don't use the model's background param - we've defined our own 
    1389             if name == 'background': 
    1390                 continue 
     1393            # No 2D-supported 
     1394            #if name not in self.p_model2.orientation_params: 
    13911395            new_name = "p2_" + name 
    1392             self.params[new_name] = value 
     1396            self.params[new_name]= value 
    13931397 
    13941398        # Set "scale" as initializing 
     
    13981402    def _set_details(self): 
    13991403        for name ,detail in self.p_model1.details.iteritems(): 
    1400             if name == 'background': 
    1401                 continue 
    14021404            new_name = "p1_" + name 
    14031405            #if new_name not in self.orientation_params: 
     
    14051407 
    14061408        for name ,detail in self.p_model2.details.iteritems(): 
    1407             if name == 'background': 
    1408                 continue 
    14091409            new_name = "p2_" + name 
    14101410            #if new_name not in self.orientation_params: 
     
    14321432             if new_name in self.p_model2.getParamList(): 
    14331433                self.p_model2.setParam(new_name, value) 
    1434         elif name == 'scale_factor' or name == 'background': 
    1435             self.params[name] = value 
     1434        elif name == 'scale_factor': 
     1435            self.params['scale_factor'] = value 
    14361436        else: 
    14371437            raise ValueError, "Model does not contain parameter %s" % name 
     
    14901490        self._set_scale_factor() 
    14911491        return self.params['scale_factor'] {factor_operator} \ 
    1492 (self.p_model1.run(x) {operator} self.p_model2.run(x)) + self.params['background'] 
     1492(self.p_model1.run(x) {operator} self.p_model2.run(x)) 
    14931493 
    14941494    def runXY(self, x = 0.0): 
    14951495        self._set_scale_factor() 
    14961496        return self.params['scale_factor'] {factor_operator} \ 
    1497 (self.p_model1.runXY(x) {operator} self.p_model2.runXY(x)) + self.params['background'] 
     1497(self.p_model1.runXY(x) {operator} self.p_model2.runXY(x)) 
    14981498 
    14991499    ## Now (May27,10) directly uses the model eval function 
     
    15031503        return self.params['scale_factor'] {factor_operator} \ 
    15041504(self.p_model1.evalDistribution(x) {operator} \ 
    1505 self.p_model2.evalDistribution(x)) + self.params['background'] 
     1505self.p_model2.evalDistribution(x)) 
    15061506 
    15071507    def set_dispersion(self, parameter, dispersion): 
Note: See TracChangeset for help on using the changeset viewer.