source: sasmodels/sasmodels/sesans.py @ 1c8ff89

Last change on this file since 1c8ff89 was 1c8ff89, checked in by awashington, 5 years ago

Apply Paul's suggested changes

  • Property mode set to 100644
File size: 2.7 KB
RevLine 
[c97724e]1"""
[d459d4e]2Conversion of scattering cross section from SANS (I(q), or rather, ds/dO) in absolute
3units (cm-1)into SESANS correlation function G using a Hankel transformation, then converting
4the SESANS correlation function into polarisation from the SESANS experiment
[c97724e]5
[d459d4e]6Everything is in units of metres except specified otherwise (NOT TRUE!!!)
7Everything is in conventional units (nm for spin echo length)
[c97724e]8
9Wim Bouwman (w.g.bouwman@tudelft.nl), June 2013
10"""
11
12from __future__ import division
13
[7ae2b7f]14import numpy as np  # type: ignore
[fa79f5c]15from numpy import pi  # type: ignore
[3f3df6c]16from scipy.special import j0
[d7af1c6]17
[94d13f1]18
[54f1d96]19class SesansTransform(object):
[94d13f1]20    """
21    Spin-Echo SANS transform calculator.  Similar to a resolution function,
22    the SesansTransform object takes I(q) for the set of *q_calc* values and
23    produces a transformed dataset
24
25    *SElength* (A) is the set of spin-echo lengths in the measured data.
26
27    *zaccept* (1/A) is the maximum acceptance of scattering vector in the spin
28    echo encoding dimension (for ToF: Q of min(R) and max(lam)).
29
30    *Rmax* (A) is the maximum size sensitivity; larger radius requires more
31    computation time.
32    """
33    #: SElength from the data in the original data units; not used by transform
34    #: but the GUI uses it, so make sure that it is present.
[54f1d96]35    q = None  # type: np.ndarray
36
[94d13f1]37    #: q values to calculate when computing transform
38    q_calc = None  # type: np.ndarray
39
[54f1d96]40    # transform arrays
[ac995be]41    _H = None   # type: np.ndarray
42    _H0 = None  # type: np.ndarray
[54f1d96]43
[1c8ff89]44    def __init__(self, z, SElength, lam, zaccept, Rmax, log_spacing=1.0003):
[94d13f1]45        # type: (np.ndarray, float, float) -> None
46        self.q = z
[1c8ff89]47        self.log_spacing = log_spacing
[9f91afe]48        self._set_hankel(SElength, lam, zaccept, Rmax)
[54f1d96]49
50    def apply(self, Iq):
[b297ba9]51        # type: (np.ndarray) -> np.ndarray
52        """
53        Apply the SESANS transform to the computed I(q).
54        """
[94d13f1]55        G0 = np.dot(self._H0, Iq)
56        G = np.dot(self._H.T, Iq)
[54f1d96]57        P = G - G0
58        return P
59
[9f91afe]60    def _set_hankel(self, SElength, lam, zaccept, Rmax):
[94d13f1]61        # type: (np.ndarray, float, float) -> None
[3f3df6c]62        SElength = np.asarray(SElength)
[94d13f1]63        q_max = 2*pi / (SElength[1] - SElength[0])
64        q_min = 0.1 * 2*pi / (np.size(SElength) * SElength[-1])
[1c8ff89]65        q = np.exp(np.arange(np.log(q_min), np.log(q_max),
66                             np.log(self.log_spacing)))
[3f3df6c]67
[1c8ff89]68        dq = np.diff(q)
69        dq = np.insert(dq, 0, dq[0])
[54f1d96]70
[3f3df6c]71        H0 = dq/(2*pi) * q
[54f1d96]72
[38935ec]73        H = np.outer(q, SElength)
[3f3df6c]74        j0(H, out=H)
[1c8ff89]75        H *= (dq * q / (2*pi)).reshape((-1, 1))
[3f3df6c]76
[1c8ff89]77        reptheta = np.outer(q, lam/2*pi)
[38935ec]78        np.arcsin(reptheta, out=reptheta)
[9f91afe]79        mask = reptheta > zaccept
[3f3df6c]80        H[mask] = 0
[38935ec]81
[3f3df6c]82        self.q_calc = q
[94d13f1]83        self._H, self._H0 = H, H0
Note: See TracBrowser for help on using the repository browser.