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