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