Changeset 40a87fa in sasmodels for sasmodels/resolution.py


Ignore:
Timestamp:
Aug 8, 2016 11:24:11 AM (8 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:
2472141
Parents:
2d65d51
Message:

lint and latex cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/resolution.py

    r7ae2b7f r40a87fa  
    154154    edges = bin_edges(q_calc) 
    155155    edges[edges < 0.0] = 0.0 # clip edges below zero 
    156     G = erf((edges[:, None] - q[None, :]) / (sqrt(2.0)*q_width)[None, :]) 
    157     weights = G[1:] - G[:-1] 
     156    cdf = erf((edges[:, None] - q[None, :]) / (sqrt(2.0)*q_width)[None, :]) 
     157    weights = cdf[1:] - cdf[:-1] 
    158158    weights /= np.sum(weights, axis=0)[None, :] 
    159159    return weights 
     
    307307            weights[i, :] = (in_x + abs_x) * np.diff(q_edges) / (2*h) 
    308308        else: 
    309             L = n_height 
    310             for k in range(-L, L+1): 
    311                 weights[i, :] += _q_perp_weights(q_edges, qi+k*h/L, w) 
    312             weights[i, :] /= 2*L + 1 
     309            for k in range(-n_height, h_height+1): 
     310                weights[i, :] += _q_perp_weights(q_edges, qi+k*h/n_height, w) 
     311            weights[i, :] /= 2*n_height + 1 
    313312 
    314313    return weights.T 
     
    523522    for i, (qi, w, h) in enumerate(zip(q, width, height)): 
    524523        if h == 0.: 
    525             r = romberg(_int_w, 0, w, args=(qi,), 
    526                         divmax=100, vec_func=True, tol=0, rtol=1e-8) 
    527             result[i] = r/w 
     524            total = romberg(_int_w, 0, w, args=(qi,), 
     525                            divmax=100, vec_func=True, tol=0, rtol=1e-8) 
     526            result[i] = total/w 
    528527        elif w == 0.: 
    529             r = romberg(_int_h, -h, h, args=(qi,), 
    530                         divmax=100, vec_func=True, tol=0, rtol=1e-8) 
    531             result[i] = r/(2*h) 
     528            total = romberg(_int_h, -h, h, args=(qi,), 
     529                            divmax=100, vec_func=True, tol=0, rtol=1e-8) 
     530            result[i] = total/(2*h) 
    532531        else: 
    533532            w_grid = np.linspace(0, w, 21)[None, :] 
    534533            h_grid = np.linspace(-h, h, 23)[:, None] 
    535             u = sqrt((qi+h_grid)**2 + w_grid**2) 
    536             Iu = np.interp(u, q_calc, Iq) 
     534            u_sub = sqrt((qi+h_grid)**2 + w_grid**2) 
     535            f_at_u = np.interp(u_sub, q_calc, Iq) 
    537536            #print(np.trapz(Iu, w_grid, axis=1)) 
    538             Is = np.trapz(np.trapz(Iu, w_grid, axis=1), h_grid[:, 0]) 
    539             result[i] = Is / (2*h*w) 
     537            total  = np.trapz(np.trapz(f_at_u, w_grid, axis=1), h_grid[:, 0]) 
     538            result[i] = total / (2*h*w) 
    540539            # from scipy.integrate import dblquad 
    541540            # r, err = dblquad(_int_wh, -h, h, lambda h: 0., lambda h: w, 
     
    564563 
    565564    _fn = lambda q, q0, dq: eval_form(q, form, pars)*gaussian(q, q0, dq) 
    566     r = [romberg(_fn, max(qi-nsigma*dqi, 1e-10*q[0]), qi+nsigma*dqi, 
    567                  args=(qi, dqi), divmax=100, vec_func=True, tol=0, rtol=1e-8) 
    568          for qi, dqi in zip(q, q_width)] 
     565    total = [romberg(_fn, max(qi-nsigma*dqi, 1e-10*q[0]), qi+nsigma*dqi, 
     566                     args=(qi, dqi), divmax=100, vec_func=True, 
     567                     tol=0, rtol=1e-8) 
     568             for qi, dqi in zip(q, q_width)] 
    569569    return np.asarray(r).flatten() 
    570570 
     
    715715 
    716716        data = np.loadtxt(data_string.split('\n')).T 
    717         q, width, answer, _ = data 
     717        q, _, answer, _ = data 
    718718        resolution = Perfect1D(q) 
    719719        output = self._eval_sphere(pars, resolution) 
     
    741741        data_string = TEST_DATA_PINHOLE_SPHERE 
    742742        pars['radius'] *= 5 
    743         radius = pars['radius'] 
    744743 
    745744        data = np.loadtxt(data_string.split('\n')).T 
     
    748747        ## Getting 0.1% requires 5 sigma and 200 points per fringe 
    749748        #q_calc = interpolate(pinhole_extend_q(q, q_width, nsigma=5), 
    750         #                     2*np.pi/radius/200) 
     749        #                     2*np.pi/pars['radius']/200) 
    751750        #tol = 0.001 
    752751        ## The default 3 sigma and no extra points gets 1% 
     
    787786        pars = TEST_PARS_SLIT_SPHERE 
    788787        data_string = TEST_DATA_SLIT_SPHERE 
    789         radius = pars['radius'] 
    790788 
    791789        data = np.loadtxt(data_string.split('\n')).T 
    792790        q, delta_qv, _, answer = data 
    793791        answer = romberg_slit_1d(q, delta_qv, 0., self.model, pars) 
    794         q_calc = slit_extend_q(interpolate(q, 2*np.pi/radius/20), 
     792        q_calc = slit_extend_q(interpolate(q, 2*np.pi/pars['radius']/20), 
    795793                               delta_qv[0], 0.) 
    796794        resolution = Slit1D(q, qx_width=delta_qv, qy_width=0, q_calc=q_calc) 
Note: See TracChangeset for help on using the changeset viewer.