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

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 c13b8cc was aaea3714, checked in by Jae Cho <jhjcho@…>, 15 years ago

new example plugin model

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