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

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 fa38d83 was fa9674b, checked in by Mathieu Doucet <doucetm@…>, 16 years ago

added plugin base model

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