source: sasmodels/sasmodels/models/two_lorentzian.py @ ec45c4f

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

remove oldname/oldpars from new models

  • Property mode set to 100644
File size: 5.5 KB
Line 
1r"""
2Definition
3----------
4
5The scattering intensity $I(q)$ is calculated as
6
7.. math::
8
9    I(q) = \frac{A}{1 +(Q\xi_1)^n} + \frac{C}{1 +(Q\xi_2)^m} + \text{B}
10
11where $A$ = Lorentzian scale factor #1, $C$ = Lorentzian scale #2,
12$\xi_1$ and $\xi_2$ are the corresponding correlation lengths, and $n$ and
13$m$ are the respective power law exponents (set $n = m = 2$ for
14Ornstein-Zernicke behaviour).
15
16For 2D data the scattering intensity is calculated in the same way as 1D,
17where the $q$ vector is defined as
18
19.. math::
20
21    q = \sqrt{q_x^2 + q_y^2}
22
23
24References
25----------
26
27None.
28
29**Author:** NIST IGOR/DANSE **on:** pre 2010
30
31**Last Modified by:** Piotr rozyczko **on:** January 29, 2016
32
33**Last Reviewed by:** Paul Butler **on:** March 21, 2016
34"""
35
36from math import sqrt
37from numpy import inf, power
38
39name = "two_lorentzian"
40title = "This model calculates an empirical functional form for SAS data \
41characterized by two Lorentzian-type functions."
42description = """I(q) = scale_1/(1.0 + pow((q*length_1),exponent_1))
43             + scale_2/(1.0 + pow((q*length_2),exponent_2) )+ background
44
45             scale_1    = Lorentzian term scaling #1
46             length_1   = Lorentzian screening length #1 [A]
47             exponent_1 = Lorentzian exponent #1
48             scale_2    = Lorentzian term scaling #2
49             length_2   = Lorentzian screening length #2 [A]
50             exponent_2 = Lorentzian exponent #2
51             background = Incoherent background
52        """
53category = "shape-independent"
54
55# pylint: disable=bad-whitespace, line-too-long
56#            ["name", "units", default, [lower, upper], "type", "description"],
57parameters = [["lorentz_scale_1",  "",     10.0, [-inf, inf], "", "First power law scale factor"],
58              ["lorentz_length_1", "Ang", 100.0, [-inf, inf], "", "First Lorentzian screening length"],
59              ["lorentz_exp_1",    "",      3.0, [-inf, inf], "", "First exponent of power law"],
60              ["lorentz_scale_2",  "",      1.0, [-inf, inf], "", "Second scale factor for broad Lorentzian peak"],
61              ["lorentz_length_2", "Ang",  10.0, [-inf, inf], "", "Second Lorentzian screening length"],
62              ["lorentz_exp_2",    "",      2.0, [-inf, inf], "", "Second exponent of power law"],
63             ]
64# pylint: enable=bad-whitespace, line-too-long
65
66
67def Iq(q,
68       lorentz_scale_1=10.0,
69       lorentz_length_1=100.0,
70       lorentz_exp_1=3.0,
71       lorentz_scale_2=1.0,
72       lorentz_length_2=10.0,
73       lorentz_exp_2=2.0):
74
75    """
76    :param q:                   Input q-value (float or [float, float])
77    :param lorentz_scale_1:     Second scale factor for broad Lorentzian peak
78    :param lorentz_length_1:    First Lorentzian screening length
79    :param lorentz_exp_1:       Exponent of the second Lorentz function
80    :param lorentz_scale_2:     Second scale factor for broad Lorentzian peak
81    :param lorentz_length_2:    Second Lorentzian screening length
82    :param lorentz_exp_2:       Exponent of the second Lorentz function
83    :return:                    Calculated intensity
84    """
85# pylint: disable=bad-whitespace
86    intensity  = lorentz_scale_1/(1.0 +
87                                  power(q*lorentz_length_1, lorentz_exp_1))
88    intensity += lorentz_scale_2/(1.0 +
89                                  power(q*lorentz_length_2, lorentz_exp_2))
90# pylint: enable=bad-whitespace
91
92    return intensity
93
94Iq.vectorized = True  # Iq accepts an array of q values
95
96
97def Iqxy(qx, qy, *args):
98    """
99    :param qx:   Input q_x-value
100    :param qy:   Input q_y-value
101    :param args: Remaining arguments
102    :return:     2D-Intensity
103    """
104
105    return Iq(sqrt(qx**2 + qy**2), *args)
106
107Iqxy.vectorized = True  # Iqxy accepts an array of qx, qy values
108
109
110demo = dict(scale=1, background=0.1,
111            lorentz_scale_1=10,
112            lorentz_length_1=100.0,
113            lorentz_exp_1=3.0,
114            lorentz_scale_2=1,
115            lorentz_length_2=10,
116            lorentz_exp_2=2.0)
117
118tests = [
119
120    # Accuracy tests based on content in test/utest_extra_models.py
121    [{'lorentz_scale_1':   10.0,
122      'lorentz_length_1': 100.0,
123      'lorentz_exp_1':      3.0,
124      'lorentz_scale_2':    1.0,
125      'lorentz_length_2':  10.0,
126      'lorentz_exp_2':      2.0,
127      'background':         0.1,
128     }, 0.001, 11.08991],
129
130    [{'lorentz_scale_1':   10.0,
131      'lorentz_length_1': 100.0,
132      'lorentz_exp_1':      3.0,
133      'lorentz_scale_2':    1.0,
134      'lorentz_length_2':  10.0,
135      'lorentz_exp_2':      2.0,
136      'background':         0.1,
137     }, 0.150141, 0.410245],
138
139    [{'lorentz_scale_1':   10.0,
140      'lorentz_length_1': 100.0,
141      'lorentz_exp_1':      3.0,
142      'lorentz_scale_2':    1.0,
143      'lorentz_length_2':  10.0,
144      'lorentz_exp_2':      2.0,
145      'background':         0.1,
146     }, 0.442528, 0.148699],
147
148    # Additional tests with larger range of parameters
149    [{'lorentz_scale_1':   10.0,
150      'lorentz_length_1': 100.0,
151      'lorentz_exp_1':      3.0,
152      'lorentz_scale_2':    1.0,
153      'lorentz_length_2':  10.0,
154      'lorentz_exp_2':      2.0,
155     }, 0.000332070182643, 10.9996228107],
156
157    [{'lorentz_scale_1':  0.0,
158      'lorentz_length_1': 0.0,
159      'lorentz_exp_1':    0.0,
160      'lorentz_scale_2':  0.0,
161      'lorentz_length_2': 0.0,
162      'lorentz_exp_2':    0.0,
163      'background':     100.0
164     }, 5.0, 100.0],
165
166    [{'lorentz_scale_1': 200.0,
167      'lorentz_length_1': 10.0,
168      'lorentz_exp_1':     0.1,
169      'lorentz_scale_2':   0.1,
170      'lorentz_length_2':  5.0,
171      'lorentz_exp_2':     2.0
172     }, 20000., 45.5659201896],
173    ]
Note: See TracBrowser for help on using the repository browser.