Changeset d83549c in sasview


Ignore:
Timestamp:
Jan 17, 2012 8:05:37 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:
530cc84
Parents:
a8db60c
Message:

added reasonable custom 2d

Files:
2 edited

Legend:

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

    r7434020 rd83549c  
    221221        self.name = 'untitled' 
    222222        self.overwrite_name = True 
     223        self.is_2d = False 
    223224        self.fname = None 
    224225        self.param_strings = '' 
     
    472473        lines = CUSTOM_TEMPLATE.split('\n') 
    473474        has_scipy = func_str.count("scipy.") 
     475        self.is_2d = func_str.count("#self.ndim = 2") 
     476        line_2d = '' 
     477        if self.is_2d: 
     478            line_2d = CUSTOM_2D_TEMP.split('\n') 
     479        line_test = TEST_TEMPLATE.split('\n') 
    474480        local_params = '' 
    475481        spaces = '        '#8spaces 
     482        # write function here 
    476483        for line in lines: 
    477484            # The location where to put the strings is  
     
    492499                    desc= self.name 
    493500                out_f.write(line% desc + "\n") 
     501            elif line.count("def function(self, x=0.0%s):"): 
     502                if self.is_2d: 
     503                    y_str = ', y=0.0' 
     504                    out_f.write(line% y_str + "\n") 
     505                else: 
     506                    out_f.write(line% '' + "\n") 
    494507            elif line.count("#function here"): 
    495508                for func_line in func_str.split('\n'): 
     
    498511                        out_f.write(spaces + f_line + "\n") 
    499512                if not func_str: 
    500                     out_f.write(spaces + 'return y' + "\n") 
     513                    dep_var = 'y' 
     514                    if self.is_2d: 
     515                        dep_var = 'z' 
     516                    out_f.write(spaces + 'return %s'% dep_var + "\n") 
    501517            elif line.count("#import scipy?"): 
    502518                if has_scipy: 
     
    506522            elif line: 
    507523                out_f.write(line + "\n") 
     524        # run string for 2d 
     525        if line_2d: 
     526            for line in line_2d: 
     527                out_f.write(line + "\n") 
     528        # Test strins 
     529        for line in line_test: 
     530            out_f.write(line + "\n") 
     531    
    508532        out_f.close()  
    509533     
     
    590614        self.description = "%s" 
    591615        self.set_details() 
    592     def function(self, x = 0.0): 
     616    def function(self, x=0.0%s): 
    593617        #local params here 
    594         #function here   
     618        #function here 
     619""" 
     620TEST_TEMPLATE = """ 
    595621###################################################################### 
    596622## THIS IS FOR TEST. DO NOT MODIFY THE FOLLOWING LINES!!!!!!!!!!!!!!!!        
     
    609635    else: 
    610636        print "===> Simple Test: Failed!" 
    611 """         
    612          
     637"""     
     638CUSTOM_2D_TEMP = """ 
     639    def run(self, x=0.0): 
     640        if x.__class__.__name__ == 'list': 
     641            x_val = x[0]*math.cos(x[1]) 
     642            y_val = x[0]*math.sin(x[1]) 
     643            return self.function(x_val, y_val) 
     644        elif x.__class__.__name__ == 'tuple': 
     645            msg = "Tuples are not allowed as input to BaseComponent models" 
     646            raise ValueError, msg 
     647        else: 
     648            return self.function(x, x) 
     649    def runXY(self, x=0.0, y=0.0): 
     650        if x.__class__.__name__ == 'list': 
     651            return self.function(x, y) 
     652        elif x.__class__.__name__ == 'tuple': 
     653            msg = "Tuples are not allowed as input to BaseComponent models" 
     654            raise ValueError, msg 
     655        else: 
     656            return self.function(x, y) 
     657    def evalDistribution(self, qdist): 
     658        if qdist.__class__.__name__ == 'list': 
     659            msg = "evalDistribution expects a list of 2 ndarrays" 
     660            if len(qdist)!=2: 
     661                raise RuntimeError, msg 
     662            if qdist[0].__class__.__name__ != 'ndarray': 
     663                raise RuntimeError, msg 
     664            if qdist[1].__class__.__name__ != 'ndarray': 
     665                raise RuntimeError, msg 
     666            v_model = numpy.vectorize(self.runXY, otypes=[float]) 
     667            iq_array = v_model(qdist[0], qdist[1]) 
     668            return iq_array 
     669        elif qdist.__class__.__name__ == 'ndarray': 
     670            v_model = numpy.vectorize(self.runXY, otypes=[float]) 
     671            iq_array = v_model(qdist) 
     672            return iq_array 
     673""" 
    613674SUM_TEMPLATE = """ 
    614675# A sample of an experimental model function for Sum(Pmodel1,Pmodel2) 
  • fittingview/src/sans/perspectives/fitting/fitting.py

    rb25caad rd83549c  
    369369        self.set_edit_menu_helper(owner, self.delete_custom_model) 
    370370     
    371     def set_edit_menu_helper(self, owner, menu): 
     371    def set_edit_menu_helper(self, owner=None, menu=None): 
    372372        """ 
    373373        help for setting list of the edit model menu labels 
    374374        """ 
     375        if menu == None: 
     376            menu = self.edit_custom_model 
    375377        list_fnames = os.listdir(models.find_plugins_dir()) 
    376378        for item in list_fnames: 
Note: See TracChangeset for help on using the changeset viewer.