1 | r""" |
---|
2 | This model calculates an empirical functional form for SAS data characterized |
---|
3 | by two power laws. |
---|
4 | |
---|
5 | Definition |
---|
6 | ---------- |
---|
7 | |
---|
8 | The scattering intensity $I(q)$ is calculated as |
---|
9 | |
---|
10 | .. math:: |
---|
11 | |
---|
12 | I(q) = \begin{cases} |
---|
13 | A q^{-m1} + \text{background} & q <= qc \\ |
---|
14 | C q^{-m2} + \text{background} & q > qc |
---|
15 | \end{cases} |
---|
16 | |
---|
17 | where $qc$ = the location of the crossover from one slope to the other, |
---|
18 | $A$ = the scaling coefficent that sets the overall intensity of the lower Q power law region, |
---|
19 | $m1$ = power law exponent at low Q, |
---|
20 | $m2$ = power law exponent at high Q |
---|
21 | |
---|
22 | The scaling of the second power law region (coefficent C) is then automatically scaled to |
---|
23 | match the first by following formula |
---|
24 | |
---|
25 | .. math:: |
---|
26 | C = \frac{A}{qc^{-m1} qc^{-m2}} |
---|
27 | |
---|
28 | .. note:: |
---|
29 | Be sure to enter the power law exponents as positive values! |
---|
30 | |
---|
31 | For 2D data the scattering intensity is calculated in the same way as 1D, |
---|
32 | where the $q$ vector is defined as |
---|
33 | |
---|
34 | .. math:: |
---|
35 | |
---|
36 | q = \sqrt{q_x^2 + q_y^2} |
---|
37 | |
---|
38 | |
---|
39 | .. figure:: img/two_power_law_1d.jpg |
---|
40 | |
---|
41 | 1D plot using the default values (with 500 data point). |
---|
42 | |
---|
43 | References |
---|
44 | ---------- |
---|
45 | |
---|
46 | None. |
---|
47 | |
---|
48 | """ |
---|
49 | |
---|
50 | from numpy import power |
---|
51 | from numpy import sqrt |
---|
52 | from numpy import inf |
---|
53 | from numpy import concatenate |
---|
54 | |
---|
55 | name = "two_power_law" |
---|
56 | title = "Two Power Law intensity calculation" |
---|
57 | description = """ |
---|
58 | I(q) = coef_A*pow(qval,-1.0*power1) + background for q<=qc |
---|
59 | =C*pow(qval,-1.0*power2) + background for q>qc |
---|
60 | where C=coef_A*pow(qc,-1.0*power1)/pow(qc,-1.0*power2). |
---|
61 | |
---|
62 | coef_A = scaling coefficent |
---|
63 | qc = crossover location [1/A] |
---|
64 | power_1 (=m1) = power law exponent at low Q |
---|
65 | power_2 (=m2) = power law exponent at high Q |
---|
66 | background = Incoherent background [1/cm] |
---|
67 | """ |
---|
68 | category = "shape-independent" |
---|
69 | |
---|
70 | # pylint: disable=bad-whitespace, line-too-long |
---|
71 | # ["name", "units", default, [lower, upper], "type", "description"], |
---|
72 | parameters = [["coefficent_1", "", 1.0, [-inf, inf], "", "coefficent A in low Q region"], |
---|
73 | ["crossover", "1/Ang", 0.04,[0, inf], "", "crossover location"], |
---|
74 | ["power_1", "", 1.0, [0, inf], "", "power law exponent at low Q"], |
---|
75 | ["power_2", "", 4.0, [0, inf], "", "power law exponent at high Q"], |
---|
76 | ] |
---|
77 | # pylint: enable=bad-whitespace, line-too-long |
---|
78 | |
---|
79 | |
---|
80 | def Iq(q, |
---|
81 | coefficent_1=1.0, |
---|
82 | crossover=0.04, |
---|
83 | power_1=1.0, |
---|
84 | power_2=4.0, |
---|
85 | ): |
---|
86 | |
---|
87 | """ |
---|
88 | :param q: Input q-value (float or [float, float]) |
---|
89 | :param coefficent_1: Scaling coefficent at low Q |
---|
90 | :param crossover: Crossover location |
---|
91 | :param power_1: Exponent of power law function at low Q |
---|
92 | :param power_2: Exponent of power law function at high Q |
---|
93 | :return: Calculated intensity |
---|
94 | """ |
---|
95 | |
---|
96 | #Two sub vectors are created to treat crossover values |
---|
97 | q_lower = q[q <= crossover] |
---|
98 | q_upper = q[q > crossover] |
---|
99 | coefficent_2 = coefficent_1*power(crossover, -1.0*power_1)/power(crossover, -1.0*power_2) |
---|
100 | intensity_lower = coefficent_1*power(q_lower, -1.0*power_1) |
---|
101 | intensity_upper = coefficent_2*power(q_upper, -1.0*power_2) |
---|
102 | intensity = concatenate((intensity_lower, intensity_upper), axis=0) |
---|
103 | |
---|
104 | return intensity |
---|
105 | |
---|
106 | Iq.vectorized = True # Iq accepts an array of q values |
---|
107 | |
---|
108 | def Iqxy(qx, qy, *args): |
---|
109 | """ |
---|
110 | :param qx: Input q_x-value |
---|
111 | :param qy: Input q_y-value |
---|
112 | :param args: Remaining arguments |
---|
113 | :return: 2D-Intensity |
---|
114 | """ |
---|
115 | |
---|
116 | return Iq(sqrt(qx**2 + qy**2), *args) |
---|
117 | |
---|
118 | Iqxy.vectorized = True # Iqxy accepts an array of qx, qy values |
---|
119 | |
---|
120 | demo = dict(scale=1, background=0.0, |
---|
121 | coefficent_1=1.0, |
---|
122 | crossover=0.04, |
---|
123 | power_1=1.0, |
---|
124 | power_2=4.0) |
---|
125 | |
---|
126 | oldname = "TwoPowerLawModel" |
---|
127 | oldpars = dict(coefficent_1='coef_A', |
---|
128 | crossover='qc', |
---|
129 | power_1='power1', |
---|
130 | power_2='power2', |
---|
131 | background='background') |
---|
132 | |
---|
133 | tests = [ |
---|
134 | # Accuracy tests based on content in test/utest_extra_models.py |
---|
135 | [{'coefficent_1': 1.0, |
---|
136 | 'crossover': 0.04, |
---|
137 | 'power_1': 1.0, |
---|
138 | 'power_2': 4.0, |
---|
139 | 'background': 0.0, |
---|
140 | }, 0.001, 1000], |
---|
141 | |
---|
142 | [{'coefficent_1': 1.0, |
---|
143 | 'crossover': 0.04, |
---|
144 | 'power_1': 1.0, |
---|
145 | 'power_2': 4.0, |
---|
146 | 'background': 0.0, |
---|
147 | }, 0.150141, 0.125945], |
---|
148 | |
---|
149 | [{'coeffcent_1': 1.0, |
---|
150 | 'crossover': 0.04, |
---|
151 | 'power_1': 1.0, |
---|
152 | 'power_2': 4.0, |
---|
153 | 'background': 0.0, |
---|
154 | }, 0.442528, 0.00166884], |
---|
155 | |
---|
156 | [{'coeffcent_1': 1.0, |
---|
157 | 'crossover': 0.04, |
---|
158 | 'power_1': 1.0, |
---|
159 | 'power_2': 4.0, |
---|
160 | 'background': 0.0, |
---|
161 | }, (0.442528, 0.00166884), 0.00166884], |
---|
162 | |
---|
163 | ] |
---|