source: sasmodels/sasmodels/models/line.py @ e66075f

core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since e66075f was e66075f, checked in by wojciech, 8 years ago

Final touches for line model

  • Property mode set to 100644
File size: 2.6 KB
Line 
1r"""
2This model calculates intensity using simple linear function
3
4Definition
5----------
6
7The 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.. math::
16    I(q) = I(qx) \cdot I(qy)
17
18.. figure:: None
19
20References
21----------
22
23None.
24
25"""
26from numpy import inf
27
28name = "line"
29title = "Line model"
30description = """\
31      I(q) = A + B*q
32
33      List of default parameters:
34      A = intercept
35      B = slope
36      """
37category = "shape-independent"
38
39# pylint: disable=bad-whitespace, line-too-long
40#             ["name", "units", default, [lower, upper], "type", "description"],
41parameters = [["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
46def 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    # TODO: In SasView code additional formula for list has been specified.
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]))
57    return inten
58
59Iq.vectorized = True # Iq accepts an array of q values
60
61def 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    """
68    # TODO: SasView documention lists 2D intensity as Iq(qx)*Iq(qy) but code says:
69    # return self._line(x[1])
70    return Iq(qx, *args)*Iq(qy, *args)
71
72Iqxy.vectorized = True  # Iqxy accepts an array of qx, qy values
73
74demo = dict(scale=1.0, background=0, intercept=1.0, slope=1.0)
75
76oldname = "LineModel"
77oldpars = dict(intercept='A', slope='B', background=None, scale=None)
78
79tests = [
80
81    [{'intercept':   1.0,
82      'slope': 1.0,
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,
91     }, 0.4, 1.4],
92
93    [{'intercept':   1.0,
94      'slope': 1.0,
95     }, 1.3, 2.3],
96
97    [{'intercept':   1.0,
98      'slope': 1.0,
99     }, 0.5, 1.5],
100
101    [{'intercept':   1.0,
102      'slope': 1.0,
103     }, [0.4, 0.5], [1.4, 1.5]],
104
105    [{'intercept':   1.0,
106      'slope': 1.0,
107     }, (1.3, 1.57), 5.911],
108]
Note: See TracBrowser for help on using the repository browser.