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