source: sasview/src/sas/sascalc/fit/pluginmodel.py @ 7858575

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.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 7858575 was 9e531f2, checked in by krzywon, 9 years ago

Code Cleanup - Fix build?!?!

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