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 06dfd39 was
79492222,
checked in by krzywon, 10 years ago
|
Changed the file and folder names to remove all SANS references.
|
-
Property mode set to
100644
|
File size:
2.1 KB
|
Rev | Line | |
---|
[3db3895] | 1 | """ |
---|
| 2 | Provide I(q) = C/q^4, |
---|
| 3 | Porod function as a BaseComponent model |
---|
[829eee9] | 4 | """ |
---|
[79492222] | 5 | from sas.models.BaseComponent import BaseComponent |
---|
[829eee9] | 6 | import math |
---|
| 7 | |
---|
| 8 | class PorodModel(BaseComponent): |
---|
[499fe7a] | 9 | """ |
---|
| 10 | Class that evaluates a Porod model. |
---|
| 11 | I(q) = scale/q^4 +background |
---|
[829eee9] | 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 |
---|
[3db3895] | 21 | self.name = "PorodModel" |
---|
[829eee9] | 22 | |
---|
| 23 | ## Define parameters |
---|
| 24 | self.params = {} |
---|
[36948c92] | 25 | self.params['scale'] = 1.0 |
---|
| 26 | self.params['background'] = 0.0 |
---|
[499fe7a] | 27 | self.description = """The Porod model. |
---|
[9ce41c6] | 28 | I(q) = scale/q^4 +background""" |
---|
[829eee9] | 29 | |
---|
| 30 | ## Parameter details [units, min, max] |
---|
| 31 | self.details = {} |
---|
[1ed3834] | 32 | self.details['scale'] = ['[1/(cm A^4)]', None, None] |
---|
[0824909] | 33 | self.details['background'] = ['[1/cm]', None, None] |
---|
[988130c6] | 34 | #list of parameter that cannot be fitted |
---|
[411d8bf] | 35 | self.fixed = [] |
---|
[829eee9] | 36 | |
---|
| 37 | def _porod(self, x): |
---|
[499fe7a] | 38 | """ |
---|
| 39 | Evaluate Porod function |
---|
| 40 | :param x: q-value |
---|
| 41 | """ |
---|
[36948c92] | 42 | return self.params['scale']/x**4.0 + self.params['background'] |
---|
[829eee9] | 43 | |
---|
| 44 | def run(self, x = 0.0): |
---|
| 45 | """ Evaluate the model |
---|
[3db3895] | 46 | @param x: input q-value (float or [float, float] as [r, theta]) |
---|
[829eee9] | 47 | @return: (porod value) |
---|
| 48 | """ |
---|
| 49 | if x.__class__.__name__ == 'list': |
---|
[a55fac1] | 50 | return self._porod(x[0]) |
---|
[829eee9] | 51 | elif x.__class__.__name__ == 'tuple': |
---|
[499fe7a] | 52 | raise ValueError, "Tuples are not allowed as input to models" |
---|
[829eee9] | 53 | else: |
---|
| 54 | return self._porod(x) |
---|
| 55 | |
---|
| 56 | def runXY(self, x = 0.0): |
---|
| 57 | """ Evaluate the model |
---|
[3db3895] | 58 | @param x: input q-value (float or [float, float] as [qx, qy]) |
---|
[829eee9] | 59 | @return: porod value |
---|
| 60 | """ |
---|
| 61 | if x.__class__.__name__ == 'list': |
---|
[a55fac1] | 62 | q = math.sqrt(x[0]**2 + x[1]**2) |
---|
| 63 | return self._porod(q) |
---|
[829eee9] | 64 | elif x.__class__.__name__ == 'tuple': |
---|
[499fe7a] | 65 | raise ValueError, "Tuples are not allowed as input to models" |
---|
[829eee9] | 66 | else: |
---|
| 67 | return self._porod(x) |
---|
Note: See
TracBrowser
for help on using the repository browser.