source: sasview/fittingview/src/sans/perspectives/fitting/plugin_models/polynominal5.py @ 74d7b59

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 74d7b59 was 19e614a, checked in by Jae Cho <jhjcho@…>, 13 years ago

let users be able to delete default custom models (WIN app only)

  • Property mode set to 100644
File size: 4.6 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"""
[e9bd127]8
9"""
[22b1d38]10## *****************************************************************************
[e9bd127]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.
[22b1d38]14## *****************************************************************************
[e9bd127]15"""
[7c8d3093]16from sans.models.pluginmodel import Model1DPlugin  ##DO NOT CHANGE THIS LINE!!!
17
[ed8fa6a3]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!!!
[7c8d3093]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 " "
[ed8fa6a3]33    ## TO RENAME YOUR MODEL: THIS NAME IS WHAT YOU SEE ON GUI.
[19e614a]34    name = "polynomial5"        ## <----- FILE NAME (NAME OF THE MODEL)   
[7c8d3093]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       
[ed8fa6a3]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       ## <-----   
[19e614a]50        ## YOU CAN MODIFY THE LINE BELLOW.MODIFY WORDS BETWEEN """   """  ONLY!!!!
51        self.description = """
52            a + b * x + c * math.pow(x,2) + d * math.pow(x,3) \n
53             + e * math.pow(x,4) + f * math.pow(x,5) 
54        """                        ## <-----   
[ed8fa6a3]55        ## DEFINE DEFAULT DETAILS
56        self.set_details()      ##DO NOT DELETE OR CHANGE THIS LINE!!!
57       
58        ## IN THIS EXAMPLE THE FUNTION IS:
59        ## F(x)=A+B*x+C*x^2+D*x^3+E*x^4+F*x^5             
[7c8d3093]60   
61    def function(self, x = 0.0): ##DO NOT CHANGE THIS LINE!!!
62        """
63        Evaluate the model
64        :param x: input x
65        :return: function value
66        """
[ed8fa6a3]67        ## DEFINE YOUR FUNCTION HERE.
[7c8d3093]68        ## YOU CAN ERASE EVERYTHING BELLOW FOR YOUR OWN FUNCTION
[ed8fa6a3]69        #Redefine parameters as local parameters, or skip and use long name
[7c8d3093]70        a = self.params['A']       ## <-----   
71        b = self.params['B']       ## <-----   
72        c = self.params['C']       ## <-----   
73        d = self.params['D']       ## <-----   
74        e = self.params['E']       ## <-----   
[ed8fa6a3]75        f = self.params['F']       ## <-----   
[7c8d3093]76 
77        ##THIS OUR FUNCTION TEMPLATE
[ed8fa6a3]78        poly = a + b * x + c * math.pow(x,2) + d * math.pow(x,3) \
79                + e * math.pow(x,4) + f * math.pow(x,5)              ## <-----               
[7c8d3093]80       
[ed8fa6a3]81        #(Just note: In Python, indentation defines the belongings
82        # of 'if', 'for', and so on..)
[7c8d3093]83        #(lim x --> 0)
[ed8fa6a3]84        if x == 0:                          ## <-----   
[7c8d3093]85            result = a                      ## <-----   
86        else:                               ## <-----   
[ed8fa6a3]87            result = poly                   ## <-----   
[7c8d3093]88
[ed8fa6a3]89        return result       ## MODIFY ONLY RESULT. DON'T DELETE RETURN!!!!
[7c8d3093]90
[ed8fa6a3]91###############################################################################
92## THIS IS FOR TEST. DO NOT MODIFY THE FOLLOWING LINES!!!!!!!!!!!!!!!!       
[7c8d3093]93if __name__ == "__main__": 
94    m= Model() 
95    out1 = m.runXY(0.0)
96    out2 = m.runXY(0.01)
97    isfine1 = numpy.isfinite(out1)
98    isfine2 = numpy.isfinite(out2)
99    print "Testing the value at Q = 0.0:"
100    print out1, " : finite? ", isfine1
101    print "Testing the value at Q = 0.01:"
102    print out2, " : finite? ", isfine2
103    if isfine1 and isfine2:
104        print "===> Simple Test: Passed!"
105    else:
106        print "===> Simple Test: Failed!"
Note: See TracBrowser for help on using the repository browser.