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 8344c50 was
27fea3f,
checked in by Gervaise Alina <gervyh@…>, 15 years ago
|
add a few models 1D
|
-
Property mode set to
100644
|
File size:
1.5 KB
|
Line | |
---|
1 | from sans.models.BaseComponent import BaseComponent |
---|
2 | import math |
---|
3 | |
---|
4 | class Model1DPlugin(BaseComponent): |
---|
5 | ## Name of the model |
---|
6 | |
---|
7 | def __init__(self , name="Plugin Model" ): |
---|
8 | """ Initialization """ |
---|
9 | BaseComponent.__init__(self) |
---|
10 | self.name = name |
---|
11 | self.details = {} |
---|
12 | self.params = {} |
---|
13 | self.description='' |
---|
14 | def function(self, x): |
---|
15 | """ |
---|
16 | Function to be implemented by the plug-in writer |
---|
17 | """ |
---|
18 | return x |
---|
19 | |
---|
20 | def run(self, x = 0.0): |
---|
21 | """ Evaluate the model |
---|
22 | @param x: input x, or [x, phi] [radian] |
---|
23 | @return: function value |
---|
24 | """ |
---|
25 | if x.__class__.__name__ == 'list': |
---|
26 | x_val = x[0]*math.cos(x[1]) |
---|
27 | y_val = x[0]*math.sin(x[1]) |
---|
28 | return self.function(x_val)*self.function(y_val) |
---|
29 | elif x.__class__.__name__ == 'tuple': |
---|
30 | raise ValueError, "Tuples are not allowed as input to BaseComponent models" |
---|
31 | else: |
---|
32 | return self.function(x) |
---|
33 | |
---|
34 | |
---|
35 | def runXY(self, x = 0.0): |
---|
36 | """ Evaluate the model |
---|
37 | @param x: input x, or [x, y] |
---|
38 | @return: function value |
---|
39 | """ |
---|
40 | if x.__class__.__name__ == 'list': |
---|
41 | return self.function(x[0])*self.function(x[1]) |
---|
42 | elif x.__class__.__name__ == 'tuple': |
---|
43 | raise ValueError, "Tuples are not allowed as input to BaseComponent models" |
---|
44 | else: |
---|
45 | return self.function(x) |
---|
Note: See
TracBrowser
for help on using the repository browser.