1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | """ |
---|
4 | Provide base functionality for all model components |
---|
5 | |
---|
6 | :author: Mathieu Doucet / UTK |
---|
7 | |
---|
8 | :contact: mathieu.doucet@nist.gov |
---|
9 | |
---|
10 | """ |
---|
11 | |
---|
12 | # info |
---|
13 | __author__ = "Mathieu Doucet / UTK" |
---|
14 | __id__ = "$Id: BaseComponent.py,v 1.2 2007/03/14 21:04:40 doucet Exp $" |
---|
15 | |
---|
16 | # imports |
---|
17 | from sas.models.BaseComponent import BaseComponent |
---|
18 | |
---|
19 | class AddComponent(BaseComponent): |
---|
20 | """ |
---|
21 | Basic model component for Addition |
---|
22 | Provides basic arithmetics |
---|
23 | """ |
---|
24 | |
---|
25 | def __init__(self, base=None, other=None): |
---|
26 | """ |
---|
27 | :param base: component to add to |
---|
28 | :param other: component to add |
---|
29 | |
---|
30 | """ |
---|
31 | BaseComponent.__init__(self) |
---|
32 | # Component to add to |
---|
33 | self.operateOn = base |
---|
34 | # Component to add |
---|
35 | self.other = other |
---|
36 | # name |
---|
37 | self.name = 'AddComponent' |
---|
38 | |
---|
39 | def run(self, x=0): |
---|
40 | """ |
---|
41 | Evaluate each part of the component and sum the results |
---|
42 | |
---|
43 | :param x: input parameter |
---|
44 | |
---|
45 | :return: value of the model at x |
---|
46 | |
---|
47 | """ |
---|
48 | return self.operateOn.run(x) + self.other.run(x) |
---|
49 | |
---|
50 | def runXY(self, x=0): |
---|
51 | """ |
---|
52 | Evaluate each part of the component and sum the results |
---|
53 | |
---|
54 | :param x: input parameter |
---|
55 | |
---|
56 | :return: value of the model at x |
---|
57 | |
---|
58 | """ |
---|
59 | return self.operateOn.runXY(x) + self.other.runXY(x) |
---|
60 | |
---|
61 | def setParam(self, name, value): |
---|
62 | """ |
---|
63 | Set the value of a model parameter |
---|
64 | |
---|
65 | :param name: name of parameter to set |
---|
66 | :param value: value to give the paramter |
---|
67 | |
---|
68 | """ |
---|
69 | return BaseComponent.setParamWithToken(self, name, |
---|
70 | value, 'add', self.other) |
---|
71 | |
---|
72 | def getParam(self, name): |
---|
73 | """ |
---|
74 | Set the value of a model parameter |
---|
75 | |
---|
76 | :param name: name of the parameter |
---|
77 | |
---|
78 | :return: value of the parameter |
---|
79 | |
---|
80 | """ |
---|
81 | return BaseComponent.getParamWithToken(self, name, 'add', self.other) |
---|
82 | |
---|
83 | def getParamList(self): |
---|
84 | """ |
---|
85 | Return a list of all available parameters for the model |
---|
86 | """ |
---|
87 | return BaseComponent.getParamListWithToken(self, 'add', self.other) |
---|
88 | |
---|
89 | |
---|
90 | # End of file |
---|