source: sasmodels/sasmodels/models/peak_lorentz.py @ c1e44e5

Last change on this file since c1e44e5 was c1e44e5, checked in by Paul Kienzle <pkienzle@…>, 5 years ago

Add local link to source files. Refs #1263.

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