Changeset f1b8c90 in sasmodels


Ignore:
Timestamp:
Mar 26, 2015 2:41:58 PM (9 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:
9e430d0
Parents:
6871c9e
Message:

tweak internal function interfaces to expose more options

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/resolution.py

    r6871c9e rf1b8c90  
    5656    be estimated from the *q* and *q_width*. 
    5757    """ 
    58     def __init__(self, q, q_width, q_calc=None): 
     58    def __init__(self, q, q_width, q_calc=None, nsigma=3): 
    5959        #*min_step* is the minimum point spacing to use when computing the 
    6060        #underlying model.  It should be on the order of 
     
    6868        # default to Perfect1D if the pinhole geometry is not defined. 
    6969        self.q, self.q_width = q, q_width 
    70         self.q_calc = pinhole_extend_q(q, q_width) \ 
     70        self.q_calc = pinhole_extend_q(q, q_width, nsigma=nsigma) \ 
    7171            if q_calc is None else np.sort(q_calc) 
    7272        self.weight_matrix = pinhole_resolution(self.q_calc, 
     
    203203    """ 
    204204    q_min, q_max = np.min(q - nsigma*q_width), np.max(q + nsigma*q_width) 
    205     return geometric_extrapolation(q, q_min, q_max) 
     205    return linear_extrapolation(q, q_min, q_max) 
    206206 
    207207 
     
    267267    """ 
    268268    Extrapolate *q* out to [*q_min*, *q_max*] using the step size in *q* as 
    269     a guide.  Extrapolation below uses steps the same size as the first 
    270     interval.  Extrapolation above uses steps the same size as the final 
     269    a guide.  Extrapolation below uses about the same size as the first 
     270    interval.  Extrapolation above uses about the same size as the final 
    271271    interval. 
    272272 
     
    276276    if q_min < q[0]: 
    277277        if q_min <= 0: q_min = q[0]/10 
    278         delta = q[1] - q[0] 
    279         q_low = np.arange(q_min, q[0], delta) 
     278        n_low = np.ceil((q[0]-q_min) / (q[1]-q[0])) if q[1]>q[0] else 15 
     279        q_low = np.linspace(q_min, q[0], n_low+1)[:-1] 
    280280    else: 
    281281        q_low = [] 
    282282    if q_max > q[-1]: 
    283         delta = q[-1] - q[-2] 
    284         q_high = np.arange(q[-1]+delta, q_max, delta) 
     283        n_high = np.ceil((q_max-q[-1]) / (q[-1]-q[-2])) if q[-1]>q[-2] else 15 
     284        q_high = np.linspace(q[-1], q_max, n_high+1)[1:] 
    285285    else: 
    286286        q_high = [] 
     
    288288 
    289289 
    290 def geometric_extrapolation(q, q_min, q_max): 
     290def geometric_extrapolation(q, q_min, q_max, points_per_decade=None): 
    291291    r""" 
    292292    Extrapolate *q* to [*q_min*, *q_max*] using geometric steps, with the 
     
    295295    if *q_min* is zero or less then *q[0]/10* is used instead. 
    296296 
    297     Starting at $q_1$ and stepping geometrically by $\Delta q$ 
    298     to $q_n$ in $n$ points gives a geometric average of: 
     297    *points_per_decade* sets the ratio between consecutive steps such 
     298    that there will be $n$ points used for every factor of 10 increase 
     299    in *q*. 
     300 
     301    If *points_per_decade* is not given, it will be estimated as follows. 
     302    Starting at $q_1$ and stepping geometrically by $\Delta q$ to $q_n$ 
     303    in $n$ points gives a geometric average of: 
    299304 
    300305    .. math:: 
     
    315320    """ 
    316321    q = np.sort(q) 
    317     delta_q = (len(q)-1)/(log(q[-1]) - log(q[0])) 
     322    if points_per_decade is None: 
     323        log_delta_q = (len(q) - 1) / (log(q[-1]) - log(q[0])) 
     324    else: 
     325        log_delta_q = log(10.) / points_per_decade 
    318326    if q_min < q[0]: 
    319327        if q_min < 0: q_min = q[0]/10 
    320         n_low = delta_q * (log(q[0])-log(q_min)) 
     328        n_low = log_delta_q * (log(q[0])-log(q_min)) 
    321329        q_low  = np.logspace(log10(q_min), log10(q[0]), np.ceil(n_low)+1)[:-1] 
    322330    else: 
    323331        q_low = [] 
    324332    if q_max > q[-1]: 
    325         n_high = delta_q * (log(q_max)-log(q[-1])) 
     333        n_high = log_delta_q * (log(q_max)-log(q[-1])) 
    326334        q_high = np.logspace(log10(q[-1]), log10(q_max), np.ceil(n_high)+1)[1:] 
    327335    else: 
     
    372380 
    373381 
    374 def romberg_pinhole_1d(q, q_width, form, pars): 
     382def romberg_pinhole_1d(q, q_width, form, pars, nsigma=5): 
    375383    """ 
    376384    Romberg integration for pinhole resolution. 
     
    388396 
    389397    _fn = lambda q, q0, dq: eval_form(q, form, pars)*gaussian(q, q0, dq) 
    390     r = [romberg(_fn, max(qi-5*dqi,0.01*q[0]), qi+5*dqi, args=(qi, dqi), 
     398    r = [romberg(_fn, max(qi-nsigma*dqi,1e-10*q[0]), qi+nsigma*dqi, args=(qi, dqi), 
    391399                 divmax=100, vec_func=True, tol=0, rtol=1e-8) 
    392400         for qi,dqi in zip(q,q_width)] 
     
    640648        output = self.Iq_sphere(pars, resolution) 
    641649        self.compare(q, output, answer, 1e-6) 
    642  
    643650 
    644651 
Note: See TracChangeset for help on using the changeset viewer.