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:: img/broad_peak_1d.jpg |
---|
13 | |
---|
14 | 1D plot using the default values (w/200 data point). |
---|
15 | |
---|
16 | References |
---|
17 | ---------- |
---|
18 | |
---|
19 | None. |
---|
20 | |
---|
21 | """ |
---|
22 | |
---|
23 | from numpy import vectorize |
---|
24 | from numpy import inf |
---|
25 | |
---|
26 | name = "line" |
---|
27 | title = "Line model" |
---|
28 | description = """\ |
---|
29 | I(q) = A + B*q |
---|
30 | |
---|
31 | List of default parameters: |
---|
32 | A = intercept |
---|
33 | B = slope |
---|
34 | """ |
---|
35 | category = "shape-independent" |
---|
36 | |
---|
37 | # pylint: disable=bad-whitespace, line-too-long |
---|
38 | # ["name", "units", default, [lower, upper], "type", "description"], |
---|
39 | parameters = [["intercept", "cm^-1", 1.0, [-inf, inf], "", "intercept in linear model"], |
---|
40 | ["slope", "Ang*cm^-1", 1.0, [-inf, inf], "", "slope in linear model"], |
---|
41 | ] |
---|
42 | |
---|
43 | def Iq(q, intercept, slope): |
---|
44 | """ |
---|
45 | :param q: Input q-value |
---|
46 | :param intercept: Intrecept in linear model |
---|
47 | :param slope: Slope in linear model |
---|
48 | :return: Calculated Intensity |
---|
49 | """ |
---|
50 | |
---|
51 | inten = intercept + slope*q |
---|
52 | return inten |
---|
53 | |
---|
54 | Iq.vectorized = True # Iq accepts an array of q values |
---|
55 | |
---|
56 | def Iqxy(qx, qy, *args): |
---|
57 | """ |
---|
58 | :param qx: Input q_x-value |
---|
59 | :param qy: Input q_y-value |
---|
60 | :param args: Remaining arguments |
---|
61 | :return: 2D-Intensity |
---|
62 | """ |
---|
63 | #TODO: Instrcution tels 2D has different deffinition than oher models |
---|
64 | #return Iq(sqrt(qx ** 2 + qy ** 2), *args) |
---|
65 | return Iq(qx,*args)*Iq(qy,*args) |
---|
66 | |
---|
67 | Iqxy.vectorized = True # Iqxy accepts an array of qx, qy values |
---|
68 | |
---|
69 | demo = dict(scale=1, background=0.1, |
---|
70 | intercept=1.0, slope=1.0) |
---|
71 | |
---|
72 | oldname = "LineModel" |
---|
73 | oldpars = dict(intercept='A', slope='B', scale=None) |
---|