[ae3ce4e] | 1 | """ |
---|
[279e371] | 2 | Wrapper for the Disperser class extension |
---|
[ae3ce4e] | 3 | """ |
---|
| 4 | from sans.models.BaseComponent import BaseComponent |
---|
| 5 | from sans_extension.c_models import Disperser |
---|
| 6 | |
---|
| 7 | class DisperseModel(Disperser, BaseComponent): |
---|
| 8 | """ |
---|
[279e371] | 9 | Wrapper class for the Disperser extension |
---|
| 10 | Python class that takes a model and averages its output |
---|
| 11 | for a distribution of its parameters. |
---|
| 12 | |
---|
| 13 | The parameters to be varied are specified at instantiation time. |
---|
| 14 | The distributions are Gaussian, with std deviations specified for |
---|
| 15 | each parameter at instantiation time. |
---|
| 16 | |
---|
| 17 | Example: :: |
---|
| 18 | |
---|
| 19 | cyl = CylinderModel() |
---|
| 20 | disp = DisperseModel(cyl, ['cyl_phi'], [0.3]) |
---|
| 21 | disp.run([0.01, 1.57]) |
---|
| 22 | |
---|
[ae3ce4e] | 23 | """ |
---|
| 24 | |
---|
| 25 | def __init__(self, model, paramList, sigmaList): |
---|
[79ac6f8] | 26 | """ |
---|
| 27 | Initialization |
---|
| 28 | |
---|
[279e371] | 29 | :param model: Model to disperse [BaseComponent] |
---|
| 30 | :param paramList: list of parameters to disperse [List of strings] |
---|
| 31 | :param sigmaList: list of std deviations for Gaussian dispersion |
---|
| 32 | [List of floats] |
---|
[79ac6f8] | 33 | |
---|
[ae3ce4e] | 34 | """ |
---|
| 35 | |
---|
| 36 | # Initialize BaseComponent first, then sphere |
---|
| 37 | BaseComponent.__init__(self) |
---|
| 38 | Disperser.__init__(self, model, paramList, sigmaList) |
---|
| 39 | ## Name of the model |
---|
| 40 | self.name = model.name |
---|
| 41 | ## Keep track of the underlying model |
---|
| 42 | self.model = model |
---|
[279e371] | 43 | self.description ='' |
---|
[988130c6] | 44 | #list of parameter that cannot be fitted |
---|
[279e371] | 45 | self.fixed = [] |
---|
[79ac6f8] | 46 | |
---|
[ae3ce4e] | 47 | def clone(self): |
---|
| 48 | """ Return a identical copy of self """ |
---|
[279e371] | 49 | return DisperseModel(self.model, self.params['paramList'], |
---|
| 50 | self.params['sigmaList']) |
---|
[ae3ce4e] | 51 | |
---|
| 52 | def setParam(self, name, value): |
---|
[279e371] | 53 | """ |
---|
| 54 | Set a parameter value |
---|
| 55 | :param name: parameter name |
---|
| 56 | """ |
---|
| 57 | if name.lower() in self.params: |
---|
| 58 | BaseComponent.setParam(self, name, value) |
---|
| 59 | else: |
---|
| 60 | self.model.setParam(name, value) |
---|
[ae3ce4e] | 61 | |
---|
| 62 | def getParam(self, name): |
---|
[279e371] | 63 | """ |
---|
| 64 | Get the value of the given parameter |
---|
| 65 | :param name: parameter name |
---|
| 66 | """ |
---|
| 67 | if name.lower() in self.params: |
---|
| 68 | return BaseComponent.getParam(self, name) |
---|
| 69 | else: |
---|
| 70 | return self.model.getParam(name) |
---|
[ae3ce4e] | 71 | |
---|
| 72 | def run(self, x = 0.0): |
---|
[79ac6f8] | 73 | """ |
---|
[279e371] | 74 | Evaluate the model |
---|
| 75 | :param x: input q, or [q,phi] |
---|
| 76 | :return: scattering function P(q) |
---|
[ae3ce4e] | 77 | """ |
---|
| 78 | return Disperser.run(self, x) |
---|
| 79 | |
---|
| 80 | def runXY(self, x = 0.0): |
---|
[79ac6f8] | 81 | """ |
---|
[279e371] | 82 | Evaluate the model |
---|
| 83 | :param x: input q, or [q,phi] |
---|
| 84 | :return: scattering function P(q) |
---|
[ae3ce4e] | 85 | """ |
---|
| 86 | return Disperser.runXY(self, x) |
---|
| 87 | |
---|
| 88 | # End of file |
---|