[421e55c] | 1 | r""" |
---|
| 2 | Definition |
---|
| 3 | ---------- |
---|
| 4 | |
---|
| 5 | The scattering intensity $I(q)$ is calculated as |
---|
| 6 | |
---|
| 7 | .. math:: |
---|
| 8 | |
---|
| 9 | I(q) = \frac{A}{1 +(Q\xi_1)^n} + \frac{C}{1 +(Q\xi_2)^m} + \text{B} |
---|
| 10 | |
---|
| 11 | where $A$ = Lorentzian scale factor #1, $C$ = Lorentzian scale #2, |
---|
[513efc5] | 12 | $\xi_1$ and $\xi_2$ are the corresponding correlation lengths, and $n$ and |
---|
| 13 | $m$ are the respective power law exponents (set $n = m = 2$ for |
---|
| 14 | Ornstein-Zernicke behaviour). |
---|
[421e55c] | 15 | |
---|
| 16 | For 2D data the scattering intensity is calculated in the same way as 1D, |
---|
| 17 | where the $q$ vector is defined as |
---|
| 18 | |
---|
| 19 | .. math:: |
---|
| 20 | |
---|
| 21 | q = \sqrt{q_x^2 + q_y^2} |
---|
| 22 | |
---|
| 23 | |
---|
| 24 | References |
---|
| 25 | ---------- |
---|
| 26 | |
---|
| 27 | None. |
---|
| 28 | |
---|
[0507e09] | 29 | Source |
---|
| 30 | ------ |
---|
| 31 | |
---|
| 32 | `two_lorentzian.py <https://github.com/SasView/sasmodels/blob/master/sasmodels/models/two_lorentzian.py>`_ |
---|
| 33 | |
---|
| 34 | Authorship and Verification |
---|
| 35 | ---------------------------- |
---|
| 36 | |
---|
[ef07e95] | 37 | * **Author:** NIST IGOR/DANSE **Date:** pre 2010 |
---|
| 38 | * **Last Modified by:** Piotr rozyczko **Date:** January 29, 2016 |
---|
| 39 | * **Last Reviewed by:** Paul Butler **Date:** March 21, 2016 |
---|
[0507e09] | 40 | * **Source added by :** Steve King **Date:** March 25, 2019 |
---|
[421e55c] | 41 | """ |
---|
| 42 | |
---|
[2d81cfe] | 43 | import numpy as np |
---|
[2c74c11] | 44 | from numpy import inf, power |
---|
[421e55c] | 45 | |
---|
| 46 | name = "two_lorentzian" |
---|
[caa7b4a] | 47 | title = "This model calculates an empirical functional form for SAS data \ |
---|
| 48 | characterized by two Lorentzian-type functions." |
---|
[421e55c] | 49 | description = """I(q) = scale_1/(1.0 + pow((q*length_1),exponent_1)) |
---|
| 50 | + scale_2/(1.0 + pow((q*length_2),exponent_2) )+ background |
---|
| 51 | |
---|
| 52 | scale_1 = Lorentzian term scaling #1 |
---|
| 53 | length_1 = Lorentzian screening length #1 [A] |
---|
| 54 | exponent_1 = Lorentzian exponent #1 |
---|
| 55 | scale_2 = Lorentzian term scaling #2 |
---|
| 56 | length_2 = Lorentzian screening length #2 [A] |
---|
| 57 | exponent_2 = Lorentzian exponent #2 |
---|
| 58 | background = Incoherent background |
---|
| 59 | """ |
---|
| 60 | category = "shape-independent" |
---|
| 61 | |
---|
[168052c] | 62 | # pylint: disable=bad-whitespace, line-too-long |
---|
[513efc5] | 63 | # ["name", "units", default, [lower, upper], "type", "description"], |
---|
[168052c] | 64 | parameters = [["lorentz_scale_1", "", 10.0, [-inf, inf], "", "First power law scale factor"], |
---|
| 65 | ["lorentz_length_1", "Ang", 100.0, [-inf, inf], "", "First Lorentzian screening length"], |
---|
| 66 | ["lorentz_exp_1", "", 3.0, [-inf, inf], "", "First exponent of power law"], |
---|
| 67 | ["lorentz_scale_2", "", 1.0, [-inf, inf], "", "Second scale factor for broad Lorentzian peak"], |
---|
| 68 | ["lorentz_length_2", "Ang", 10.0, [-inf, inf], "", "Second Lorentzian screening length"], |
---|
| 69 | ["lorentz_exp_2", "", 2.0, [-inf, inf], "", "Second exponent of power law"], |
---|
| 70 | ] |
---|
| 71 | # pylint: enable=bad-whitespace, line-too-long |
---|
[421e55c] | 72 | |
---|
| 73 | |
---|
[513efc5] | 74 | def Iq(q, |
---|
[168052c] | 75 | lorentz_scale_1=10.0, |
---|
| 76 | lorentz_length_1=100.0, |
---|
| 77 | lorentz_exp_1=3.0, |
---|
| 78 | lorentz_scale_2=1.0, |
---|
| 79 | lorentz_length_2=10.0, |
---|
| 80 | lorentz_exp_2=2.0): |
---|
[421e55c] | 81 | |
---|
| 82 | """ |
---|
| 83 | :param q: Input q-value (float or [float, float]) |
---|
| 84 | :param lorentz_scale_1: Second scale factor for broad Lorentzian peak |
---|
| 85 | :param lorentz_length_1: First Lorentzian screening length |
---|
| 86 | :param lorentz_exp_1: Exponent of the second Lorentz function |
---|
| 87 | :param lorentz_scale_2: Second scale factor for broad Lorentzian peak |
---|
| 88 | :param lorentz_length_2: Second Lorentzian screening length |
---|
| 89 | :param lorentz_exp_2: Exponent of the second Lorentz function |
---|
| 90 | :return: Calculated intensity |
---|
| 91 | """ |
---|
[168052c] | 92 | # pylint: disable=bad-whitespace |
---|
[513efc5] | 93 | intensity = lorentz_scale_1/(1.0 + |
---|
| 94 | power(q*lorentz_length_1, lorentz_exp_1)) |
---|
| 95 | intensity += lorentz_scale_2/(1.0 + |
---|
| 96 | power(q*lorentz_length_2, lorentz_exp_2)) |
---|
[168052c] | 97 | # pylint: enable=bad-whitespace |
---|
[421e55c] | 98 | return intensity |
---|
| 99 | |
---|
| 100 | Iq.vectorized = True # Iq accepts an array of q values |
---|
| 101 | |
---|
[48462b0] | 102 | def random(): |
---|
[b297ba9] | 103 | """Return a random parameter set for the model.""" |
---|
[48462b0] | 104 | scale = 10**np.random.uniform(0, 4, 2) |
---|
| 105 | length = 10**np.random.uniform(1, 4, 2) |
---|
| 106 | expon = np.random.uniform(1, 6, 2) |
---|
| 107 | |
---|
| 108 | pars = dict( |
---|
| 109 | #background=0, |
---|
| 110 | scale=1, # scale provided in model |
---|
| 111 | lorentz_scale_1=scale[0], |
---|
| 112 | lorentz_length_1=length[0], |
---|
| 113 | lorentz_exp_1=expon[0], |
---|
| 114 | lorentz_scale_2=scale[1], |
---|
| 115 | lorentz_length_2=length[1], |
---|
| 116 | lorentz_exp_2=expon[1], |
---|
| 117 | ) |
---|
| 118 | return pars |
---|
| 119 | |
---|
[421e55c] | 120 | |
---|
| 121 | demo = dict(scale=1, background=0.1, |
---|
[168052c] | 122 | lorentz_scale_1=10, |
---|
| 123 | lorentz_length_1=100.0, |
---|
| 124 | lorentz_exp_1=3.0, |
---|
| 125 | lorentz_scale_2=1, |
---|
| 126 | lorentz_length_2=10, |
---|
| 127 | lorentz_exp_2=2.0) |
---|
[421e55c] | 128 | |
---|
[07a6700] | 129 | tests = [ |
---|
[168052c] | 130 | |
---|
| 131 | # Accuracy tests based on content in test/utest_extra_models.py |
---|
| 132 | [{'lorentz_scale_1': 10.0, |
---|
| 133 | 'lorentz_length_1': 100.0, |
---|
| 134 | 'lorentz_exp_1': 3.0, |
---|
| 135 | 'lorentz_scale_2': 1.0, |
---|
| 136 | 'lorentz_length_2': 10.0, |
---|
| 137 | 'lorentz_exp_2': 2.0, |
---|
| 138 | 'background': 0.1, |
---|
| 139 | }, 0.001, 11.08991], |
---|
| 140 | |
---|
| 141 | [{'lorentz_scale_1': 10.0, |
---|
| 142 | 'lorentz_length_1': 100.0, |
---|
| 143 | 'lorentz_exp_1': 3.0, |
---|
| 144 | 'lorentz_scale_2': 1.0, |
---|
| 145 | 'lorentz_length_2': 10.0, |
---|
| 146 | 'lorentz_exp_2': 2.0, |
---|
| 147 | 'background': 0.1, |
---|
| 148 | }, 0.150141, 0.410245], |
---|
| 149 | |
---|
| 150 | [{'lorentz_scale_1': 10.0, |
---|
| 151 | 'lorentz_length_1': 100.0, |
---|
| 152 | 'lorentz_exp_1': 3.0, |
---|
| 153 | 'lorentz_scale_2': 1.0, |
---|
| 154 | 'lorentz_length_2': 10.0, |
---|
| 155 | 'lorentz_exp_2': 2.0, |
---|
| 156 | 'background': 0.1, |
---|
| 157 | }, 0.442528, 0.148699], |
---|
| 158 | |
---|
| 159 | # Additional tests with larger range of parameters |
---|
| 160 | [{'lorentz_scale_1': 10.0, |
---|
| 161 | 'lorentz_length_1': 100.0, |
---|
| 162 | 'lorentz_exp_1': 3.0, |
---|
| 163 | 'lorentz_scale_2': 1.0, |
---|
| 164 | 'lorentz_length_2': 10.0, |
---|
| 165 | 'lorentz_exp_2': 2.0, |
---|
| 166 | }, 0.000332070182643, 10.9996228107], |
---|
| 167 | |
---|
| 168 | [{'lorentz_scale_1': 0.0, |
---|
| 169 | 'lorentz_length_1': 0.0, |
---|
| 170 | 'lorentz_exp_1': 0.0, |
---|
| 171 | 'lorentz_scale_2': 0.0, |
---|
| 172 | 'lorentz_length_2': 0.0, |
---|
| 173 | 'lorentz_exp_2': 0.0, |
---|
| 174 | 'background': 100.0 |
---|
| 175 | }, 5.0, 100.0], |
---|
| 176 | |
---|
| 177 | [{'lorentz_scale_1': 200.0, |
---|
| 178 | 'lorentz_length_1': 10.0, |
---|
| 179 | 'lorentz_exp_1': 0.1, |
---|
| 180 | 'lorentz_scale_2': 0.1, |
---|
| 181 | 'lorentz_length_2': 5.0, |
---|
| 182 | 'lorentz_exp_2': 2.0 |
---|
| 183 | }, 20000., 45.5659201896], |
---|
| 184 | ] |
---|