1 | r""" |
---|
2 | This model calculates intensity using simple linear function |
---|
3 | Definition |
---|
4 | ---------- |
---|
5 | |
---|
6 | The scattering intensity $I(q)$ is calculated as |
---|
7 | |
---|
8 | .. math:: |
---|
9 | |
---|
10 | I(q) = A + B*q |
---|
11 | |
---|
12 | .. figure:: None |
---|
13 | |
---|
14 | References |
---|
15 | ---------- |
---|
16 | |
---|
17 | None. |
---|
18 | |
---|
19 | """ |
---|
20 | from numpy import inf |
---|
21 | |
---|
22 | name = "line" |
---|
23 | title = "Line model" |
---|
24 | description = """\ |
---|
25 | I(q) = A + B*q |
---|
26 | |
---|
27 | List of default parameters: |
---|
28 | A = intercept |
---|
29 | B = slope |
---|
30 | """ |
---|
31 | category = "shape-independent" |
---|
32 | |
---|
33 | # pylint: disable=bad-whitespace, line-too-long |
---|
34 | # ["name", "units", default, [lower, upper], "type", "description"], |
---|
35 | parameters = [["intercept", "cm^-1", 1.0, [-inf, inf], "", "intercept in linear model"], |
---|
36 | ["slope", "Ang*cm^-1", 1.0, [-inf, inf], "", "slope in linear model"], |
---|
37 | ] |
---|
38 | # pylint: enable=bad-whitespace, line-too-long |
---|
39 | |
---|
40 | def Iq(q, intercept, slope): |
---|
41 | """ |
---|
42 | :param q: Input q-value |
---|
43 | :param intercept: Intrecept in linear model |
---|
44 | :param slope: Slope in linear model |
---|
45 | :return: Calculated Intensity |
---|
46 | """ |
---|
47 | inten = intercept + slope*q |
---|
48 | return inten |
---|
49 | |
---|
50 | Iq.vectorized = True # Iq accepts an array of q values |
---|
51 | |
---|
52 | def Iqxy(qx, qy, *args): |
---|
53 | """ |
---|
54 | :param qx: Input q_x-value |
---|
55 | :param qy: Input q_y-value |
---|
56 | :param args: Remaining arguments |
---|
57 | :return: 2D-Intensity |
---|
58 | """ |
---|
59 | #TODO: Instrcution tels 2D has different deffinition than oher models |
---|
60 | #return Iq(sqrt(qx ** 2 + qy ** 2), *args) |
---|
61 | return Iq(qx, *args)*Iq(qy, *args) |
---|
62 | |
---|
63 | Iqxy.vectorized = True # Iqxy accepts an array of qx, qy values |
---|
64 | |
---|
65 | demo = dict(intercept=1.0, slope=1.0) |
---|
66 | |
---|
67 | oldname = "LineModel" |
---|
68 | oldpars = dict(intercept='A', slope='B', scale=None, background=None) |
---|
69 | |
---|
70 | tests = [ |
---|
71 | # Accuracy tests based on content in test/utest_other_models.py |
---|
72 | [{'intercept': 1.0, |
---|
73 | 'slope': 1.0, |
---|
74 | }, 0.4, 1.4], |
---|
75 | |
---|
76 | [{'intercept': 1.0, |
---|
77 | 'slope': 1.0, |
---|
78 | }, 1.3, 2.3], |
---|
79 | |
---|
80 | [{'intercept': 1.0, |
---|
81 | 'slope': 1.0, |
---|
82 | },0.5, 1.5], |
---|
83 | |
---|
84 | [{'intercept': 1.0, |
---|
85 | 'slope': 1.0, |
---|
86 | }, [0.4,0.5], [1.4,1.5]], |
---|
87 | |
---|
88 | [{'intercept': 1.0, |
---|
89 | 'slope': 1.0, |
---|
90 | }, [1.3,1.57], [2.3,2.57]], |
---|
91 | ] |
---|