Changes in sasmodels/sesans.py [94d13f1:2cdc35b] in sasmodels


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/sesans.py

    r94d13f1 r2cdc35b  
    2020    Spin-Echo SANS transform calculator.  Similar to a resolution function, 
    2121    the SesansTransform object takes I(q) for the set of *q_calc* values and 
    22     produces a transformed dataset 
     22    produces a transformed dataset. 
    2323 
    2424    *SElength* (A) is the set of spin-echo lengths in the measured data. 
     
    4848 
    4949    def apply(self, Iq): 
    50         # tye: (np.ndarray) -> np.ndarray 
    5150        G0 = np.dot(self._H0, Iq) 
    5251        G = np.dot(self._H.T, Iq) 
     
    7372        self.q_calc = q 
    7473        self._H, self._H0 = H, H0 
     74 
     75class OrientedSesansTransform(object): 
     76    """ 
     77    Oriented Spin-Echo SANS transform calculator.  Similar to a resolution 
     78    function, the OrientedSesansTransform object takes I(q) for the set 
     79    of *q_calc* values and produces a transformed dataset. 
     80 
     81    *SElength* (A) is the set of spin-echo lengths in the measured data. 
     82 
     83    *zaccept* (1/A) is the maximum acceptance of scattering vector in the spin 
     84    echo encoding dimension (for ToF: Q of min(R) and max(lam)). 
     85 
     86    *Rmax* (A) is the maximum size sensitivity; larger radius requires more 
     87    computation time. 
     88    """ 
     89    #: SElength from the data in the original data units; not used by transform 
     90    #: but the GUI uses it, so make sure that it is present. 
     91    q = None  # type: np.ndarray 
     92 
     93    #: q values to calculate when computing transform 
     94    q_calc = None  # type: np.ndarray 
     95 
     96    # transform arrays 
     97    _cosmat = None  # type: np.ndarray 
     98    _cos0 = None # type: np.ndarray 
     99    _Iq_shape = None # type: Tuple[int, int] 
     100 
     101    def __init__(self, z, SElength, zaccept, Rmax): 
     102        # type: (np.ndarray, float, float) -> None 
     103        #import logging; logging.info("creating SESANS transform") 
     104        self.q = z 
     105        self._set_cosmat(SElength, zaccept, Rmax) 
     106 
     107    def apply(self, Iq): 
     108        dq = self.q_calc[0][0] 
     109        Iq = np.reshape(Iq, self._Iq_shape) 
     110        G0 = self._cos0 * np.sum(Iq) * dq 
     111        G = np.sum(np.dot(Iq, self._cosmat), axis=0) * dq 
     112        P = G - G0 
     113        return P 
     114 
     115    def _set_cosmat(self, SElength, zaccept, Rmax): 
     116        # type: (np.ndarray, float, float) -> None 
     117        # Force float32 arrays, otherwise run into memory problems on some machines 
     118        SElength = np.asarray(SElength, dtype='float32') 
     119 
     120        # Rmax = #value in text box somewhere in FitPage? 
     121        q_max = 2 * pi / (SElength[1] - SElength[0]) 
     122        q_min = 0.1 * 2 * pi / (np.size(SElength) * SElength[-1]) 
     123        q_min *= 100 
     124 
     125        q = np.arange(q_min, q_max, q_min, dtype='float32') 
     126        dq = q_min 
     127 
     128        cos0 = np.float32(dq / (2 * pi)) 
     129        cosmat = np.float32(dq / (2 * pi)) * np.cos(q[:, None] * SElength[None, :]) 
     130 
     131        qx, qy = np.meshgrid(q, q) 
     132        self._Iq_shape = qx.shape 
     133        self.q_calc = qx.flatten(), qy.flatten() 
     134        self._cosmat, self._cos0 = cosmat, cos0 
Note: See TracChangeset for help on using the changeset viewer.