source: sasmodels/sasmodels/models/line.py @ 99658f6

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 99658f6 was 108e70e, checked in by Paul Kienzle <pkienzle@…>, 6 years ago

use Iqac/Iqabc? for the new orientation interface but Iqxy for the old

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