[48be770] | 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 | |
---|
[525f3a9] | 12 | I(q) = \text{scale} \cdot q^{-power} + \text{background} |
---|
[48be770] | 13 | |
---|
[525f3a9] | 14 | Note the minus sign in front of the exponent. The exponent *power* |
---|
| 15 | should therefore be entered as a **positive** number for fitting. |
---|
[48be770] | 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 | .. image:: img/power_law_1d.jpg |
---|
| 22 | |
---|
| 23 | *Figure. 1D plot using the default values (w/200 data point).* |
---|
| 24 | |
---|
| 25 | REFERENCE |
---|
| 26 | |
---|
| 27 | None. |
---|
| 28 | """ |
---|
| 29 | |
---|
| 30 | from numpy import inf, sqrt |
---|
| 31 | |
---|
| 32 | name = "power_law" |
---|
| 33 | title = "Simple power law with a flat background" |
---|
| 34 | |
---|
| 35 | description = """\ |
---|
| 36 | Evaluates the function |
---|
[525f3a9] | 37 | I(q) = scale * q^(-power) + background |
---|
| 38 | NB: enter power as a positive number! |
---|
[48be770] | 39 | """ |
---|
| 40 | category = "shape-independent" |
---|
| 41 | |
---|
| 42 | # ["name", "units", default, [lower, upper], "type", "description"], |
---|
[525f3a9] | 43 | parameters = [["power", "", 4.0, [-inf, inf], "", "Power law exponent"]] |
---|
[48be770] | 44 | |
---|
[525f3a9] | 45 | # NB: Scale and Background are implicit parameters on every model |
---|
| 46 | def Iq(q,power): |
---|
| 47 | inten = (q**-power) |
---|
[48be770] | 48 | return inten |
---|
| 49 | Iq.vectorized = True # Iq accepts an array of Q values |
---|
| 50 | |
---|
| 51 | def Iqxy(qx, qy, *args): |
---|
| 52 | return Iq(sqrt(qx ** 2 + qy ** 2), *args) |
---|
| 53 | Iqxy.vectorized = True # Iqxy accepts an array of Qx, Qy values |
---|
| 54 | |
---|
| 55 | demo = dict(scale=1.0, |
---|
[525f3a9] | 56 | power=4.0, |
---|
| 57 | background=0.0) |
---|
[48be770] | 58 | |
---|
| 59 | oldname = "PowerLawAbsModel" |
---|
| 60 | oldpars = dict(scale='scale', |
---|
[525f3a9] | 61 | power='m', |
---|
| 62 | background='background') |
---|
[8fe0b9b] | 63 | |
---|
| 64 | tests = [ |
---|
[525f3a9] | 65 | [ {'scale': 1.0, 'power': 4.0, 'background' : 0.0}, [0.0106939, 0.469418], [7.64644e+07, 20.5949]] |
---|
[8fe0b9b] | 66 | ] |
---|