source: sasview/fittingview/src/sans/perspectives/fitting/plugin_models/testmodel.py @ 4b73c3e

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

Additional comments

  • Property mode set to 100644
File size: 3.9 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"""
16
17from sans.models.pluginmodel import Model1DPlugin  ##DO NOT CHANGE THIS LINE!!!
18import math                  ##DO NOT CHANGE THIS LINE!!!
19import numpy               ##DO NOT CHANGE THIS LINE!!!
20
21##PLEASE READ COMMENTS CAREFULLY !!! COMMENT ARE IN CAPITAL LETTERS AND AFTER ##
22## THESE COMMENTS ARE THERE TO GUIDE YOU. YOU CAN REMOVE THEM ONLY WHEN YOU ARE
23## CONFORTABLE ENOUGH WITH OUR MODEL PLUGIN OPTION
24
25
26## <-----  SIGN DEFINES WHERE YOU CAN MODIFY THE CODE
27
28class Model(Model1DPlugin):##DO NOT CHANGE THIS LINE!!!
29    """
30    ##YOU CAN BE MODIFY ANYTHING BETWEEN """ """
31    ##DESCRIPTION OF MODEL PLUG-IN GOES HERE
32   
33    ##EXAMPLE:Class that evaluates a cos(x) model.
34    """
35   
36    ## YOU CAN MODIFY THE LINE BELLOW. CHANGE ONLY WORDS BETWEEN " "
37    ## TO RENAME YOUR MODEL
38    name = "A+Bcos(2x)+Csin(2x)"      ## <----- NAME OF THE MODEL   
39   
40    def __init__(self):
41        """
42        Initialization
43        """
44        Model1DPlugin.__init__(self, name= self.name)##DO NOT CHANGE THIS LINE!!!
45       
46        ## EDIT PARAMETERS' NAMES AND VALUE
47        ## DELETE MODIFIABLE LINE HERE WILL REDUCE THE NUMBER OF PARAMETERS
48        self.params = {}                        ##DO NOT CHANGE THIS LINE!!!
49        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER
50        ## YOU CAN ALSO DELETE THIS LINE
51        self.params['A'] = 1.0       ## <----- 
52        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER
53        ## YOU CAN ALSO DELETE THIS LINE   
54        self.params['B'] = 1.0       ## <-----
55        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER
56        ## YOU CAN ALSO DELETE THIS LINE   
57        self.params['C'] = 10.0      ## <----- 
58
59        ## DEFINE DEFAULT DETAILS
60        self.set_details()      ##DO NOT DELETE OR CHANGE THIS LINE!!!
61       
62        ## YOU CAN MODIFY THE LINE BELLOW.MODIFY WORDS BETWEEN """   """  ONLY!!!!
63        self.description = "F(x)=A+Bcos(2x)+Csin(2x) "     ## <-----
64   
65    def function(self, x = 0.0):  ##DO NOT CHANGE THIS LINE!!!
66        """
67        Evaluate the model
68       
69        :param x: input x
70       
71        :return: function value
72       
73        """
74        ## ADD YOUR FUNCTION HERE.
75        ## REUSE THE PARAMETERS DEFINED PREVIOUSLY TO WRITE YOUR FUNCTION.
76       
77        ## IN THIS EXAMPLE THE FUNTION IS:
78        ## A+Bcos(2x)+Csin(2x)
79        ## YOU CAN USE math.sin or sin directly
80        ## NOTE: sin, cos ARE FUNCTIONS  IMPORTED FROM PYTHON MATH LIBRARY
81        ## FOR MORE INFORMATION CHECK http://docs.python.org/library/math.html     
82        ## OTHER FUNCTIONS ARE ALSO
83        ##  AVAILABLE http://www.scipy.org/Numpy_Functions_by_Category
84        ## numpy FUNCTIONS ARE FOR EXPERT USER
85       
86        return self.params['A']+self.params['B']*math.cos(2.0*x)+self.params['C']*math.sin(2.0*x)
87   
88## 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.