Changeset 40a87fa in sasmodels for sasmodels/resolution.py
- Timestamp:
- Aug 8, 2016 11:24:11 AM (8 years ago)
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/resolution.py
r7ae2b7f r40a87fa 154 154 edges = bin_edges(q_calc) 155 155 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] 158 158 weights /= np.sum(weights, axis=0)[None, :] 159 159 return weights … … 307 307 weights[i, :] = (in_x + abs_x) * np.diff(q_edges) / (2*h) 308 308 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 313 312 314 313 return weights.T … … 523 522 for i, (qi, w, h) in enumerate(zip(q, width, height)): 524 523 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/w524 total = romberg(_int_w, 0, w, args=(qi,), 525 divmax=100, vec_func=True, tol=0, rtol=1e-8) 526 result[i] = total/w 528 527 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) 532 531 else: 533 532 w_grid = np.linspace(0, w, 21)[None, :] 534 533 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) 537 536 #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) 540 539 # from scipy.integrate import dblquad 541 540 # r, err = dblquad(_int_wh, -h, h, lambda h: 0., lambda h: w, … … 564 563 565 564 _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)] 569 569 return np.asarray(r).flatten() 570 570 … … 715 715 716 716 data = np.loadtxt(data_string.split('\n')).T 717 q, width, answer, _ = data717 q, _, answer, _ = data 718 718 resolution = Perfect1D(q) 719 719 output = self._eval_sphere(pars, resolution) … … 741 741 data_string = TEST_DATA_PINHOLE_SPHERE 742 742 pars['radius'] *= 5 743 radius = pars['radius']744 743 745 744 data = np.loadtxt(data_string.split('\n')).T … … 748 747 ## Getting 0.1% requires 5 sigma and 200 points per fringe 749 748 #q_calc = interpolate(pinhole_extend_q(q, q_width, nsigma=5), 750 # 2*np.pi/ radius/200)749 # 2*np.pi/pars['radius']/200) 751 750 #tol = 0.001 752 751 ## The default 3 sigma and no extra points gets 1% … … 787 786 pars = TEST_PARS_SLIT_SPHERE 788 787 data_string = TEST_DATA_SLIT_SPHERE 789 radius = pars['radius']790 788 791 789 data = np.loadtxt(data_string.split('\n')).T 792 790 q, delta_qv, _, answer = data 793 791 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), 795 793 delta_qv[0], 0.) 796 794 resolution = Slit1D(q, qx_width=delta_qv, qy_width=0, q_calc=q_calc)
Note: See TracChangeset
for help on using the changeset viewer.