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