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