[a36c6d3] | 1 | r""" |
---|
| 2 | This model calculates an empirical functional form for SAS data characterized |
---|
| 3 | by two Lorentzian-type functions. |
---|
| 4 | |
---|
| 5 | Definition |
---|
| 6 | ---------- |
---|
| 7 | |
---|
| 8 | The scattering intensity $I(q)$ is calculated as |
---|
| 9 | |
---|
| 10 | .. math:: |
---|
| 11 | |
---|
| 12 | I(q) = \frac{A}{1 +(Q\xi_1)^n} + \frac{C}{1 +(Q\xi_2)^m} + \text{B} |
---|
| 13 | |
---|
| 14 | where $A$ = Lorentzian scale factor #1, $C$ = Lorentzian scale #2, |
---|
| 15 | $\xi_1$ and $\xi_2$ are the corresponding correlation lengths, and $n$ and |
---|
| 16 | $m$ are the respective power law exponents (set $n = m = 2$ for |
---|
| 17 | Ornstein-Zernicke behaviour). |
---|
| 18 | |
---|
| 19 | For 2D data the scattering intensity is calculated in the same way as 1D, |
---|
| 20 | where the $q$ vector is defined as |
---|
| 21 | |
---|
| 22 | .. math:: |
---|
| 23 | |
---|
| 24 | q = \sqrt{q_x^2 + q_y^2} |
---|
| 25 | |
---|
| 26 | |
---|
| 27 | .. figure:: img/two_lorentzian.jpg |
---|
| 28 | |
---|
| 29 | 1D plot using the default values (w/500 data point). |
---|
| 30 | |
---|
| 31 | References |
---|
| 32 | ---------- |
---|
| 33 | |
---|
| 34 | None. |
---|
| 35 | |
---|
| 36 | """ |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | from sas.models.BaseComponent import BaseComponent |
---|
| 40 | from numpy import power |
---|
| 41 | import math |
---|
| 42 | |
---|
| 43 | class TwoPowerLawModel(BaseComponent): |
---|
| 44 | """ |
---|
| 45 | Class that evaluates a TwoPowerLawModel. |
---|
| 46 | |
---|
| 47 | Calculate:: |
---|
| 48 | |
---|
| 49 | I(q) = coef_A pow(qval,-power1) for q<=qc |
---|
| 50 | I(q) = C pow(qval,-power2) for q>qc |
---|
| 51 | |
---|
| 52 | where C=coef_A pow(qc,-power1)/pow(qc,-power2). |
---|
| 53 | |
---|
| 54 | List of default parameters: |
---|
| 55 | |
---|
| 56 | * coef_A = coefficient |
---|
| 57 | * power1 = (-) Power @ low Q |
---|
| 58 | * power2 = (-) Power @ high Q |
---|
| 59 | * qc = crossover Q-value |
---|
| 60 | * background = incoherent background |
---|
| 61 | """ |
---|
| 62 | |
---|
| 63 | def __init__(self): |
---|
| 64 | """ Initialization """ |
---|
| 65 | |
---|
| 66 | # Initialize BaseComponent first, then sphere |
---|
| 67 | BaseComponent.__init__(self) |
---|
| 68 | |
---|
| 69 | ## Name of the model |
---|
| 70 | self.name = "TwoPowerLaw" |
---|
| 71 | self.description="""I(q) = coef_A*pow(qval,-1.0*power1) for q<=qc |
---|
| 72 | =C*pow(qval,-1.0*power2) for q>qc |
---|
| 73 | where C=coef_A*pow(qc,-1.0*power1)/pow(qc,-1.0*power2). |
---|
| 74 | List of default parameters: |
---|
| 75 | coef_A = coefficient |
---|
| 76 | power1 = (-) Power @ low Q |
---|
| 77 | power2 = (-) Power @ high Q |
---|
| 78 | qc = crossover Q-value |
---|
| 79 | background = incoherent background |
---|
| 80 | """ |
---|
| 81 | ## Define parameters |
---|
| 82 | self.params = {} |
---|
| 83 | self.params['coef_A'] = 1.0 |
---|
| 84 | self.params['power1'] = 1.0 |
---|
| 85 | self.params['power2'] = 4.0 |
---|
| 86 | self.params['qc'] = 0.04 |
---|
| 87 | self.params['background'] = 0.0 |
---|
| 88 | ## Parameter details [units, min, max] |
---|
| 89 | self.details = {} |
---|
| 90 | self.details['coef_A'] = ['', None, None] |
---|
| 91 | self.details['power1'] = ['', None, None] |
---|
| 92 | self.details['power2'] = ['', None, None] |
---|
| 93 | self.details['qc'] = ['1/A', None, None] |
---|
| 94 | self.details['background'] = ['[1/cm]', None, None] |
---|
| 95 | |
---|
| 96 | #list of parameter that cannot be fitted |
---|
| 97 | self.fixed= [] |
---|
| 98 | def _twopowerlaw(self, x): |
---|
| 99 | """ |
---|
| 100 | Model definition |
---|
| 101 | """ |
---|
| 102 | qc= self.params['qc'] |
---|
| 103 | if(x<=qc): |
---|
| 104 | inten = self.params['coef_A']*power(x,-1.0*self.params['power1']) |
---|
| 105 | else: |
---|
| 106 | scale = self.params['coef_A']*power(qc,-1.0*self.params['power1']) \ |
---|
| 107 | / power(qc,-1.0*self.params['power2']) |
---|
| 108 | inten = scale*power(x,-1.0*self.params['power2']) |
---|
| 109 | inten += self.params['background'] |
---|
| 110 | |
---|
| 111 | return inten |
---|
| 112 | |
---|
| 113 | def run(self, x = 0.0): |
---|
| 114 | """ Evaluate the model |
---|
| 115 | @param x: input q-value (float or [float, float] as [r, theta]) |
---|
| 116 | @return: (guinier value) |
---|
| 117 | """ |
---|
| 118 | if x.__class__.__name__ == 'list': |
---|
| 119 | return self._twopowerlaw(x[0]) |
---|
| 120 | elif x.__class__.__name__ == 'tuple': |
---|
| 121 | raise ValueError, "Tuples are not allowed as input to BaseComponent models" |
---|
| 122 | else: |
---|
| 123 | return self._twopowerlaw(x) |
---|
| 124 | |
---|
| 125 | def runXY(self, x = 0.0): |
---|
| 126 | """ Evaluate the model |
---|
| 127 | @param x: input q-value (float or [float, float] as [qx, qy]) |
---|
| 128 | @return: guinier value |
---|
| 129 | """ |
---|
| 130 | if x.__class__.__name__ == 'list': |
---|
| 131 | q = math.sqrt(x[0]**2 + x[1]**2) |
---|
| 132 | return self._twopowerlaw(q) |
---|
| 133 | elif x.__class__.__name__ == 'tuple': |
---|
| 134 | raise ValueError, "Tuples are not allowed as input to BaseComponent models" |
---|
| 135 | else: |
---|
| 136 | return self._twopowerlaw(x) |
---|