Changeset e7724f5 in sasmodels


Ignore:
Timestamp:
Mar 26, 2015 2:45:00 PM (10 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:
6ee9d39
Parents:
2c801fe (diff), 42ade62 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of github.com:sasview/sasmodels

Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/kerneldll.py

    raa4946b r2c801fe  
    1717from . import generate 
    1818from .kernelpy import PyInput, PyModel 
     19from .exception import annotate_exception 
    1920 
    2021# Compiler platform details 
     
    145146 
    146147        #print "dll",self.dllpath 
    147         self.dll = ct.CDLL(self.dllpath) 
     148        try: 
     149            self.dll = ct.CDLL(self.dllpath) 
     150        except Exception, exc: 
     151            annotate_exception("while loading "+self.dllpath) 
     152            raise 
    148153 
    149154        fp = c_float if self.dtype == generate.F32 else c_double 
  • sasmodels/model_test.py

    rdb8756e r9e430d0  
    5151from .core import list_models, load_model_definition, load_model, HAVE_OPENCL 
    5252from .core import make_kernel, call_kernel, call_ER, call_VR 
    53  
    54  
    55 def annotate_exception(exc, msg): 
    56     """ 
    57     Add an annotation to the current exception, which can then be forwarded 
    58     to the caller using a bare "raise" statement to reraise the annotated 
    59     exception. 
    60     Example:: 
    61         >>> D = {} 
    62         >>> try: 
    63         ...    print D['hello'] 
    64         ... except Exception,exc: 
    65         ...    annotate_exception(exc, "while accessing 'D'") 
    66         ...    raise 
    67         Traceback (most recent call last): 
    68             ... 
    69         KeyError: "hello while accessing 'D'" 
    70     """ 
    71     args = exc.args 
    72     if not args: 
    73         exc.args = (msg,) 
    74     else: 
    75         try: 
    76             arg0 = " ".join((args[0],msg)) 
    77             exc.args = tuple([arg0] + list(args[1:])) 
    78         except: 
    79             exc.args = (" ".join((str(exc),msg)),) 
     53from .exception import annotate_exception 
    8054 
    8155 
  • 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.