source: sasmodels/sasmodels/models/power_law.py @ 0507e09

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 0507e09 was 0507e09, checked in by smk78, 5 years ago

Added link to source code to each model. Closes #883

  • Property mode set to 100644
File size: 2.0 KB
RevLine 
[48be770]1#power_law model
2#conversion of PowerLawAbsModel.py
[b15849c]3#converted by Steve King, Dec 2015
[48be770]4
5r"""
6This model calculates a simple power law with a flat background.
7
8Definition
9----------
10
11.. math::
12
[eb69cce]13    I(q) = \text{scale} \cdot q^{-\text{power}} + \text{background}
[48be770]14
[841753c]15Note the minus sign in front of the exponent. The exponent *power*
[525f3a9]16should therefore be entered as a **positive** number for fitting.
[48be770]17
[841753c]18Also note that unlike many other models, *scale* in this model
19is NOT explicitly related to a volume fraction. Be careful if
[48be770]20combining this model with other models.
21
22
[eb69cce]23References
24----------
[48be770]25
26None.
[0507e09]27
28Source
29------
30
31`power_law.py <https://github.com/SasView/sasmodels/blob/master/sasmodels/models/power_law.py>`_
32
33Authorship and Verification
34----------------------------
35
36* **Author:**
37* **Last Modified by:**
38* **Last Reviewed by:**
39* **Source added by :** Steve King **Date:** March 25, 2019
[48be770]40"""
41
[2d81cfe]42import numpy as np
[2c74c11]43from numpy import inf, errstate
[48be770]44
[841753c]45name = "power_law"
[48be770]46title = "Simple power law with a flat background"
47
[841753c]48description = """
49    Evaluates the function
50    I(q) = scale * q^(-power) + background
51    NB: enter power as a positive number!
52    """
[48be770]53category = "shape-independent"
54
55#             ["name", "units", default, [lower, upper], "type", "description"],
[525f3a9]56parameters = [["power", "", 4.0, [-inf, inf], "", "Power law exponent"]]
[48be770]57
[525f3a9]58# NB: Scale and Background are implicit parameters on every model
[841753c]59def Iq(q, power):
60    # pylint: disable=missing-docstring
[2c74c11]61    with errstate(divide='ignore'):
[40a87fa]62        result = q**-power
63    return result
[eb69cce]64Iq.vectorized = True  # Iq accepts an array of q values
[48be770]65
[404ebbd]66def random():
[b297ba9]67    """Return a random parameter set for the model."""
[404ebbd]68    power = np.random.uniform(1, 6)
69    pars = dict(
70        scale=0.1**power*10**np.random.uniform(-4, 2),
71        power=power,
72    )
73    return pars
74
[40a87fa]75demo = dict(scale=1.0, power=4.0, background=0.0)
[48be770]76
[8fe0b9b]77tests = [
[841753c]78    [{'scale': 1.0, 'power': 4.0, 'background' : 0.0},
79     [0.0106939, 0.469418], [7.64644e+07, 20.5949]],
80    ]
Note: See TracBrowser for help on using the repository browser.