source: sasmodels/sasmodels/models/two_lorentzian.py @ 513efc5

core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 513efc5 was 513efc5, checked in by piotr, 8 years ago

Code review issues from PK addressed.

Added Taylor expansion utility function.

  • Property mode set to 100644
File size: 4.7 KB
Line 
1r"""
2This model calculates an empirical functional form for SAS data characterized
3by two Lorentzian-type functions.
4
5Definition
6----------
7
8The scattering intensity $I(q)$ is calculated as
9
10.. math::
11
12    I(q) = \frac{A}{1 +(Q\xi_1)^n} + \frac{C}{1 +(Q\xi_2)^m} + \text{B}
13
14where $A$ = Lorentzian scale factor #1, $C$ = Lorentzian scale #2,
15$\xi_1$ and $\xi_2$ are the corresponding correlation lengths, and $n$ and
16$m$ are the respective power law exponents (set $n = m = 2$ for
17Ornstein-Zernicke behaviour).
18
19For 2D data the scattering intensity is calculated in the same way as 1D,
20where the $q$ vector is defined as
21
22.. math::
23
24    q = \sqrt{q_x^2 + q_y^2}
25
26
27.. figure:: img/two_lorentzian.jpg
28
29    1D plot using the default values (w/500 data point).
30
31References
32----------
33
34None.
35
36"""
37
38from math import sqrt
39from numpy import inf, power
40
41name = "two_lorentzian"
42title = "Two Lorentzian type peak"
43description = """I(q) = scale_1/(1.0 + pow((q*length_1),exponent_1))
44             + scale_2/(1.0 + pow((q*length_2),exponent_2) )+ background
45
46             scale_1    = Lorentzian term scaling #1
47             length_1   = Lorentzian screening length #1 [A]
48             exponent_1 = Lorentzian exponent #1
49             scale_2    = Lorentzian term scaling #2
50             length_2   = Lorentzian screening length #2 [A]
51             exponent_2 = Lorentzian exponent #2
52             background = Incoherent background
53        """
54category = "shape-independent"
55
56#            ["name", "units", default, [lower, upper], "type", "description"],
57parameters = [["lorentz_scale_1",  "",     10.0, [-inf, inf], "",
58               "First power law scale factor"],
59              ["lorentz_length_1", "Ang", 100.0, [-inf, inf], "",
60               "First Lorentzian screening length"],
61              ["lorentz_exp_1",    "",      3.0, [-inf, inf], "",
62               "First exponent of power law"],
63              ["lorentz_scale_2",  "",      1.0, [-inf, inf], "",
64               "Second scale factor for broad Lorentzian peak"],
65              ["lorentz_length_2", "Ang",  10.0, [-inf, inf], "",
66               "Second Lorentzian screening length"],
67              ["lorentz_exp_2",    "",      2.0, [-inf, inf], "",
68               "Second exponent of power law"],
69              ]
70
71
72def Iq(q,
73       lorentz_scale_1,
74       lorentz_length_1,
75       lorentz_exp_1,
76       lorentz_scale_2,
77       lorentz_length_2,
78       lorentz_exp_2):
79
80    """
81    :param q:                   Input q-value (float or [float, float])
82    :param lorentz_scale_1:     Second scale factor for broad Lorentzian peak
83    :param lorentz_length_1:    First Lorentzian screening length
84    :param lorentz_exp_1:       Exponent of the second Lorentz function
85    :param lorentz_scale_2:     Second scale factor for broad Lorentzian peak
86    :param lorentz_length_2:    Second Lorentzian screening length
87    :param lorentz_exp_2:       Exponent of the second Lorentz function
88    :return:                    Calculated intensity
89    """
90
91    intensity  = lorentz_scale_1/(1.0 +
92                                  power(q*lorentz_length_1, lorentz_exp_1))
93    intensity += lorentz_scale_2/(1.0 +
94                                  power(q*lorentz_length_2, lorentz_exp_2))
95
96    return intensity
97
98Iq.vectorized = True  # Iq accepts an array of q values
99
100
101def Iqxy(qx, qy, *args):
102        iq = Iq(sqrt(qx**2 + qy**2), *args)
103
104        return iq
105
106Iqxy.vectorized = True  # Iqxy accepts an array of qx, qy values
107
108
109demo = dict(scale=1, background=0.1,
110            lorentz_scale_1=10, lorentz_length_1=100.0, lorentz_exp_1=3.0,
111            lorentz_scale_2=1,  lorentz_length_2=10,    lorentz_exp_2=2.0)
112
113oldname = "TwoLorentzianModel"
114oldpars = dict(background='background',
115               lorentz_scale_1='scale_1',   lorentz_scale_2='scale_2',
116               lorentz_length_1='length_1', lorentz_length_2='length_2',
117               lorentz_exp_1='exponent_1',  lorentz_exp_2='exponent_2')
118
119tests = [[{'lorentz_scale_1':   10.0,
120           'lorentz_length_1': 100.0,
121           'lorentz_exp_1':      3.0,
122           'lorentz_scale_2':    1.0,
123           'lorentz_length_2':  10.0,
124           'lorentz_exp_2':      2.0,
125           }, 0.000332070182643, 10.9996228107],
126
127         [{'lorentz_scale_1':  0.0,
128           'lorentz_length_1': 0.0,
129           'lorentz_exp_1':    0.0,
130           'lorentz_scale_2':  0.0,
131           'lorentz_length_2': 0.0,
132           'lorentz_exp_2':    0.0,
133           'background':     100.0
134           }, 5.0, 100.0],
135
136         [{'lorentz_scale_1': 200.0,
137           'lorentz_length_1': 10.0,
138           'lorentz_exp_1':     0.1,
139           'lorentz_scale_2':   0.1,
140           'lorentz_length_2':  5.0,
141           'lorentz_exp_2':     2.0
142           }, 20000., 45.5659201896],
143         ]
Note: See TracBrowser for help on using the repository browser.