[0cb1c7a] | 1 | r""" |
---|
| 2 | This model calculates intensity using simple linear function |
---|
[2556095] | 3 | |
---|
[0cb1c7a] | 4 | Definition |
---|
| 5 | ---------- |
---|
| 6 | |
---|
| 7 | The scattering intensity $I(q)$ is calculated as |
---|
| 8 | |
---|
| 9 | .. math:: |
---|
| 10 | |
---|
[34d6cab] | 11 | I(q) = A + B \cdot q |
---|
| 12 | |
---|
| 13 | .. note:: |
---|
| 14 | For 2D plots intensity has different definition than other shape independent models |
---|
| 15 | .. math:: |
---|
| 16 | I(q) = I(qx) \cdot I(qy) |
---|
[0cb1c7a] | 17 | |
---|
[43cb3b8] | 18 | .. figure:: None |
---|
[0cb1c7a] | 19 | |
---|
| 20 | References |
---|
| 21 | ---------- |
---|
| 22 | |
---|
| 23 | None. |
---|
| 24 | |
---|
| 25 | """ |
---|
| 26 | from numpy import inf |
---|
| 27 | |
---|
| 28 | name = "line" |
---|
| 29 | title = "Line model" |
---|
| 30 | description = """\ |
---|
| 31 | I(q) = A + B*q |
---|
| 32 | |
---|
| 33 | List of default parameters: |
---|
| 34 | A = intercept |
---|
| 35 | B = slope |
---|
| 36 | """ |
---|
| 37 | category = "shape-independent" |
---|
| 38 | |
---|
| 39 | # pylint: disable=bad-whitespace, line-too-long |
---|
| 40 | # ["name", "units", default, [lower, upper], "type", "description"], |
---|
[2556095] | 41 | parameters = [["intercept", "1/cm", 1.0, [-inf, inf], "", "intercept in linear model"], |
---|
| 42 | ["slope", "Ang/cm", 1.0, [-inf, inf], "", "slope in linear model"], |
---|
| 43 | ] |
---|
[fcd5e83] | 44 | # pylint: enable=bad-whitespace, line-too-long |
---|
[0cb1c7a] | 45 | |
---|
| 46 | def Iq(q, intercept, slope): |
---|
| 47 | """ |
---|
| 48 | :param q: Input q-value |
---|
| 49 | :param intercept: Intrecept in linear model |
---|
| 50 | :param slope: Slope in linear model |
---|
| 51 | :return: Calculated Intensity |
---|
| 52 | """ |
---|
| 53 | inten = intercept + slope*q |
---|
[e66075f] | 54 | # TODO: In SasView code additional formula for list has been specified. |
---|
[2556095] | 55 | # if inten(x) = intercept + slope*x: |
---|
| 56 | # then if q is a list, Iq=inten(x[0]*math.cos(x[1]))*inten(x[0]*math.sin(x[1])) |
---|
[0cb1c7a] | 57 | return inten |
---|
| 58 | |
---|
| 59 | Iq.vectorized = True # Iq accepts an array of q values |
---|
| 60 | |
---|
| 61 | def Iqxy(qx, qy, *args): |
---|
| 62 | """ |
---|
| 63 | :param qx: Input q_x-value |
---|
| 64 | :param qy: Input q_y-value |
---|
| 65 | :param args: Remaining arguments |
---|
| 66 | :return: 2D-Intensity |
---|
| 67 | """ |
---|
[e66075f] | 68 | # TODO: SasView documention lists 2D intensity as Iq(qx)*Iq(qy) but code says: |
---|
[2556095] | 69 | # return self._line(x[1]) |
---|
| 70 | return Iq(qx, *args)*Iq(qy, *args) |
---|
[0cb1c7a] | 71 | |
---|
[2556095] | 72 | Iqxy.vectorized = True # Iqxy accepts an array of qx, qy values |
---|
[0cb1c7a] | 73 | |
---|
[0a4628d] | 74 | demo = dict(scale=1.0, background=0, intercept=1.0, slope=1.0) |
---|
[0cb1c7a] | 75 | |
---|
| 76 | oldname = "LineModel" |
---|
[0a4628d] | 77 | oldpars = dict(intercept='A', slope='B', background=None, scale=None) |
---|
[fcd5e83] | 78 | |
---|
| 79 | tests = [ |
---|
[2fb1d88] | 80 | |
---|
[fcd5e83] | 81 | [{'intercept': 1.0, |
---|
| 82 | 'slope': 1.0, |
---|
[2556095] | 83 | }, 1.0, 2.0], |
---|
| 84 | |
---|
| 85 | [{'intercept': 1.0, |
---|
| 86 | 'slope': 1.0, |
---|
| 87 | }, 0.0, 1.0], |
---|
| 88 | |
---|
| 89 | [{'intercept': 1.0, |
---|
| 90 | 'slope': 1.0, |
---|
[43cb3b8] | 91 | }, 0.4, 1.4], |
---|
| 92 | |
---|
| 93 | [{'intercept': 1.0, |
---|
| 94 | 'slope': 1.0, |
---|
| 95 | }, 1.3, 2.3], |
---|
[fcd5e83] | 96 | |
---|
| 97 | [{'intercept': 1.0, |
---|
| 98 | 'slope': 1.0, |
---|
[0a4628d] | 99 | }, 0.5, 1.5], |
---|
[fcd5e83] | 100 | |
---|
| 101 | [{'intercept': 1.0, |
---|
| 102 | 'slope': 1.0, |
---|
[0a4628d] | 103 | }, [0.4, 0.5], [1.4, 1.5]], |
---|
[fcd5e83] | 104 | |
---|
| 105 | [{'intercept': 1.0, |
---|
| 106 | 'slope': 1.0, |
---|
[2556095] | 107 | }, (1.3, 1.57), 5.911], |
---|
[0a4628d] | 108 | ] |
---|