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 43ecc75f was
988130c6,
checked in by Gervaise Alina <gervyh@…>, 16 years ago
|
self.fixed field added in models but need to change wrapper generator
|
-
Property mode set to
100644
|
File size:
2.2 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 = 1.0 |
---|
18 | B = 1.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 | self.description='f(x) = A + Bx' |
---|
35 | ## Parameter details [units, min, max] |
---|
36 | self.details = {} |
---|
37 | self.details['A'] = ['', None, None] |
---|
38 | self.details['B'] = ['', None, None] |
---|
39 | # fixed paramaters |
---|
40 | self.fixed=[] |
---|
41 | def _line(self, x): |
---|
42 | """ |
---|
43 | Evaluate the function |
---|
44 | @param x: x-value |
---|
45 | @return: function value |
---|
46 | """ |
---|
47 | return self.params['A'] + x *self.params['B'] |
---|
48 | |
---|
49 | def run(self, x = 0.0): |
---|
50 | """ Evaluate the model |
---|
51 | @param x: simple value |
---|
52 | @return: (Line value) |
---|
53 | """ |
---|
54 | if x.__class__.__name__ == 'list': |
---|
55 | return self._line(x[0]*math.cos(x[1]))*self._line(x[0]*math.sin(x[1])) |
---|
56 | elif x.__class__.__name__ == 'tuple': |
---|
57 | raise ValueError, "Tuples are not allowed as input to BaseComponent models" |
---|
58 | else: |
---|
59 | return self._line(x) |
---|
60 | |
---|
61 | def runXY(self, x = 0.0): |
---|
62 | """ Evaluate the model |
---|
63 | @param x: simple value |
---|
64 | @return: Line value |
---|
65 | """ |
---|
66 | if x.__class__.__name__ == 'list': |
---|
67 | return self._line(x[0])*self._line(x[1]) |
---|
68 | elif x.__class__.__name__ == 'tuple': |
---|
69 | raise ValueError, "Tuples are not allowed as input to BaseComponent models" |
---|
70 | else: |
---|
71 | return self._line(x) |
---|
72 | |
---|
73 | |
---|
74 | if __name__ == "__main__": |
---|
75 | l = Line() |
---|
76 | print "hello" |
---|
77 | |
---|
78 | # End of file |
---|
Note: See
TracBrowser
for help on using the repository browser.