1 | """ |
---|
2 | Provide I(q) = C/q^4, |
---|
3 | Porod function as a BaseComponent model |
---|
4 | """ |
---|
5 | from sas.models.BaseComponent import BaseComponent |
---|
6 | import math |
---|
7 | |
---|
8 | class PorodModel(BaseComponent): |
---|
9 | """ |
---|
10 | Class that evaluates a Porod model. |
---|
11 | I(q) = scale/q^4 +background |
---|
12 | """ |
---|
13 | |
---|
14 | def __init__(self): |
---|
15 | """ Initialization """ |
---|
16 | |
---|
17 | # Initialize BaseComponent first, then sphere |
---|
18 | BaseComponent.__init__(self) |
---|
19 | |
---|
20 | ## Name of the model |
---|
21 | self.name = "PorodModel" |
---|
22 | |
---|
23 | ## Define parameters |
---|
24 | self.params = {} |
---|
25 | self.params['scale'] = 1.0 |
---|
26 | self.params['background'] = 0.0 |
---|
27 | self.description = """The Porod model. |
---|
28 | I(q) = scale/q^4 +background""" |
---|
29 | |
---|
30 | ## Parameter details [units, min, max] |
---|
31 | self.details = {} |
---|
32 | self.details['scale'] = ['[1/(cm A^4)]', None, None] |
---|
33 | self.details['background'] = ['[1/cm]', None, None] |
---|
34 | #list of parameter that cannot be fitted |
---|
35 | self.fixed = [] |
---|
36 | |
---|
37 | def _porod(self, x): |
---|
38 | """ |
---|
39 | Evaluate Porod function |
---|
40 | :param x: q-value |
---|
41 | """ |
---|
42 | return self.params['scale']/x**4.0 + self.params['background'] |
---|
43 | |
---|
44 | def run(self, x = 0.0): |
---|
45 | """ Evaluate the model |
---|
46 | @param x: input q-value (float or [float, float] as [r, theta]) |
---|
47 | @return: (porod value) |
---|
48 | """ |
---|
49 | if x.__class__.__name__ == 'list': |
---|
50 | return self._porod(x[0]) |
---|
51 | elif x.__class__.__name__ == 'tuple': |
---|
52 | raise ValueError, "Tuples are not allowed as input to models" |
---|
53 | else: |
---|
54 | return self._porod(x) |
---|
55 | |
---|
56 | def runXY(self, x = 0.0): |
---|
57 | """ Evaluate the model |
---|
58 | @param x: input q-value (float or [float, float] as [qx, qy]) |
---|
59 | @return: porod value |
---|
60 | """ |
---|
61 | if x.__class__.__name__ == 'list': |
---|
62 | q = math.sqrt(x[0]**2 + x[1]**2) |
---|
63 | return self._porod(q) |
---|
64 | elif x.__class__.__name__ == 'tuple': |
---|
65 | raise ValueError, "Tuples are not allowed as input to models" |
---|
66 | else: |
---|
67 | return self._porod(x) |
---|