[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 | |
---|
[eb69cce] | 12 | I(q) = \text{scale} \cdot q^{-\text{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 | |
---|
[eb69cce] | 21 | .. figure:: img/power_law_1d.jpg |
---|
[48be770] | 22 | |
---|
[eb69cce] | 23 | 1D plot using the default values (w/200 data point). |
---|
[48be770] | 24 | |
---|
[eb69cce] | 25 | References |
---|
| 26 | ---------- |
---|
[48be770] | 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 |
---|
[525f3a9] | 38 | I(q) = scale * q^(-power) + background |
---|
| 39 | NB: enter power as a positive number! |
---|
[48be770] | 40 | """ |
---|
| 41 | category = "shape-independent" |
---|
| 42 | |
---|
| 43 | # ["name", "units", default, [lower, upper], "type", "description"], |
---|
[525f3a9] | 44 | parameters = [["power", "", 4.0, [-inf, inf], "", "Power law exponent"]] |
---|
[48be770] | 45 | |
---|
[525f3a9] | 46 | # NB: Scale and Background are implicit parameters on every model |
---|
| 47 | def Iq(q,power): |
---|
| 48 | inten = (q**-power) |
---|
[48be770] | 49 | return inten |
---|
[eb69cce] | 50 | Iq.vectorized = True # Iq accepts an array of q values |
---|
[48be770] | 51 | |
---|
| 52 | def Iqxy(qx, qy, *args): |
---|
| 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 = [ |
---|
[525f3a9] | 66 | [ {'scale': 1.0, 'power': 4.0, 'background' : 0.0}, [0.0106939, 0.469418], [7.64644e+07, 20.5949]] |
---|
[8fe0b9b] | 67 | ] |
---|