# source:sasmodels/example/weights/cyclic_gaussian.py@342b3dd

Last change on this file since 342b3dd was 342b3dd, checked in by Paul Kienzle <pkienzle@…>, 4 years ago

add laplace and cyclic gaussian example distributions in example/weights

• Property mode set to 100644
File size: 1.6 KB
Line
1import numpy as np
2from numpy import exp, sin, cos, pi, radians, degrees
3
4from sasmodels.weights import Dispersion as BaseDispersion
5
6class Dispersion(BaseDispersion):
7    r"""
8    Cyclic gaussian dispersion on orientation.
9
10    .. math:
11
12        w(\theta) = e^{-\frac{\sin^2 \theta}{2 \sigma^2}}
13
14    This provides a close match to the gaussian distribution for
15    low angles (with $\sin \theta \approx \theta$), but the tails
16    are limited to $\pm 90^\circ$.  For $\sigma$ large the
17    distribution is approximately uniform.  The usual polar coordinate
18    projection applies, with $\theta$ weights scaled by $\cos \theta$
19    and $\phi$ weights unscaled.
20
21    This is closely related to a Maier-Saupe distribution with order
22    parameter $P_2$ and appropriate scaling constants, and changes
23    between $\sin$ and $\cos$ as appropriate for the coordinate system
24    representation.
25    """
26    type = "cyclic_gaussian"
27    default = dict(npts=35, width=1, nsigmas=3)
28
29    # Note: center is always zero for orientation distributions
30    def _weights(self, center, sigma, lb, ub):
31        # Convert sigma in degrees to the approximately equivalent Maier-Saupe "a"