Changes in / [2f9f1ec:630156b] in sasmodels


Ignore:
Files:
10 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/direct_model.py

    r2cdc35b ra769b54  
    202202 
    203203        if self.data_type == 'sesans': 
    204             from sas.sascalc.data_util.nxsunit import Converter 
    205             qmax, qunits = data.sample.zacceptance 
    206             SElength = Converter(data._xunit)(data.x, "A") 
    207             zaccept = Converter(qunits)(qmax, "1/A"), 
    208             Rmax = 10000000 
    209             index = slice(None, None)  # equivalent to index [:] 
    210             Iq = data.y[index] 
    211             dIq = data.dy[index] 
    212             oriented = getattr(data, 'oriented', False) 
    213             if oriented: 
    214                 res = sesans.OrientedSesansTransform(data.x[index], SElength, zaccept, Rmax) 
    215                 # Oriented sesans transform produces q_calc = [qx, qy] 
    216                 q_vectors = res.q_calc 
     204            q = sesans.make_q(data.sample.zacceptance, data.Rmax) 
     205            index = slice(None, None) 
     206            res = None 
     207            if data.y is not None: 
     208                Iq, dIq = data.y, data.dy 
    217209            else: 
    218                 res = sesans.SesansTransform(data.x[index], SElength, zaccept, Rmax) 
    219                 # Unoriented sesans transform produces q_calc = q 
    220                 q_vectors = [res.q_calc] 
     210                Iq, dIq = None, None 
     211            #self._theory = np.zeros_like(q) 
     212            q_vectors = [q] 
     213            q_mono = sesans.make_all_q(data) 
    221214        elif self.data_type == 'Iqxy': 
    222215            #if not model.info.parameters.has_2d: 
     
    237230            #self._theory = np.zeros_like(self.Iq) 
    238231            q_vectors = res.q_calc 
     232            q_mono = [] 
    239233        elif self.data_type == 'Iq': 
    240234            index = (data.x >= data.qmin) & (data.x <= data.qmax) 
     
    261255            #self._theory = np.zeros_like(self.Iq) 
    262256            q_vectors = [res.q_calc] 
     257            q_mono = [] 
    263258        elif self.data_type == 'Iq-oriented': 
    264259            index = (data.x >= data.qmin) & (data.x <= data.qmax) 
     
    277272                                      qy_width=data.dxl[index]) 
    278273            q_vectors = res.q_calc 
     274            q_mono = [] 
    279275        else: 
    280276            raise ValueError("Unknown data type") # never gets here 
     
    283279        # so we can save/restore state 
    284280        self._kernel_inputs = q_vectors 
     281        self._kernel_mono_inputs = q_mono 
    285282        self._kernel = None 
    286283        self.Iq, self.dIq, self.index = Iq, dIq, index 
     
    309306        if self._kernel is None: 
    310307            self._kernel = self._model.make_kernel(self._kernel_inputs) 
     308            self._kernel_mono = ( 
     309                self._model.make_kernel(self._kernel_mono_inputs) 
     310                if self._kernel_mono_inputs else None) 
    311311 
    312312        Iq_calc = call_kernel(self._kernel, pars, cutoff=cutoff) 
     
    316316        # TODO: refactor so we don't store the result in the model 
    317317        self.Iq_calc = None 
    318         result = self.resolution.apply(Iq_calc) 
    319         if hasattr(self.resolution, 'nx'): 
    320             self.Iq_calc = ( 
    321                 self.resolution.qx_calc, self.resolution.qy_calc, 
    322                 np.reshape(Iq_calc, (self.resolution.ny, self.resolution.nx)) 
    323             ) 
     318        if self.data_type == 'sesans': 
     319            Iq_mono = (call_kernel(self._kernel_mono, pars, mono=True) 
     320                       if self._kernel_mono_inputs else None) 
     321            result = sesans.transform(self._data, 
     322                                      self._kernel_inputs[0], Iq_calc, 
     323                                      self._kernel_mono_inputs, Iq_mono) 
     324        else: 
     325            result = self.resolution.apply(Iq_calc) 
     326            if hasattr(self.resolution, 'nx'): 
     327                self.Iq_calc = ( 
     328                    self.resolution.qx_calc, self.resolution.qy_calc, 
     329                    np.reshape(Iq_calc, (self.resolution.ny, self.resolution.nx)) 
     330                ) 
    324331        return result 
    325332 
  • sasmodels/sesans.py

    r2cdc35b r94d13f1  
    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 
    5051        G0 = np.dot(self._H0, Iq) 
    5152        G = np.dot(self._H.T, Iq) 
     
    7273        self.q_calc = q 
    7374        self._H, self._H0 = H, H0 
    74  
    75 class 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.