source: sasmodels/sasmodels/models/peak_lorentz.py @ 71b751d

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 71b751d was 2d81cfe, checked in by Paul Kienzle <pkienzle@…>, 6 years ago

lint

  • Property mode set to 100644
File size: 1.9 KB
Line 
1r"""
2This model describes a Lorentzian shaped peak on a flat background.
3
4Definition
5----------
6
7The scattering intensity $I(q)$ is calculated as
8
9.. math::
10
11    I(q) = \frac{scale}{\bigl(1+\bigl(\frac{q-q_0}{B}\bigr)^2\bigr)} + background
12
13with the peak having height of $I_0$ centered at $q_0$ and having
14a HWHM (half-width half-maximum) of B.
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
30import numpy as np
31from numpy import inf
32
33name = "peak_lorentz"
34title = "A Lorentzian peak on a flat background"
35description = """\
36      Class that evaluates a lorentzian  shaped peak.
37
38        F(q) = scale/(1+[(q-q0)/B]^2 ) + background
39
40        The model has three parameters:
41            scale     =  scale
42            peak_pos        =  peak position
43            peak_hwhm        =  half-width-half-maximum of peak
44            background=  incoherent background"""
45
46category = "shape-independent"
47
48#             ["name", "units", default, [lower, upper], "type", "description"],
49parameters = [["peak_pos", "1/Ang", 0.05, [-inf, inf], "", "Peak postion in q"],
50              ["peak_hwhm", "1/Ang", 0.005, [-inf, inf], "", "HWHM of peak"],
51             ]
52
53def Iq(q, peak_pos, peak_hwhm):
54    """
55        Return I(q)
56    """
57    inten = (1/(1+((q-peak_pos)/peak_hwhm)**2))
58    return inten
59Iq.vectorized = True  # Iq accepts an array of q values
60
61def random():
62    peak_pos = 10**np.random.uniform(-3, -1)
63    peak_hwhm = peak_pos * 10**np.random.uniform(-3, 0)
64    pars = dict(
65        #background=0,
66        scale=10**np.random.uniform(2, 6),
67        peak_pos=peak_pos,
68        peak_hwhm=peak_hwhm,
69    )
70    return pars
71
72demo = dict(scale=100, background=1.0,
73            peak_pos=0.05, peak_hwhm=0.005)
74
75tests = [[{'scale':100.0, 'background':1.0}, 0.001, 2.0305]]
Note: See TracBrowser for help on using the repository browser.