source: sasview/sansmodels/src/sans/models/pluginmodel.py @ 7a69683

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 7a69683 was 996fd35, checked in by Gervaise Alina <gervyh@…>, 16 years ago

name change from 2 model

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