Changeset 7c8d3093 in sasview


Ignore:
Timestamp:
Dec 20, 2011 5:25:39 PM (12 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:
b025572
Parents:
1352c78
Message:

more completion of custom model edit

Files:
3 added
7 edited

Legend:

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

    r4c5448c r7c8d3093  
    1212if sys.platform.count("win32")>0: 
    1313    PANEL_WIDTH = 800 
    14     PANEL_HEIGHT = 600 
     14    PANEL_HEIGHT = 700 
    1515    FONT_VARIANT = 0 
    1616else: 
    1717    PANEL_WIDTH = 830 
    18     PANEL_HEIGHT = 620 
     18    PANEL_HEIGHT = 730 
    1919    FONT_VARIANT = 1 
    2020ID_COMPILE = wx.NewId()  
     
    5959        self.dataDir = dataDir 
    6060        self.Centre() 
    61         self.fileMenu.FindItemById(wx.ID_NEW).Enable(False) 
     61         
     62        self.Bind(wx.EVT_MENU, self.OnNewFile, id=wx.ID_NEW) 
    6263        self.Bind(wx.EVT_MENU, self.OnOpenFile, id=wx.ID_OPEN) 
    6364        self.Bind(wx.EVT_MENU, self.OnSaveFile, id=wx.ID_SAVE) 
     
    6768        self.Bind(wx.EVT_UPDATE_UI, self.OnUpdateCompileMenu, id=ID_COMPILE) 
    6869        self.Bind(wx.EVT_UPDATE_UI, self.OnUpdateCompileMenu, id=ID_RUN) 
    69          
     70        if not title.count('Python Shell'): 
     71            # Delete menu item (open and new) if not python shell 
     72            self.fileMenu.Delete(wx.ID_NEW) 
     73            self.fileMenu.Delete(wx.ID_OPEN) 
     74         
     75    
    7076    def _add_menu(self): 
    7177        """ 
     
    7682                 'Compile the file') 
    7783        self.compileMenu.AppendSeparator() 
    78         self.compileMenu.Append(ID_RUN, 'Run', 
     84        self.compileMenu.Append(ID_RUN, 'Run in Shell', 
    7985                 'Run the file in the Python Shell') 
    80         self.MenuBar.Insert(3, self.compileMenu, '&Compile') 
     86        self.MenuBar.Insert(3, self.compileMenu, '&Run') 
    8187     
    8288    def OnHelp(self, event): 
     
    109115                           wx.OK|wx.ICON_INFORMATION)   
    110116        dial.ShowModal() 
     117         
     118    def OnNewFile(self, event): 
     119        """ 
     120        OnFileOpen   
     121        """ 
     122        self.OnFileNew(event) 
    111123 
    112124    def OnOpenFile(self, event): 
     
    134146        self.Show(True) 
    135147 
    136     def bufferSaveAs(self): 
    137         """ 
    138         Save buffer to a new filename: Bypass the annoying suggest save  
    139         """ 
     148    def bufferOpen(self): 
     149        """ 
     150        Open file in buffer, bypassing editor bufferOpen 
     151        """ 
     152        if self.bufferHasChanged(): 
     153            cancel = self.bufferSuggestSave() 
     154            if cancel: 
     155                return cancel 
    140156        filedir = '' 
    141157        if self.buffer and self.buffer.doc.filedir: 
    142158            filedir = self.buffer.doc.filedir 
    143         result = editor.saveSingle(directory=filedir) 
     159        result = editor.openSingle(directory=filedir,   
     160                            wildcard='Python Files (*.py)|*.py') 
     161        if result.path: 
     162            self.bufferCreate(result.path) 
     163        cancel = False 
     164        return cancel 
     165     
     166    def bufferSaveAs(self): 
     167        """ 
     168        Save buffer to a new filename: Bypassing editor bufferSaveAs 
     169        """ 
     170        filedir = '' 
     171        if self.buffer and self.buffer.doc.filedir: 
     172            filedir = self.buffer.doc.filedir 
     173        result = editor.saveSingle(directory=filedir,  
     174                                   filename='untitled.py', 
     175                                   wildcard='Python Files (*.py)|*.py') 
    144176        if result.path: 
    145177            self.buffer.saveAs(result.path) 
     
    148180            cancel = True 
    149181        return cancel 
     182     
    150183     
    151184    def update_custom_combo(self): 
     
    176209            # Why we have to do this (Otherwise problems on Windows)? 
    177210            forward_path = self.buffer.doc.filepath.replace('\\', '/') 
    178             self.shell.Execute("execfile('%s')"% forward_path) 
     211            self.shell.Execute("execfile('%s')"% forward_path)  
    179212            self.shell.Hide() 
    180213            self.shell.Show(True) 
    181             self.shell.SetFocus() 
     214            return self.shell.GetText().split(">>>")[-2] 
    182215        else: 
    183216            mssg = "\n This is not a python file." 
     
    185218            icon = wx.ICON_ERROR 
    186219            wx.MessageBox(str(mssg), title, style=icon) 
     220            return 0 
    187221         
    188222    def OnCompile(self, event): 
     
    192226        if self._check_changed(): 
    193227            return True 
    194         if self._get_err_msg(): 
     228        run_out = self.OnRun(None) 
     229        if self._get_err_msg(run_out): 
    195230            if self._manager != None and self.panel != None: 
    196                 self._manager.set_edit_menu(self.parent) 
     231                self._manager.set_edit_menu_helper(self.parent) 
    197232                wx.CallAfter(self.update_custom_combo) 
    198233     
     
    206241                return cancel 
    207242              
    208     def _get_err_msg(self): 
     243    def _get_err_msg(self, text=''): 
    209244        """ 
    210245        Get err_msg 
     
    229264        if msg != None: 
    230265            mssg += "Error occurred:\n" 
    231             mssg += str(msg) 
    232             title = 'Warning' 
    233             icon = wx.ICON_WARNING 
     266            mssg += str(msg) + "\n\n" 
     267            if text: 
     268                mssg += "Run-Test results:\n" 
     269                mssg += str(text) 
     270                title = 'Warning' 
     271                icon = wx.ICON_WARNING 
    234272        else: 
    235             mssg += "Successful." 
     273            mssg += "Successful.\n\n" 
     274            if text: 
     275                mssg += "Run-Test results:\n" 
     276                mssg += str(text) 
    236277            title = 'Info' 
    237278            icon = wx.ICON_INFORMATION 
  • fittingview/src/sans/perspectives/fitting/fitting.py

    r26e1001 r7c8d3093  
    211211        resetf_help += "Otherwise, the same initial param values will be used " 
    212212        resetf_help += "for all fittings."  
    213         self.menu1.AppendCheckItem(self.id_reset_flag, "Chain Fitting [BatchFit Only]",  
     213        self.menu1.AppendCheckItem(self.id_reset_flag,  
     214                                   "Chain Fitting [BatchFit Only]",  
    214215                                   resetf_help)  
    215216        wx.EVT_MENU(owner, self.id_reset_flag,  self.on_reset_batch_flag) 
     
    238239        """ 
    239240        id = event.GetId() 
    240         label = self.edit_model_menu.GetLabel(id) 
     241        label = self.edit_menu.GetLabel(id) 
    241242        from sans.perspectives.calculator.pyconsole import PyConsole 
    242243        filename = os.path.join(models.find_plugins_dir(), label) 
     
    245246        self.put_icon(frame) 
    246247        frame.Show(True)  
    247          
     248     
     249    def make_sum_model(self, event): 
     250        """ 
     251        Edit summodel template and make one 
     252        """ 
     253        id = event.GetId() 
     254        model_list = [] 
     255        model_manager = models.ModelManager() 
     256        model_list = model_manager.get_model_name_list() 
     257 
     258        from sans.perspectives.fitting.fitting_widgets import TextDialog 
     259        textdial = TextDialog(None, -1, 'Easy Custom Sum(p1,p2)', model_list) 
     260        self.put_icon(textdial) 
     261        if textdial.ShowModal() == wx.ID_OK: 
     262            try: 
     263                label = textdial.getText() 
     264                plug_dir = models.find_plugins_dir() 
     265                fname = os.path.join(plug_dir, "sum_temp.py") 
     266                name1 = label[0] 
     267                name2 = label[1] 
     268                textdial.write_string(fname, name1, name2) 
     269                textdial.compile_file(fname) 
     270 
     271                page = self.fit_panel.get_current_page() 
     272                temp = self.fit_panel.reset_pmodel_list() 
     273                if temp: 
     274                    page.model_list_box = temp 
     275                    current_val = page.formfactorbox.GetValue() 
     276                    pos = page.formfactorbox.GetSelection() 
     277                    page._show_combox_helper() 
     278                    page.formfactorbox.SetSelection(pos) 
     279                    page.formfactorbox.SetValue(current_val) 
     280                #wx.CallAfter(textdial.delete_file, fname) 
     281            except: 
     282                raise 
     283                if self.parent != None: 
     284                    from sans.guiframe.events import StatusEvent  
     285                    msg= "Easy Custom Sum: Error occurred..." 
     286                    wx.PostEvent(self.parent, StatusEvent(status = msg )) 
     287                else: 
     288                    raise 
     289        textdial.Destroy() 
     290 
     291   
    248292    def set_edit_menu(self, owner):     
    249293        """ 
    250294        Set list of the edit model menu labels 
     295        """ 
     296        id = wx.NewId() 
     297        self.edit_model_menu.Append(id, 'Easy Custom Sum(p1, p2)',  
     298                                    'Sum two models')  
     299        wx.EVT_MENU(owner, id,  self.make_sum_model) 
     300        e_id = wx.NewId() 
     301        self.edit_menu =wx.Menu() 
     302        self.edit_model_menu.AppendMenu(e_id,  
     303                                    'Edit Sample File', self.edit_menu)  
     304        self.set_edit_menu_helper(owner) 
     305     
     306    def set_edit_menu_helper(self, owner): 
     307        """ 
     308        help for setting list of the edit model menu labels 
    251309        """ 
    252310        list_fnames = os.listdir(models.find_plugins_dir()) 
     
    254312            name = os.path.basename(item) 
    255313            toks = os.path.splitext(name) 
    256             if toks[1]=='.py' and not toks[0]=='__init__': 
     314            if toks[1]=='.py' and not toks[0] =='__init__' \ 
     315                                and not toks[0] =='sum_temp': 
    257316                has_file = False 
    258                 for item in self.edit_model_menu.GetMenuItems(): 
    259                     if name == self.edit_model_menu.GetLabel(item.GetId()): 
     317                for item in self.edit_menu.GetMenuItems(): 
     318                    if name == self.edit_menu.GetLabel(item.GetId()): 
    260319                        has_file = True 
    261320                if not has_file: 
    262321                    id = wx.NewId() 
    263                     self.edit_model_menu.Append(id, name)  
     322                    self.edit_menu.Append(id, name)  
    264323                    wx.EVT_MENU(owner, id,  self.edit_custom_model) 
    265324                    has_file = False 
     
    641700             
    642701        """ 
    643         if string.find(item,".")!=-1: 
    644             param_names= re.split("\.",item) 
    645             model_name=param_names[0]            
     702        if string.find(item, ".") != -1: 
     703            param_names = re.split("\.", item) 
     704            model_name = param_names[0]            
    646705            ##Assume max len is 3; eg., M0.radius.width 
    647706            if len(param_names) == 3: 
    648                 param_name=param_names[1]+"."+param_names[2] 
     707                param_name = param_names[1] + "." + param_names[2] 
    649708            else: 
    650                 param_name=param_names[1]                     
    651             return model_name,param_name 
     709                param_name = param_names[1]                     
     710            return model_name, param_name 
    652711    
    653712    def set_ftol(self, ftol=None): 
  • fittingview/src/sans/perspectives/fitting/fitting_widgets.py

    r657490af r7c8d3093  
    1212 
    1313import wx 
     14import sys 
     15import os 
    1416from wx.lib.scrolledpanel import ScrolledPanel 
    1517 
     18#TextDialog size 
     19if sys.platform.count("win32") > 0: 
     20    FONT_VARIANT = 0 
     21    PNL_WIDTH = 460 
     22    PNL_HITE = 210 
     23else: 
     24    FONT_VARIANT = 1 
     25    PNL_WIDTH = 500 
     26    PNL_HITE = 250 
    1627 
    1728MAX_NBR_DATA = 4 
     
    156167                                wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 
    157168        static_line = wx.StaticLine(self, -1) 
    158          
    159169        self._sizer_txt.Add(self._panel, 0, wx.EXPAND|wx.ALL, 10) 
    160170        self._sizer_main.Add(self._sizer_txt, 0, wx.EXPAND|wx.ALL, 10) 
     
    191201            self._data_text_ctrl.SetForegroundColour('red') 
    192202         
     203  
     204class TextDialog(wx.Dialog): 
     205    """ 
     206    Dialog for easy custom sum models   
     207    """ 
     208    def __init__(self, parent=None, id=None, title='', model_list=[]): 
     209        """ 
     210        Dialog window popup when selecting 'Easy Custom Sum' on the menu 
     211        """ 
     212        wx.Dialog.__init__(self, parent=parent, id=id,  
     213                           title=title, size=(PNL_WIDTH, PNL_HITE)) 
     214        self.parent = parent 
     215        #Font 
     216        self.SetWindowVariant(variant=FONT_VARIANT) 
     217        # default 
     218        self.model_list = model_list 
     219        self._build_sizer() 
     220        self.model1_name = str(self.model1.GetValue()) 
     221        self.model2_name = str(self.model2.GetValue()) 
     222         
     223    def _build_sizer(self): 
     224        """ 
     225        Build gui 
     226        """ 
     227        _BOX_WIDTH = 195 # combobox width 
     228        vbox  = wx.BoxSizer(wx.VERTICAL) 
     229        sizer = wx.GridBagSizer(1, 3) 
     230        sum_description= wx.StaticBox(self, -1, 'Select',  
     231                                       size=(PNL_WIDTH-30, 70)) 
     232        sum_box = wx.StaticBoxSizer(sum_description, wx.VERTICAL) 
     233        model1_box = wx.BoxSizer(wx.HORIZONTAL) 
     234        model2_box = wx.BoxSizer(wx.HORIZONTAL) 
     235        model_vbox = wx.BoxSizer(wx.VERTICAL) 
     236        self.model1 =  wx.ComboBox(self, -1, style=wx.CB_READONLY) 
     237        wx.EVT_COMBOBOX(self.model1, -1, self.on_model1) 
     238        self.model1.SetMinSize((_BOX_WIDTH, -1)) 
     239        self.model1.SetToolTipString("model1") 
     240        self.model2 =  wx.ComboBox(self, -1, style=wx.CB_READONLY) 
     241        wx.EVT_COMBOBOX(self.model2, -1, self.on_model2) 
     242        self.model2.SetMinSize((_BOX_WIDTH, -1)) 
     243        self.model2.SetToolTipString("model2") 
     244        self._set_model_list() 
     245        self.model1.SetSelection(0) 
     246        self.model2.SetSelection(1) 
     247         # Buttons on the bottom 
     248        self.static_line_1 = wx.StaticLine(self, -1) 
     249        self.okButton = wx.Button(self,wx.ID_OK, 'OK', size=(_BOX_WIDTH/2, 25)) 
     250        self.closeButton = wx.Button(self,wx.ID_CANCEL, 'Cancel',  
     251                                     size=(_BOX_WIDTH/2, 25)) 
     252        # Intro 
     253        explanation  = "  custom model = scale_factor * (model1 + model2)\n" 
     254        model_string = " Model%s (p%s):" 
     255        vbox.Add(sizer) 
     256        ix = 0 
     257        iy = 1 
     258        sizer.Add(wx.StaticText(self, -1, explanation), (iy, ix), 
     259                 (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     260        model1_box.Add(wx.StaticText(self,-1, model_string% (1, 1)), -1, 0) 
     261        model1_box.Add((_BOX_WIDTH-35,10)) 
     262        model1_box.Add(wx.StaticText(self, -1, model_string% (2, 2)), -1, 0) 
     263        model2_box.Add(self.model1, -1, 0) 
     264        model2_box.Add((20,10)) 
     265        model2_box.Add(self.model2, -1, 0) 
     266        model_vbox.Add(model1_box, -1, 0) 
     267        model_vbox.Add(model2_box, -1, 0) 
     268        sum_box.Add(model_vbox, -1, 10) 
     269        iy += 1 
     270        ix = 0 
     271        sizer.Add(sum_box, (iy, ix), 
     272                  (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     273        vbox.Add((10,10)) 
     274        vbox.Add(self.static_line_1, 0, wx.EXPAND, 10) 
     275        sizer_button = wx.BoxSizer(wx.HORIZONTAL) 
     276        sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     277        sizer_button.Add(self.okButton, 0,  
     278                         wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 0) 
     279        sizer_button.Add(self.closeButton, 0, 
     280                          wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 15)         
     281        vbox.Add(sizer_button, 0, wx.EXPAND|wx.BOTTOM|wx.TOP, 10) 
     282        self.SetSizer(vbox) 
     283        self.Centre() 
     284                  
     285    def _set_model_list(self): 
     286        """ 
     287        Set the list of models 
     288        """ 
     289        # list of model names 
     290        list = self.model_list 
     291        if len(list) > 1: 
     292            list.sort() 
     293        for idx in range(len(list)): 
     294            self.model1.Append(list[idx],idx)  
     295            self.model2.Append(list[idx],idx) 
     296            
     297    def on_model1(self, event): 
     298        """ 
     299        Set model1 
     300        """ 
     301        event.Skip() 
     302        self.model1_name = str(self.model1.GetValue()) 
     303             
     304    def on_model2(self, event): 
     305        """ 
     306        Set model2 
     307        """ 
     308        event.Skip() 
     309        self.model2_name = str(self.model2.GetValue()) 
     310  
     311    def getText(self): 
     312        """ 
     313        Returns model name string as list 
     314        """ 
     315        return [self.model1_name, self.model2_name] 
     316     
     317    def write_string(self, fname, name1, name2): 
     318        """ 
     319        Write and Save file 
     320        """ 
     321        try: 
     322            out_f =  open(fname,'w') 
     323        except : 
     324            raise 
     325        lines = SUM_TEMPLATE.split('\n') 
     326        for line in lines: 
     327            if line.count("import %s as P1"): 
     328                out_f.write(line % (name1, name1) + "\n") 
     329            elif line.count("import %s as P2"): 
     330                out_f.write(line % (name2, name2) + "\n") 
     331            else: 
     332                out_f.write(line + "\n") 
     333        out_f.close()  
     334         
     335    def compile_file(self, path): 
     336        """ 
     337        Compile the file in the path 
     338        """ 
     339        try: 
     340            import py_compile 
     341            py_compile.compile(file=path, doraise=True) 
     342        except: 
     343            type, value, traceback = sys.exc_info() 
     344            return value 
     345         
     346    def delete_file(self, path): 
     347        """ 
     348        Delete file in the path 
     349        """ 
     350        try: 
     351            os.remove(path) 
     352        except: 
     353            raise 
     354         
     355         
     356SUM_TEMPLATE = """ 
     357# A sample of an experimental model function for Sum(Pmodel1,Pmodel2) 
     358import copy 
     359from sans.models.pluginmodel import Model1DPlugin 
     360# User can change the name of the model (only with single functional model) 
     361#P1_model:  
     362from sans.models.%s import %s as P1 
     363 
     364#P2_model:  
     365from sans.models.%s import %s as P2 
     366 
     367class Model(Model1DPlugin): 
     368    name = "" 
     369    def __init__(self): 
     370        Model1DPlugin.__init__(self, name='') 
     371        p_model1 = P1() 
     372        p_model2 = P2() 
     373        ## Setting  model name model description 
     374        self.description="" 
     375        self.name = self._get_name(p_model1.name, p_model2.name) 
     376        self.description = p_model1.name 
     377        self.description += p_model2.name 
     378        self.fill_description(p_model1, p_model2) 
     379 
     380        ## Define parameters 
     381        self.params = {} 
     382 
     383        ## Parameter details [units, min, max] 
     384        self.details = {} 
     385         
     386        # non-fittable parameters 
     387        self.non_fittable = p_model1.non_fittable   
     388        self.non_fittable += p_model2.non_fittable   
     389             
     390        ##models  
     391        self.p_model1= p_model1 
     392        self.p_model2= p_model2 
     393         
    193394        
     395        ## dispersion 
     396        self._set_dispersion() 
     397        ## Define parameters 
     398        self._set_params() 
     399        ## New parameter:Scaling factor 
     400        self.params['scale_factor'] = 1 
     401         
     402        ## Parameter details [units, min, max] 
     403        self._set_details() 
     404        self.details['scale_factor'] = ['', None, None] 
     405 
     406         
     407        #list of parameter that can be fitted 
     408        self._set_fixed_params()   
     409        ## parameters with orientation 
     410        for item in self.p_model1.orientation_params: 
     411            new_item = "p1_" + item 
     412            if not new_item in self.orientation_params: 
     413                self.orientation_params.append(new_item) 
     414             
     415        for item in self.p_model2.orientation_params: 
     416            new_item = "p2_" + item 
     417            if not new_item in self.orientation_params: 
     418                self.orientation_params.append(new_item) 
     419        # get multiplicity if model provide it, else 1. 
     420        try: 
     421            multiplicity1 = p_model1.multiplicity 
     422            try: 
     423                multiplicity2 = p_model2.multiplicity 
     424            except: 
     425                multiplicity2 = 1 
     426        except: 
     427            multiplicity1 = 1 
     428            multiplicity2 = 1 
     429        ## functional multiplicity of the model 
     430        self.multiplicity1 = multiplicity1   
     431        self.multiplicity2 = multiplicity2     
     432        self.multiplicity_info = []    
     433         
     434    def _clone(self, obj): 
     435        obj.params     = copy.deepcopy(self.params) 
     436        obj.description     = copy.deepcopy(self.description) 
     437        obj.details    = copy.deepcopy(self.details) 
     438        obj.dispersion = copy.deepcopy(self.dispersion) 
     439        obj.p_model1  = self.p_model1.clone() 
     440        obj.p_model2  = self.p_model2.clone() 
     441        #obj = copy.deepcopy(self) 
     442        return obj 
     443     
     444    def _get_name(self, name1, name2): 
     445        name = self._get_upper_name(name1) 
     446        name += "+" 
     447        name += self._get_upper_name(name2) 
     448        return name 
     449     
     450    def _get_upper_name(self, name=None): 
     451        if name == None: 
     452            return "" 
     453        upper_name = "" 
     454        str_name = str(name) 
     455        for index in range(len(str_name)): 
     456            if str_name[index].isupper(): 
     457                upper_name += str_name[index] 
     458        return upper_name 
     459         
     460    def _set_dispersion(self): 
     461        ##set dispersion only from p_model  
     462        for name , value in self.p_model1.dispersion.iteritems(): 
     463            #if name.lower() not in self.p_model1.orientation_params: 
     464            new_name = "p1_" + name 
     465            self.dispersion[new_name]= value  
     466        for name , value in self.p_model2.dispersion.iteritems(): 
     467            #if name.lower() not in self.p_model2.orientation_params: 
     468            new_name = "p2_" + name 
     469            self.dispersion[new_name]= value  
     470             
     471    def function(self, x=0.0):  
     472        return 0 
     473                                
     474    def getProfile(self): 
     475        try: 
     476            x,y = self.p_model1.getProfile() 
     477        except: 
     478            x = None 
     479            y = None 
     480             
     481        return x, y 
     482     
     483    def _set_params(self): 
     484        for name , value in self.p_model1.params.iteritems(): 
     485            # No 2D-supported 
     486            #if name not in self.p_model1.orientation_params: 
     487            new_name = "p1_" + name 
     488            self.params[new_name]= value 
     489             
     490        for name , value in self.p_model2.params.iteritems(): 
     491            # No 2D-supported 
     492            #if name not in self.p_model2.orientation_params: 
     493            new_name = "p2_" + name 
     494            self.params[new_name]= value 
     495                 
     496        # Set "scale" as initializing 
     497        self._set_scale_factor() 
     498       
     499             
     500    def _set_details(self): 
     501        for name ,detail in self.p_model1.details.iteritems(): 
     502            new_name = "p1_" + name 
     503            #if new_name not in self.orientation_params: 
     504            self.details[new_name]= detail 
     505             
     506        for name ,detail in self.p_model2.details.iteritems(): 
     507            new_name = "p2_" + name 
     508            #if new_name not in self.orientation_params: 
     509            self.details[new_name]= detail 
     510     
     511    def _set_scale_factor(self): 
     512        pass 
     513         
     514                 
     515    def setParam(self, name, value): 
     516        # set param to p1+p2 model 
     517        self._setParamHelper(name, value) 
     518         
     519        ## setParam to p model  
     520        model_pre = name.split('_', 1)[0] 
     521        new_name = name.split('_', 1)[1] 
     522        if model_pre == "p1": 
     523            if new_name in self.p_model1.getParamList(): 
     524                self.p_model1.setParam(new_name, value) 
     525        elif model_pre == "p2": 
     526             if new_name in self.p_model2.getParamList(): 
     527                self.p_model2.setParam(new_name, value) 
     528        elif name.lower() == 'scale_factor': 
     529            self.params['scale_factor'] = value 
     530        else: 
     531            raise ValueError, "Model does not contain parameter %s" % name 
     532             
     533    def getParam(self, name): 
     534        # Look for dispersion parameters 
     535        toks = name.split('.') 
     536        if len(toks)==2: 
     537            for item in self.dispersion.keys(): 
     538                # 2D not supported 
     539                if item.lower()==toks[0].lower(): 
     540                    for par in self.dispersion[item]: 
     541                        if par.lower() == toks[1].lower(): 
     542                            return self.dispersion[item][par] 
     543        else: 
     544            # Look for standard parameter 
     545            for item in self.params.keys(): 
     546                if item.lower()==name.lower(): 
     547                    return self.params[item] 
     548        return   
     549        #raise ValueError, "Model does not contain parameter %s" % name 
     550        
     551    def _setParamHelper(self, name, value): 
     552        # Look for dispersion parameters 
     553        toks = name.split('.') 
     554        if len(toks)== 2: 
     555            for item in self.dispersion.keys(): 
     556                if item.lower()== toks[0].lower(): 
     557                    for par in self.dispersion[item]: 
     558                        if par.lower() == toks[1].lower(): 
     559                            self.dispersion[item][par] = value 
     560                            return 
     561        else: 
     562            # Look for standard parameter 
     563            for item in self.params.keys(): 
     564                if item.lower()== name.lower(): 
     565                    self.params[item] = value 
     566                    return 
     567             
     568        raise ValueError, "Model does not contain parameter %s" % name 
     569              
     570    
     571    def _set_fixed_params(self): 
     572        for item in self.p_model1.fixed: 
     573            new_item = "p1" + item 
     574            self.fixed.append(new_item) 
     575        for item in self.p_model2.fixed: 
     576            new_item = "p2" + item 
     577            self.fixed.append(new_item) 
     578 
     579        self.fixed.sort() 
     580                 
     581                     
     582    def run(self, x = 0.0): 
     583        self._set_scale_factor() 
     584        return self.params['scale_factor'] * \ 
     585(self.p_model1.run(x) + self.p_model2.run(x)) 
     586     
     587    def runXY(self, x = 0.0): 
     588        self._set_scale_factor() 
     589        return self.params['scale_factor'] * \ 
     590(self.p_model1.runXY(x) + self.p_model2.runXY(x)) 
     591     
     592    ## Now (May27,10) directly uses the model eval function  
     593    ## instead of the for-loop in Base Component. 
     594    def evalDistribution(self, x = []): 
     595        self._set_scale_factor() 
     596        return self.params['scale_factor'] * \ 
     597(self.p_model1.evalDistribution(x) + \ 
     598self.p_model2.evalDistribution(x)) 
     599 
     600    def set_dispersion(self, parameter, dispersion): 
     601        value= None 
     602        new_pre = parameter.split("_", 1)[0] 
     603        new_parameter = parameter.split("_", 1)[1] 
     604        try: 
     605            if new_pre == 'p1' and \ 
     606new_parameter in self.p_model1.dispersion.keys(): 
     607                value= self.p_model1.set_dispersion(new_parameter, dispersion) 
     608            if new_pre == 'p2' and \ 
     609new_parameter in self.p_model2.dispersion.keys(): 
     610                value= self.p_model2.set_dispersion(new_parameter, dispersion) 
     611            self._set_dispersion() 
     612            return value 
     613        except: 
     614            raise  
     615 
     616    def fill_description(self, p_model1, p_model2): 
     617        description = "" 
     618        description +="This model gives the summation of  %s and %s. "% \ 
     619( p_model1.name, p_model2.name ) 
     620        self.description += description 
     621         
     622if __name__ == "__main__":  
     623    m1= Model()  
     624    #m1.setParam("p1_scale", 25)   
     625    #m1.setParam("p1_length", 1000) 
     626    #m1.setParam("p2_scale", 100)  
     627    #m1.setParam("p2_rg", 100)  
     628    out1 = m1.runXY(0.01) 
     629 
     630    m2= Model() 
     631    #m2.p_model1.setParam("scale", 25)  
     632    #m2.p_model1.setParam("length", 1000)  
     633    #m2.p_model2.setParam("scale", 100) 
     634    #m2.p_model2.setParam("rg", 100) 
     635    out2 = m2.p_model1.runXY(0.01) + m2.p_model2.runXY(0.01) 
     636    print out1, " = ", out2 
     637    if out1 == out2: 
     638        print "===> Simple Test: Passed!" 
     639    else: 
     640        print "===> Simple Test: Failed!" 
     641""" 
     642         
     643if __name__ == "__main__":  
     644    app = wx.PySimpleApp() 
     645    frame = TextDialog(id=1, model_list=["SphereModel", "CylinderModel"])    
     646    frame.Show(True) 
     647    app.MainLoop()              
     648 
     649           
  • fittingview/src/sans/perspectives/fitting/models.py

    r96814e1 r7c8d3093  
    226226        """ 
    227227        """ 
    228         
    229228        self.stored_plugins = {} 
    230229        self._getModelList() 
    231          
    232230         
    233231    def findModels(self): 
     
    250248         
    251249        """ 
     250        # regular model names only 
     251        self.model_name_list = [] 
    252252        from sans.models.SphereModel import SphereModel 
    253253        self.shape_list.append(SphereModel) 
    254254        self.multiplication_factor.append(SphereModel) 
     255        self.model_name_list.append(SphereModel.__name__) 
    255256         
    256257        from sans.models.BinaryHSModel import BinaryHSModel 
    257258        self.shape_list.append(BinaryHSModel) 
     259        self.model_name_list.append(BinaryHSModel.__name__) 
    258260                         
    259261        from sans.models.FuzzySphereModel import FuzzySphereModel 
    260262        self.shape_list.append(FuzzySphereModel) 
    261263        self.multiplication_factor.append(FuzzySphereModel) 
     264        self.model_name_list.append(FuzzySphereModel.__name__) 
    262265            
    263266        from sans.models.CoreShellModel import CoreShellModel 
    264267        self.shape_list.append(CoreShellModel) 
    265268        self.multiplication_factor.append(CoreShellModel) 
     269        self.model_name_list.append(CoreShellModel.__name__) 
    266270         
    267271        from sans.models.CoreMultiShellModel import CoreMultiShellModel 
     
    273277        self.shape_list.append(VesicleModel) 
    274278        self.multiplication_factor.append(VesicleModel) 
     279        self.model_name_list.append(VesicleModel.__name__) 
    275280         
    276281        from sans.models.MultiShellModel import MultiShellModel 
    277282        self.shape_list.append(MultiShellModel) 
    278283        self.multiplication_factor.append(MultiShellModel) 
     284        self.model_name_list.append(MultiShellModel.__name__) 
    279285         
    280286        from sans.models.OnionExpShellModel import OnionExpShellModel 
     
    290296        from sans.models.PearlNecklaceModel import PearlNecklaceModel 
    291297        self.shape_list.append(PearlNecklaceModel) 
     298        self.model_name_list.append(PearlNecklaceModel.__name__) 
    292299        #self.multiplication_factor.append(PearlNecklaceModel) 
    293300         
     
    295302        self.shape_list.append(CylinderModel) 
    296303        self.multiplication_factor.append(CylinderModel) 
     304        self.model_name_list.append(CylinderModel.__name__) 
    297305         
    298306        from sans.models.CoreShellCylinderModel import CoreShellCylinderModel 
    299307        self.shape_list.append(CoreShellCylinderModel) 
    300308        self.multiplication_factor.append(CoreShellCylinderModel) 
     309        self.model_name_list.append(CoreShellCylinderModel.__name__) 
    301310         
    302311        from sans.models.HollowCylinderModel import HollowCylinderModel 
    303312        self.shape_list.append(HollowCylinderModel) 
    304313        self.multiplication_factor.append(HollowCylinderModel) 
     314        self.model_name_list.append(HollowCylinderModel.__name__) 
    305315               
    306316        from sans.models.FlexibleCylinderModel import FlexibleCylinderModel 
    307317        self.shape_list.append(FlexibleCylinderModel) 
     318        self.model_name_list.append(FlexibleCylinderModel.__name__) 
    308319 
    309320        from sans.models.FlexCylEllipXModel import FlexCylEllipXModel 
    310321        self.shape_list.append(FlexCylEllipXModel) 
     322        self.model_name_list.append(FlexCylEllipXModel.__name__) 
    311323         
    312324        from sans.models.StackedDisksModel import StackedDisksModel 
    313325        self.shape_list.append(StackedDisksModel) 
    314326        self.multiplication_factor.append(StackedDisksModel) 
     327        self.model_name_list.append(StackedDisksModel.__name__) 
    315328         
    316329        from sans.models.ParallelepipedModel import ParallelepipedModel 
    317330        self.shape_list.append(ParallelepipedModel) 
    318331        self.multiplication_factor.append(ParallelepipedModel) 
     332        self.model_name_list.append(ParallelepipedModel.__name__) 
    319333         
    320334        from sans.models.CSParallelepipedModel import CSParallelepipedModel 
    321335        self.shape_list.append(CSParallelepipedModel) 
    322336        self.multiplication_factor.append(CSParallelepipedModel) 
     337        self.model_name_list.append(CSParallelepipedModel.__name__) 
    323338         
    324339        from sans.models.EllipticalCylinderModel import EllipticalCylinderModel 
    325340        self.shape_list.append(EllipticalCylinderModel) 
    326341        self.multiplication_factor.append(EllipticalCylinderModel) 
     342        self.model_name_list.append(EllipticalCylinderModel.__name__) 
    327343         
    328344        from sans.models.BarBellModel import BarBellModel 
    329345        self.shape_list.append(BarBellModel) 
     346        self.model_name_list.append(BarBellModel.__name__) 
    330347        # not implemeted yet! 
    331348        #self.multiplication_factor.append(BarBellModel) 
     
    333350        from sans.models.CappedCylinderModel import CappedCylinderModel 
    334351        self.shape_list.append(CappedCylinderModel) 
     352        self.model_name_list.append(CappedCylinderModel.__name__) 
    335353        # not implemeted yet! 
    336354        #self.multiplication_factor.append(CappedCylinderModel) 
     
    339357        self.shape_list.append(EllipsoidModel) 
    340358        self.multiplication_factor.append(EllipsoidModel) 
     359        self.model_name_list.append(EllipsoidModel.__name__) 
    341360       
    342361        from sans.models.CoreShellEllipsoidModel import CoreShellEllipsoidModel 
    343362        self.shape_list.append(CoreShellEllipsoidModel) 
    344363        self.multiplication_factor.append(CoreShellEllipsoidModel) 
     364        self.model_name_list.append(CoreShellEllipsoidModel.__name__) 
    345365          
    346366        from sans.models.TriaxialEllipsoidModel import TriaxialEllipsoidModel 
    347367        self.shape_list.append(TriaxialEllipsoidModel) 
    348368        self.multiplication_factor.append(TriaxialEllipsoidModel) 
     369        self.model_name_list.append(TriaxialEllipsoidModel.__name__) 
    349370         
    350371        from sans.models.LamellarModel import LamellarModel 
    351372        self.shape_list.append(LamellarModel) 
     373        self.model_name_list.append(LamellarModel.__name__) 
    352374         
    353375        from sans.models.LamellarFFHGModel import LamellarFFHGModel 
    354376        self.shape_list.append(LamellarFFHGModel) 
     377        self.model_name_list.append(LamellarFFHGModel.__name__) 
    355378         
    356379        from sans.models.LamellarPSModel import LamellarPSModel 
    357380        self.shape_list.append(LamellarPSModel) 
     381        self.model_name_list.append(LamellarPSModel.__name__) 
    358382      
    359383        from sans.models.LamellarPSHGModel import LamellarPSHGModel 
    360384        self.shape_list.append(LamellarPSHGModel) 
     385        self.model_name_list.append(LamellarPSHGModel.__name__) 
    361386         
    362387        from sans.models.LamellarPCrystalModel import LamellarPCrystalModel 
    363388        self.shape_list.append(LamellarPCrystalModel) 
     389        self.model_name_list.append(LamellarPCrystalModel.__name__) 
    364390         
    365391        from sans.models.SCCrystalModel import SCCrystalModel 
    366392        self.shape_list.append(SCCrystalModel) 
     393        self.model_name_list.append(SCCrystalModel.__name__) 
    367394         
    368395        from sans.models.FCCrystalModel import FCCrystalModel 
    369396        self.shape_list.append(FCCrystalModel) 
     397        self.model_name_list.append(FCCrystalModel.__name__) 
    370398         
    371399        from sans.models.BCCrystalModel import BCCrystalModel 
    372400        self.shape_list.append(BCCrystalModel) 
     401        self.model_name_list.append(BCCrystalModel.__name__) 
    373402       
    374403        ## Structure factor  
    375404        from sans.models.SquareWellStructure import SquareWellStructure 
    376405        self.struct_list.append(SquareWellStructure) 
     406        self.model_name_list.append(SquareWellStructure.__name__) 
    377407         
    378408        from sans.models.HardsphereStructure import HardsphereStructure 
    379409        self.struct_list.append(HardsphereStructure) 
     410        self.model_name_list.append(HardsphereStructure.__name__) 
    380411          
    381412        from sans.models.StickyHSStructure import StickyHSStructure 
    382413        self.struct_list.append(StickyHSStructure) 
     414        self.model_name_list.append(StickyHSStructure.__name__) 
    383415         
    384416        from sans.models.HayterMSAStructure import HayterMSAStructure 
    385417        self.struct_list.append(HayterMSAStructure) 
     418        self.model_name_list.append(HayterMSAStructure.__name__) 
    386419         
    387420        ##shape-independent models 
    388421        from sans.models.PowerLawAbsModel import PowerLawAbsModel 
    389422        self.shape_indep_list.append( PowerLawAbsModel ) 
     423        self.model_name_list.append(PowerLawAbsModel.__name__) 
    390424         
    391425        from sans.models.BEPolyelectrolyte import BEPolyelectrolyte 
    392426        self.shape_indep_list.append(BEPolyelectrolyte ) 
     427        self.model_name_list.append(BEPolyelectrolyte.__name__) 
    393428        self.form_factor_dict[str(wx.NewId())] =  [SphereModel] 
    394429         
    395430        from sans.models.BroadPeakModel import BroadPeakModel 
    396431        self.shape_indep_list.append(BroadPeakModel) 
     432        self.model_name_list.append(BroadPeakModel.__name__) 
    397433         
    398434        from sans.models.CorrLengthModel import CorrLengthModel 
    399435        self.shape_indep_list.append(CorrLengthModel) 
     436        self.model_name_list.append(CorrLengthModel.__name__) 
    400437         
    401438        from sans.models.DABModel import DABModel 
    402439        self.shape_indep_list.append(DABModel ) 
     440        self.model_name_list.append(DABModel.__name__) 
    403441         
    404442        from sans.models.DebyeModel import DebyeModel 
    405443        self.shape_indep_list.append(DebyeModel ) 
     444        self.model_name_list.append(DebyeModel.__name__) 
    406445         
    407446        #FractalModel (a c-model)is now being used instead of FractalAbsModel. 
    408447        from sans.models.FractalModel import FractalModel 
    409448        self.shape_indep_list.append(FractalModel ) 
     449        self.model_name_list.append(FractalModel.__name__) 
    410450         
    411451        from sans.models.FractalCoreShellModel import FractalCoreShellModel 
    412452        self.shape_indep_list.append(FractalCoreShellModel ) 
     453        self.model_name_list.append(FractalCoreShellModel.__name__) 
    413454         
    414455        from sans.models.GaussLorentzGelModel import GaussLorentzGelModel 
    415456        self.shape_indep_list.append(GaussLorentzGelModel)  
     457        self.model_name_list.append(GaussLorentzGelModel.__name__) 
    416458                 
    417459        from sans.models.GuinierModel import GuinierModel 
    418460        self.shape_indep_list.append(GuinierModel ) 
     461        self.model_name_list.append(GuinierModel.__name__) 
    419462         
    420463        from sans.models.GuinierPorodModel import GuinierPorodModel 
    421464        self.shape_indep_list.append(GuinierPorodModel ) 
     465        self.model_name_list.append(GuinierPorodModel.__name__) 
    422466 
    423467        from sans.models.LorentzModel import LorentzModel 
    424468        self.shape_indep_list.append( LorentzModel)  
     469        self.model_name_list.append(LorentzModel.__name__) 
    425470         
    426471        from sans.models.PeakGaussModel import PeakGaussModel 
    427472        self.shape_indep_list.append(PeakGaussModel) 
     473        self.model_name_list.append(PeakGaussModel.__name__) 
    428474         
    429475        from sans.models.PeakLorentzModel import PeakLorentzModel 
    430476        self.shape_indep_list.append(PeakLorentzModel) 
     477        self.model_name_list.append( PeakLorentzModel.__name__) 
    431478         
    432479        from sans.models.Poly_GaussCoil import Poly_GaussCoil 
    433480        self.shape_indep_list.append(Poly_GaussCoil) 
     481        self.model_name_list.append(Poly_GaussCoil.__name__) 
    434482         
    435483        from sans.models.PolymerExclVolume import PolymerExclVolume 
    436484        self.shape_indep_list.append(PolymerExclVolume) 
     485        self.model_name_list.append(PolymerExclVolume.__name__) 
    437486         
    438487        from sans.models.PorodModel import PorodModel 
    439         self.shape_indep_list.append(PorodModel )       
     488        self.shape_indep_list.append(PorodModel )   
     489        self.model_name_list.append(PorodModel.__name__)     
    440490         
    441491        from sans.models.RPA10Model import RPA10Model 
     
    445495        from sans.models.TeubnerStreyModel import TeubnerStreyModel 
    446496        self.shape_indep_list.append(TeubnerStreyModel ) 
     497        self.model_name_list.append(TeubnerStreyModel.__name__) 
    447498         
    448499        from sans.models.TwoLorentzianModel import TwoLorentzianModel 
    449500        self.shape_indep_list.append(TwoLorentzianModel ) 
     501        self.model_name_list.append(TwoLorentzianModel.__name__) 
    450502         
    451503        from sans.models.TwoPowerLawModel import TwoPowerLawModel 
    452504        self.shape_indep_list.append(TwoPowerLawModel ) 
     505        self.model_name_list.append(TwoPowerLawModel.__name__) 
    453506         
    454507        from sans.models.UnifiedPowerRgModel import UnifiedPowerRgModel 
     
    458511        from sans.models.LineModel import LineModel 
    459512        self.shape_indep_list.append(LineModel) 
     513        self.model_name_list.append(LineModel.__name__) 
    460514         
    461515        from sans.models.ReflectivityModel import ReflectivityModel 
     
    695749        return self.model_combobox.get_list() 
    696750     
     751    def get_model_name_list(self): 
     752        """ 
     753        return regular model name list 
     754        """ 
     755        return self.model_name_list 
    697756   
    698757         
     
    730789        return self.__modelmanager.get_model_list() 
    731790     
     791    def get_model_name_list(self): 
     792        return self.__modelmanager.get_model_name_list() 
     793     
    732794     
    733795   
  • fittingview/src/sans/perspectives/fitting/plugin_models/sum_p1_p2.py

    r96814e1 r7c8d3093  
    22import copy 
    33from sans.models.pluginmodel import Model1DPlugin 
    4 # User can change the name of the model (only with single functional model) 
    5 from sans.models.CylinderModel import CylinderModel as P1 
    6 from sans.models.PolymerExclVolume import PolymerExclVolume as P2 
    7  
    8  
     4# Possible model names 
     5""" 
     6BCCrystalModel, BEPolyelectrolyte, BarBellModel, BinaryHSModel, BroadPeakModel, 
     7CSParallelepipedModel, CappedCylinderModel, CoreShellCylinderModel, 
     8CoreShellEllipsoidModel, CoreShellModel, CorrLengthModel, CylinderModel,  
     9DABModel, DebyeModel, EllipsoidModel, EllipticalCylinderModel, FCCrystalModel, 
     10FlexCylEllipXModel, FlexibleCylinderModel, FractalCoreShellModel, FractalModel, 
     11FuzzySphereModel, GaussLorentzGelModel, GuinierModel, GuinierPorodModel, 
     12HardsphereStructure, HayterMSAStructure, HollowCylinderModel, LamellarFFHGModel, 
     13LamellarModel, LamellarPCrystalModel, LamellarPSHGModel, LamellarPSModel, 
     14LineModel, LorentzModel, MultiShellModel, ParallelepipedModel, PeakGaussModel, 
     15PeakLorentzModel, PearlNecklaceModel, Poly_GaussCoil, PolymerExclVolume, 
     16PorodModel, PowerLawAbsModel, SCCrystalModel, SphereModel, SquareWellStructure, 
     17StackedDisksModel, StickyHSStructure, TeubnerStreyModel, TriaxialEllipsoidModel, 
     18TwoLorentzianModel, TwoPowerLawModel, VesicleModel 
     19""" 
     20## This is same as the Easy Custom Sum(p1 + p2)  
     21# 
     22#     Custom model = scale_factor * (P1 + P2) 
     23# 
     24## User can REPLACE model names below two arrowed lines (two names per line) 
     25from sans.models.CylinderModel import CylinderModel as P1          #<======== 
     26from sans.models.PolymerExclVolume import PolymerExclVolume as P2  #<======== 
     27 
     28#####DO NOT CHANGE ANYTHING BELOW THIS LINE  
     29#####------------------------------------------------------------------------ 
    930class Model(Model1DPlugin): 
    1031    """ 
     
    2344        ## Setting  model name model description 
    2445        self.description="" 
    25         self.name = "Sum[" + "P1(Cyl)"  +", "+ "P2(PEV)" + "]" 
     46        self.name = self._get_name(p_model1.name, p_model2.name) 
    2647        self.description = p_model1.name+"\n" 
    2748        self.description += p_model2.name+"\n" 
     
    5273        ## Parameter details [units, min, max] 
    5374        self._set_details() 
    54         self.details['scale_factor'] = ['',     None, None] 
     75        self.details['scale_factor'] = ['',  None, None] 
    5576 
    5677         
     
    96117        return obj 
    97118     
    98      
     119    def _get_name(self, name1, name2): 
     120        """ 
     121        Get combined name from two model names 
     122        """ 
     123        name = self._get_upper_name(name1) 
     124        name += "+" 
     125        name += self._get_upper_name(name2) 
     126        return name 
     127     
     128    def _get_upper_name(self, name=None): 
     129        """ 
     130        Get uppercase string from model name 
     131        """ 
     132        if name == None: 
     133            return "" 
     134        upper_name = "" 
     135        str_name = str(name) 
     136        for index in range(len(str_name)): 
     137            if str_name[index].isupper(): 
     138                upper_name += str_name[index] 
     139        return upper_name 
     140         
    99141    def _set_dispersion(self): 
    100142        """ 
     
    339381if __name__ == "__main__":  
    340382    m1= Model()  
    341     m1.setParam("p1_scale", 25)   
    342     m1.setParam("p1_length", 1000) 
    343     m1.setParam("p2_scale", 100)  
    344     m1.setParam("p2_rg", 100)  
     383    #m1.setParam("p1_scale", 25)   
     384    #m1.setParam("p1_length", 1000) 
     385    #m1.setParam("p2_scale", 100)  
     386    #m1.setParam("p2_rg", 100)  
    345387    out1 = m1.runXY(0.01) 
    346388 
    347389    m2= Model() 
    348     m2.p_model1.setParam("scale", 25)  
    349     m2.p_model1.setParam("length", 1000)  
    350     m2.p_model2.setParam("scale", 100) 
    351     m2.p_model2.setParam("rg", 100) 
     390    #m2.p_model1.setParam("scale", 25)  
     391    #m2.p_model1.setParam("length", 1000)  
     392    #m2.p_model2.setParam("scale", 100) 
     393    #m2.p_model2.setParam("rg", 100) 
    352394    out2 = m2.p_model1.runXY(0.01) + m2.p_model2.runXY(0.01) 
     395    print "Testing at Q = 0.01:" 
    353396    print out1, " = ", out2 
    354  
    355     
     397    if out1 == out2: 
     398        print "===> Simple Test: Passed!" 
     399    else: 
     400        print "===> Simple Test: Failed!" 
  • fittingview/src/sans/perspectives/fitting/plugin_models/testmodel.py

    r96814e1 r7c8d3093  
    77""" 
    88from sans.models.pluginmodel import Model1DPlugin  ##DO NOT CHANGE THIS LINE!!! 
    9 from math import *                    ##DO NOT CHANGE THIS LINE!!! 
    10 from numpy import *                ##DO NOT CHANGE THIS LINE!!! 
     9import math                  ##DO NOT CHANGE THIS LINE!!! 
     10import numpy               ##DO NOT CHANGE THIS LINE!!! 
    1111 
    1212##PLEASE READ COMMENTS CAREFULLY !!! COMMENT ARE IN CAPITAL LETTERS AND AFTER ## 
     
    8383        ## numpy FUNCTIONS ARE FOR EXPERT USER 
    8484         
    85         return self.params['A']+self.params['B']*cos(2.0*x)+self.params['C']*math.sin(2.0*x) 
    86     
     85        return self.params['A']+self.params['B']*math.cos(2.0*x)+self.params['C']*math.sin(2.0*x) 
     86     
     87## DO NOT MODIFY THE FOLLOWING LINES!!!!!!!!!!!!!!!!        
     88if __name__ == "__main__":  
     89    m= Model()  
     90    out1 = m.runXY(0.0) 
     91    out2 = m.runXY(0.01) 
     92    isfine1 = numpy.isfinite(out1) 
     93    isfine2 = numpy.isfinite(out2) 
     94    print "Testing the value at Q = 0.0:" 
     95    print out1, " : finite? ", isfine1 
     96    print "Testing the value at Q = 0.01:" 
     97    print out2, " : finite? ", isfine2 
     98    if isfine1 and isfine2: 
     99        print "===> Simple Test: Passed!" 
     100    else: 
     101        print "===> Simple Test: Failed!" 
  • fittingview/src/sans/perspectives/fitting/plugin_models/testmodel_2.py

    r96814e1 r7c8d3093  
    133133            result = 1                      ## <-----    
    134134        else:                               ## <-----    
    135             result = sin(poly)/poly    ## <-----    
     135            result = math.sin(poly)/poly    ## <-----    
    136136             
    137137        #Re-scale                          ## <-----    
     
    139139 
    140140        return result ## MODIFY ONLY RESULT. DON'T DELETE RETURN!!!! 
    141     
     141     
     142## DO NOT MODIFY THE FOLLOWING LINES!!!!!!!!!!!!!!!!        
     143if __name__ == "__main__":  
     144    m= Model()  
     145    out1 = m.runXY(0.0) 
     146    out2 = m.runXY(0.01) 
     147    isfine1 = numpy.isfinite(out1) 
     148    isfine2 = numpy.isfinite(out2) 
     149    print "Testing the value at Q = 0.0:" 
     150    print out1, " : finite? ", isfine1 
     151    print "Testing the value at Q = 0.01:" 
     152    print out2, " : finite? ", isfine2 
     153    if isfine1 and isfine2: 
     154        print "===> Simple Test: Passed!" 
     155    else: 
     156        print "===> Simple Test: Failed!" 
Note: See TracChangeset for help on using the changeset viewer.