[ae3ce4e] | 1 | #!/usr/bin/env python |
---|
[79ac6f8] | 2 | |
---|
| 3 | """ |
---|
| 4 | Provide base functionality for all model components |
---|
| 5 | |
---|
| 6 | :author: Mathieu Doucet / UTK |
---|
| 7 | |
---|
| 8 | :contact: mathieu.doucet@nist.gov |
---|
| 9 | |
---|
[ae3ce4e] | 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 sans.models.BaseComponent import BaseComponent |
---|
| 18 | |
---|
| 19 | class AddComponent(BaseComponent): |
---|
[79ac6f8] | 20 | """ |
---|
| 21 | Basic model component for Addition |
---|
| 22 | Provides basic arithmetics |
---|
[ae3ce4e] | 23 | """ |
---|
| 24 | |
---|
| 25 | def __init__(self, base=None, other=None): |
---|
| 26 | """ |
---|
[79ac6f8] | 27 | :param base: component to add to |
---|
| 28 | :param other: component to add |
---|
| 29 | |
---|
[ae3ce4e] | 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 | """ |
---|
[79ac6f8] | 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 | |
---|
[ae3ce4e] | 47 | """ |
---|
| 48 | return self.operateOn.run(x) + self.other.run(x) |
---|
| 49 | |
---|
[3db3895] | 50 | def runXY(self, x=0): |
---|
| 51 | """ |
---|
[79ac6f8] | 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 | |
---|
[3db3895] | 58 | """ |
---|
| 59 | return self.operateOn.runXY(x) + self.other.runXY(x) |
---|
| 60 | |
---|
[ae3ce4e] | 61 | def setParam(self, name, value): |
---|
| 62 | """ |
---|
[79ac6f8] | 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 | |
---|
[ae3ce4e] | 68 | """ |
---|
| 69 | return BaseComponent.setParamWithToken(self, name, |
---|
| 70 | value, 'add', self.other) |
---|
| 71 | |
---|
| 72 | def getParam(self, name): |
---|
| 73 | """ |
---|
[79ac6f8] | 74 | Set the value of a model parameter |
---|
| 75 | |
---|
| 76 | :param name: name of the parameter |
---|
| 77 | |
---|
| 78 | :return: value of the parameter |
---|
| 79 | |
---|
[ae3ce4e] | 80 | """ |
---|
| 81 | return BaseComponent.getParamWithToken(self, name, 'add', self.other) |
---|
| 82 | |
---|
| 83 | def getParamList(self): |
---|
[79ac6f8] | 84 | """ |
---|
| 85 | Return a list of all available parameters for the model |
---|
[ae3ce4e] | 86 | """ |
---|
| 87 | return BaseComponent.getParamListWithToken(self, 'add', self.other) |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | # End of file |
---|