[3330bb4] | 1 | r""" |
---|
| 2 | This model calculates intensity using simple linear function |
---|
| 3 | |
---|
| 4 | Definition |
---|
| 5 | ---------- |
---|
| 6 | |
---|
| 7 | The scattering intensity $I(q)$ is calculated as |
---|
| 8 | |
---|
| 9 | .. math:: |
---|
| 10 | |
---|
| 11 | I(q) = \text{scale} (A + B \cdot q) + \text{background} |
---|
| 12 | |
---|
| 13 | .. note:: |
---|
| 14 | For 2D plots intensity has different definition than other shape independent models |
---|
| 15 | |
---|
| 16 | .. math:: |
---|
[c63a7c8] | 17 | |
---|
[3330bb4] | 18 | I(q) = \text{scale} (I(qx) \cdot I(qy)) + \text{background} |
---|
| 19 | |
---|
| 20 | References |
---|
| 21 | ---------- |
---|
| 22 | |
---|
| 23 | None. |
---|
| 24 | """ |
---|
[2d81cfe] | 25 | |
---|
| 26 | import numpy as np |
---|
[3330bb4] | 27 | from numpy import inf |
---|
| 28 | |
---|
| 29 | name = "line" |
---|
| 30 | title = "Line model" |
---|
| 31 | description = """\ |
---|
| 32 | I(q) = A + B*q |
---|
| 33 | |
---|
| 34 | List of default parameters: |
---|
| 35 | A = intercept |
---|
| 36 | B = slope |
---|
| 37 | """ |
---|
| 38 | category = "shape-independent" |
---|
| 39 | |
---|
| 40 | # pylint: disable=bad-whitespace, line-too-long |
---|
| 41 | # ["name", "units", default, [lower, upper], "type", "description"], |
---|
| 42 | parameters = [["intercept", "1/cm", 1.0, [-inf, inf], "", "intercept in linear model"], |
---|
| 43 | ["slope", "Ang/cm", 1.0, [-inf, inf], "", "slope in linear model"], |
---|
| 44 | ] |
---|
| 45 | # pylint: enable=bad-whitespace, line-too-long |
---|
| 46 | |
---|
| 47 | def Iq(q, intercept, slope): |
---|
| 48 | """ |
---|
| 49 | :param q: Input q-value |
---|
| 50 | :param intercept: Intrecept in linear model |
---|
| 51 | :param slope: Slope in linear model |
---|
| 52 | :return: Calculated Intensity |
---|
| 53 | """ |
---|
| 54 | inten = intercept + slope*q |
---|
| 55 | return inten |
---|
| 56 | |
---|
| 57 | Iq.vectorized = True # Iq accepts an array of q values |
---|
| 58 | |
---|
[108e70e] | 59 | |
---|
[3330bb4] | 60 | def Iqxy(qx, qy, *args): |
---|
| 61 | """ |
---|
| 62 | :param qx: Input q_x-value |
---|
| 63 | :param qy: Input q_y-value |
---|
| 64 | :param args: Remaining arguments |
---|
| 65 | :return: 2D-Intensity |
---|
| 66 | """ |
---|
| 67 | # TODO: SasView documents 2D intensity as Iq(qx)*Iq(qy), but returns Iq(qy) |
---|
| 68 | # Note: SasView.run([r, theta]) does return Iq(qx)*Iq(qy) |
---|
| 69 | return Iq(qx, *args)*Iq(qy, *args) |
---|
| 70 | |
---|
| 71 | Iqxy.vectorized = True # Iqxy accepts an array of qx qy values |
---|
| 72 | |
---|
[108e70e] | 73 | # uncomment the following to test Iqxy in C models |
---|
| 74 | #del Iq, Iqxy |
---|
| 75 | #c_code = """ |
---|
| 76 | #static double Iq(double q, double b, double m) { return m*q+b; } |
---|
| 77 | #static double Iqxy(double qx, double qy, double b, double m) |
---|
| 78 | #{ return (m*qx+b)*(m*qy+b); } |
---|
| 79 | #""" |
---|
| 80 | |
---|
[404ebbd] | 81 | def random(): |
---|
[48462b0] | 82 | scale = 10**np.random.uniform(0, 3) |
---|
| 83 | slope = np.random.uniform(-1, 1)*1e2 |
---|
[404ebbd] | 84 | offset = 1e-5 + (0 if slope > 0 else -slope) |
---|
[48462b0] | 85 | intercept = 10**np.random.uniform(0, 1) + offset |
---|
[404ebbd] | 86 | pars = dict( |
---|
[48462b0] | 87 | #background=0, |
---|
| 88 | scale=scale, |
---|
[404ebbd] | 89 | slope=slope, |
---|
| 90 | intercept=intercept, |
---|
| 91 | ) |
---|
| 92 | return pars |
---|
[3330bb4] | 93 | |
---|
| 94 | tests = [ |
---|
| 95 | [{'intercept': 1.0, 'slope': 1.0, }, 1.0, 2.001], |
---|
| 96 | [{'intercept': 1.0, 'slope': 1.0, }, 0.0, 1.001], |
---|
| 97 | [{'intercept': 1.0, 'slope': 1.0, }, 0.4, 1.401], |
---|
| 98 | [{'intercept': 1.0, 'slope': 1.0, }, 1.3, 2.301], |
---|
| 99 | [{'intercept': 1.0, 'slope': 1.0, }, 0.5, 1.501], |
---|
| 100 | [{'intercept': 1.0, 'slope': 1.0, }, [0.4, 0.5], [1.401, 1.501]], |
---|
| 101 | [{'intercept': 1.0, 'slope': 1.0, 'background': 0.0, }, (1.3, 1.57), 5.911], |
---|
| 102 | ] |
---|