source: sasview/src/sas/plottools/LineModel.py @ 9701348

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 9701348 was 79492222, checked in by krzywon, 10 years ago

Changed the file and folder names to remove all SANS references.

  • Property mode set to 100644
File size: 2.2 KB
Line 
1#!/usr/bin/env python
2"""
3Provide Line function (y= A + Bx)
4"""
5
6import math
7
8class LineModel(object):
9    """
10    Class that evaluates a linear model.
11   
12    f(x) = A + Bx
13     
14    List of default parameters:
15    A = 0.0
16    B = 0.0
17    """
18       
19    def __init__(self):
20        """ Initialization """
21        ## Name of the model
22        self.name = "LineModel"
23
24        ## Define parameters
25        self.params = {}
26        self.params['A'] = 1.0
27        self.params['B'] = 1.0
28
29        ## Parameter details [units, min, max]
30        self.details = {}
31        self.details['A'] = ['', None, None]
32        self.details['B'] = ['', None, None]
33               
34    def getParam(self, name):
35        """
36        """
37        return self.params[name.upper()]
38   
39    def setParam(self, name, value):
40        """
41        """
42        self.params[name.upper()] = value
43   
44    def _line(self, x):
45        """
46        Evaluate the function
47       
48        :param x: x-value
49       
50        :return: function value
51       
52        """
53        return  self.params['A'] + (x * self.params['B'])
54   
55    def run(self, x = 0.0):
56        """
57        Evaluate the model
58       
59        :param x: simple value
60       
61        :return: (Line value)
62        """
63        if x.__class__.__name__ == 'list':
64            return self._line(x[0] * math.cos(x[1])) * \
65                                self._line(x[0] * math.sin(x[1]))
66        elif x.__class__.__name__ == 'tuple':
67            msg  = "Tuples are not allowed as input to BaseComponent models"
68            raise ValueError, msg
69        else:
70            return self._line(x)
71   
72    def runXY(self, x = 0.0):
73        """
74        Evaluate the model
75           
76        :param x: simple value
77       
78        :return: Line value
79       
80        """
81        if x.__class__.__name__ == 'list':
82            return self._line(x[0]) * self._line(x[1])
83        elif x.__class__.__name__ == 'tuple':
84            msg = "Tuples are not allowed as input to BaseComponent models"
85            raise ValueError, msg
86        else:
87            return self._line(x)
88   
89
90if __name__ == "__main__": 
91    l = Line()
92
Note: See TracBrowser for help on using the repository browser.