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:: |
---|
17 | |
---|
18 | I(q) = \text{scale} (I(qx) \cdot I(qy)) + \text{background} |
---|
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"], |
---|
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 | ] |
---|
44 | # pylint: enable=bad-whitespace, line-too-long |
---|
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 |
---|
54 | return inten |
---|
55 | |
---|
56 | Iq.vectorized = True # Iq accepts an array of q values |
---|
57 | |
---|
58 | def Iqxy(qx, qy, *args): |
---|
59 | """ |
---|
60 | :param qx: Input q_x-value |
---|
61 | :param qy: Input q_y-value |
---|
62 | :param args: Remaining arguments |
---|
63 | :return: 2D-Intensity |
---|
64 | """ |
---|
65 | # TODO: SasView documents 2D intensity as Iq(qx)*Iq(qy), but returns Iq(qy) |
---|
66 | # Note: SasView.run([r, theta]) does return Iq(qx)*Iq(qy) |
---|
67 | return Iq(qx, *args)*Iq(qy, *args) |
---|
68 | |
---|
69 | Iqxy.vectorized = True # Iqxy accepts an array of qx qy values |
---|
70 | |
---|
71 | def random(): |
---|
72 | import numpy as np |
---|
73 | scale = 10**np.random.uniform(0, 3) |
---|
74 | slope = np.random.uniform(-1, 1)*1e2 |
---|
75 | offset = 1e-5 + (0 if slope > 0 else -slope) |
---|
76 | intercept = 10**np.random.uniform(0, 1) + offset |
---|
77 | pars = dict( |
---|
78 | #background=0, |
---|
79 | scale=scale, |
---|
80 | slope=slope, |
---|
81 | intercept=intercept, |
---|
82 | ) |
---|
83 | return pars |
---|
84 | |
---|
85 | tests = [ |
---|
86 | [{'intercept': 1.0, 'slope': 1.0, }, 1.0, 2.001], |
---|
87 | [{'intercept': 1.0, 'slope': 1.0, }, 0.0, 1.001], |
---|
88 | [{'intercept': 1.0, 'slope': 1.0, }, 0.4, 1.401], |
---|
89 | [{'intercept': 1.0, 'slope': 1.0, }, 1.3, 2.301], |
---|
90 | [{'intercept': 1.0, 'slope': 1.0, }, 0.5, 1.501], |
---|
91 | [{'intercept': 1.0, 'slope': 1.0, }, [0.4, 0.5], [1.401, 1.501]], |
---|
92 | [{'intercept': 1.0, 'slope': 1.0, 'background': 0.0, }, (1.3, 1.57), 5.911], |
---|
93 | ] |
---|