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