[c5b059c] | 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. |
---|
[55e82f0] | 9 | |
---|
[c5b059c] | 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 |
---|
[55e82f0] | 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 |
---|
[c5b059c] | 17 | projection applies, with $\theta$ weights scaled by $\cos \theta$ |
---|
| 18 | and $\phi$ weights unscaled. |
---|
| 19 | |
---|
[55e82f0] | 20 | This is eqivalent to a Maier-Saupe distribution with order |
---|
[35d2300] | 21 | parameter $a = 1/(2 \sigma^2)$, with $\sigma$ in radians. |
---|
[c5b059c] | 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): |
---|
[55e82f0] | 28 | # Convert sigma in degrees to radians |
---|
[c5b059c] | 29 | sigma = radians(sigma) |
---|
| 30 | |
---|
[55e82f0] | 31 | # Limit width to +/- 90 degrees |
---|
[c5b059c] | 32 | width = min(self.nsigmas*sigma, pi/2) |
---|
[55e82f0] | 33 | x = np.linspace(-width, width, self.npts) |
---|
[c5b059c] | 34 | |
---|
[55e82f0] | 35 | # Truncate the distribution in case the parameter value is limited |
---|
| 36 | x[(x >= radians(lb)) & (x <= radians(ub))] |
---|
[c5b059c] | 37 | |
---|
[55e82f0] | 38 | # Return orientation in degrees with Maier-Saupe weights |
---|
| 39 | return degrees(x), exp(-0.5*sin(x)**2/sigma**2) |
---|