source: sasmodels/sasmodels/models/power_law.py @ 525f3a9

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

Scale & Background removed from model calculation as implicit parameters
in sasmodels models; parameter 'm' changed to 'power'; re-parameterized
with just q and 'power'.

  • Property mode set to 100644
File size: 1.7 KB
Line 
1#power_law model
2#conversion of PowerLawAbsModel.py
3
4r"""
5This model calculates a simple power law with a flat background.
6
7Definition
8----------
9
10.. math::
11
12    I(q) = \text{scale} \cdot q^{-power} + \text{background}
13
14Note the minus sign in front of the exponent. The exponent *power*
15should therefore be entered as a **positive** number for fitting.
16
17Also note that unlike many other models, *scale* in this model
18is NOT explicitly related to a volume fraction. Be careful if
19combining this model with other models.
20
21.. image:: img/power_law_1d.jpg
22
23*Figure. 1D plot using the default values (w/200 data point).*
24
25REFERENCE
26
27None.
28"""
29
30from numpy import inf, sqrt
31
32name =  "power_law"
33title = "Simple power law with a flat background"
34
35description = """\
36        Evaluates the function
37        I(q) = scale * q^(-power) + background
38        NB: enter power as a positive number!
39        """
40category = "shape-independent"
41
42#             ["name", "units", default, [lower, upper], "type", "description"],
43parameters = [["power", "", 4.0, [-inf, inf], "", "Power law exponent"]]
44
45# NB: Scale and Background are implicit parameters on every model
46def Iq(q,power):
47    inten = (q**-power)
48    return inten
49Iq.vectorized = True  # Iq accepts an array of Q values
50
51def Iqxy(qx, qy, *args):
52    return Iq(sqrt(qx ** 2 + qy ** 2), *args)
53Iqxy.vectorized = True # Iqxy accepts an array of Qx, Qy values
54
55demo = dict(scale=1.0,
56            power=4.0,
57            background=0.0)
58
59oldname = "PowerLawAbsModel"
60oldpars = dict(scale='scale',
61               power='m',
62               background='background')
63
64tests = [
65        [ {'scale': 1.0, 'power': 4.0, 'background' : 0.0}, [0.0106939, 0.469418], [7.64644e+07, 20.5949]]
66        ]
Note: See TracBrowser for help on using the repository browser.