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 (w/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 | |
---|
54 | name = "two_power_law" |
---|
55 | title = "Two Power Law intensity calculation" |
---|
56 | description = """ |
---|
57 | I(q) = coef_A*pow(qval,-1.0*power1) + background for q<=qc |
---|
58 | =C*pow(qval,-1.0*power2) + background for q>qc |
---|
59 | where C=coef_A*pow(qc,-1.0*power1)/pow(qc,-1.0*power2). |
---|
60 | |
---|
61 | coef_A = scaling coefficent |
---|
62 | qc = crossover location [1/A] |
---|
63 | power_1 (=m1) = power law exponent at low Q |
---|
64 | power_2 (=m2) = power law exponent at high Q |
---|
65 | background = Incoherent background [1/cm] |
---|
66 | """ |
---|
67 | category = "shape-independent" |
---|
68 | |
---|
69 | # pylint: disable=bad-whitespace, line-too-long |
---|
70 | # ["name", "units", default, [lower, upper], "type", "description"], |
---|
71 | parameters = [["coefficent_1", "", 1.0, [-inf, inf], "", "coefficent A in low Q region"], |
---|
72 | ["crossover", "1/Ang", 0.04,[0, inf], "", "crossover location"], |
---|
73 | ["power_1", "", 1.0, [0, inf], "", "power law exponent at low Q"], |
---|
74 | ["power_2", "", 4.0, [0, inf], "", "power law exponent at high Q"], |
---|
75 | ] |
---|
76 | # pylint: enable=bad-whitespace, line-too-long |
---|
77 | |
---|
78 | def Iq(q, |
---|
79 | coefficent_1=1.0, |
---|
80 | crossover=0.04, |
---|
81 | power_1=1.0, |
---|
82 | power_2=4.0, |
---|
83 | ): |
---|
84 | |
---|
85 | """ |
---|
86 | :param q: Input q-value (float or [float, float]) |
---|
87 | :param coefA: Scaling coefficent at low Q |
---|
88 | :param crossover: Crossover location |
---|
89 | :param power_1: Exponent of power law function at low Q |
---|
90 | :param power_2: Exponent of power law function at high Q |
---|
91 | :return: Calculated intensity |
---|
92 | """ |
---|
93 | # pylint: disable=bad-whitespace |
---|
94 | |
---|
95 | if q<=crossover: |
---|
96 | intensity = coefficent_1*power(q,-1.0*power_1) |
---|
97 | else: |
---|
98 | coefficent_2 = coefficent_1*power(crossover,-1.0*power_1)/power(crossover,-1.0*power_2) |
---|
99 | intensity = coefficent_2*power(q,-1.0*power_2) |
---|
100 | |
---|
101 | return intensity |
---|
102 | |
---|
103 | Iq.vectorized = False # Iq accepts an array of q values |
---|
104 | |
---|
105 | def Iqxy(qx, qy, *args): |
---|
106 | """ |
---|
107 | :param qx: Input q_x-value |
---|
108 | :param qy: Input q_y-value |
---|
109 | :param args: Remaining arguments |
---|
110 | :return: 2D-Intensity |
---|
111 | """ |
---|
112 | |
---|
113 | return Iq(sqrt(qx**2 + qy**2), *args) |
---|
114 | |
---|
115 | Iqxy.vectorized = False # Iqxy accepts an array of qx, qy values |
---|
116 | |
---|
117 | demo = dict(scale=1, background=0.1, |
---|
118 | coefficent_1=1.0, |
---|
119 | crossover=0.04, |
---|
120 | power_1=1.0, |
---|
121 | power_2=4.0) |
---|
122 | |
---|
123 | oldname = "TwoPowerLawModel" |
---|
124 | oldpars = dict(coefficent_1='coef_A', |
---|
125 | crossover='qc', |
---|
126 | power_1='power1', |
---|
127 | power_2='power2', |
---|
128 | background='background') |
---|
129 | |
---|
130 | tests = [ |
---|
131 | |
---|
132 | # Accuracy tests based on content in test/utest_extra_models.py |
---|
133 | [{'coefficent_1': 1.0, |
---|
134 | 'crossover': 0.04, |
---|
135 | 'power_1': 1.0, |
---|
136 | 'power_2': 4.0, |
---|
137 | 'background': 0.0, |
---|
138 | }, 0.001, 1000], |
---|
139 | |
---|
140 | [{'coefficent_1': 1.0, |
---|
141 | 'crossover': 0.04, |
---|
142 | 'power_1': 1.0, |
---|
143 | 'power_2': 4.0, |
---|
144 | 'background': 0.0, |
---|
145 | }, 0.150141, 0.125945], |
---|
146 | |
---|
147 | [{'coeffcent_1': 1.0, |
---|
148 | 'crossover': 0.04, |
---|
149 | 'power_1': 1.0, |
---|
150 | 'power_2': 4.0, |
---|
151 | 'background': 0.0, |
---|
152 | }, 0.442528, 0.00166884], |
---|
153 | ] |
---|