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 f1181977 was
a55fac1,
checked in by Mathieu Doucet <doucetm@…>, 16 years ago
|
Modified 2D non-shape models to be the same as 1D when not defined otherwise
|
-
Property mode set to
100644
|
File size:
2.1 KB
|
Rev | Line | |
---|
[829eee9] | 1 | #!/usr/bin/env python |
---|
[3db3895] | 2 | """ |
---|
| 3 | Provide I(q) = I_0 exp ( - R_g^2 q^2 / 3.0) |
---|
| 4 | Guinier function as a BaseComponent model |
---|
[829eee9] | 5 | """ |
---|
| 6 | |
---|
| 7 | from sans.models.BaseComponent import BaseComponent |
---|
| 8 | import math |
---|
| 9 | |
---|
| 10 | class GuinierModel(BaseComponent): |
---|
[3db3895] | 11 | """ |
---|
| 12 | Class that evaluates a Guinier model. |
---|
[829eee9] | 13 | |
---|
[3db3895] | 14 | I(q) = I_0 exp ( - R_g^2 q^2 / 3.0 ) |
---|
[829eee9] | 15 | |
---|
| 16 | List of default parameters: |
---|
[3db3895] | 17 | I_0 = Scale |
---|
| 18 | R_g = Radius of gyration |
---|
| 19 | |
---|
[829eee9] | 20 | """ |
---|
| 21 | |
---|
| 22 | def __init__(self): |
---|
| 23 | """ Initialization """ |
---|
| 24 | |
---|
| 25 | # Initialize BaseComponent first, then sphere |
---|
| 26 | BaseComponent.__init__(self) |
---|
| 27 | |
---|
| 28 | ## Name of the model |
---|
| 29 | self.name = "Guinier" |
---|
| 30 | |
---|
| 31 | ## Define parameters |
---|
| 32 | self.params = {} |
---|
[3db3895] | 33 | self.params['scale'] = 1.0 |
---|
| 34 | self.params['rg'] = 0.1 |
---|
[829eee9] | 35 | |
---|
| 36 | ## Parameter details [units, min, max] |
---|
| 37 | self.details = {} |
---|
[3db3895] | 38 | self.details['scale'] = ['cm-1', None, None] |
---|
| 39 | self.details['rg'] = ['A', None, None] |
---|
[829eee9] | 40 | |
---|
| 41 | def _guinier(self, x): |
---|
[3db3895] | 42 | return self.params['scale'] * math.exp( -(self.params['rg']*x)**2 / 3.0 ) |
---|
[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: (guinier value) |
---|
| 48 | """ |
---|
| 49 | if x.__class__.__name__ == 'list': |
---|
[a55fac1] | 50 | return self._guinier(x[0]) |
---|
[829eee9] | 51 | elif x.__class__.__name__ == 'tuple': |
---|
| 52 | raise ValueError, "Tuples are not allowed as input to BaseComponent models" |
---|
| 53 | else: |
---|
| 54 | return self._guinier(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: guinier value |
---|
| 60 | """ |
---|
| 61 | if x.__class__.__name__ == 'list': |
---|
[a55fac1] | 62 | q = math.sqrt(x[0]**2 + x[1]**2) |
---|
| 63 | return self._guinier(q) |
---|
[829eee9] | 64 | elif x.__class__.__name__ == 'tuple': |
---|
| 65 | raise ValueError, "Tuples are not allowed as input to BaseComponent models" |
---|
| 66 | else: |
---|
| 67 | return self._guinier(x) |
---|
Note: See
TracBrowser
for help on using the repository browser.