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

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since fc0b7aa was c63a7c8, checked in by lewis, 7 years ago

Change line.py docs

  • Property mode set to 100644
File size: 2.5 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) = \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
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    return inten
55
56Iq.vectorized = True # Iq accepts an array of q values
57
58def 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
69Iqxy.vectorized = True  # Iqxy accepts an array of qx qy values
70
71def 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
85tests = [
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]
Note: See TracBrowser for help on using the repository browser.