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 aa03e0d 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
|
Rev | Line | |
---|
[a9d5684] | 1 | #!/usr/bin/env python |
---|
[2df0b74] | 2 | """ |
---|
| 3 | Provide Line function (y= A + Bx) |
---|
[a9d5684] | 4 | """ |
---|
| 5 | |
---|
| 6 | import math |
---|
| 7 | |
---|
| 8 | class LineModel(object): |
---|
[2df0b74] | 9 | """ |
---|
[a9d5684] | 10 | Class that evaluates a linear model. |
---|
[2df0b74] | 11 | |
---|
[a9d5684] | 12 | f(x) = A + Bx |
---|
[2df0b74] | 13 | |
---|
[a9d5684] | 14 | List of default parameters: |
---|
| 15 | A = 0.0 |
---|
[2df0b74] | 16 | B = 0.0 |
---|
[a9d5684] | 17 | """ |
---|
[2df0b74] | 18 | |
---|
[a9d5684] | 19 | def __init__(self): |
---|
| 20 | """ Initialization """ |
---|
[2df0b74] | 21 | # # Name of the model |
---|
[a9d5684] | 22 | self.name = "LineModel" |
---|
| 23 | |
---|
[2df0b74] | 24 | # # Define parameters |
---|
[a9d5684] | 25 | self.params = {} |
---|
| 26 | self.params['A'] = 1.0 |
---|
| 27 | self.params['B'] = 1.0 |
---|
| 28 | |
---|
[2df0b74] | 29 | # # Parameter details [units, min, max] |
---|
[a9d5684] | 30 | self.details = {} |
---|
| 31 | self.details['A'] = ['', None, None] |
---|
| 32 | self.details['B'] = ['', None, None] |
---|
[2df0b74] | 33 | |
---|
[a9d5684] | 34 | def getParam(self, name): |
---|
| 35 | """ |
---|
[2df0b74] | 36 | Return parameter value |
---|
[a9d5684] | 37 | """ |
---|
| 38 | return self.params[name.upper()] |
---|
[2df0b74] | 39 | |
---|
[a9d5684] | 40 | def setParam(self, name, value): |
---|
| 41 | """ |
---|
[2df0b74] | 42 | Set parameter value |
---|
[a9d5684] | 43 | """ |
---|
| 44 | self.params[name.upper()] = value |
---|
[2df0b74] | 45 | |
---|
[a9d5684] | 46 | def _line(self, x): |
---|
| 47 | """ |
---|
| 48 | Evaluate the function |
---|
[2df0b74] | 49 | |
---|
[a9d5684] | 50 | :param x: x-value |
---|
[2df0b74] | 51 | |
---|
[a9d5684] | 52 | :return: function value |
---|
[2df0b74] | 53 | |
---|
[a9d5684] | 54 | """ |
---|
| 55 | return self.params['A'] + (x * self.params['B']) |
---|
[2df0b74] | 56 | |
---|
| 57 | def run(self, x=0.0): |
---|
| 58 | """ |
---|
[a9d5684] | 59 | Evaluate the model |
---|
[2df0b74] | 60 | |
---|
[a9d5684] | 61 | :param x: simple value |
---|
[2df0b74] | 62 | |
---|
[a9d5684] | 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': |
---|
[2df0b74] | 69 | msg = "Tuples are not allowed as input to BaseComponent models" |
---|
[a9d5684] | 70 | raise ValueError, msg |
---|
| 71 | else: |
---|
| 72 | return self._line(x) |
---|
[2df0b74] | 73 | |
---|
| 74 | def runXY(self, x=0.0): |
---|
| 75 | """ |
---|
[a9d5684] | 76 | Evaluate the model |
---|
[2df0b74] | 77 | |
---|
[a9d5684] | 78 | :param x: simple value |
---|
[2df0b74] | 79 | |
---|
[a9d5684] | 80 | :return: Line value |
---|
[2df0b74] | 81 | |
---|
[a9d5684] | 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.