source: sasmodels/sasmodels/models/two_power_law.py @ 6cefbc9

core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 6cefbc9 was 40a87fa, checked in by Paul Kienzle <pkienzle@…>, 8 years ago

lint and latex cleanup

  • Property mode set to 100644
File size: 4.0 KB
RevLine 
[a36c6d3]1r"""
2Definition
3----------
4
5The 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]14where $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]16power law region, $m1$ = power law exponent at low Q, and $m2$ = power law
[c6652bb]17exponent at high Q.  The scaling of the second power law region (coefficent C)
18is 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
26For 2D data the scattering intensity is calculated in the same way as 1D,
27where the $q$ vector is defined as
28
29.. math::
30
31    q = \sqrt{q_x^2 + q_y^2}
32
33
34References
35----------
36
37None.
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
[2c74c11]46from numpy import inf, power, empty, errstate
[8115d82]47
48name = "two_power_law"
[c6652bb]49title = "This model calculates an empirical functional form for SAS data \
50characterized by two power laws."
[8115d82]51description = """
[c6652bb]52            I(q) = coef_A*pow(qval,-1.0*power1) + background for q<=q_c
53            =C*pow(qval,-1.0*power2) + background for q>q_c
54            where C=coef_A*pow(q_c,-1.0*power1)/pow(q_c,-1.0*power2).
[8115d82]55
56            coef_A = scaling coefficent
[c6652bb]57            q_c = crossover location [1/A]
[8115d82]58            power_1 (=m1) = power law exponent at low Q
59            power_2 (=m2) = power law exponent at high Q
60            background = Incoherent background [1/cm]
[a36c6d3]61        """
[8115d82]62category = "shape-independent"
63
[40a87fa]64# pylint: disable=bad-whitespace, line-too-long
65#   ["name", "units", default, [lower, upper], "type", "description"],
66parameters = [
67    ["coefficent_1", "",       1.0, [-inf, inf], "", "coefficent A in low Q region"],
68    ["crossover",    "1/Ang",  0.04,[0, inf],    "", "crossover location"],
69    ["power_1",      "",       1.0, [0, inf],    "", "power law exponent at low Q"],
70    ["power_2",      "",       4.0, [0, inf],    "", "power law exponent at high Q"],
71    ]
72# pylint: enable=bad-whitespace, line-too-long
[8115d82]73
[7e1d090]74
[8115d82]75def Iq(q,
[34d6cab]76       coefficent_1=1.0,
77       crossover=0.04,
[8115d82]78       power_1=1.0,
79       power_2=4.0,
[7e1d090]80      ):
[8115d82]81
82    """
83    :param q:                   Input q-value (float or [float, float])
[7e1d090]84    :param coefficent_1:        Scaling coefficent at low Q
[34d6cab]85    :param crossover:           Crossover location
[8115d82]86    :param power_1:             Exponent of power law function at low Q
87    :param power_2:             Exponent of power law function at high Q
88    :return:                    Calculated intensity
89    """
[40a87fa]90    result= empty(q.shape, 'd')
91    index = (q <= crossover)
[2c74c11]92    with errstate(divide='ignore'):
93        coefficent_2 = coefficent_1 * power(crossover, power_2 - power_1)
[40a87fa]94        result[index] = coefficent_1 * power(q[index], -power_1)
95        result[~index] = coefficent_2 * power(q[~index], -power_2)
96    return result
[8115d82]97
[3eb3312]98Iq.vectorized = True  # Iq accepts an array of q values
[8115d82]99
[7e1d090]100demo = dict(scale=1, background=0.0,
[34d6cab]101            coefficent_1=1.0,
102            crossover=0.04,
[8115d82]103            power_1=1.0,
104            power_2=4.0)
105
106tests = [
107    # Accuracy tests based on content in test/utest_extra_models.py
[34d6cab]108    [{'coefficent_1':     1.0,
109      'crossover':  0.04,
[8115d82]110      'power_1':    1.0,
111      'power_2':    4.0,
[34d6cab]112      'background': 0.0,
[7e1d090]113     }, 0.001, 1000],
[8115d82]114
[34d6cab]115    [{'coefficent_1':     1.0,
116      'crossover':  0.04,
[8115d82]117      'power_1':    1.0,
118      'power_2':    4.0,
[34d6cab]119      'background': 0.0,
[7e1d090]120     }, 0.150141, 0.125945],
[8115d82]121
[34d6cab]122    [{'coeffcent_1':    1.0,
123      'crossover':  0.04,
[8115d82]124      'power_1':    1.0,
125      'power_2':    4.0,
[34d6cab]126      'background': 0.0,
[7e1d090]127     }, 0.442528, 0.00166884],
[3eb3312]128
129    [{'coeffcent_1':    1.0,
130      'crossover':  0.04,
131      'power_1':    1.0,
132      'power_2':    4.0,
133      'background': 0.0,
[7e1d090]134     }, (0.442528, 0.00166884), 0.00166884],
[3eb3312]135
[34d6cab]136]
Note: See TracBrowser for help on using the repository browser.