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