Changeset 80a6775 in sasview for sansview


Ignore:
Timestamp:
Jul 1, 2010 5:09:55 PM (14 years ago)
Author:
Gervaise Alina <gervyh@…>
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:
733e90b
Parents:
38eee13
Message:

ADD DESCRIPTION PLUG-IN MODEL

Location:
sansview/plugins
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sansview/plugins/testmodel.py

    r5062bbf r80a6775  
    11""" 
    22Test plug-in model 
     3These are links of available functions: 
     4 
     5http://docs.python.org/library/math.html 
     6http://www.scipy.org/Numpy_Functions_by_Category 
    37""" 
    4 from sans.models.pluginmodel import Model1DPlugin 
     8from sans.models.pluginmodel import Model1DPlugin  ##DO NOT CHANGE THIS LINE!!! 
     9from math import *                    ##DO NOT CHANGE THIS LINE!!! 
     10from numpy import *                ##DO NOT CHANGE THIS LINE!!! 
    511 
    6 import math 
     12##PLEASE READ COMMENTS CAREFULLY !!! COMMENT ARE IN CAPITAL LETTERS AND AFTER ## 
     13## THESE COMMENTS ARE THERE TO GUIDE YOU. YOU CAN REMOVE THEM ONLY WHEN YOU ARE 
     14## CONFORTABLE ENOUGH WITH OUR MODEL PLUGIN OPTION 
    715 
    816 
    9 # Your model HAS to be called Model 
    10 class Model(Model1DPlugin): 
     17## <-----  SIGN DEFINES WHERE YOU CAN MODIFY THE CODE 
     18 
     19class Model(Model1DPlugin):##DO NOT CHANGE THIS LINE!!! 
    1120    """ 
    12     Class that evaluates a cos(x) model.  
     21    ##YOU CAN BE MODIFY ANYTHING BETWEEN """ """ 
     22    ##DESCRIPTION OF MODEL PLUG-IN GOES HERE 
     23     
     24    ##EXAMPLE:Class that evaluates a cos(x) model.  
    1325    """ 
    1426     
    15     ## Name of the model 
    16     name = "A+Bcos(2x)+Csin(2x)" 
     27    ## YOU CAN MODIFY THE LINE BELLOW. CHANGE ONLY WORDS BETWEEN " "  
     28    ## TO RENAME YOUR MODEL 
     29    name = "A+Bcos(2x)+Csin(2x)"      ## <----- NAME OF THE MODEL    
    1730     
    1831    def __init__(self): 
     
    2033        Initialization 
    2134        """ 
    22         Model1DPlugin.__init__(self, name= self.name) 
     35        Model1DPlugin.__init__(self, name= self.name)##DO NOT CHANGE THIS LINE!!! 
    2336         
    24         ## Parameters definition and defaults 
    25         self.params = {} 
    26         self.params['A'] = 1.0 
    27         self.params['B'] = 1.0 
    28         self.params['C'] = 10.0 
     37        ## EDIT PARAMETERS' NAMES AND VALUE 
     38        ## DELETE MODIFIABLE LINE HERE WILL REDUCE THE NUMBER OF PARAMETERS 
     39        self.params = {}                        ##DO NOT CHANGE THIS LINE!!! 
     40        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER  
     41        ## YOU CAN ALSO DELETE THIS LINE 
     42        self.params['A'] = 1.0       ## <-----   
     43        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER  
     44        ## YOU CAN ALSO DELETE THIS LINE    
     45        self.params['B'] = 1.0       ## <-----  
     46        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER  
     47        ## YOU CAN ALSO DELETE THIS LINE     
     48        self.params['C'] = 10.0      ## <-----   
    2949 
    30         ## Parameter details [units, min, max] 
    31         self.details = {} 
    32         self.details['A'] = ['', -1e16, 1e16] 
    33         self.details['B'] = ['', -1e16, 1e16] 
    34         self.details['C'] = ['', -1e16, 1e16] 
    35         self.description = "F(x)=A+Bcos(2x)+Csin(2x) " 
     50        ## STORING PARAMETERS  [UNIT, MINIMUM VALUE, MAXIMUM VALUE] 
     51        self.details = {}       ##DO NOT CHANGE THIS LINE!!! 
     52        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ',WORD BETWEEN 
     53        ## ' ', TWO OTHER NUMBERS TO NEW VALUE OR YOU CAN ALSO DELETE TH LINE     
     54        self.details['A'] = ['', -1e16, 1e16]        ## <-----  
     55        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ',WORD BETWEEN 
     56        ## ' ', TWO OTHER NUMBERS TO NEW VALUE OR YOU CAN ALSO DELETE TH LINE     
     57        self.details['B'] = ['', -1e16, 1e16]         ## <-----  
     58        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ',WORD BETWEEN 
     59        ## ' ', TWO OTHER NUMBERS TO NEW VALUE OR YOU CAN ALSO DELETE TH LINE     
     60        self.details['C'] = ['', -1e16, 1e16]         ## <-----  
     61        ## YOU CAN MODIFY THE LINE BELLOW.MODIFY WORDS BETWEEN """   """  ONLY!!!! 
     62        self.description = "F(x)=A+Bcos(2x)+Csin(2x) " ## <-----  
    3663    
    37     def function(self, x = 0.0): 
     64    def function(self, x = 0.0):  ##DO NOT CHANGE THIS LINE!!! 
    3865        """ 
    3966        Evaluate the model 
     
    4471         
    4572        """ 
    46         return self.params['A']+self.params['B']*math.cos(2.0*x)+self.params['C']*math.sin(2.0*x) 
     73        ## ADD YOUR FUNCTION HERE. 
     74        ## REUSE THE PARAMETERS DEFINED PREVIOUSLY TO WRITE YOUR FUNCTION. 
     75         
     76        ## IN THIS EXAMPLE THE FUNTION IS: 
     77        ## A+Bcos(2x)+Csin(2x) 
     78        ## YOU CAN USE math.sin or sin directly 
     79        ## NOTE: sin, cos ARE FUNCTIONS  IMPORTED FROM PYTHON MATH LIBRARY 
     80        ## FOR MORE INFORMATION CHECK http://docs.python.org/library/math.html       
     81        ## OTHER FUNCTIONS ARE ALSO  
     82        ##  AVAILABLE http://www.scipy.org/Numpy_Functions_by_Category 
     83        ## numpy FUNCTIONS ARE FOR EXPERT USER 
     84         
     85        return self.params['A']+self.params['B']*cos(2.0*x)+self.params['C']*math.sin(2.0*x) 
    4786    
  • sansview/plugins/testmodel_2.py

    r5062bbf r80a6775  
    11""" 
    22Test plug-in model 
     3These are links of available functions: 
     4 
     5http://docs.python.org/library/math.html 
     6http://www.scipy.org/Numpy_Functions_by_Category 
    37""" 
    4 from sans.models.pluginmodel import Model1DPlugin   ##Do not change this line!!! 
    5 import math                                         ##Do not change this line!!! 
     8from sans.models.pluginmodel import Model1DPlugin  ##DO NOT CHANGE THIS LINE!!! 
     9from math import *                    ##DO NOT CHANGE THIS LINE!!! 
     10from numpy import *                ##DO NOT CHANGE THIS LINE!!! 
    611 
    7 # Modify ONLY lines with '## YOU CAN MODIFY THIS LINE'. 
    8 # Your model HAS to be called Model 
    9 class Model(Model1DPlugin):         ##Do not change this line!!! 
     12##PLEASE READ COMMENTS CAREFULLY !!! COMMENT ARE IN CAPITAL LETTERS AND AFTER ## 
     13## THESE COMMENTS ARE THERE TO GUIDE YOU. YOU CAN REMOVE THEM ONLY WHEN YOU ARE 
     14## CONFORTABLE ENOUGH WITH OUR MODEL PLUGIN OPTION 
     15 
     16 
     17## <-----  SIGN DEFINES WHERE YOU CAN MODIFY THE CODE 
     18 
     19class Model(Model1DPlugin): ##DO NOT CHANGE THIS LINE!!! 
    1020    """ 
    11     Class that evaluates a ploynomial model.  
     21    ##YOU CAN BE MODIFY ANYTHING BETWEEN """ """ 
     22    ##DESCRIPTION OF MODEL PLUG-IN GOES HERE 
     23     
     24    ##EXAMPLE: Class that evaluates a polynomial model.  
    1225    """ 
    13      
    14     ## Name of your model 
    15     name = "sin(poly)/(poly)"    ## YOU CAN MODIFY THIS LINE. 
    16      
    17     def __init__(self):      ##Do not change this line!!! 
     26    ## YOU CAN MODIFY THE LINE BELLOW. CHANGE ONLY WORDS BETWEEN " "  
     27    ## TO RENAME YOUR MODEL 
     28    name = "sin(poly)/(poly)" ## <----- NAME OF THE MODEL    
     29                                 
     30    def __init__(self):      ##DO NOT CHANGE THIS LINE!!! 
    1831        """ 
    1932        Initialization 
    2033        """ 
    21         Model1DPlugin.__init__(self, name= self.name)  ##Do not change this line!!! 
     34        Model1DPlugin.__init__(self, name=self.name) ##DO NOT CHANGE THIS LINE!!! 
    2235         
    23         ## Parameters definition and defaults 
    24         self.params = {}                    ##Do not change this line!!! 
    25         self.params['scale'] = 1.0          ## YOU CAN MODIFY THIS LINE 
    26         self.params['A'] = 0.0              ## YOU CAN MODIFY THIS LINE 
    27         self.params['B'] = 10.0             ## YOU CAN MODIFY THIS LINE 
    28         self.params['C'] = 0.0             ## YOU CAN MODIFY THIS LINE 
    29         self.params['D'] = 0.0              ## YOU CAN MODIFY THIS LINE 
    30         self.params['E'] = 0.0              ## YOU CAN MODIFY THIS LINE 
    31         self.params['F'] = 0.0              ## YOU CAN MODIFY THIS LINE 
     36        ## EDIT PARAMETERS' NAMES AND VALUE 
     37        ## DELETE MODIFIABLE LINE HERE WILL REDUCE THE NUMBER OF PARAMETERS 
     38        self.params = {}                ##DO NOT CHANGE THIS LINE!!! 
     39         
     40        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER  
     41        ## YOU CAN ALSO DELETE THIS LINE 
     42        self.params['scale'] = 1.0   ## <-----    
     43        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER  
     44        ## YOU CAN ALSO DELETE THIS LINE                                                       
     45        self.params['A'] = 0.0       ## <-----    
     46        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER  
     47        ## YOU CAN ALSO DELETE THIS LINE                  
     48        self.params['B'] = 10.0      ## <-----    
     49        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER  
     50        ## YOU CAN ALSO DELETE THIS LINE                   
     51        self.params['C'] = 0.0       ## <-----    
     52        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER  
     53        ## YOU CAN ALSO DELETE THIS LINE                 
     54        self.params['D'] = 0.0     ## <-----    
     55        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER  
     56        ## YOU CAN ALSO DELETE THIS LINE                    
     57        self.params['E'] = 0.0     ## <-----    
     58        ## YOU CAN MODIFY THELINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER  
     59        ## YOU CAN ALSO DELETE THIS LINE                   
     60        self.params['F'] = 0.0     ## <-----           
    3261 
    33         ## Parameter details [units, min, max] 
    34         self.details = {}                           ##Do not change this line!!! 
    35         self.details['scale'] = ['',None, None]   ## YOU CAN MODIFY THIS LINE 
    36         self.details['A'] = ['', None, None]       ## YOU CAN MODIFY THIS LINE 
    37         self.details['B'] = ['', None, None]       ## YOU CAN MODIFY THIS LINE 
    38         self.details['C'] = ['', None, None]       ## YOU CAN MODIFY THIS LINE 
    39         self.details['D'] = ['', None, None]       ## YOU CAN MODIFY THIS LINE 
    40         self.details['E'] = ['', None, None]       ## YOU CAN MODIFY THIS LINE 
    41         self.details['F'] = ['', 0, 1e16]       ## YOU CAN MODIFY THIS LINE      
    42            
    43         self.description = "scale * sin(F(x)/F(x)) \n where F(x)=A+B*x+C*x^2+D*x^3+E*x^4+F*x^5"  ## YOU CAN MODIFY THIS LINE 
     62        ## STORING PARAMETERS  [UNIT, MINIMUM VALUE, MAXIMUM VALUE] 
     63        self.details = {}    ##DO NOT CHANGE THIS LINE!!! 
     64        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ',WORD BETWEEN 
     65        ## ' ', TWO OTHER NUMBESR TO NEW VALUE OR YOU CAN ALSO DELETE TH LINE       
     66        self.details['scale'] = ['',None, None]    ## <-----    
     67        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ',WORD BETWEEN 
     68        ## ' ', TWO OTHER NUMBERS TO NEW VALUE OR YOU CAN ALSO DELETE TH LINE      
     69        self.details['A'] = ['', None, None]        ## <-----    
     70        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ',WORD BETWEEN 
     71        ## ' ', TWO OTHER NUMBERS TO NEW VALUE OR YOU CAN ALSO DELETE TH LINE      
     72        self.details['B'] = ['', None, None]        ## <-----    
     73        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ',WORD BETWEEN 
     74        ## ' ', TWO OTHER NUMBERS TO NEW VALUE OR YOU CAN ALSO DELETE TH LINE      
     75        self.details['C'] = ['', None, None]        ## <-----    
     76        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ',WORD BETWEEN 
     77        ## ' ', TWO OTHER NUMBERS TO NEW VALUE OR YOU CAN ALSO DELETE TH LINE      
     78        self.details['D'] = ['', None, None]        ## <-----    
     79        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ',WORD BETWEEN 
     80        ## ' ', TWO OTHER NUMBERS TO NEW VALUE OR YOU CAN ALSO DELETE TH LINE      
     81        self.details['E'] = ['', None, None]        ## <-----    
     82        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ',WORD BETWEEN 
     83        ## ' ', TWO OTHER NUMBERS TO NEW VALUE OR YOU CAN ALSO DELETE TH LINE      
     84        self.details['F'] = ['', 0, 1e16]           ## <-----    
     85        ## YOU CAN MODIFY THE LINE BELLOW.MODIFY WORDS BETWEEN """   """  ONLY!!!! 
     86        self.description = """ 
     87            scale * sin(F(x)/F(x)) \n where F(x)=A+B*x+C*x^2+D*x^3+E*x^4+F*x^5 
     88                 """                        ## <-----    
    4489    
    45     def function(self, x = 0.0): ##Do not change this line!!! 
     90    def function(self, x = 0.0): ##DO NOT CHANGE THIS LINE!!! 
    4691        """  
    4792        Evaluate the model 
     
    5297         
    5398        """ 
    54         ##You can modify from HERE to the END of this function!!! 
     99        ## ADD YOUR FUNCTION HERE. 
     100        ## REUSE THE PARAMETERS DEFINED PREVIOUSLY TO WRITE YOUR FUNCTION. 
    55101         
     102        ## IN THIS EXAMPLE THE FUNTION IS: 
     103        ## scale * sin(F(x)/F(x)) \n where F(x)=A+B*x+C*x^2+D*x^3+E*x^4+F*x^5 
     104         
     105        ## YOU CAN REWRITE OUR EXAMPLE WITH EVERYTING INSIDE " " : 
     106        ## "RETURN self.params['scale']* (self.params['A'] + self.params['B']*x + \ 
     107        ##   self.params['C']* pow(x,2) + self.params['D']*pow(x,3)+\ 
     108        ## self.params['E']*pow(x,4) +self.params['F']*pow(x,5)  ) "   
     109          
     110        ## NOTE: pow IS A FUNCTION IMPORTED FROM PYTHON MATH LIBRARY 
     111        ## FOR MORE INFORMATION CHECK http://docs.python.org/library/math.html       
     112        ## OTHER FUNCTIONS ARE ALSO  
     113        ###  AVAILABLE http://www.scipy.org/Numpy_Functions_by_Category 
     114        ## numpy FUNCTIONS ARE FOR EXPERT USER 
     115         
     116          
     117        ## YOU CAN ERASE EVERYTHING BELLOW FOR YOUR OWN FUNCTION 
    56118        #Redefine parameters as local parameters 
    57         a = self.params['A']       
    58         b = self.params['B']        
    59         c = self.params['C']        
    60         d = self.params['D']        
    61         e = self.params['E']       
    62         f = self.params['F']        
    63         scl = self.params['scale']   
    64          
    65         #Polynomial 
     119        a = self.params['A']       ## <-----    
     120        b = self.params['B']       ## <-----    
     121        c = self.params['C']       ## <-----    
     122        d = self.params['D']       ## <-----    
     123        e = self.params['E']       ## <-----    
     124        f = self.params['F']        ## <-----    
     125        scl = self.params['scale']   ## <-----    
     126        ##THIS OUR FUNCTION TEMPLATE 
    66127        poly = a + b*x + c*math.pow(x,2) + d*math.pow(x,3) \ 
    67              + e*math.pow(x,4) +f*math.pow(x,5)                   
     128             + e*math.pow(x,4) +f*math.pow(x,5)      ## <-----                 
    68129         
    69130        #Remove a singular point (lim poly --> 0) for sin(poly)/poly 
    70131        #(Just note: In Python, indentation defines the belongings of 'if', 'for', and so on..) 
    71         if poly == 0: 
    72             result = 1 
    73         else: 
    74             result = math.sin(poly)/poly 
     132        if poly == 0:                       ## <-----    
     133            result = 1                      ## <-----    
     134        else:                               ## <-----    
     135            result = sin(poly)/poly    ## <-----    
    75136             
    76         #Re-scale 
    77         result *=scl       
     137        #Re-scale                          ## <-----    
     138        result *=scl                       ## <-----    
    78139 
    79         return result 
     140        return result ## MODIFY ONLY RESULT. DON'T DELETE RETURN!!!! 
    80141    
Note: See TracChangeset for help on using the changeset viewer.