source: sasmodels/sasmodels/models/peak_lorentz.py @ 0507e09

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 0507e09 was 0507e09, checked in by smk78, 5 years ago

Added link to source code to each model. Closes #883

  • Property mode set to 100644
File size: 2.3 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
29Source
30------
31
32`peak_lorentz.py <https://github.com/SasView/sasmodels/blob/master/sasmodels/models/peak_lorentz.py>`_
33
34`peak_lorentz.c <https://github.com/SasView/sasmodels/blob/master/sasmodels/models/peak_lorentz.c>`_
35
36Authorship and Verification
37----------------------------
38
39* **Author:**
40* **Last Modified by:**
41* **Last Reviewed by:**
42* **Source added by :** Steve King **Date:** March 25, 2019
43"""
44
45import numpy as np
46from numpy import inf
47
48name = "peak_lorentz"
49title = "A Lorentzian peak on a flat background"
50description = """\
51      Class that evaluates a lorentzian  shaped peak.
52
53        F(q) = scale/(1+[(q-q0)/B]^2 ) + background
54
55        The model has three parameters:
56            scale     =  scale
57            peak_pos        =  peak position
58            peak_hwhm        =  half-width-half-maximum of peak
59            background=  incoherent background"""
60
61category = "shape-independent"
62
63#             ["name", "units", default, [lower, upper], "type", "description"],
64parameters = [["peak_pos", "1/Ang", 0.05, [-inf, inf], "", "Peak postion in q"],
65              ["peak_hwhm", "1/Ang", 0.005, [-inf, inf], "", "HWHM of peak"],
66             ]
67
68def Iq(q, peak_pos, peak_hwhm):
69    """
70        Return I(q)
71    """
72    inten = (1/(1+((q-peak_pos)/peak_hwhm)**2))
73    return inten
74Iq.vectorized = True  # Iq accepts an array of q values
75
76def random():
77    """Return a random parameter set for the model."""
78    peak_pos = 10**np.random.uniform(-3, -1)
79    peak_hwhm = peak_pos * 10**np.random.uniform(-3, 0)
80    pars = dict(
81        #background=0,
82        scale=10**np.random.uniform(2, 6),
83        peak_pos=peak_pos,
84        peak_hwhm=peak_hwhm,
85    )
86    return pars
87
88demo = dict(scale=100, background=1.0,
89            peak_pos=0.05, peak_hwhm=0.005)
90
91tests = [[{'scale':100.0, 'background':1.0}, 0.001, 2.0305]]
Note: See TracBrowser for help on using the repository browser.