source: sasmodels/sasmodels/models/two_lorentzian.py @ 421e55c

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

Convert TwoLorentzian? model

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