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^{-m} + \text{background} |
---|

13 | |
---|

14 | Note the minus sign in front of the exponent. The exponent *m* |
---|

15 | should therefore be entered as a **positive** number. |
---|

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 |
---|

37 | I(q) = scale * q^(-m) + bkgd |
---|

38 | NB: enter m as a positive number! |
---|

39 | """ |
---|

40 | category = "shape-independent" |
---|

41 | |
---|

42 | # ["name", "units", default, [lower, upper], "type", "description"], |
---|

43 | parameters = [["scale", "", 1.0, [-inf, inf], "", "Power law scale factor"], |
---|

44 | ["m", "", 4.0, [-inf, inf], "", "Power law exponent"], |
---|

45 | ["bkgd", "", 0.0, [-inf, inf], "", "Background level"]] |
---|

46 | |
---|

47 | def Iq(scale,m,bkgd): |
---|

48 | inten = (scale * q ** m + bkgd) |
---|

49 | return inten |
---|

50 | Iq.vectorized = True # Iq accepts an array of Q values |
---|

51 | |
---|

52 | def Iqxy(qx, qy, *args): |
---|

53 | return Iq(sqrt(qx ** 2 + qy ** 2), *args) |
---|

54 | Iqxy.vectorized = True # Iqxy accepts an array of Qx, Qy values |
---|

55 | |
---|

56 | demo = dict(scale=1.0, |
---|

57 | m=4.0, |
---|

58 | bkgd=0.0) |
---|

59 | |
---|

60 | oldname = "PowerLawAbsModel" |
---|

61 | oldpars = dict(scale='scale', |
---|

62 | m='m', |
---|

63 | bkgd='background') |
---|

64 | |
---|

65 | tests = [ |
---|

66 | [ {'scale': 1.0, 'm': 4.0, 'bkgd' : 0.0}, [0.0106939, 0.469418], [7.64644e+07, 20.5949]] |
---|

67 | ] |
---|