Changeset 9f703d0 in sasview


Ignore:
Timestamp:
Aug 30, 2017 7:45:58 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:
14fbdba
Parents:
1c699de
git-author:
Lewis O'Driscoll <lewis.o'driscoll@…> (08/30/17 07:40:17)
git-committer:
Lewis O'Driscoll <lewis.o'driscoll@…> (08/30/17 07:45:58)
Message:

Update Sum/Multi? model to use better string formatting

File:
1 edited

Legend:

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

    r07ec714 r9f703d0  
    496496        if operator == '*': 
    497497            name = 'Multi' 
    498             factor = 'BackGround' 
     498            factor = 'background' 
    499499            f_oper = '+' 
    500500        else: 
     
    535535        if description == '': 
    536536            description = name1 + self._operator + name2 
    537         text = self._operator_choice.GetValue() 
    538         if text.count('+') > 0: 
     537        operator_text = self._operator_choice.GetValue() 
     538        if '+' in operator_text: 
    539539            factor = 'scale_factor' 
    540540            f_oper = '*' 
    541541            default_val = '1.0' 
    542542        else: 
    543             factor = 'BackGround' 
     543            factor = 'background' 
    544544            f_oper = '+' 
    545545            default_val = '0.0' 
     
    549549        except: 
    550550            raise 
    551         lines = SUM_TEMPLATE.split('\n') 
    552         for line in lines: 
    553             try: 
    554                 if line.count("scale_factor"): 
    555                     line = line.replace('scale_factor', factor) 
    556                     #print "scale_factor", line 
    557                 if line.count("= %s"): 
    558                     out_f.write(line % (default_val) + "\n") 
    559                 elif line.count("import Model as P1"): 
    560                     if self.is_p1_custom: 
    561                         line = line.replace('#', '') 
    562                         out_f.write(line % name1 + "\n") 
    563                     else: 
    564                         out_f.write(line + "\n") 
    565                 elif line.count("import %s as P1"): 
    566                     if not self.is_p1_custom: 
    567                         line = line.replace('#', '') 
    568                         out_f.write(line % (name1) + "\n") 
    569                     else: 
    570                         out_f.write(line + "\n") 
    571                 elif line.count("import Model as P2"): 
    572                     if self.is_p2_custom: 
    573                         line = line.replace('#', '') 
    574                         out_f.write(line % name2 + "\n") 
    575                     else: 
    576                         out_f.write(line + "\n") 
    577                 elif line.count("import %s as P2"): 
    578                     if not self.is_p2_custom: 
    579                         line = line.replace('#', '') 
    580                         out_f.write(line % (name2) + "\n") 
    581                     else: 
    582                         out_f.write(line + "\n") 
    583                 elif line.count("P1 = find_model"): 
    584                     out_f.write(line % (name1) + "\n") 
    585                 elif line.count("P2 = find_model"): 
    586                     out_f.write(line % (name2) + "\n") 
    587  
    588                 elif line.count("self.description = '%s'"): 
    589                     out_f.write(line % description + "\n") 
    590                 #elif line.count("run") and line.count("%s"): 
    591                 #    out_f.write(line % self._operator + "\n") 
    592                 #elif line.count("evalDistribution") and line.count("%s"): 
    593                 #    out_f.write(line % self._operator + "\n") 
    594                 elif line.count("return") and line.count("%s") == 2: 
    595                     #print "line return", line 
    596                     out_f.write(line % (f_oper, self._operator) + "\n") 
    597                 elif line.count("out2")and line.count("%s"): 
    598                     out_f.write(line % self._operator + "\n") 
    599                 else: 
    600                     out_f.write(line + "\n") 
    601             except: 
    602                 raise 
     551        output = SUM_TEMPLATE.format(model1=name1, model2=name2,  
     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") 
    603556        out_f.close() 
    604         #else: 
    605         #    msg = "Name exists already." 
    606557 
    607558    def compile_file(self, path): 
     
    12941245    def __init__(self, multiplicity=1): 
    12951246        Model1DPlugin.__init__(self, name='') 
    1296         P1 = find_model('%s') 
    1297         P2 = find_model('%s') 
     1247        P1 = find_model('{model1}') 
     1248        P2 = find_model('{model2}') 
    12981249        p_model1 = P1() 
    12991250        p_model2 = P2() 
    13001251        ## Setting  model name model description 
    1301         self.description = '%s' 
     1252        self.description = '{description}' 
    13021253        if self.name.rstrip().lstrip() == '': 
    13031254            self.name = self._get_name(p_model1.name, p_model2.name) 
     
    13111262 
    13121263        ## Parameter details [units, min, max] 
    1313         self.details = {} 
     1264        self.details = {{}} 
    13141265        ## Magnetic Panrameters 
    13151266        self.magnetic_params = [] 
     
    13281279        self._set_params() 
    13291280        ## New parameter:scaling_factor 
    1330         self.params['scale_factor'] = %s 
     1281        self.params['scale_factor'] = {scale_factor_default} 
    13311282 
    13321283        ## Parameter details [units, min, max] 
     
    15381489    def run(self, x = 0.0): 
    15391490        self._set_scale_factor() 
    1540         return self.params['scale_factor'] %s \ 
    1541 (self.p_model1.run(x) %s self.p_model2.run(x)) 
     1491        return self.params['scale_factor'] {factor_operator} \ 
     1492(self.p_model1.run(x) {operator} self.p_model2.run(x)) 
    15421493 
    15431494    def runXY(self, x = 0.0): 
    15441495        self._set_scale_factor() 
    1545         return self.params['scale_factor'] %s \ 
    1546 (self.p_model1.runXY(x) %s self.p_model2.runXY(x)) 
     1496        return self.params['scale_factor'] {factor_operator} \ 
     1497(self.p_model1.runXY(x) {operator} self.p_model2.runXY(x)) 
    15471498 
    15481499    ## Now (May27,10) directly uses the model eval function 
     
    15501501    def evalDistribution(self, x = []): 
    15511502        self._set_scale_factor() 
    1552         return self.params['scale_factor'] %s \ 
    1553 (self.p_model1.evalDistribution(x) %s \ 
     1503        return self.params['scale_factor'] {factor_operator} \ 
     1504(self.p_model1.evalDistribution(x) {operator} \ 
    15541505self.p_model2.evalDistribution(x)) 
    15551506 
     
    15891540    #m2.p_model2.setParam("scale", 100) 
    15901541    #m2.p_model2.setParam("rg", 100) 
    1591     out2 = m2.p_model1.runXY(0.01) %s m2.p_model2.runXY(0.01)\n 
     1542    out2 = m2.p_model1.runXY(0.01) {operator} m2.p_model2.runXY(0.01)\n 
    15921543    print "My name is %s."% m1.name 
    15931544    print out1, " = ", out2 
Note: See TracChangeset for help on using the changeset viewer.