source: sasview/sansview/plugins/testmodel.py @ 6572274

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 6572274 was 80a6775, checked in by Gervaise Alina <gervyh@…>, 14 years ago

ADD DESCRIPTION PLUG-IN MODEL

  • Property mode set to 100644
File size: 3.7 KB
RevLine 
[1c66bc5]1"""
[5062bbf]2Test plug-in model
[80a6775]3These are links of available functions:
4
5http://docs.python.org/library/math.html
6http://www.scipy.org/Numpy_Functions_by_Category
[1c66bc5]7"""
[80a6775]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
[948add7]15
[b30f001]16
[80a6775]17## <-----  SIGN DEFINES WHERE YOU CAN MODIFY THE CODE
[1c66bc5]18
[80a6775]19class Model(Model1DPlugin):##DO NOT CHANGE THIS LINE!!!
[5062bbf]20    """
[80a6775]21    ##YOU CAN BE MODIFY ANYTHING BETWEEN """ """
22    ##DESCRIPTION OF MODEL PLUG-IN GOES HERE
23   
24    ##EXAMPLE:Class that evaluates a cos(x) model.
[1c66bc5]25    """
26   
[80a6775]27    ## YOU CAN MODIFY THE LINE BELLOW. CHANGE ONLY WORDS BETWEEN " "
28    ## TO RENAME YOUR MODEL
29    name = "A+Bcos(2x)+Csin(2x)"      ## <----- NAME OF THE MODEL   
[1c66bc5]30   
31    def __init__(self):
[5062bbf]32        """
33        Initialization
34        """
[80a6775]35        Model1DPlugin.__init__(self, name= self.name)##DO NOT CHANGE THIS LINE!!!
[1c66bc5]36       
[80a6775]37        ## EDIT PARAMETERS' NAMES AND VALUE
38        ## DELETE MODIFIABLE LINE HERE WILL REDUCE THE NUMBER OF PARAMETERS
39        self.params = {}                        ##DO NOT CHANGE THIS LINE!!!
40        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER
41        ## YOU CAN ALSO DELETE THIS LINE
42        self.params['A'] = 1.0       ## <----- 
43        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER
44        ## YOU CAN ALSO DELETE THIS LINE   
45        self.params['B'] = 1.0       ## <-----
46        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER
47        ## YOU CAN ALSO DELETE THIS LINE   
48        self.params['C'] = 10.0      ## <----- 
[1c66bc5]49
[80a6775]50        ## STORING PARAMETERS  [UNIT, MINIMUM VALUE, MAXIMUM VALUE]
51        self.details = {}       ##DO NOT CHANGE THIS LINE!!!
52        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ',WORD BETWEEN
53        ## ' ', TWO OTHER NUMBERS TO NEW VALUE OR YOU CAN ALSO DELETE TH LINE   
54        self.details['A'] = ['', -1e16, 1e16]        ## <-----
55        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ',WORD BETWEEN
56        ## ' ', TWO OTHER NUMBERS TO NEW VALUE OR YOU CAN ALSO DELETE TH LINE   
57        self.details['B'] = ['', -1e16, 1e16]         ## <-----
58        ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ',WORD BETWEEN
59        ## ' ', TWO OTHER NUMBERS TO NEW VALUE OR YOU CAN ALSO DELETE TH LINE   
60        self.details['C'] = ['', -1e16, 1e16]         ## <-----
61        ## YOU CAN MODIFY THE LINE BELLOW.MODIFY WORDS BETWEEN """   """  ONLY!!!!
62        self.description = "F(x)=A+Bcos(2x)+Csin(2x) " ## <-----
[1c66bc5]63   
[80a6775]64    def function(self, x = 0.0):  ##DO NOT CHANGE THIS LINE!!!
[5062bbf]65        """
66        Evaluate the model
67       
68        :param x: input x
69       
70        :return: function value
71       
[1c66bc5]72        """
[80a6775]73        ## ADD YOUR FUNCTION HERE.
74        ## REUSE THE PARAMETERS DEFINED PREVIOUSLY TO WRITE YOUR FUNCTION.
75       
76        ## IN THIS EXAMPLE THE FUNTION IS:
77        ## A+Bcos(2x)+Csin(2x)
78        ## YOU CAN USE math.sin or sin directly
79        ## NOTE: sin, cos ARE FUNCTIONS  IMPORTED FROM PYTHON MATH LIBRARY
80        ## FOR MORE INFORMATION CHECK http://docs.python.org/library/math.html     
81        ## OTHER FUNCTIONS ARE ALSO
82        ##  AVAILABLE http://www.scipy.org/Numpy_Functions_by_Category
83        ## numpy FUNCTIONS ARE FOR EXPERT USER
84       
85        return self.params['A']+self.params['B']*cos(2.0*x)+self.params['C']*math.sin(2.0*x)
[1c66bc5]86   
Note: See TracBrowser for help on using the repository browser.