source: sasmodels/sasmodels/models/line.py @ 48462b0

core_shell_microgelscostrafo411magnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 48462b0 was 48462b0, checked in by Paul Kienzle <pkienzle@…>, 7 years ago

tuned random model generation for even more models

  • 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    I(q) = \text{scale} (I(qx) \cdot I(qy)) + \text{background}
18
19References
20----------
21
22None.
23
24"""
25from numpy import inf
26
27name = "line"
28title = "Line model"
29description = """\
30      I(q) = A + B*q
31
32      List of default parameters:
33      A = intercept
34      B = slope
35      """
36category = "shape-independent"
37
38# pylint: disable=bad-whitespace, line-too-long
39#             ["name", "units", default, [lower, upper], "type", "description"],
40parameters = [["intercept", "1/cm",   1.0, [-inf, inf], "", "intercept in linear model"],
41              ["slope",     "Ang/cm", 1.0, [-inf, inf], "", "slope in linear model"],
42             ]
43# pylint: enable=bad-whitespace, line-too-long
44
45def Iq(q, intercept, slope):
46    """
47    :param q:           Input q-value
48    :param intercept:   Intrecept in linear model
49    :param slope:       Slope in linear model
50    :return:            Calculated Intensity
51    """
52    inten = intercept + slope*q
53    return inten
54
55Iq.vectorized = True # Iq accepts an array of q values
56
57def Iqxy(qx, qy, *args):
58    """
59    :param qx:   Input q_x-value
60    :param qy:   Input q_y-value
61    :param args: Remaining arguments
62    :return:     2D-Intensity
63    """
64    # TODO: SasView documents 2D intensity as Iq(qx)*Iq(qy), but returns Iq(qy)
65    # Note: SasView.run([r, theta]) does return Iq(qx)*Iq(qy)
66    return Iq(qx, *args)*Iq(qy, *args)
67
68Iqxy.vectorized = True  # Iqxy accepts an array of qx qy values
69
70def random():
71    import numpy as np
72    scale = 10**np.random.uniform(0, 3)
73    slope = np.random.uniform(-1, 1)*1e2
74    offset = 1e-5 + (0 if slope > 0 else -slope)
75    intercept = 10**np.random.uniform(0, 1) + offset
76    pars = dict(
77        #background=0,
78        scale=scale,
79        slope=slope,
80        intercept=intercept,
81    )
82    return pars
83
84tests = [
85    [{'intercept': 1.0, 'slope': 1.0, }, 1.0, 2.001],
86    [{'intercept': 1.0, 'slope': 1.0, }, 0.0, 1.001],
87    [{'intercept': 1.0, 'slope': 1.0, }, 0.4, 1.401],
88    [{'intercept': 1.0, 'slope': 1.0, }, 1.3, 2.301],
89    [{'intercept': 1.0, 'slope': 1.0, }, 0.5, 1.501],
90    [{'intercept': 1.0, 'slope': 1.0, }, [0.4, 0.5], [1.401, 1.501]],
91    [{'intercept': 1.0, 'slope': 1.0, 'background': 0.0, }, (1.3, 1.57), 5.911],
92]
Note: See TracBrowser for help on using the repository browser.