Changeset 490c617 in sasview


Ignore:
Timestamp:
Aug 2, 2017 8:29:05 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, costrafo411, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
5c3c310
Parents:
bc04647
Message:

Parse parameter values correctly if line ends in comment

File:
1 edited

Legend:

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

    ra1b8fee r490c617  
    657657        self.warning = "" 
    658658        #This does not seem to be used anywhere so commenting out for now 
    659         #    -- PDB 2/26/17  
     659        #    -- PDB 2/26/17 
    660660        #self._description = "New Plugin Model" 
    661661        self.function_tcl = None 
     
    740740        self.param_sizer.AddMany([(param_txt, 0, wx.LEFT, 10), 
    741741                                  (self.param_tcl, 1, wx.EXPAND | wx.ALL, 10)]) 
    742          
     742 
    743743        # Parameters with polydispersity 
    744744        pd_param_txt = wx.StaticText(self, -1, 'Fit Parameters requiring ' + \ 
     
    755755        self.pd_param_tcl.setDisplayLineNumbers(True) 
    756756        self.pd_param_tcl.SetToolTipString(pd_param_tip) 
    757          
     757 
    758758        self.param_sizer.AddMany([(pd_param_txt, 0, wx.LEFT, 10), 
    759759                                  (self.pd_param_tcl, 1, wx.EXPAND | wx.ALL, 10)]) 
     
    10301030        if has_scipy: 
    10311031            lines.insert(0, 'import scipy') 
    1032          
    1033         # Think about 2D later         
     1032 
     1033        # Think about 2D later 
    10341034        #self.is_2d = func_str.count("#self.ndim = 2") 
    10351035        #line_2d = '' 
    10361036        #if self.is_2d: 
    10371037        #    line_2d = CUSTOM_2D_TEMP.split('\n') 
    1038          
    1039         # Also think about test later         
     1038 
     1039        # Also think about test later 
    10401040        #line_test = TEST_TEMPLATE.split('\n') 
    10411041        #local_params = '' 
     
    10431043        spaces4  = ' '*4 
    10441044        spaces13 = ' '*13 
    1045         spaces16 = ' '*16      
     1045        spaces16 = ' '*16 
    10461046        param_names = []    # to store parameter names 
    10471047        has_scipy = func_str.count("scipy.") 
     
    10551055            out_f.write(line + '\n') 
    10561056            if line.count('#name'): 
    1057                 out_f.write('name = "%s" \n' % name)                
     1057                out_f.write('name = "%s" \n' % name) 
    10581058            elif line.count('#title'): 
    1059                 out_f.write('title = "User model for %s"\n' % name)                
     1059                out_f.write('title = "User model for %s"\n' % name) 
    10601060            elif line.count('#description'): 
    1061                 out_f.write('description = "%s"\n' % desc_str)                
     1061                out_f.write('description = "%s"\n' % desc_str) 
    10621062            elif line.count('#parameters'): 
    10631063                out_f.write('parameters = [ \n') 
     
    10751075                        out_f.write("%s['%s', '', %s, [-numpy.inf, numpy.inf], 'volume', ''],\n" % (spaces16, pname, pvalue)) 
    10761076                out_f.write('%s]\n' % spaces13) 
    1077              
     1077 
    10781078        # No form_volume or ER available in simple model editor 
    10791079        out_f.write('def form_volume(*arg): \n') 
     
    10821082        out_f.write('def ER(*arg): \n') 
    10831083        out_f.write('    return 1.0 \n') 
    1084          
     1084 
    10851085        # function to compute 
    10861086        out_f.write('\n') 
     
    10911091        for func_line in func_str.split('\n'): 
    10921092            out_f.write('%s%s\n' % (spaces4, func_line)) 
    1093          
     1093 
    10941094        Iqxy_string = 'return Iq(numpy.sqrt(x**2+y**2) ' 
    1095              
     1095 
    10961096        out_f.write('\n') 
    10971097        out_f.write('def Iqxy(x, y ') 
     
    11131113        items = line.split(";") 
    11141114        for item in items: 
    1115             name = item.split("=")[0].lstrip().rstrip() 
     1115            name = item.split("=")[0].strip() 
    11161116            try: 
    1117                 value = item.split("=")[1].lstrip().rstrip() 
     1117                value = item.split("=")[1].strip() 
     1118                if value.count("#"): 
     1119                    # If line ends in a comment, remove it before parsing float 
     1120                    value = value[:value.index("#")].strip() 
    11181121                float(value) 
    1119             except: 
     1122            except ValueError: 
    11201123                value = 1.0 # default 
    11211124 
     
    12041207import numpy 
    12051208 
    1206 #name  
     1209#name 
    12071210 
    12081211#title 
     
    12101213#description 
    12111214 
    1212 #parameters  
     1215#parameters 
    12131216 
    12141217""" 
Note: See TracChangeset for help on using the changeset viewer.