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

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

Added unit tests to line model

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