source: sasmodels/sasmodels/models/power_law.py @ b15849c

core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since b15849c was b15849c, checked in by smk78, 8 years ago

Added a comment

  • 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.. figure:: img/power_law_1d.jpg
23
24    1D plot using the default values (w/200 data point).
25
26References
27----------
28
29None.
30"""
31
32from numpy import inf, sqrt
33
34name = "power_law"
35title = "Simple power law with a flat background"
36
37description = """
38    Evaluates the function
39    I(q) = scale * q^(-power) + background
40    NB: enter power as a positive number!
41    """
42category = "shape-independent"
43
44#             ["name", "units", default, [lower, upper], "type", "description"],
45parameters = [["power", "", 4.0, [-inf, inf], "", "Power law exponent"]]
46
47# NB: Scale and Background are implicit parameters on every model
48def Iq(q, power):
49    # pylint: disable=missing-docstring
50    inten = (q**-power)
51    return inten
52Iq.vectorized = True  # Iq accepts an array of q values
53
54def Iqxy(qx, qy, *args):
55    # pylint: disable=missing-docstring
56    return Iq(sqrt(qx ** 2 + qy ** 2), *args)
57Iqxy.vectorized = True # Iqxy accepts an array of qx, qy values
58
59demo = dict(scale=1.0,
60            power=4.0,
61            background=0.0)
62
63oldname = "PowerLawAbsModel"
64oldpars = dict(scale='scale',
65               power='m',
66               background='background')
67
68tests = [
69    [{'scale': 1.0, 'power': 4.0, 'background' : 0.0},
70     [0.0106939, 0.469418], [7.64644e+07, 20.5949]],
71    ]
Note: See TracBrowser for help on using the repository browser.