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