File: peak_lorentz.py

package info (click to toggle)
mccode 3.5.19%2Bds5-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,113,256 kB
  • sloc: ansic: 40,697; python: 25,137; yacc: 8,438; sh: 5,405; javascript: 4,596; lex: 1,632; cpp: 742; perl: 296; lisp: 273; makefile: 226; fortran: 132
file content (80 lines) | stat: -rw-r--r-- 1,995 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
r"""
This model describes a Lorentzian shaped peak on a flat background.

Definition
----------

The scattering intensity $I(q)$ is calculated as

.. math::

    I(q) = \frac{scale}{\bigl(1+\bigl(\frac{q-q_0}{B}\bigr)^2\bigr)} + background

with the peak having height of $I_0$ centered at $q_0$ and having
a HWHM (half-width half-maximum) of B.

For 2D data the scattering intensity is calculated in the same way as 1D,
where the $q$ vector is defined as

.. math::

    q = \sqrt{q_x^2 + q_y^2}


References
----------

None.

Authorship and Verification
----------------------------

* **Author:**
* **Last Modified by:**
* **Last Reviewed by:**
"""

import numpy as np
from numpy import inf

name = "peak_lorentz"
title = "A Lorentzian peak on a flat background"
description = """\
      Class that evaluates a Lorentzian shaped peak.

        F(q) = scale/(1+[(q-q0)/B]^2 ) + background

        The model has three parameters:
            scale     =  scale
            peak_pos        =  peak position
            peak_hwhm        =  half-width-half-maximum of peak
            background=  incoherent background"""

category = "shape-independent"

#             ["name", "units", default, [lower, upper], "type", "description"],
parameters = [["peak_pos", "1/Ang", 0.05, [-inf, inf], "", "Peak postion in q"],
              ["peak_hwhm", "1/Ang", 0.005, [-inf, inf], "", "HWHM of peak"],
             ]

def Iq(q, peak_pos, peak_hwhm):
    """
        Return I(q)
    """
    inten = (1/(1+((q-peak_pos)/peak_hwhm)**2))
    return inten
Iq.vectorized = True  # Iq accepts an array of q values

def random():
    """Return a random parameter set for the model."""
    peak_pos = 10**np.random.uniform(-3, -1)
    peak_hwhm = peak_pos * 10**np.random.uniform(-3, 0)
    pars = dict(
        #background=0,
        scale=10**np.random.uniform(2, 6),
        peak_pos=peak_pos,
        peak_hwhm=peak_hwhm,
    )
    return pars

tests = [[{'scale':100.0, 'background':1.0}, 0.001, 2.0305]]