source: sasmodels/sasmodels/models/two_power_law.py @ 46ed760

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

remove oldname/oldpars from new models

  • Property mode set to 100644
File size: 4.4 KB
Line 
1r"""
2Definition
3----------
4
5The scattering intensity $I(q)$ is calculated as
6
7.. math::
8
9    I(q) = \begin{cases}
10    A q^{-m1} + \text{background} & q <= q_c \\
11    C q^{-m2} + \text{background} & q > q_c
12    \end{cases}
13
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
16power law region, $m1$ = power law exponent at low Q, and $m2$ = power law
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:
19
20.. math::
21    C = \frac{A q_c^{m2}}{q_c^{m1}}
22
23.. note::
24    Be sure to enter the power law exponents as positive values!
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
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
44"""
45
46from numpy import power
47from numpy import sqrt
48from numpy import inf
49from numpy import concatenate
50
51name = "two_power_law"
52title = "This model calculates an empirical functional form for SAS data \
53characterized by two power laws."
54description = """
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).
58
59            coef_A = scaling coefficent
60            q_c = crossover location [1/A]
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]
64        """
65category = "shape-independent"
66
67#            ["name", "units", default, [lower, upper], "type", "description"],
68parameters = [["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"],
76             ]
77
78
79def Iq(q,
80       coefficent_1=1.0,
81       crossover=0.04,
82       power_1=1.0,
83       power_2=4.0,
84      ):
85
86    """
87    :param q:                   Input q-value (float or [float, float])
88    :param coefficent_1:        Scaling coefficent at low Q
89    :param crossover:           Crossover location
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    """
94
95    #Two sub vectors are created to treat crossover values
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)
102
103    return intensity
104
105Iq.vectorized = True  # Iq accepts an array of q values
106
107def 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
117Iqxy.vectorized = True  # Iqxy accepts an array of qx, qy values
118
119demo = dict(scale=1, background=0.0,
120            coefficent_1=1.0,
121            crossover=0.04,
122            power_1=1.0,
123            power_2=4.0)
124
125tests = [
126    # Accuracy tests based on content in test/utest_extra_models.py
127    [{'coefficent_1':     1.0,
128      'crossover':  0.04,
129      'power_1':    1.0,
130      'power_2':    4.0,
131      'background': 0.0,
132     }, 0.001, 1000],
133
134    [{'coefficent_1':     1.0,
135      'crossover':  0.04,
136      'power_1':    1.0,
137      'power_2':    4.0,
138      'background': 0.0,
139     }, 0.150141, 0.125945],
140
141    [{'coeffcent_1':    1.0,
142      'crossover':  0.04,
143      'power_1':    1.0,
144      'power_2':    4.0,
145      'background': 0.0,
146     }, 0.442528, 0.00166884],
147
148    [{'coeffcent_1':    1.0,
149      'crossover':  0.04,
150      'power_1':    1.0,
151      'power_2':    4.0,
152      'background': 0.0,
153     }, (0.442528, 0.00166884), 0.00166884],
154
155]
Note: See TracBrowser for help on using the repository browser.