Changeset 2cdc35b in sasmodels


Ignore:
Timestamp:
Apr 11, 2017 11:44:18 AM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
costrafo411
Children:
2f9f1ec
Parents:
7c1cce3
Message:

provide working oriented/unoriented sesans examples

Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/direct_model.py

    ra769b54 r2cdc35b  
    202202 
    203203        if self.data_type == 'sesans': 
    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 
     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 
    209217            else: 
    210                 Iq, dIq = None, None 
    211             #self._theory = np.zeros_like(q) 
    212             q_vectors = [q] 
    213             q_mono = sesans.make_all_q(data) 
     218                res = sesans.SesansTransform(data.x[index], SElength, zaccept, Rmax) 
     219                # Unoriented sesans transform produces q_calc = q 
     220                q_vectors = [res.q_calc] 
    214221        elif self.data_type == 'Iqxy': 
    215222            #if not model.info.parameters.has_2d: 
     
    230237            #self._theory = np.zeros_like(self.Iq) 
    231238            q_vectors = res.q_calc 
    232             q_mono = [] 
    233239        elif self.data_type == 'Iq': 
    234240            index = (data.x >= data.qmin) & (data.x <= data.qmax) 
     
    255261            #self._theory = np.zeros_like(self.Iq) 
    256262            q_vectors = [res.q_calc] 
    257             q_mono = [] 
    258263        elif self.data_type == 'Iq-oriented': 
    259264            index = (data.x >= data.qmin) & (data.x <= data.qmax) 
     
    272277                                      qy_width=data.dxl[index]) 
    273278            q_vectors = res.q_calc 
    274             q_mono = [] 
    275279        else: 
    276280            raise ValueError("Unknown data type") # never gets here 
     
    279283        # so we can save/restore state 
    280284        self._kernel_inputs = q_vectors 
    281         self._kernel_mono_inputs = q_mono 
    282285        self._kernel = None 
    283286        self.Iq, self.dIq, self.index = Iq, dIq, index 
     
    306309        if self._kernel is None: 
    307310            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         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                 ) 
     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            ) 
    331324        return result 
    332325 
  • sasmodels/sesans.py

    r7c1cce3 r2cdc35b  
    4545        #import logging; logging.info("creating SESANS transform") 
    4646        self.q = z 
    47         # isoriented flag determines whether data is from an oriented sample or 
    48         # not, should be a selection variable upon entering SESANS data. 
    4947        self._set_hankel(SElength, zaccept, Rmax) 
    5048 
     
    105103        #import logging; logging.info("creating SESANS transform") 
    106104        self.q = z 
    107         # isoriented flag determines whether data is from an oriented sample or 
    108         # not, should be a selection variable upon entering SESANS data. 
    109105        self._set_cosmat(SElength, zaccept, Rmax) 
    110106 
     
    113109        Iq = np.reshape(Iq, self._Iq_shape) 
    114110        G0 = self._cos0 * np.sum(Iq) * dq 
    115         G = np.sum(np.dot(Iq, self._cosmat.T), axis=1) * dq 
     111        G = np.sum(np.dot(Iq, self._cosmat), axis=0) * dq 
    116112        P = G - G0 
    117113        return P 
     
    125121        q_max = 2 * pi / (SElength[1] - SElength[0]) 
    126122        q_min = 0.1 * 2 * pi / (np.size(SElength) * SElength[-1]) 
     123        q_min *= 100 
    127124 
    128125        q = np.arange(q_min, q_max, q_min, dtype='float32') 
     
    130127 
    131128        cos0 = np.float32(dq / (2 * pi)) 
    132         cosmat = np.float32(dq / (2 * pi)) * np.cos(q[:, None] * SE[None, :]) 
     129        cosmat = np.float32(dq / (2 * pi)) * np.cos(q[:, None] * SElength[None, :]) 
    133130 
    134131        qx, qy = np.meshgrid(q, q) 
Note: See TracChangeset for help on using the changeset viewer.