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 3409a90 was
d7bb526,
checked in by Piotr Rozyczko <piotr.rozyczko@…>, 9 years ago
|
Refactored plottools into sasgui
|
-
Property mode set to
100644
|
File size:
2.1 KB
|
Line | |
---|
1 | #!/usr/bin/env python |
---|
2 | """ |
---|
3 | Provide Line function (y= A + Bx) |
---|
4 | """ |
---|
5 | |
---|
6 | import math |
---|
7 | |
---|
8 | class 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 | Return parameter value |
---|
37 | """ |
---|
38 | return self.params[name.upper()] |
---|
39 | |
---|
40 | def setParam(self, name, value): |
---|
41 | """ |
---|
42 | Set parameter value |
---|
43 | """ |
---|
44 | self.params[name.upper()] = value |
---|
45 | |
---|
46 | def _line(self, x): |
---|
47 | """ |
---|
48 | Evaluate the function |
---|
49 | |
---|
50 | :param x: x-value |
---|
51 | |
---|
52 | :return: function value |
---|
53 | |
---|
54 | """ |
---|
55 | return self.params['A'] + (x * self.params['B']) |
---|
56 | |
---|
57 | def run(self, x=0.0): |
---|
58 | """ |
---|
59 | Evaluate the model |
---|
60 | |
---|
61 | :param x: simple value |
---|
62 | |
---|
63 | :return: (Line value) |
---|
64 | """ |
---|
65 | if x.__class__.__name__ == 'list': |
---|
66 | return self._line(x[0] * math.cos(x[1])) * \ |
---|
67 | self._line(x[0] * math.sin(x[1])) |
---|
68 | elif x.__class__.__name__ == 'tuple': |
---|
69 | msg = "Tuples are not allowed as input to BaseComponent models" |
---|
70 | raise ValueError, msg |
---|
71 | else: |
---|
72 | return self._line(x) |
---|
73 | |
---|
74 | def runXY(self, x=0.0): |
---|
75 | """ |
---|
76 | Evaluate the model |
---|
77 | |
---|
78 | :param x: simple value |
---|
79 | |
---|
80 | :return: Line value |
---|
81 | |
---|
82 | """ |
---|
83 | if x.__class__.__name__ == 'list': |
---|
84 | return self._line(x[0]) * self._line(x[1]) |
---|
85 | elif x.__class__.__name__ == 'tuple': |
---|
86 | msg = "Tuples are not allowed as input to BaseComponent models" |
---|
87 | raise ValueError, msg |
---|
88 | else: |
---|
89 | return self._line(x) |
---|
Note: See
TracBrowser
for help on using the repository browser.