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