source: sasmodels/sasmodels/models/broad_peak.py @ 0bdddc2

core_shell_microgelscostrafo411magnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 0bdddc2 was 0bdddc2, checked in by Paul Kienzle <pkienzle@…>, 7 years ago

extend sascomp so it can display sets of random models; extend model def to allow random parameter generation

  • Property mode set to 100644
File size: 4.2 KB
Line 
1r"""
2Definition
3----------
4
5This model calculates an empirical functional form for SAS data characterized
6by a broad scattering peak. Many SAS spectra are characterized by a broad peak
7even though they are from amorphous soft materials. For example, soft systems
8that show a SAS peak include copolymers, polyelectrolytes, multiphase systems,
9layered structures, etc.
10
11The d-spacing corresponding to the broad peak is a characteristic distance
12between the scattering inhomogeneities (such as in lamellar, cylindrical, or
13spherical morphologies, or for bicontinuous structures).
14
15The scattering intensity $I(q)$ is calculated as
16
17.. math:: I(q) = \frac{A}{q^n} + \frac{C}{1 + (|q - q_0|\xi)^m} + B
18
19Here the peak position is related to the d-spacing as $q_0 = 2\pi / d_0$.
20
21$A$ is the Porod law scale factor, $n$ the Porod exponent, $C$ is the
22Lorentzian scale factor, $m$ the exponent of $q$, $\xi$ the screening length,
23and $B$ the flat background.
24
25For 2D data the scattering intensity is calculated in the same way as 1D,
26where the $q$ vector is defined as
27
28.. math:: q = \sqrt{q_x^2 + q_y^2}
29
30References
31----------
32
33None.
34
35Authorship and Verification
36----------------------------
37
38* **Author:** NIST IGOR/DANSE **Date:** pre 2010
39* **Last Modified by:** Paul kienle **Date:** July 24, 2016
40* **Last Reviewed by:** Richard Heenan **Date:** March 21, 2016
41"""
42
43from numpy import inf, errstate
44
45name = "broad_peak"
46title = "Broad Lorentzian type peak on top of a power law decay"
47description = """\
48      I(q) = scale_p/pow(q,exponent)+scale_l/
49      (1.0 + pow((fabs(q-q_peak)*length_l),exponent_l) )+ background
50
51      List of default parameters:
52      porod_scale = Porod term scaling
53      porod_exp = Porod exponent
54      lorentz_scale = Lorentzian term scaling
55      lorentz_length = Lorentzian screening length [A]
56      peak_pos = peak location [1/A]
57      lorentz_exp = Lorentzian exponent
58      background = Incoherent background"""
59category = "shape-independent"
60
61# pylint: disable=bad-whitespace, line-too-long
62#             ["name", "units", default, [lower, upper], "type", "description"],
63parameters = [["porod_scale",    "",  1.0e-05, [-inf, inf], "", "Power law scale factor"],
64              ["porod_exp",      "",      3.0, [-inf, inf], "", "Exponent of power law"],
65              ["lorentz_scale",  "",     10.0, [-inf, inf], "", "Scale factor for broad Lorentzian peak"],
66              ["lorentz_length", "Ang",  50.0, [-inf, inf], "", "Lorentzian screening length"],
67              ["peak_pos",       "1/Ang", 0.1, [-inf, inf], "", "Peak position in q"],
68              ["lorentz_exp",    "",      2.0, [-inf, inf], "", "Exponent of Lorentz function"],
69             ]
70# pylint: enable=bad-whitespace, line-too-long
71
72def Iq(q,
73       porod_scale=1.0e-5,
74       porod_exp=3.0,
75       lorentz_scale=10.0,
76       lorentz_length=50.0,
77       peak_pos=0.1,
78       lorentz_exp=2.0):
79    """
80    :param q:              Input q-value
81    :param porod_scale:    Power law scale factor
82    :param porod_exp:      Exponent of power law
83    :param lorentz_scale:  Scale factor for broad Lorentzian peak
84    :param lorentz_length: Lorentzian screening length
85    :param peak_pos:       Peak position in q
86    :param lorentz_exp:    Exponent of Lorentz function
87    :return:               Calculated intensity
88    """
89    z = abs(q - peak_pos) * lorentz_length
90    with errstate(divide='ignore'):
91        inten = (porod_scale / q ** porod_exp
92                 + lorentz_scale / (1 + z ** lorentz_exp))
93    return inten
94Iq.vectorized = True  # Iq accepts an array of q values
95
96def random():
97    import numpy as np
98    pars = dict(
99        scale=1,
100        porod_scale=10**np.random.uniform(-8, -5),
101        porod_exp=np.random.uniform(1, 6),
102        lorentz_scale=10**np.random.uniform(0.3, 6),
103        lorentz_length=10**np.random.uniform(0, 2),
104        peak_pos=10**np.random.uniform(-3, -1),
105        lorentz_exp=np.random.uniform(1, 4),
106    )
107    pars['lorentz_length'] /= pars['peak_pos']
108    pars['lorentz_scale'] *= pars['porod_scale'] / pars['peak_pos']**pars['porod_exp']
109    #pars['porod_scale'] = 0.
110    return pars
111
112demo = dict(scale=1, background=0,
113            porod_scale=1.0e-05, porod_exp=3,
114            lorentz_scale=10, lorentz_length=50, peak_pos=0.1, lorentz_exp=2)
Note: See TracBrowser for help on using the repository browser.