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 fa9674b was
5ef6709,
checked in by Gervaise Alina <gervyh@…>, 16 years ago
|
name of the model changed
|
-
Property mode set to
100644
|
File size:
2.1 KB
|
Line | |
---|
1 | #!/usr/bin/env python |
---|
2 | """ |
---|
3 | Provide Line function (y= A + Bx) as a BaseComponent model |
---|
4 | """ |
---|
5 | |
---|
6 | from sans.models.BaseComponent import BaseComponent |
---|
7 | import math |
---|
8 | |
---|
9 | |
---|
10 | class LineModel(BaseComponent): |
---|
11 | """ |
---|
12 | Class that evaluates a linear model. |
---|
13 | |
---|
14 | f(x) = A + Bx |
---|
15 | |
---|
16 | List of default parameters: |
---|
17 | A = 0.0 |
---|
18 | B = 0.0 |
---|
19 | """ |
---|
20 | |
---|
21 | def __init__(self): |
---|
22 | """ Initialization """ |
---|
23 | |
---|
24 | # Initialize BaseComponent first, then sphere |
---|
25 | BaseComponent.__init__(self) |
---|
26 | |
---|
27 | ## Name of the model |
---|
28 | self.name = "LineModel" |
---|
29 | |
---|
30 | ## Define parameters |
---|
31 | self.params = {} |
---|
32 | self.params['A'] = 1.0 |
---|
33 | self.params['B'] = 1.0 |
---|
34 | |
---|
35 | ## Parameter details [units, min, max] |
---|
36 | self.details = {} |
---|
37 | self.details['A'] = ['', None, None] |
---|
38 | self.details['B'] = ['', None, None] |
---|
39 | |
---|
40 | def _line(self, x): |
---|
41 | """ |
---|
42 | Evaluate the function |
---|
43 | @param x: x-value |
---|
44 | @return: function value |
---|
45 | """ |
---|
46 | return self.params['A'] + x *self.params['B'] |
---|
47 | |
---|
48 | def run(self, x = 0.0): |
---|
49 | """ Evaluate the model |
---|
50 | @param x: simple value |
---|
51 | @return: (Line value) |
---|
52 | """ |
---|
53 | if x.__class__.__name__ == 'list': |
---|
54 | return self._line(x[0]*math.cos(x[1]))*self._line(x[0]*math.sin(x[1])) |
---|
55 | elif x.__class__.__name__ == 'tuple': |
---|
56 | raise ValueError, "Tuples are not allowed as input to BaseComponent models" |
---|
57 | else: |
---|
58 | return self._line(x) |
---|
59 | |
---|
60 | def runXY(self, x = 0.0): |
---|
61 | """ Evaluate the model |
---|
62 | @param x: simple value |
---|
63 | @return: Line value |
---|
64 | """ |
---|
65 | if x.__class__.__name__ == 'list': |
---|
66 | return self._line(x[0])*self._line(x[1]) |
---|
67 | elif x.__class__.__name__ == 'tuple': |
---|
68 | raise ValueError, "Tuples are not allowed as input to BaseComponent models" |
---|
69 | else: |
---|
70 | return self._line(x) |
---|
71 | |
---|
72 | |
---|
73 | if __name__ == "__main__": |
---|
74 | l = Line() |
---|
75 | print "hello" |
---|
76 | |
---|
77 | # End of file |
---|
Note: See
TracBrowser
for help on using the repository browser.