""" This software was developed by the University of Tennessee as part of the Distributed Data Analysis of Neutron Scattering Experiments (DANSE) project funded by the US National Science Foundation. See the license text in license.txt copyright 2009, University of Tennessee """ ## TODO: Need test,and check Gaussian averaging import numpy, math,time ## Singular point SIGMA_ZERO = 1.0e-010 ## Limit of how many sigmas to be covered for the Gaussian smearing # default: 2.5 to cover 98.7% of Gaussian LIMIT = 2.5 ## Defaults R_BIN = {'Xhigh':10.0, 'High':5.0,'Med':5.0,'Low':3.0} PHI_BIN ={'Xhigh':20.0,'High':12.0,'Med':6.0,'Low':4.0} class Smearer2D: """ Gaussian Q smearing class for SANS 2d data """ def __init__(self, data=None,model=None,index=None,limit=LIMIT,accuracy='Low'): """ Assumption: equally spaced bins in dq_r, dq_phi space. @param data: 2d data used to set the smearing parameters @param model: model function @param index: 1d array with len(data) to define the range of the calculation: elements are given as True or False @param nr: number of bins in dq_r-axis @param nphi: number of bins in dq_phi-axis """ ## data self.data = data ## model self.model = model ## Accuracy: Higher stands for more sampling points in both directions of r and phi. self.accuracy = accuracy ## number of bins in r axis for over-sampling self.nr = R_BIN ## number of bins in phi axis for over-sampling self.nphi = PHI_BIN ## maximum nsigmas self.limit = limit self.index = index self.smearer = True def get_data(self): """ get qx_data, qy_data, dqx_data,dqy_data,and calculate phi_data=arctan(qx_data/qy_data) """ if self.data == None or self.data.__class__.__name__ == 'Data1D': return None if self.data.dqx_data == None or self.data.dqy_data == None: return None self.qx_data = self.data.qx_data[self.index] self.qy_data = self.data.qy_data[self.index] self.dqx_data = self.data.dqx_data[self.index] self.dqy_data = self.data.dqy_data[self.index] self.phi_data = numpy.arctan(self.qx_data/self.qy_data) ## Remove singular points if exists self.dqx_data[self.dqx_data