Changeset 1198f90 in sasmodels for sasmodels/resolution.py
 Timestamp:
 May 17, 2018 8:07:02 PM (4 years ago)
 Branches:
 master, core_shell_microgels, magnetic_model, ticket1257vesicleproduct, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
 Children:
 df0d2ca
 Parents:
 33969b6
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

sasmodels/resolution.py
r2d81cfe r1198f90 20 20 MINIMUM_RESOLUTION = 1e8 21 21 MINIMUM_ABSOLUTE_Q = 0.02 # relative to the minimum q in the data 22 PINHOLE_N_SIGMA = 2.5 # From: Barker & Pedersen 1995 JAC 22 23 23 24 class Resolution(object): … … 65 66 *q_calc* is the list of points to calculate, or None if this should 66 67 be estimated from the *q* and *q_width*. 67 """ 68 def __init__(self, q, q_width, q_calc=None, nsigma=3): 68 69 *nsigma* is the width of the resolution function. Should be 2.5. 70 See :func:`pinhole_resolution` for details. 71 """ 72 def __init__(self, q, q_width, q_calc=None, nsigma=PINHOLE_N_SIGMA): 69 73 #*min_step* is the minimum point spacing to use when computing the 70 74 #underlying model. It should be on the order of … … 88 92 # Build weight matrix from calculated q values 89 93 self.weight_matrix = pinhole_resolution( 90 self.q_calc, self.q, np.maximum(q_width, MINIMUM_RESOLUTION)) 94 self.q_calc, self.q, np.maximum(q_width, MINIMUM_RESOLUTION), 95 nsigma=nsigma) 91 96 self.q_calc = abs(self.q_calc) 92 97 … … 154 159 155 160 156 def pinhole_resolution(q_calc, q, q_width ):157 """161 def pinhole_resolution(q_calc, q, q_width, nsigma=PINHOLE_N_SIGMA): 162 r""" 158 163 Compute the convolution matrix *W* for pinhole resolution 1D data. 159 164 … … 162 167 *W*, the resolution smearing can be computed using *dot(W,q)*. 163 168 169 Note that resolution is limited to $\pm 2.5 \sigma$.[1] The true resolution 170 function is a broadened triangle, and does not extend over the entire 171 range $(\infty, +\infty)$. It is important to impose this limitation 172 since some models fall so steeply that the weighted value in gaussian 173 tails would otherwise dominate the integral. 174 164 175 *q_calc* must be increasing. *q_width* must be greater than zero. 176 177 [1] Barker, J. G., and J. S. Pedersen. 1995. Instrumental Smearing Effects 178 in Radially Symmetric SmallAngle Neutron Scattering by Numerical and 179 Analytical Methods. Journal of Applied Crystallography 28 (2): 10514. 180 https://doi.org/10.1107/S0021889894010095. 165 181 """ 166 182 # The current algorithm is a midpoint rectangle rule. In the test case, … … 170 186 cdf = erf((edges[:, None]  q[None, :]) / (sqrt(2.0)*q_width)[None, :]) 171 187 weights = cdf[1:]  cdf[:1] 188 # Limit q range to +/ 2.5 sigma 189 weights[q_calc[:, None] < (q  nsigma*q_width)[None, :]] = 0. 190 weights[q_calc[:, None] > (q + nsigma*q_width)[None, :]] = 0. 172 191 weights /= np.sum(weights, axis=0)[None, :] 173 192 return weights
Note: See TracChangeset
for help on using the changeset viewer.