source: sasview/sansview/plugins/testmodel_2.py @ edb3a5d0

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 edb3a5d0 was 5062bbf, checked in by Gervaise Alina <gervyh@…>, 14 years ago

working on documentation

  • Property mode set to 100644
File size: 3.2 KB
Line 
1"""
2Test plug-in model
3"""
4from sans.models.pluginmodel import Model1DPlugin   ##Do not change this line!!!
5import math                                         ##Do not change this line!!!
6
7# Modify ONLY lines with '## YOU CAN MODIFY THIS LINE'.
8# Your model HAS to be called Model
9class Model(Model1DPlugin):         ##Do not change this line!!!
10    """
11    Class that evaluates a ploynomial model.
12    """
13   
14    ## Name of your model
15    name = "sin(poly)/(poly)"    ## YOU CAN MODIFY THIS LINE.
16   
17    def __init__(self):      ##Do not change this line!!!
18        """
19        Initialization
20        """
21        Model1DPlugin.__init__(self, name= self.name)  ##Do not change this line!!!
22       
23        ## Parameters definition and defaults
24        self.params = {}                    ##Do not change this line!!!
25        self.params['scale'] = 1.0          ## YOU CAN MODIFY THIS LINE
26        self.params['A'] = 0.0              ## YOU CAN MODIFY THIS LINE
27        self.params['B'] = 10.0             ## YOU CAN MODIFY THIS LINE
28        self.params['C'] = 0.0             ## YOU CAN MODIFY THIS LINE
29        self.params['D'] = 0.0              ## YOU CAN MODIFY THIS LINE
30        self.params['E'] = 0.0              ## YOU CAN MODIFY THIS LINE
31        self.params['F'] = 0.0              ## YOU CAN MODIFY THIS LINE
32
33        ## Parameter details [units, min, max]
34        self.details = {}                           ##Do not change this line!!!
35        self.details['scale'] = ['',None, None]   ## YOU CAN MODIFY THIS LINE
36        self.details['A'] = ['', None, None]       ## YOU CAN MODIFY THIS LINE
37        self.details['B'] = ['', None, None]       ## YOU CAN MODIFY THIS LINE
38        self.details['C'] = ['', None, None]       ## YOU CAN MODIFY THIS LINE
39        self.details['D'] = ['', None, None]       ## YOU CAN MODIFY THIS LINE
40        self.details['E'] = ['', None, None]       ## YOU CAN MODIFY THIS LINE
41        self.details['F'] = ['', 0, 1e16]       ## YOU CAN MODIFY THIS LINE     
42         
43        self.description = "scale * sin(F(x)/F(x)) \n where F(x)=A+B*x+C*x^2+D*x^3+E*x^4+F*x^5"  ## YOU CAN MODIFY THIS LINE
44   
45    def function(self, x = 0.0): ##Do not change this line!!!
46        """
47        Evaluate the model
48       
49        :param x: input x
50       
51        :return: function value
52       
53        """
54        ##You can modify from HERE to the END of this function!!!
55       
56        #Redefine parameters as local parameters
57        a = self.params['A']     
58        b = self.params['B']       
59        c = self.params['C']       
60        d = self.params['D']       
61        e = self.params['E']     
62        f = self.params['F']       
63        scl = self.params['scale'] 
64       
65        #Polynomial
66        poly = a + b*x + c*math.pow(x,2) + d*math.pow(x,3) \
67             + e*math.pow(x,4) +f*math.pow(x,5)                 
68       
69        #Remove a singular point (lim poly --> 0) for sin(poly)/poly
70        #(Just note: In Python, indentation defines the belongings of 'if', 'for', and so on..)
71        if poly == 0:
72            result = 1
73        else:
74            result = math.sin(poly)/poly
75           
76        #Re-scale
77        result *=scl     
78
79        return result
80   
Note: See TracBrowser for help on using the repository browser.