source: sasmodels/sasmodels/models/power_law.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: 1.8 KB
Line 
1#power_law model
2#conversion of PowerLawAbsModel.py
3#converted by Steve King, Dec 2015
4
5r"""
6This model calculates a simple power law with a flat background.
7
8Definition
9----------
10
11.. math::
12
13    I(q) = \text{scale} \cdot q^{-\text{power}} + \text{background}
14
15Note the minus sign in front of the exponent. The exponent *power*
16should therefore be entered as a **positive** number for fitting.
17
18Also note that unlike many other models, *scale* in this model
19is NOT explicitly related to a volume fraction. Be careful if
20combining this model with other models.
21
22
23References
24----------
25
26None.
27
28Authorship and Verification
29----------------------------
30
31* **Author:**
32* **Last Modified by:**
33* **Last Reviewed by:**
34"""
35
36import numpy as np
37from numpy import inf, errstate
38
39name = "power_law"
40title = "Simple power law with a flat background"
41
42description = """
43    Evaluates the function
44    I(q) = scale * q^(-power) + background
45    NB: enter power as a positive number!
46    """
47category = "shape-independent"
48
49#             ["name", "units", default, [lower, upper], "type", "description"],
50parameters = [["power", "", 4.0, [-inf, inf], "", "Power law exponent"]]
51
52# NB: Scale and Background are implicit parameters on every model
53def Iq(q, power):
54    # pylint: disable=missing-docstring
55    with errstate(divide='ignore'):
56        result = q**-power
57    return result
58Iq.vectorized = True  # Iq accepts an array of q values
59
60def random():
61    """Return a random parameter set for the model."""
62    power = np.random.uniform(1, 6)
63    pars = dict(
64        scale=0.1**power*10**np.random.uniform(-4, 2),
65        power=power,
66    )
67    return pars
68
69demo = dict(scale=1.0, power=4.0, background=0.0)
70
71tests = [
72    [{'scale': 1.0, 'power': 4.0, 'background' : 0.0},
73     [0.0106939, 0.469418], [7.64644e+07, 20.5949]],
74    ]
Note: See TracBrowser for help on using the repository browser.