source: sasmodels/sasmodels/models/line.py @ 43cb3b8

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

Test sets added for array comparison

  • Property mode set to 100644
File size: 2.2 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*q
11
12.. figure:: None
13
14References
15----------
16
17None.
18
19"""
20from numpy import inf
21
22name = "line"
23title = "Line model"
24description = """\
25      I(q) = A + B*q
26
27      List of default parameters:
28      A = intercept
29      B = slope
30      """
31category = "shape-independent"
32
33# pylint: disable=bad-whitespace, line-too-long
34#             ["name", "units", default, [lower, upper], "type", "description"],
35parameters = [["intercept",     "cm^-1",        1.0, [-inf, inf], "", "intercept in linear model"],
36              ["slope",     "Ang*cm^-1",    1.0, [-inf, inf], "", "slope in linear model"],
37              ]
38# pylint: enable=bad-whitespace, line-too-long
39
40def Iq(q, intercept, slope):
41    """
42    :param q:           Input q-value
43    :param intercept:   Intrecept in linear model
44    :param slope:       Slope in linear model
45    :return:            Calculated Intensity
46    """
47    inten = intercept + slope*q
48    return inten
49
50Iq.vectorized = True # Iq accepts an array of q values
51
52def Iqxy(qx, qy, *args):
53    """
54    :param qx:   Input q_x-value
55    :param qy:   Input q_y-value
56    :param args: Remaining arguments
57    :return:     2D-Intensity
58    """
59    #TODO: Instrcution tels 2D has different deffinition than oher models
60    #return Iq(sqrt(qx ** 2 + qy ** 2), *args)
61    return  Iq(qx, *args)*Iq(qy, *args)
62
63Iqxy.vectorized = True # Iqxy accepts an array of qx, qy values
64
65demo = dict(intercept=1.0, slope=1.0)
66
67oldname = "LineModel"
68oldpars = dict(intercept='A', slope='B', scale=None, background=None)
69
70tests = [
71    # Accuracy tests based on content in test/utest_other_models.py
72    [{'intercept':   1.0,
73      'slope': 1.0,
74     }, 0.4, 1.4],
75
76    [{'intercept':   1.0,
77      'slope': 1.0,
78     }, 1.3, 2.3],
79
80    [{'intercept':   1.0,
81      'slope': 1.0,
82     },0.5, 1.5],
83
84    [{'intercept':   1.0,
85      'slope': 1.0,
86     }, [0.4,0.5], [1.4,1.5]],
87
88    [{'intercept':   1.0,
89      'slope': 1.0,
90     }, [1.3,1.57], [2.3,2.57]],
91]
Note: See TracBrowser for help on using the repository browser.