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 892a2cc 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:
1.8 KB
|
Line | |
---|
1 | |
---|
2 | from sas.models.BaseComponent import BaseComponent |
---|
3 | import math |
---|
4 | |
---|
5 | class Model1DPlugin(BaseComponent): |
---|
6 | ## Name of the model |
---|
7 | |
---|
8 | def __init__(self , name="Plugin Model" ): |
---|
9 | """ Initialization """ |
---|
10 | BaseComponent.__init__(self) |
---|
11 | self.name = name |
---|
12 | self.details = {} |
---|
13 | self.params = {} |
---|
14 | self.description = 'plugin model' |
---|
15 | |
---|
16 | def function(self, x): |
---|
17 | """ |
---|
18 | Function to be implemented by the plug-in writer |
---|
19 | """ |
---|
20 | return x |
---|
21 | |
---|
22 | def run(self, x = 0.0): |
---|
23 | """ |
---|
24 | Evaluate the model |
---|
25 | |
---|
26 | :param x: input x, or [x, phi] [radian] |
---|
27 | |
---|
28 | :return: function value |
---|
29 | |
---|
30 | """ |
---|
31 | if x.__class__.__name__ == 'list': |
---|
32 | x_val = x[0]*math.cos(x[1]) |
---|
33 | y_val = x[0]*math.sin(x[1]) |
---|
34 | return self.function(x_val)*self.function(y_val) |
---|
35 | elif x.__class__.__name__ == 'tuple': |
---|
36 | raise ValueError, "Tuples are not allowed as input to BaseComponent models" |
---|
37 | else: |
---|
38 | return self.function(x) |
---|
39 | |
---|
40 | |
---|
41 | def runXY(self, x = 0.0): |
---|
42 | """ |
---|
43 | Evaluate the model |
---|
44 | |
---|
45 | :param x: input x, or [x, y] |
---|
46 | |
---|
47 | :return: function value |
---|
48 | |
---|
49 | """ |
---|
50 | if x.__class__.__name__ == 'list': |
---|
51 | return self.function(x[0])*self.function(x[1]) |
---|
52 | elif x.__class__.__name__ == 'tuple': |
---|
53 | raise ValueError, "Tuples are not allowed as input to BaseComponent models" |
---|
54 | else: |
---|
55 | return self.function(x) |
---|
56 | |
---|
57 | def set_details(self): |
---|
58 | """ |
---|
59 | Set default details |
---|
60 | """ |
---|
61 | if not self.params: |
---|
62 | return {} |
---|
63 | |
---|
64 | for key in self.params.keys(): |
---|
65 | self.details[key] = ['', None, None] |
---|
Note: See
TracBrowser
for help on using the repository browser.