Changeset 1198f90 in sasmodels for sasmodels/resolution.py


Ignore:
Timestamp:
May 17, 2018 6:07:02 PM (6 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
df0d2ca
Parents:
33969b6
Message:

limit pinhole resolution integral to ± 2.5 dq

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/resolution.py

    r2d81cfe r1198f90  
    2020MINIMUM_RESOLUTION = 1e-8 
    2121MINIMUM_ABSOLUTE_Q = 0.02  # relative to the minimum q in the data 
     22PINHOLE_N_SIGMA = 2.5 # From: Barker & Pedersen 1995 JAC 
    2223 
    2324class Resolution(object): 
     
    6566    *q_calc* is the list of points to calculate, or None if this should 
    6667    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): 
    6973        #*min_step* is the minimum point spacing to use when computing the 
    7074        #underlying model.  It should be on the order of 
     
    8892        # Build weight matrix from calculated q values 
    8993        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) 
    9196        self.q_calc = abs(self.q_calc) 
    9297 
     
    154159 
    155160 
    156 def pinhole_resolution(q_calc, q, q_width): 
    157     """ 
     161def pinhole_resolution(q_calc, q, q_width, nsigma=PINHOLE_N_SIGMA): 
     162    r""" 
    158163    Compute the convolution matrix *W* for pinhole resolution 1-D data. 
    159164 
     
    162167    *W*, the resolution smearing can be computed using *dot(W,q)*. 
    163168 
     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 
    164175    *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 Small-Angle Neutron Scattering by Numerical and 
     179    Analytical Methods. Journal of Applied Crystallography 28 (2): 105--14. 
     180    https://doi.org/10.1107/S0021889894010095. 
    165181    """ 
    166182    # The current algorithm is a midpoint rectangle rule.  In the test case, 
     
    170186    cdf = erf((edges[:, None] - q[None, :]) / (sqrt(2.0)*q_width)[None, :]) 
    171187    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. 
    172191    weights /= np.sum(weights, axis=0)[None, :] 
    173192    return weights 
Note: See TracChangeset for help on using the changeset viewer.