source: sasview/sansview/plugins/testmodel_2.py @ 7972223

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 7972223 was 80a6775, checked in by Gervaise Alina <gervyh@…>, 14 years ago

ADD DESCRIPTION PLUG-IN MODEL

  • Property mode set to 100644
File size: 7.0 KB
Line 
1"""
2Test 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
7"""
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!!!
11
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!!!
20    """
21    ##YOU CAN BE MODIFY ANYTHING BETWEEN """ """
22    ##DESCRIPTION OF MODEL PLUG-IN GOES HERE
23   
24    ##EXAMPLE: Class that evaluates a polynomial model.
25    """
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!!!
31        """
32        Initialization
33        """
34        Model1DPlugin.__init__(self, name=self.name) ##DO NOT CHANGE THIS LINE!!!
35       
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     ## <-----         
61
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                 """                        ## <-----   
89   
90    def function(self, x = 0.0): ##DO NOT CHANGE THIS LINE!!!
91        """
92        Evaluate the model
93       
94        :param x: input x
95       
96        :return: function value
97       
98        """
99        ## ADD YOUR FUNCTION HERE.
100        ## REUSE THE PARAMETERS DEFINED PREVIOUSLY TO WRITE YOUR FUNCTION.
101       
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
118        #Redefine parameters as local parameters
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
127        poly = a + b*x + c*math.pow(x,2) + d*math.pow(x,3) \
128             + e*math.pow(x,4) +f*math.pow(x,5)      ## <-----               
129       
130        #Remove a singular point (lim poly --> 0) for sin(poly)/poly
131        #(Just note: In Python, indentation defines the belongings of 'if', 'for', and so on..)
132        if poly == 0:                       ## <-----   
133            result = 1                      ## <-----   
134        else:                               ## <-----   
135            result = sin(poly)/poly    ## <-----   
136           
137        #Re-scale                          ## <-----   
138        result *=scl                       ## <-----   
139
140        return result ## MODIFY ONLY RESULT. DON'T DELETE RETURN!!!!
141   
Note: See TracBrowser for help on using the repository browser.