source: sasview/sansmodels/src/sans/models/pluginmodel.py @ 458c930

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

working on documentation

  • Property mode set to 100644
File size: 1.5 KB
RevLine 
[79ac6f8]1
[cfbe9b5]2from sans.models.BaseComponent import BaseComponent
[fa9674b]3import math
4
[cfbe9b5]5class Model1DPlugin(BaseComponent):
[fa9674b]6    ## Name of the model
[996fd35]7   
8    def __init__(self , name="Plugin Model" ):
[fa9674b]9        """ Initialization """
[f2f3814]10        BaseComponent.__init__(self)
[996fd35]11        self.name = name
[fa9674b]12        self.details = {}
13        self.params  = {}
[5f89fb8]14        self.description=''
[79ac6f8]15       
[fa9674b]16    def function(self, x):
17        """
[79ac6f8]18        Function to be implemented by the plug-in writer
[fa9674b]19        """
20        return x
21       
22    def run(self, x = 0.0):
[79ac6f8]23        """
24        Evaluate the model
25       
26        :param x: input x, or [x, phi] [radian]
27       
28        :return: function value
29       
[fa9674b]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)
[27fea3f]39       
[fa9674b]40   
41    def runXY(self, x = 0.0):
[79ac6f8]42        """
43        Evaluate the model
44       
45        :param x: input x, or [x, y]
46       
47        :return: function value
48       
[fa9674b]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:
[79ac6f8]55            return self.function(x)
Note: See TracBrowser for help on using the repository browser.