1 | r""" |
---|
2 | This model describes a Lorentzian shaped peak on a flat background. |
---|
3 | |
---|
4 | Definition |
---|
5 | ---------- |
---|
6 | |
---|
7 | The 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 | |
---|
13 | with the peak having height of $I_0$ centered at $q_0$ and having |
---|
14 | a HWHM (half-width half-maximum) of B. |
---|
15 | |
---|
16 | For 2D data the scattering intensity is calculated in the same way as 1D, |
---|
17 | where the $q$ vector is defined as |
---|
18 | |
---|
19 | .. math:: |
---|
20 | |
---|
21 | q = \sqrt{q_x^2 + q_y^2} |
---|
22 | |
---|
23 | |
---|
24 | References |
---|
25 | ---------- |
---|
26 | |
---|
27 | None. |
---|
28 | |
---|
29 | """ |
---|
30 | |
---|
31 | from numpy import inf |
---|
32 | |
---|
33 | name = "peak_lorentz" |
---|
34 | title = "A Lorentzian peak on a flat background" |
---|
35 | description = """\ |
---|
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 | |
---|
46 | category = "shape-independent" |
---|
47 | |
---|
48 | # ["name", "units", default, [lower, upper], "type", "description"], |
---|
49 | parameters = [["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 | |
---|
53 | def 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 |
---|
59 | Iq.vectorized = True # Iq accepts an array of q values |
---|
60 | |
---|
61 | def random(): |
---|
62 | import numpy as np |
---|
63 | peak_pos = 10**np.random.uniform(-3, -1) |
---|
64 | peak_hwhm = peak_pos * 10**np.random.uniform(-3, 0) |
---|
65 | pars = dict( |
---|
66 | #background=0, |
---|
67 | scale=10**np.random.uniform(2, 6), |
---|
68 | peak_pos=peak_pos, |
---|
69 | peak_hwhm=peak_hwhm, |
---|
70 | ) |
---|
71 | return pars |
---|
72 | |
---|
73 | demo = dict(scale=100, background=1.0, |
---|
74 | peak_pos=0.05, peak_hwhm=0.005) |
---|
75 | |
---|
76 | tests = [[{'scale':100.0, 'background':1.0}, 0.001, 2.0305]] |
---|