[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 |
---|
[40a87fa] | 16 | power law region, $m1$ = power law exponent at low Q, and $m2$ = power law |
---|
[c6652bb] | 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 | |
---|
[ef07e95] | 39 | * **Author:** NIST IGOR/DANSE **Date:** pre 2010 |
---|
| 40 | * **Last Modified by:** Wojciech Wpotrzebowski **Date:** February 18, 2016 |
---|
| 41 | * **Last Reviewed by:** Paul Butler **Date:** March 21, 2016 |
---|
[a36c6d3] | 42 | """ |
---|
| 43 | |
---|
[2d81cfe] | 44 | import numpy as np |
---|
[2c74c11] | 45 | from numpy import inf, power, empty, errstate |
---|
[8115d82] | 46 | |
---|
| 47 | name = "two_power_law" |
---|
[c6652bb] | 48 | title = "This model calculates an empirical functional form for SAS data \ |
---|
| 49 | characterized by two power laws." |
---|
[8115d82] | 50 | description = """ |
---|
[c6652bb] | 51 | I(q) = coef_A*pow(qval,-1.0*power1) + background for q<=q_c |
---|
| 52 | =C*pow(qval,-1.0*power2) + background for q>q_c |
---|
| 53 | where C=coef_A*pow(q_c,-1.0*power1)/pow(q_c,-1.0*power2). |
---|
[8115d82] | 54 | |
---|
| 55 | coef_A = scaling coefficent |
---|
[c6652bb] | 56 | q_c = crossover location [1/A] |
---|
[8115d82] | 57 | power_1 (=m1) = power law exponent at low Q |
---|
| 58 | power_2 (=m2) = power law exponent at high Q |
---|
| 59 | background = Incoherent background [1/cm] |
---|
[a36c6d3] | 60 | """ |
---|
[8115d82] | 61 | category = "shape-independent" |
---|
| 62 | |
---|
[40a87fa] | 63 | # pylint: disable=bad-whitespace, line-too-long |
---|
| 64 | # ["name", "units", default, [lower, upper], "type", "description"], |
---|
| 65 | parameters = [ |
---|
| 66 | ["coefficent_1", "", 1.0, [-inf, inf], "", "coefficent A in low Q region"], |
---|
| 67 | ["crossover", "1/Ang", 0.04,[0, inf], "", "crossover location"], |
---|
| 68 | ["power_1", "", 1.0, [0, inf], "", "power law exponent at low Q"], |
---|
| 69 | ["power_2", "", 4.0, [0, inf], "", "power law exponent at high Q"], |
---|
| 70 | ] |
---|
| 71 | # pylint: enable=bad-whitespace, line-too-long |
---|
[8115d82] | 72 | |
---|
[7e1d090] | 73 | |
---|
[8115d82] | 74 | def Iq(q, |
---|
[34d6cab] | 75 | coefficent_1=1.0, |
---|
| 76 | crossover=0.04, |
---|
[8115d82] | 77 | power_1=1.0, |
---|
| 78 | power_2=4.0, |
---|
[7e1d090] | 79 | ): |
---|
[8115d82] | 80 | """ |
---|
| 81 | :param q: Input q-value (float or [float, float]) |
---|
[7e1d090] | 82 | :param coefficent_1: Scaling coefficent at low Q |
---|
[34d6cab] | 83 | :param crossover: Crossover location |
---|
[8115d82] | 84 | :param power_1: Exponent of power law function at low Q |
---|
| 85 | :param power_2: Exponent of power law function at high Q |
---|
| 86 | :return: Calculated intensity |
---|
| 87 | """ |
---|
[2d81cfe] | 88 | result = empty(q.shape, 'd') |
---|
[40a87fa] | 89 | index = (q <= crossover) |
---|
[2c74c11] | 90 | with errstate(divide='ignore'): |
---|
| 91 | coefficent_2 = coefficent_1 * power(crossover, power_2 - power_1) |
---|
[40a87fa] | 92 | result[index] = coefficent_1 * power(q[index], -power_1) |
---|
| 93 | result[~index] = coefficent_2 * power(q[~index], -power_2) |
---|
| 94 | return result |
---|
[8115d82] | 95 | |
---|
[3eb3312] | 96 | Iq.vectorized = True # Iq accepts an array of q values |
---|
[8115d82] | 97 | |
---|
[48462b0] | 98 | def random(): |
---|
[b297ba9] | 99 | """Return a random parameter set for the model.""" |
---|
[48462b0] | 100 | coefficient_1 = 1 |
---|
| 101 | crossover = 10**np.random.uniform(-3, -1) |
---|
| 102 | power_1 = np.random.uniform(1, 6) |
---|
| 103 | power_2 = np.random.uniform(1, 6) |
---|
| 104 | pars = dict( |
---|
| 105 | scale=1, #background=0, |
---|
| 106 | coefficient_1=coefficient_1, |
---|
| 107 | crossover=crossover, |
---|
| 108 | power_1=power_1, |
---|
| 109 | power_2=power_2, |
---|
| 110 | ) |
---|
| 111 | return pars |
---|
| 112 | |
---|
[7e1d090] | 113 | demo = dict(scale=1, background=0.0, |
---|
[34d6cab] | 114 | coefficent_1=1.0, |
---|
| 115 | crossover=0.04, |
---|
[8115d82] | 116 | power_1=1.0, |
---|
| 117 | power_2=4.0) |
---|
| 118 | |
---|
| 119 | tests = [ |
---|
| 120 | # Accuracy tests based on content in test/utest_extra_models.py |
---|
[34d6cab] | 121 | [{'coefficent_1': 1.0, |
---|
| 122 | 'crossover': 0.04, |
---|
[8115d82] | 123 | 'power_1': 1.0, |
---|
| 124 | 'power_2': 4.0, |
---|
[34d6cab] | 125 | 'background': 0.0, |
---|
[7e1d090] | 126 | }, 0.001, 1000], |
---|
[8115d82] | 127 | |
---|
[34d6cab] | 128 | [{'coefficent_1': 1.0, |
---|
| 129 | 'crossover': 0.04, |
---|
[8115d82] | 130 | 'power_1': 1.0, |
---|
| 131 | 'power_2': 4.0, |
---|
[34d6cab] | 132 | 'background': 0.0, |
---|
[7e1d090] | 133 | }, 0.150141, 0.125945], |
---|
[8115d82] | 134 | |
---|
[bb4b509] | 135 | [{'coefficent_1': 1.0, |
---|
[34d6cab] | 136 | 'crossover': 0.04, |
---|
[8115d82] | 137 | 'power_1': 1.0, |
---|
| 138 | 'power_2': 4.0, |
---|
[34d6cab] | 139 | 'background': 0.0, |
---|
[7e1d090] | 140 | }, 0.442528, 0.00166884], |
---|
[3eb3312] | 141 | |
---|
[bb4b509] | 142 | [{'coefficent_1': 1.0, |
---|
[3eb3312] | 143 | 'crossover': 0.04, |
---|
| 144 | 'power_1': 1.0, |
---|
| 145 | 'power_2': 4.0, |
---|
| 146 | 'background': 0.0, |
---|
[7e1d090] | 147 | }, (0.442528, 0.00166884), 0.00166884], |
---|
[3eb3312] | 148 | |
---|
[34d6cab] | 149 | ] |
---|