source: sasview/fittingview/src/sans/perspectives/fitting/plugin_models/polynominal5.py @ 2b4c8ca

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 2b4c8ca was e9bd127, checked in by Jae Cho <jhjcho@…>, 13 years ago

Additional comments

  • Property mode set to 100644
File size: 4.3 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"""
8
9"""
10## *****************************************************************************
11Please select the 'Compile' from the menubar after the modification and saving.
12Note that we recommend to save the file as a different file name.
13Otherwise, it could be removed in the future on re-installation of the SansView.
14## *****************************************************************************
15"""
16from sans.models.pluginmodel import Model1DPlugin  ##DO NOT CHANGE THIS LINE!!!
17
18## FOR MORE INFORMATION CHECK http://docs.python.org/library/math.html     
19## AND http://www.scipy.org/Numpy_Functions_by_Category
20import math                    ##DO NOT CHANGE THIS LINE!!!
21import numpy                   ##DO NOT CHANGE THIS LINE!!!
22
23## <-----  SIGN DEFINES WHERE YOU CAN MODIFY THE CODE
24
25class Model(Model1DPlugin): ##DO NOT CHANGE THIS LINE!!!
26    """
27    ##YOU CAN BE MODIFY ANYTHING BETWEEN """ """
28    ##DESCRIPTION OF MODEL PLUG-IN GOES HERE
29   
30    ##EXAMPLE: Class that evaluates a polynomial model.
31    """
32    ## YOU CAN MODIFY THE LINE BELLOW. CHANGE ONLY WORDS BETWEEN " "
33    ## TO RENAME YOUR MODEL: THIS NAME IS WHAT YOU SEE ON GUI.
34    name = "polynomial5"        ## <----- NAME OF THE MODEL   
35                               
36    def __init__(self):      ##DO NOT CHANGE THIS LINE!!!
37        """
38        Initialization
39        """
40        Model1DPlugin.__init__(self, name=self.name) ##DO NOT CHANGE THIS LINE!!!
41       
42        ## HERE WE DEFINE THE PARAM NAME AND ITS INITIAL VALUE
43        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER                                                     
44        self.params['A'] = 0.1       ## <-----               
45        self.params['B'] = 10.0      ## <-----                 
46        self.params['C'] = 0.0       ## <-----               
47        self.params['D'] = 0.0       ## <-----                   
48        self.params['E'] = 0.0       ## <-----                 
49        self.params['F'] = 0.0       ## <-----   
50       
51        ## DEFINE DEFAULT DETAILS
52        self.set_details()      ##DO NOT DELETE OR CHANGE THIS LINE!!!
53       
54        ## IN THIS EXAMPLE THE FUNTION IS:
55        ## F(x)=A+B*x+C*x^2+D*x^3+E*x^4+F*x^5             
56   
57    def function(self, x = 0.0): ##DO NOT CHANGE THIS LINE!!!
58        """
59        Evaluate the model
60        :param x: input x
61        :return: function value
62        """
63        ## DEFINE YOUR FUNCTION HERE.
64        ## YOU CAN ERASE EVERYTHING BELLOW FOR YOUR OWN FUNCTION
65        #Redefine parameters as local parameters, or skip and use long name
66        a = self.params['A']       ## <-----   
67        b = self.params['B']       ## <-----   
68        c = self.params['C']       ## <-----   
69        d = self.params['D']       ## <-----   
70        e = self.params['E']       ## <-----   
71        f = self.params['F']       ## <-----   
72 
73        ##THIS OUR FUNCTION TEMPLATE
74        poly = a + b * x + c * math.pow(x,2) + d * math.pow(x,3) \
75                + e * math.pow(x,4) + f * math.pow(x,5)              ## <-----               
76       
77        #(Just note: In Python, indentation defines the belongings
78        # of 'if', 'for', and so on..)
79        #(lim x --> 0)
80        if x == 0:                          ## <-----   
81            result = a                      ## <-----   
82        else:                               ## <-----   
83            result = poly                   ## <-----   
84
85        return result       ## MODIFY ONLY RESULT. DON'T DELETE RETURN!!!!
86
87###############################################################################
88## THIS IS FOR TEST. DO NOT MODIFY THE FOLLOWING LINES!!!!!!!!!!!!!!!!       
89if __name__ == "__main__": 
90    m= Model() 
91    out1 = m.runXY(0.0)
92    out2 = m.runXY(0.01)
93    isfine1 = numpy.isfinite(out1)
94    isfine2 = numpy.isfinite(out2)
95    print "Testing the value at Q = 0.0:"
96    print out1, " : finite? ", isfine1
97    print "Testing the value at Q = 0.01:"
98    print out2, " : finite? ", isfine2
99    if isfine1 and isfine2:
100        print "===> Simple Test: Passed!"
101    else:
102        print "===> Simple Test: Failed!"
Note: See TracBrowser for help on using the repository browser.