Changeset 841753c in sasmodels for sasmodels/resolution2d.py
- Timestamp:
- Jan 28, 2016 3:42:34 PM (8 years ago)
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/resolution2d.py
r9404dd3 r841753c 2 2 #This software was developed by the University of Tennessee as part of the 3 3 #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. 5 5 #See the license text in license.txt 6 6 """ … … 19 19 ## Defaults 20 20 NR = {'xhigh':10, 'high':5, 'med':5, 'low':3} 21 NPHI = {'xhigh':20, 'high':12, 'med':6, 'low':4}21 NPHI = {'xhigh':20, 'high':12, 'med':6, 'low':4} 22 22 23 23 class Pinhole2D(Resolution): … … 25 25 Gaussian Q smearing class for SAS 2d data 26 26 """ 27 27 28 28 def __init__(self, data=None, index=None, 29 29 nsigma=NSIGMA, accuracy='Low', coords='polar'): 30 30 """ 31 31 Assumption: equally spaced bins in dq_r, dq_phi space. 32 32 33 33 :param data: 2d data used to set the smearing parameters 34 34 :param index: 1d array with len(data) to define the range … … 42 42 ## number of bins in r axis for over-sampling 43 43 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 45 45 self.nphi = NPHI[accuracy.lower()] 46 46 ## maximum nsigmas 47 self.nsigma = nsigma47 self.nsigma = nsigma 48 48 self.coords = coords 49 49 self._init_data(data, index) … … 85 85 def _calc_res(self): 86 86 """ 87 Over sampling of r_nbins times phi_nbins, calculate Gaussian weights, 87 Over sampling of r_nbins times phi_nbins, calculate Gaussian weights, 88 88 then find smeared intensity 89 """ 89 """ 90 90 nr, nphi = self.nr, self.nphi 91 91 # Total number of bins = # of bins … … 143 143 if self.coords == 'polar': 144 144 q_r = sqrt(qx**2 + qy**2) 145 qx_res = ( 145 qx_res = ((dqx*cos(dphi) + q_r) * cos(-q_phi) + 146 146 dqy*sin(dphi) * sin(-q_phi)) 147 147 qy_res = (-(dqx*cos(dphi) + q_r) * sin(-q_phi) + … … 167 167 else: 168 168 return theory 169 170 """171 if __name__ == '__main__':172 ## Test w/ 2D linear function173 x = 0.001*np.arange(1, 11)174 dx = np.ones(len(x))*0.0003175 y = 0.001*np.arange(1, 11)176 dy = np.ones(len(x))*0.001177 z = np.ones(10)178 dz = sqrt(z)179 180 from sas.dataloader import Data2D181 #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 = z185 out.qx_data = x186 out.qy_data = y187 out.dqx_data = dx188 out.dqy_data = dy189 out.q_data = sqrt(dx * dx + dy * dy)190 index = np.ones(len(x), dtype = bool)191 out.mask = index192 from sas.models.LineModel import LineModel193 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 function212 x = 0.001*np.arange(1,11)213 dx = np.ones(len(x))*0.001214 y = 0.001*np.arange(1,11)215 dy = np.ones(len(x))*0.001216 z = np.ones(10)217 dz = sqrt(z)218 219 from DataLoader import Data2D220 #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 = z224 out.qx_data = x225 out.qy_data = y226 out.dqx_data = dx227 out.dqy_data = dy228 index = np.ones(len(x), dtype = bool)229 out.mask = index230 from sas.models.Constant import Constant231 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.