source: sasmodels/sasmodels/models/line.py @ 4932fdd

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

Line model - pylint cleaned-up

  • Property mode set to 100644
File size: 2.4 KB
Line 
1r"""
2This model calculates intensity using simple linear function
3Definition
4----------
5
6The scattering intensity $I(q)$ is calculated as
7
8.. math::
9
10    I(q) = A + B \cdot q
11
12.. note::
13    For 2D plots intensity has different definition than other shape independent models
14.. math::
15    I(q) = I(qx) \cdot I(qy)
16
17.. figure:: None
18
19References
20----------
21
22None.
23
24"""
25from numpy import inf
26from numpy import cos
27from numpy import sin
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
59def Iqxy(qx, qy, *args):
60    """
61    :param qx:   Input q_x-value
62    :param qy:   Input q_y-value
63    :param args: Remaining arguments
64    :return:     2D-Intensity
65    """
66    #TODO: Instrcution tels 2D has different deffinition than oher models
67    #return  Iq(qy,*args)*Iq(qy,*args)
68    return  Iq(qx, *args)*Iq(qy, *args)
69
70Iqxy.vectorized = True # Iqxy accepts an array of qx, qy values
71
72demo = dict(scale=1.0, background=0, intercept=1.0, slope=1.0)
73
74oldname = "LineModel"
75oldpars = dict(intercept='A', slope='B', background=None, scale=None)
76
77tests = [
78    # Accuracy tests based on content in test/utest_other_models.py
79    [{'intercept':   1.0,
80      'slope': 1.0,
81     }, 0.4, 1.4],
82
83    [{'intercept':   1.0,
84      'slope': 1.0,
85     }, 1.3, 2.3],
86
87    [{'intercept':   1.0,
88      'slope': 1.0,
89     }, 0.5, 1.5],
90
91    [{'intercept':   1.0,
92      'slope': 1.0,
93     }, [0.4, 0.5], [1.4, 1.5]],
94
95    [{'intercept':   1.0,
96      'slope': 1.0,
97     }, (1.3, 1.57),2.30238060425],
98]
Note: See TracBrowser for help on using the repository browser.