[0cb1c7a] | 1 | r""" |
---|
| 2 | This model calculates intensity using simple linear function |
---|
| 3 | Definition |
---|
| 4 | ---------- |
---|
| 5 | |
---|
| 6 | The 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 | |
---|
| 16 | References |
---|
| 17 | ---------- |
---|
| 18 | |
---|
| 19 | None. |
---|
| 20 | |
---|
| 21 | """ |
---|
| 22 | from numpy import inf |
---|
| 23 | |
---|
| 24 | name = "line" |
---|
| 25 | title = "Line model" |
---|
| 26 | description = """\ |
---|
| 27 | I(q) = A + B*q |
---|
| 28 | |
---|
| 29 | List of default parameters: |
---|
| 30 | A = intercept |
---|
| 31 | B = slope |
---|
| 32 | """ |
---|
| 33 | category = "shape-independent" |
---|
| 34 | |
---|
| 35 | # pylint: disable=bad-whitespace, line-too-long |
---|
| 36 | # ["name", "units", default, [lower, upper], "type", "description"], |
---|
| 37 | parameters = [["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 | ] |
---|
[fcd5e83] | 40 | # pylint: enable=bad-whitespace, line-too-long |
---|
[0cb1c7a] | 41 | |
---|
| 42 | def 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 | |
---|
| 52 | Iq.vectorized = True # Iq accepts an array of q values |
---|
| 53 | |
---|
| 54 | def 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) |
---|
[fcd5e83] | 63 | return Iq(qx, *args)*Iq(qy, *args) |
---|
[0cb1c7a] | 64 | |
---|
| 65 | Iqxy.vectorized = True # Iqxy accepts an array of qx, qy values |
---|
| 66 | |
---|
[fcd5e83] | 67 | demo = dict(intercept=1.0, slope=1.0) |
---|
[0cb1c7a] | 68 | |
---|
| 69 | oldname = "LineModel" |
---|
[fcd5e83] | 70 | oldpars = dict(intercept='A', slope='B', scale=None, background=None) |
---|
| 71 | |
---|
| 72 | tests = [ |
---|
| 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 | ] |
---|