source: sasview/sansmodels/src/sans/models/pluginmodel.py @ 0cbfaeb

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 0cbfaeb was 79ac6f8, checked in by Gervaise Alina <gervyh@…>, 14 years ago

working on documentation

  • Property mode set to 100644
File size: 1.5 KB
Line 
1
2from sans.models.BaseComponent import BaseComponent
3import math
4
5class Model1DPlugin(BaseComponent):
6    ## Name of the model
7   
8    def __init__(self , name="Plugin Model" ):
9        """ Initialization """
10        BaseComponent.__init__(self)
11        self.name = name
12        self.details = {}
13        self.params  = {}
14        self.description=''
15       
16    def function(self, x):
17        """
18        Function to be implemented by the plug-in writer
19        """
20        return x
21       
22    def run(self, x = 0.0):
23        """
24        Evaluate the model
25       
26        :param x: input x, or [x, phi] [radian]
27       
28        :return: function value
29       
30        """
31        if x.__class__.__name__ == 'list':
32            x_val = x[0]*math.cos(x[1])
33            y_val = x[0]*math.sin(x[1])
34            return self.function(x_val)*self.function(y_val)
35        elif x.__class__.__name__ == 'tuple':
36            raise ValueError, "Tuples are not allowed as input to BaseComponent models"
37        else:
38            return self.function(x)
39       
40   
41    def runXY(self, x = 0.0):
42        """
43        Evaluate the model
44       
45        :param x: input x, or [x, y]
46       
47        :return: function value
48       
49        """
50        if x.__class__.__name__ == 'list':
51            return self.function(x[0])*self.function(x[1])
52        elif x.__class__.__name__ == 'tuple':
53            raise ValueError, "Tuples are not allowed as input to BaseComponent models"
54        else:
55            return self.function(x)
Note: See TracBrowser for help on using the repository browser.