Changeset e499ca0 in sasview


Ignore:
Timestamp:
Jan 22, 2012 4:07:55 PM (13 years ago)
Author:
Jae Cho <jhjcho@…>
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.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
f9feff3
Parents:
d2c4c06
Message:

set 'import math' as default

File:
1 edited

Legend:

Unmodified
Added
Removed
  • calculatorview/src/sans/perspectives/calculator/model_editor.py

    r2b4c8ca re499ca0  
    287287        Do the layout for parameter related widgets 
    288288        """ 
    289         param_txt = wx.StaticText(self, -1, 'Parameters : ')  
     289        param_txt = wx.StaticText(self, -1, 'Fit Parameters (if any): ')  
    290290        param_tip = "#Set the parameters and initial values.\n" 
    291291        param_tip += "#Example:\n" 
     
    307307        function_txt = wx.StaticText(self, -1, 'Function(x) : ')  
    308308        hint_function = "#Example:\n" 
    309         hint_function += "new_x = x * math.pi\n" 
    310         hint_function += "if new_x <= 0:\n" 
     309        hint_function += "if x <= 0:\n" 
    311310        hint_function += "    y = A + B\n" 
    312311        hint_function += "else:\n" 
    313         hint_function += "    y = A + B * numpy.cos(new_x)\n" 
     312        hint_function += "    y = A + B * cos(2 * pi * x)\n" 
    314313        hint_function += "return y\n" 
    315314        id  = wx.NewId()  
     
    423422        # Sort out the errors if occur 
    424423        if self.check_name(): 
     424            name = self.name_tcl.GetValue().lstrip().rstrip() 
    425425            description = self.desc_tcl.GetValue() 
    426426            param_str = self.param_tcl.GetText() 
     
    471471        except : 
    472472            raise 
     473        # Prepare the content of the function 
    473474        lines = CUSTOM_TEMPLATE.split('\n') 
     475        im_np = 'import numpy' 
     476        im_sp = 'import scipy' 
     477        if func_str.count(im_np): 
     478            func_str = func_str.replace(im_np, '') 
     479        if func_str.count(im_sp): 
     480            func_str = func_str.replace(im_sp, '') 
    474481        has_scipy = func_str.count("scipy.") 
    475482        self.is_2d = func_str.count("#self.ndim = 2") 
     
    495502                    out_f.write(local_params) 
    496503            elif line.count("self.description = "): 
     504                des0 = self.name + "\\n" 
    497505                desc = str(desc_str.lstrip().rstrip().replace('\"', '')) 
    498                 if not desc: 
    499                     desc= self.name 
    500                 out_f.write(line% desc + "\n") 
     506                out_f.write(line% (des0 + desc) + "\n") 
    501507            elif line.count("def function(self, x=0.0%s):"): 
    502508                if self.is_2d: 
     
    544550        for item in items: 
    545551            name = item.split("=")[0].lstrip().rstrip() 
    546             value = item.split("=")[1].lstrip().rstrip() 
    547552            try: 
     553                value = item.split("=")[1].lstrip().rstrip() 
    548554                float(value) 
    549555            except: 
    550                raise 
     556                value = 1.0 # default 
    551557            params_str += spaces + "self.params['%s'] = %s\n"% (name, value) 
    552558             
     
    604610CUSTOM_TEMPLATE = """ 
    605611from sans.models.pluginmodel import Model1DPlugin 
    606 import math 
     612from math import * 
    607613import numpy 
    608614#import scipy? 
Note: See TracChangeset for help on using the changeset viewer.