Changeset 841753c in sasmodels for sasmodels/resolution2d.py


Ignore:
Timestamp:
Jan 28, 2016 3:42:34 PM (8 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
d4666ca
Parents:
69ec80f
Message:

delint

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/resolution2d.py

    r9404dd3 r841753c  
    22#This software was developed by the University of Tennessee as part of the 
    33#Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
    4 #project funded by the US National Science Foundation.  
     4#project funded by the US National Science Foundation. 
    55#See the license text in license.txt 
    66""" 
     
    1919## Defaults 
    2020NR = {'xhigh':10, 'high':5, 'med':5, 'low':3} 
    21 NPHI ={'xhigh':20, 'high':12, 'med':6, 'low':4} 
     21NPHI = {'xhigh':20, 'high':12, 'med':6, 'low':4} 
    2222 
    2323class Pinhole2D(Resolution): 
     
    2525    Gaussian Q smearing class for SAS 2d data 
    2626    """ 
    27       
     27 
    2828    def __init__(self, data=None, index=None, 
    2929                 nsigma=NSIGMA, accuracy='Low', coords='polar'): 
    3030        """ 
    3131        Assumption: equally spaced bins in dq_r, dq_phi space. 
    32          
     32 
    3333        :param data: 2d data used to set the smearing parameters 
    3434        :param index: 1d array with len(data) to define the range 
     
    4242        ## number of bins in r axis for over-sampling 
    4343        self.nr = NR[accuracy.lower()] 
    44         ## number of bins in phi axis for over-sampling  
     44        ## number of bins in phi axis for over-sampling 
    4545        self.nphi = NPHI[accuracy.lower()] 
    4646        ## maximum nsigmas 
    47         self.nsigma= nsigma 
     47        self.nsigma = nsigma 
    4848        self.coords = coords 
    4949        self._init_data(data, index) 
     
    8585    def _calc_res(self): 
    8686        """ 
    87         Over sampling of r_nbins times phi_nbins, calculate Gaussian weights,  
     87        Over sampling of r_nbins times phi_nbins, calculate Gaussian weights, 
    8888        then find smeared intensity 
    89         """     
     89        """ 
    9090        nr, nphi = self.nr, self.nphi 
    9191        # Total number of bins = # of bins 
     
    143143        if self.coords == 'polar': 
    144144            q_r = sqrt(qx**2 + qy**2) 
    145             qx_res = ( (dqx*cos(dphi) + q_r) * cos(-q_phi) + 
     145            qx_res = ((dqx*cos(dphi) + q_r) * cos(-q_phi) + 
    146146                           dqy*sin(dphi) * sin(-q_phi)) 
    147147            qy_res = (-(dqx*cos(dphi) + q_r) * sin(-q_phi) + 
     
    167167        else: 
    168168            return theory 
    169  
    170 """ 
    171 if __name__ == '__main__': 
    172     ## Test w/ 2D linear function 
    173     x = 0.001*np.arange(1, 11) 
    174     dx = np.ones(len(x))*0.0003 
    175     y = 0.001*np.arange(1, 11) 
    176     dy = np.ones(len(x))*0.001 
    177     z = np.ones(10) 
    178     dz = sqrt(z) 
    179  
    180     from sas.dataloader import Data2D 
    181     #for i in range(10): print(i, 0.001 + i*0.008/9.0) 
    182     #for i in range(100): print(i, int(math.floor( (i/ (100/9.0)) ))) 
    183     out = Data2D() 
    184     out.data = z 
    185     out.qx_data = x 
    186     out.qy_data = y 
    187     out.dqx_data = dx 
    188     out.dqy_data = dy 
    189     out.q_data = sqrt(dx * dx + dy * dy) 
    190     index = np.ones(len(x), dtype = bool) 
    191     out.mask = index 
    192     from sas.models.LineModel import LineModel 
    193     model = LineModel() 
    194     model.setParam("A", 0) 
    195  
    196     smear = Smearer2D(out, model, index) 
    197     #smear.set_accuracy('Xhigh') 
    198     value = smear.get_value() 
    199     ## All data are ones, so the smeared should also be ones. 
    200     print("Data length =", len(value)) 
    201     print(" 2D linear function, I = 0 + 1*qy") 
    202     text = " Gaussian weighted averaging on a 2D linear function will " 
    203     text += "provides the results same as without the averaging." 
    204     print(text) 
    205     print("qx_data", "qy_data", "I_nonsmear", "I_smeared") 
    206     for ind in range(len(value)): 
    207         print(x[ind], y[ind], model.evalDistribution([x, y])[ind], value[ind]) 
    208  
    209  
    210 if __name__ == '__main__': 
    211     ## Another Test w/ constant function 
    212     x = 0.001*np.arange(1,11) 
    213     dx = np.ones(len(x))*0.001 
    214     y = 0.001*np.arange(1,11) 
    215     dy = np.ones(len(x))*0.001 
    216     z = np.ones(10) 
    217     dz = sqrt(z) 
    218  
    219     from DataLoader import Data2D 
    220     #for i in range(10): print(i, 0.001 + i*0.008/9.0) 
    221     #for i in range(100): print(i, int(math.floor( (i/ (100/9.0)) ))) 
    222     out = Data2D() 
    223     out.data = z 
    224     out.qx_data = x 
    225     out.qy_data = y 
    226     out.dqx_data = dx 
    227     out.dqy_data = dy 
    228     index = np.ones(len(x), dtype = bool) 
    229     out.mask = index 
    230     from sas.models.Constant import Constant 
    231     model = Constant() 
    232  
    233     value = Smearer2D(out,model,index).get_value() 
    234     ## All data are ones, so the smeared values should also be ones. 
    235     print("Data length =",len(value), ", Data=",value) 
    236 """ 
Note: See TracChangeset for help on using the changeset viewer.