[2f6f4c3] | 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 | |
---|
[04b0b30] | 13 | with the peak having height of $I_0$ centered at $q_0$ and having |
---|
| 14 | a HWHM (half-width half-maximum) of B. |
---|
[2f6f4c3] | 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. |
---|
[0507e09] | 28 | |
---|
| 29 | Source |
---|
| 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 | |
---|
| 36 | Authorship and Verification |
---|
| 37 | ---------------------------- |
---|
| 38 | |
---|
| 39 | * **Author:** |
---|
| 40 | * **Last Modified by:** |
---|
| 41 | * **Last Reviewed by:** |
---|
| 42 | * **Source added by :** Steve King **Date:** March 25, 2019 |
---|
[2f6f4c3] | 43 | """ |
---|
| 44 | |
---|
[2d81cfe] | 45 | import numpy as np |
---|
[2c74c11] | 46 | from numpy import inf |
---|
[2f6f4c3] | 47 | |
---|
| 48 | name = "peak_lorentz" |
---|
| 49 | title = "A Lorentzian peak on a flat background" |
---|
| 50 | description = """\ |
---|
| 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 | |
---|
| 61 | category = "shape-independent" |
---|
| 62 | |
---|
| 63 | # ["name", "units", default, [lower, upper], "type", "description"], |
---|
| 64 | parameters = [["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 | |
---|
| 68 | def Iq(q, peak_pos, peak_hwhm): |
---|
[04b0b30] | 69 | """ |
---|
| 70 | Return I(q) |
---|
| 71 | """ |
---|
[2f6f4c3] | 72 | inten = (1/(1+((q-peak_pos)/peak_hwhm)**2)) |
---|
| 73 | return inten |
---|
| 74 | Iq.vectorized = True # Iq accepts an array of q values |
---|
| 75 | |
---|
[404ebbd] | 76 | def random(): |
---|
[b297ba9] | 77 | """Return a random parameter set for the model.""" |
---|
[404ebbd] | 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 | |
---|
[2f6f4c3] | 88 | demo = dict(scale=100, background=1.0, |
---|
| 89 | peak_pos=0.05, peak_hwhm=0.005) |
---|
| 90 | |
---|
[14ba6f6] | 91 | tests = [[{'scale':100.0, 'background':1.0}, 0.001, 2.0305]] |
---|