1 | import numpy as np |
---|
2 | from numpy import exp, sin, cos, pi, radians, degrees |
---|
3 | |
---|
4 | from sasmodels.weights import Dispersion as BaseDispersion |
---|
5 | |
---|
6 | class 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" |
---|
32 | sigma = radians(sigma) |
---|
33 | a = -0.5/sigma**2 |
---|
34 | |
---|
35 | # Limit width to +/-90 degrees; use an open interval since the |
---|
36 | # pattern at +90 is the same as that at -90. |
---|
37 | width = min(self.nsigmas*sigma, pi/2) |
---|
38 | x = np.linspace(-width, width, self.npts+2)[1:-1] |
---|
39 | |
---|
40 | # Return orientation in degrees with Maier-Saupe weights |
---|
41 | return degrees(x), exp(a*sin(x)**2) |
---|
42 | |
---|