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, but the tails are limited to $\pm 90^\circ$. For $\sigma$ |
---|
16 | large the distribution is approximately uniform. The usual polar coordinate |
---|
17 | projection applies, with $\theta$ weights scaled by $\cos \theta$ |
---|
18 | and $\phi$ weights unscaled. |
---|
19 | |
---|
20 | This is eqivalent to a Maier-Saupe distribution with order |
---|
21 | parameter $a = 1/(2 \sigma^2)$, with $\sigma$ in radians. |
---|
22 | """ |
---|
23 | type = "cyclic_gaussian" |
---|
24 | default = dict(npts=35, width=1, nsigmas=3) |
---|
25 | |
---|
26 | # Note: center is always zero for orientation distributions |
---|
27 | def _weights(self, center, sigma, lb, ub): |
---|
28 | # Convert sigma in degrees to radians |
---|
29 | sigma = radians(sigma) |
---|
30 | |
---|
31 | # Limit width to +/- 90 degrees |
---|
32 | width = min(self.nsigmas*sigma, pi/2) |
---|
33 | x = np.linspace(-width, width, self.npts) |
---|
34 | |
---|
35 | # Truncate the distribution in case the parameter value is limited |
---|
36 | x[(x >= radians(lb)) & (x <= radians(ub))] |
---|
37 | |
---|
38 | # Return orientation in degrees with Maier-Saupe weights |
---|
39 | return degrees(x), exp(-0.5*sin(x)**2/sigma**2) |
---|