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