source: sasview/fittingview/src/sans/perspectives/fitting/plugin_models/polynominal5.py @ 6e01f06

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 6e01f06 was 7c8d3093, checked in by Jae Cho <jhjcho@…>, 13 years ago

more completion of custom model edit

  • Property mode set to 100644
File size: 6.5 KB
RevLine 
[7c8d3093]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!!!
9import math                    ##DO NOT CHANGE THIS LINE!!!
10import numpy                    ##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 = "polynomial5" ## <----- 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['A'] = 0.0       ## <-----   
43        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER
44        ## YOU CAN ALSO DELETE THIS LINE                 
45        self.params['B'] = 10.0      ## <-----   
46        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER
47        ## YOU CAN ALSO DELETE THIS LINE                 
48        self.params['C'] = 0.0       ## <-----   
49        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER
50        ## YOU CAN ALSO DELETE THIS LINE               
51        self.params['D'] = 0.0     ## <-----   
52        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER
53        ## YOU CAN ALSO DELETE THIS LINE                   
54        self.params['E'] = 0.0     ## <-----   
55        ## YOU CAN MODIFY THELINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER
56        ## YOU CAN ALSO DELETE THIS LINE                 
57        self.params['F'] = 0.0     ## <-----         
58
59        ## STORING PARAMETERS  [UNIT, MINIMUM VALUE, MAXIMUM VALUE]
60        self.details = {}    ##DO NOT CHANGE THIS LINE!!!
61        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ',WORD BETWEEN
62        ## ' ', TWO OTHER NUMBERS TO NEW VALUE OR YOU CAN ALSO DELETE TH LINE     
63        self.details['A'] = ['', None, None]        ## <-----   
64        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ',WORD BETWEEN
65        ## ' ', TWO OTHER NUMBERS TO NEW VALUE OR YOU CAN ALSO DELETE TH LINE     
66        self.details['B'] = ['', 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['C'] = ['', 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['D'] = ['', 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['E'] = ['', 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['F'] = ['', None, None]           ## <-----   
79        ## YOU CAN MODIFY THE LINE BELLOW.MODIFY WORDS BETWEEN """   """  ONLY!!!!
80        self.description = """
81        F(x) where F(x)=A+B*x+C*x^2+D*x^3+E*x^4+F*x^5
82        """                        ## <-----   
83   
84    def function(self, x = 0.0): ##DO NOT CHANGE THIS LINE!!!
85        """
86        Evaluate the model
87        :param x: input x
88        :return: function value
89        """
90        ## ADD YOUR FUNCTION HERE.
91        ## REUSE THE PARAMETERS DEFINED PREVIOUSLY TO WRITE YOUR FUNCTION.
92       
93        ## IN THIS EXAMPLE THE FUNTION IS:
94        ## F(x)=A+B*x+C*x^2+D*x^3+E*x^4+F*x^5
95     
96        ## NOTE: pow IS A FUNCTION IMPORTED FROM PYTHON MATH LIBRARY
97        ## FOR MORE INFORMATION CHECK http://docs.python.org/library/math.html     
98        ## OTHER FUNCTIONS ARE ALSO
99        ###  AVAILABLE http://www.scipy.org/Numpy_Functions_by_Category
100        ## numpy FUNCTIONS ARE FOR EXPERT USER
101       
102         
103        ## YOU CAN ERASE EVERYTHING BELLOW FOR YOUR OWN FUNCTION
104        #Redefine parameters as local parameters
105        a = self.params['A']       ## <-----   
106        b = self.params['B']       ## <-----   
107        c = self.params['C']       ## <-----   
108        d = self.params['D']       ## <-----   
109        e = self.params['E']       ## <-----   
110        f = self.params['F']        ## <-----   
111 
112        ##THIS OUR FUNCTION TEMPLATE
113        poly = a + b*x + c*math.pow(x,2) + d*math.pow(x,3) \
114             + e*math.pow(x,4) +f*math.pow(x,5)      ## <-----               
115       
116        #(lim x --> 0)
117        #(Just note: In Python, indentation defines the belongings of 'if', 'for', and so on..)
118        if x == 0:                       ## <-----   
119            result = a                      ## <-----   
120        else:                               ## <-----   
121            result = poly    ## <-----   
122
123        return result ## MODIFY ONLY RESULT. DON'T DELETE RETURN!!!!
124
125## DO NOT MODIFY THE FOLLOWING LINES!!!!!!!!!!!!!!!!       
126if __name__ == "__main__": 
127    m= Model() 
128    out1 = m.runXY(0.0)
129    out2 = m.runXY(0.01)
130    isfine1 = numpy.isfinite(out1)
131    isfine2 = numpy.isfinite(out2)
132    print "Testing the value at Q = 0.0:"
133    print out1, " : finite? ", isfine1
134    print "Testing the value at Q = 0.01:"
135    print out2, " : finite? ", isfine2
136    if isfine1 and isfine2:
137        print "===> Simple Test: Passed!"
138    else:
139        print "===> Simple Test: Failed!"
Note: See TracBrowser for help on using the repository browser.