ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change
on this file since 3db3895 was
3db3895,
checked in by Mathieu Doucet <doucetm@…>, 17 years ago
|
Fixed new models - still need validation
|
-
Property mode set to
100644
|
File size:
1.8 KB
|
Rev | Line | |
---|
[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 | |
---|
[3db3895] | 13 | I(q) = scale/q^4 |
---|
[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 = {} |
---|
[3db3895] | 28 | self.params['scale'] = 0.0 |
---|
[829eee9] | 29 | |
---|
| 30 | |
---|
| 31 | ## Parameter details [units, min, max] |
---|
| 32 | self.details = {} |
---|
[3db3895] | 33 | self.details['scale'] = ['', None, None] |
---|
[829eee9] | 34 | |
---|
| 35 | |
---|
| 36 | def _porod(self, x): |
---|
[3db3895] | 37 | return self.params['scale']/x**4.0 |
---|
[829eee9] | 38 | |
---|
| 39 | def run(self, x = 0.0): |
---|
| 40 | """ Evaluate the model |
---|
[3db3895] | 41 | @param x: input q-value (float or [float, float] as [r, theta]) |
---|
[829eee9] | 42 | @return: (porod value) |
---|
| 43 | """ |
---|
| 44 | if x.__class__.__name__ == 'list': |
---|
| 45 | return self._porod(x[0]*math.cos(x[1]))*self._porod(x[0]*math.sin(x[1])) |
---|
| 46 | elif x.__class__.__name__ == 'tuple': |
---|
| 47 | raise ValueError, "Tuples are not allowed as input to BaseComponent models" |
---|
| 48 | else: |
---|
| 49 | return self._porod(x) |
---|
| 50 | |
---|
| 51 | def runXY(self, x = 0.0): |
---|
| 52 | """ Evaluate the model |
---|
[3db3895] | 53 | @param x: input q-value (float or [float, float] as [qx, qy]) |
---|
[829eee9] | 54 | @return: porod value |
---|
| 55 | """ |
---|
| 56 | if x.__class__.__name__ == 'list': |
---|
| 57 | return self._porod(x[0])*self._porod(x[1]) |
---|
| 58 | elif x.__class__.__name__ == 'tuple': |
---|
| 59 | raise ValueError, "Tuples are not allowed as input to BaseComponent models" |
---|
| 60 | else: |
---|
| 61 | return self._porod(x) |
---|
Note: See
TracBrowser
for help on using the repository browser.