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, |
---|
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). |
---|
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 | |
---|
29 | **Author:** NIST IGOR/DANSE **on:** pre 2010 |
---|
30 | |
---|
31 | **Last Modified by:** Piotr rozyczko **on:** January 29, 2016 |
---|
32 | |
---|
33 | **Last Reviewed by:** Paul Butler **on:** March 21, 2016 |
---|
34 | """ |
---|
35 | |
---|
36 | from numpy import inf, power |
---|
37 | |
---|
38 | name = "two_lorentzian" |
---|
39 | title = "This model calculates an empirical functional form for SAS data \ |
---|
40 | characterized by two Lorentzian-type functions." |
---|
41 | description = """I(q) = scale_1/(1.0 + pow((q*length_1),exponent_1)) |
---|
42 | + scale_2/(1.0 + pow((q*length_2),exponent_2) )+ background |
---|
43 | |
---|
44 | scale_1 = Lorentzian term scaling #1 |
---|
45 | length_1 = Lorentzian screening length #1 [A] |
---|
46 | exponent_1 = Lorentzian exponent #1 |
---|
47 | scale_2 = Lorentzian term scaling #2 |
---|
48 | length_2 = Lorentzian screening length #2 [A] |
---|
49 | exponent_2 = Lorentzian exponent #2 |
---|
50 | background = Incoherent background |
---|
51 | """ |
---|
52 | category = "shape-independent" |
---|
53 | |
---|
54 | # pylint: disable=bad-whitespace, line-too-long |
---|
55 | # ["name", "units", default, [lower, upper], "type", "description"], |
---|
56 | parameters = [["lorentz_scale_1", "", 10.0, [-inf, inf], "", "First power law scale factor"], |
---|
57 | ["lorentz_length_1", "Ang", 100.0, [-inf, inf], "", "First Lorentzian screening length"], |
---|
58 | ["lorentz_exp_1", "", 3.0, [-inf, inf], "", "First exponent of power law"], |
---|
59 | ["lorentz_scale_2", "", 1.0, [-inf, inf], "", "Second scale factor for broad Lorentzian peak"], |
---|
60 | ["lorentz_length_2", "Ang", 10.0, [-inf, inf], "", "Second Lorentzian screening length"], |
---|
61 | ["lorentz_exp_2", "", 2.0, [-inf, inf], "", "Second exponent of power law"], |
---|
62 | ] |
---|
63 | # pylint: enable=bad-whitespace, line-too-long |
---|
64 | |
---|
65 | |
---|
66 | def Iq(q, |
---|
67 | lorentz_scale_1=10.0, |
---|
68 | lorentz_length_1=100.0, |
---|
69 | lorentz_exp_1=3.0, |
---|
70 | lorentz_scale_2=1.0, |
---|
71 | lorentz_length_2=10.0, |
---|
72 | lorentz_exp_2=2.0): |
---|
73 | |
---|
74 | """ |
---|
75 | :param q: Input q-value (float or [float, float]) |
---|
76 | :param lorentz_scale_1: Second scale factor for broad Lorentzian peak |
---|
77 | :param lorentz_length_1: First Lorentzian screening length |
---|
78 | :param lorentz_exp_1: Exponent of the second Lorentz function |
---|
79 | :param lorentz_scale_2: Second scale factor for broad Lorentzian peak |
---|
80 | :param lorentz_length_2: Second Lorentzian screening length |
---|
81 | :param lorentz_exp_2: Exponent of the second Lorentz function |
---|
82 | :return: Calculated intensity |
---|
83 | """ |
---|
84 | # pylint: disable=bad-whitespace |
---|
85 | intensity = lorentz_scale_1/(1.0 + |
---|
86 | power(q*lorentz_length_1, lorentz_exp_1)) |
---|
87 | intensity += lorentz_scale_2/(1.0 + |
---|
88 | power(q*lorentz_length_2, lorentz_exp_2)) |
---|
89 | # pylint: enable=bad-whitespace |
---|
90 | |
---|
91 | return intensity |
---|
92 | |
---|
93 | Iq.vectorized = True # Iq accepts an array of q values |
---|
94 | |
---|
95 | |
---|
96 | demo = dict(scale=1, background=0.1, |
---|
97 | lorentz_scale_1=10, |
---|
98 | lorentz_length_1=100.0, |
---|
99 | lorentz_exp_1=3.0, |
---|
100 | lorentz_scale_2=1, |
---|
101 | lorentz_length_2=10, |
---|
102 | lorentz_exp_2=2.0) |
---|
103 | |
---|
104 | tests = [ |
---|
105 | |
---|
106 | # Accuracy tests based on content in test/utest_extra_models.py |
---|
107 | [{'lorentz_scale_1': 10.0, |
---|
108 | 'lorentz_length_1': 100.0, |
---|
109 | 'lorentz_exp_1': 3.0, |
---|
110 | 'lorentz_scale_2': 1.0, |
---|
111 | 'lorentz_length_2': 10.0, |
---|
112 | 'lorentz_exp_2': 2.0, |
---|
113 | 'background': 0.1, |
---|
114 | }, 0.001, 11.08991], |
---|
115 | |
---|
116 | [{'lorentz_scale_1': 10.0, |
---|
117 | 'lorentz_length_1': 100.0, |
---|
118 | 'lorentz_exp_1': 3.0, |
---|
119 | 'lorentz_scale_2': 1.0, |
---|
120 | 'lorentz_length_2': 10.0, |
---|
121 | 'lorentz_exp_2': 2.0, |
---|
122 | 'background': 0.1, |
---|
123 | }, 0.150141, 0.410245], |
---|
124 | |
---|
125 | [{'lorentz_scale_1': 10.0, |
---|
126 | 'lorentz_length_1': 100.0, |
---|
127 | 'lorentz_exp_1': 3.0, |
---|
128 | 'lorentz_scale_2': 1.0, |
---|
129 | 'lorentz_length_2': 10.0, |
---|
130 | 'lorentz_exp_2': 2.0, |
---|
131 | 'background': 0.1, |
---|
132 | }, 0.442528, 0.148699], |
---|
133 | |
---|
134 | # Additional tests with larger range of parameters |
---|
135 | [{'lorentz_scale_1': 10.0, |
---|
136 | 'lorentz_length_1': 100.0, |
---|
137 | 'lorentz_exp_1': 3.0, |
---|
138 | 'lorentz_scale_2': 1.0, |
---|
139 | 'lorentz_length_2': 10.0, |
---|
140 | 'lorentz_exp_2': 2.0, |
---|
141 | }, 0.000332070182643, 10.9996228107], |
---|
142 | |
---|
143 | [{'lorentz_scale_1': 0.0, |
---|
144 | 'lorentz_length_1': 0.0, |
---|
145 | 'lorentz_exp_1': 0.0, |
---|
146 | 'lorentz_scale_2': 0.0, |
---|
147 | 'lorentz_length_2': 0.0, |
---|
148 | 'lorentz_exp_2': 0.0, |
---|
149 | 'background': 100.0 |
---|
150 | }, 5.0, 100.0], |
---|
151 | |
---|
152 | [{'lorentz_scale_1': 200.0, |
---|
153 | 'lorentz_length_1': 10.0, |
---|
154 | 'lorentz_exp_1': 0.1, |
---|
155 | 'lorentz_scale_2': 0.1, |
---|
156 | 'lorentz_length_2': 5.0, |
---|
157 | 'lorentz_exp_2': 2.0 |
---|
158 | }, 20000., 45.5659201896], |
---|
159 | ] |
---|