Changeset d86f0fc in sasmodels
- Timestamp:
- Mar 26, 2018 1:52:24 PM (7 years ago)
- Branches:
- master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 802c412
- Parents:
- f4ae8c4
- Location:
- sasmodels
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/compare.py
r3221de0 rd86f0fc 718 718 model = core.build_model(model_info, dtype=dtype, platform="ocl") 719 719 calculator = DirectModel(data, model, cutoff=cutoff) 720 engine_type = calculator._model.__class__.__name__.replace('Model', '').upper()720 engine_type = calculator._model.__class__.__name__.replace('Model', '').upper() 721 721 bits = calculator._model.dtype.itemsize*8 722 722 precision = "fast" if getattr(calculator._model, 'fast', False) else str(bits) … … 1491 1491 vmin, vmax = limits 1492 1492 self.limits = vmax*1e-7, 1.3*vmax 1493 import pylab; pylab.clf() 1493 import pylab 1494 pylab.clf() 1494 1495 plot_models(self.opts, result, limits=self.limits) 1495 1496 -
sasmodels/data.py
rf549e37 rd86f0fc 706 706 else: 707 707 vmin_scaled, vmax_scaled = vmin, vmax 708 nx, ny = len(data.x_bins), len(data.y_bins)708 #nx, ny = len(data.x_bins), len(data.y_bins) 709 709 x_bins, y_bins, image = _build_matrix(data, plottable) 710 710 plt.imshow(image, … … 772 772 if loop >= max_loop: # this protects never-ending loop 773 773 break 774 image = _fillup_pixels( self,image=image, weights=weights)774 image = _fillup_pixels(image=image, weights=weights) 775 775 loop += 1 776 776 … … 817 817 return x_bins, y_bins 818 818 819 def _fillup_pixels( self,image=None, weights=None):819 def _fillup_pixels(image=None, weights=None): 820 820 """ 821 821 Fill z values of the empty cells of 2d image matrix -
sasmodels/generate.py
ra0243f7 rd86f0fc 290 290 import loops. 291 291 """ 292 if (info.source and any(lib.startswith('lib/gauss') for lib in info.source)): 293 import os.path 292 if info.source and any(lib.startswith('lib/gauss') for lib in info.source): 294 293 from .gengauss import gengauss 295 path = os.path.join(MODEL_PATH, "lib", "gauss%d.c"%n)296 if not os.path.exists(path):294 path = joinpath(MODEL_PATH, "lib", "gauss%d.c"%n) 295 if not exists(path): 297 296 gengauss(n, path) 298 297 info.source = ["lib/gauss%d.c"%n if lib.startswith('lib/gauss') 299 298 else lib for lib in info.source] 300 299 301 300 def format_units(units): … … 321 320 for w, h in zip(column_widths, PARTABLE_HEADERS)] 322 321 323 sep= " ".join("="*w for w in column_widths)322 underbar = " ".join("="*w for w in column_widths) 324 323 lines = [ 325 sep,324 underbar, 326 325 " ".join("%-*s" % (w, h) 327 326 for w, h in zip(column_widths, PARTABLE_HEADERS)), 328 sep,327 underbar, 329 328 ] 330 329 for p in pars: … … 335 334 "%*g" % (column_widths[3], p.default), 336 335 ])) 337 lines.append( sep)336 lines.append(underbar) 338 337 return "\n".join(lines) 339 338 … … 613 612 """ 614 613 spaces = " "*depth 615 sep= "\n" + spaces616 return spaces + sep.join(s.split("\n"))614 interline_separator = "\n" + spaces 615 return spaces + interline_separator.join(s.split("\n")) 617 616 618 617 … … 620 619 def load_template(filename): 621 620 # type: (str) -> str 621 """ 622 Load template file from sasmodels resource directory. 623 """ 622 624 path = joinpath(DATA_PATH, filename) 623 625 mtime = getmtime(path) -
sasmodels/guyou.py
r0d5a655 rd86f0fc 31 31 # 32 32 # 2017-11-01 Paul Kienzle 33 # * converted to python, using degrees rather than radians 33 # * converted to python, with degrees rather than radians 34 """ 35 Convert between latitude-longitude and Guyou map coordinates. 36 """ 37 34 38 from __future__ import division, print_function 35 39 36 40 import numpy as np 37 from numpy import sqrt, pi, tan, cos, sin, log, exp, arctan2 as atan2, sign, radians, degrees 41 from numpy import sqrt, pi, tan, cos, sin, sign, radians, degrees 42 from numpy import sinh, arctan as atan 43 44 # scipy version of special functions 45 from scipy.special import ellipj as ellipticJ, ellipkinc as ellipticF 38 46 39 47 _ = """ … … 59 67 """ 60 68 61 # scipy version of special functions62 from scipy.special import ellipj as ellipticJ, ellipkinc as ellipticF63 from numpy import sinh, sign, arctan as atan64 65 69 def ellipticJi(u, v, m): 66 70 scalar = np.isscalar(u) and np.isscalar(v) and np.isscalar(m) 67 71 u, v, m = np.broadcast_arrays(u, v, m) 68 result = np.empty_like([u, u,u], 'D')69 real = v==070 imag = u==072 result = np.empty_like([u, u, u], 'D') 73 real = (v == 0) 74 imag = (u == 0) 71 75 mixed = ~(real|imag) 72 76 result[:, real] = _ellipticJi_real(u[real], m[real]) 73 77 result[:, imag] = _ellipticJi_imag(v[imag], m[imag]) 74 78 result[:, mixed] = _ellipticJi(u[mixed], v[mixed], m[mixed]) 75 return result[0, :] if scalar else result79 return result[0, :] if scalar else result 76 80 77 81 def _ellipticJi_real(u, m): … … 104 108 result = np.empty_like(phi, 'D') 105 109 index = (phi == 0) 106 result[index] = ellipticF(atan(sinh(abs(phi[index]))), 1-m[index]) * sign(psi[index]) 110 result[index] = ellipticF(atan(sinh(abs(phi[index]))), 111 1-m[index]) * sign(psi[index]) 107 112 result[~index] = ellipticFi(phi[~index], psi[~index], m[~index]) 108 113 return result.reshape(1)[0] if scalar else result … … 117 122 cotlambda2 = (-b + sqrt(b * b - 4 * c)) / 2 118 123 re = ellipticF(atan(1 / sqrt(cotlambda2)), m) * sign(phi) 119 im = ellipticF(atan(sqrt(np.maximum(0,(cotlambda2 / cotphi2 - 1) / m))), 1 - m) * sign(psi) 124 im = ellipticF(atan(sqrt(np.maximum(0, (cotlambda2 / cotphi2 - 1) / m))), 125 1 - m) * sign(psi) 120 126 return re + 1j*im 121 127 122 sqrt2 = sqrt(2)128 SQRT2 = sqrt(2) 123 129 124 130 # [PAK] renamed k_ => cos_u, k => sin_u, k*k => sinsq_u to avoid k,K confusion … … 127 133 # K = 3.165103454447431823666270142140819753058976299237578486994... 128 134 def guyou(lam, phi): 135 """Transform from (latitude, longitude) to point (x, y)""" 129 136 # [PAK] wrap into [-pi/2, pi/2] radians 130 137 x, y = np.asarray(lam), np.asarray(phi) … … 135 142 136 143 # Compute constant K 137 cos_u = ( sqrt2 - 1) / (sqrt2 + 1)144 cos_u = (SQRT2 - 1) / (SQRT2 + 1) 138 145 sinsq_u = 1 - cos_u**2 139 146 K = ellipticF(pi/2, sinsq_u) … … 144 151 at = atan(r * (cos(lam) - 1j*sin(lam))) 145 152 t = ellipticFi(at.real, at.imag, sinsq_u) 146 x, y = (-t.imag, sign(phi + (phi ==0))*(0.5 * K - t.real))153 x, y = (-t.imag, sign(phi + (phi == 0))*(0.5 * K - t.real)) 147 154 148 155 # [PAK] convert to degrees, and return to original tile … … 150 157 151 158 def guyou_invert(x, y): 159 """Transform from point (x, y) on plot to (latitude, longitude)""" 152 160 # [PAK] wrap into [-pi/2, pi/2] radians 153 161 x, y = np.asarray(x), np.asarray(y) … … 158 166 159 167 # compute constant K 160 cos_u = ( sqrt2 - 1) / (sqrt2 + 1)168 cos_u = (SQRT2 - 1) / (SQRT2 + 1) 161 169 sinsq_u = 1 - cos_u**2 162 170 K = ellipticF(pi/2, sinsq_u) … … 174 182 175 183 def plot_grid(): 184 """Plot the latitude-longitude grid for Guyou transform""" 176 185 import matplotlib.pyplot as plt 177 186 from numpy import linspace … … 203 212 plt.ylabel('latitude') 204 213 214 def main(): 215 plot_grid() 216 import matplotlib.pyplot as plt 217 plt.show() 218 205 219 if __name__ == "__main__": 206 plot_grid() 207 import matplotlib.pyplot as plt; plt.show() 208 220 main() 209 221 210 222 _ = """ -
sasmodels/jitter.py
r199bd07 rd86f0fc 7 7 """ 8 8 from __future__ import division, print_function 9 10 import sys, os11 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.realpath(__file__))))12 9 13 10 import argparse … … 50 47 def draw_ellipsoid(ax, size, view, jitter, steps=25, alpha=1): 51 48 """Draw an ellipsoid.""" 52 a, b,c = size49 a, b, c = size 53 50 u = np.linspace(0, 2 * np.pi, steps) 54 51 v = np.linspace(0, np.pi, steps) … … 61 58 62 59 draw_labels(ax, view, jitter, [ 63 ('c+', [ 0, 0, c], [ 1, 0,0]),64 ('c-', [ 0, 0,-c], [ 0, 0,-1]),65 ('a+', [ a, 0, 0], [ 0, 0,1]),66 ('a-', [-a, 0, 0], [ 0, 0,-1]),67 ('b+', [ 0, b, 0], [-1, 0,0]),68 ('b-', [ 0,-b, 0], [-1, 0,0]),60 ('c+', [+0, +0, +c], [+1, +0, +0]), 61 ('c-', [+0, +0, -c], [+0, +0, -1]), 62 ('a+', [+a, +0, +0], [+0, +0, +1]), 63 ('a-', [-a, +0, +0], [+0, +0, -1]), 64 ('b+', [+0, +b, +0], [-1, +0, +0]), 65 ('b-', [+0, -b, +0], [-1, +0, +0]), 69 66 ]) 70 67 71 68 def draw_sc(ax, size, view, jitter, steps=None, alpha=1): 69 """Draw points for simple cubic paracrystal""" 72 70 atoms = _build_sc() 73 71 _draw_crystal(ax, size, view, jitter, atoms=atoms) 74 72 75 73 def draw_fcc(ax, size, view, jitter, steps=None, alpha=1): 74 """Draw points for face-centered cubic paracrystal""" 76 75 # Build the simple cubic crystal 77 76 atoms = _build_sc() … … 88 87 89 88 def draw_bcc(ax, size, view, jitter, steps=None, alpha=1): 89 """Draw points for body-centered cubic paracrystal""" 90 90 # Build the simple cubic crystal 91 91 atoms = _build_sc() … … 127 127 """Draw a parallelepiped.""" 128 128 a, b, c = size 129 x = a*np.array([ 1,-1, 1,-1, 1,-1, 1,-1])130 y = b*np.array([ 1, 1,-1,-1, 1, 1,-1,-1])131 z = c*np.array([ 1, 1, 1, 1,-1,-1,-1,-1])129 x = a*np.array([+1, -1, +1, -1, +1, -1, +1, -1]) 130 y = b*np.array([+1, +1, -1, -1, +1, +1, -1, -1]) 131 z = c*np.array([+1, +1, +1, +1, -1, -1, -1, -1]) 132 132 tri = np.array([ 133 133 # counter clockwise triangles 134 134 # z: up/down, x: right/left, y: front/back 135 [0, 1,2], [3,2,1], # top face136 [6, 5,4], [5,6,7], # bottom face137 [0, 2,6], [6,4,0], # right face138 [1, 5,7], [7,3,1], # left face139 [2, 3,6], [7,6,3], # front face140 [4, 1,0], [5,1,4], # back face135 [0, 1, 2], [3, 2, 1], # top face 136 [6, 5, 4], [5, 6, 7], # bottom face 137 [0, 2, 6], [6, 4, 0], # right face 138 [1, 5, 7], [7, 3, 1], # left face 139 [2, 3, 6], [7, 6, 3], # front face 140 [4, 1, 0], [5, 1, 4], # back face 141 141 ]) 142 142 … … 149 149 # rotate that face. 150 150 if 1: 151 x = a*np.array([ 1,-1, 1,-1, 1,-1, 1,-1])152 y = b*np.array([ 1, 1,-1,-1, 1, 1,-1,-1])153 z = c*np.array([ 1, 1, 1, 1,-1,-1,-1,-1])151 x = a*np.array([+1, -1, +1, -1, +1, -1, +1, -1]) 152 y = b*np.array([+1, +1, -1, -1, +1, +1, -1, -1]) 153 z = c*np.array([+1, +1, +1, +1, -1, -1, -1, -1]) 154 154 x, y, z = transform_xyz(view, jitter, x, y, abs(z)+0.001) 155 ax.plot_trisurf(x, y, triangles=tri, Z=z, color=[1, 0.6,0.6], alpha=alpha)155 ax.plot_trisurf(x, y, triangles=tri, Z=z, color=[1, 0.6, 0.6], alpha=alpha) 156 156 157 157 draw_labels(ax, view, jitter, [ 158 ('c+', [ 0, 0, c], [ 1, 0,0]),159 ('c-', [ 0, 0,-c], [ 0, 0,-1]),160 ('a+', [ a, 0, 0], [ 0, 0,1]),161 ('a-', [-a, 0, 0], [ 0, 0,-1]),162 ('b+', [ 0, b, 0], [-1, 0,0]),163 ('b-', [ 0,-b, 0], [-1, 0,0]),158 ('c+', [+0, +0, +c], [+1, +0, +0]), 159 ('c-', [+0, +0, -c], [+0, +0, -1]), 160 ('a+', [+a, +0, +0], [+0, +0, +1]), 161 ('a-', [-a, +0, +0], [+0, +0, -1]), 162 ('b+', [+0, +b, +0], [-1, +0, +0]), 163 ('b-', [+0, -b, +0], [-1, +0, +0]), 164 164 ]) 165 165 … … 187 187 cloud = [ 188 188 [-1, -1, -1], 189 [-1, -1, 190 [-1, -1, 191 [-1, 192 [-1, 0,0],193 [-1, 0,1],194 [-1, 195 [-1, 1,0],196 [-1, 1,1],197 [ 198 [ 0, -1,0],199 [ 0, -1,1],200 [ 0,0, -1],201 [ 0, 0,0],202 [ 0, 0,1],203 [ 0,1, -1],204 [ 0, 1,0],205 [ 0, 1,1],206 [ 207 [ 1, -1,0],208 [ 1, -1,1],209 [ 1,0, -1],210 [ 1, 0,0],211 [ 1, 0,1],212 [ 1,1, -1],213 [ 1, 1,0],214 [ 1, 1,1],189 [-1, -1, +0], 190 [-1, -1, +1], 191 [-1, +0, -1], 192 [-1, +0, +0], 193 [-1, +0, +1], 194 [-1, +1, -1], 195 [-1, +1, +0], 196 [-1, +1, +1], 197 [+0, -1, -1], 198 [+0, -1, +0], 199 [+0, -1, +1], 200 [+0, +0, -1], 201 [+0, +0, +0], 202 [+0, +0, +1], 203 [+0, +1, -1], 204 [+0, +1, +0], 205 [+0, +1, +1], 206 [+1, -1, -1], 207 [+1, -1, +0], 208 [+1, -1, +1], 209 [+1, +0, -1], 210 [+1, +0, +0], 211 [+1, +0, +1], 212 [+1, +1, -1], 213 [+1, +1, +0], 214 [+1, +1, +1], 215 215 ] 216 216 dtheta, dphi, dpsi = jitter … … 228 228 for v in 'xyz': 229 229 a, b, c = size 230 lim = np.sqrt(a**2 +b**2+c**2)230 lim = np.sqrt(a**2 + b**2 + c**2) 231 231 getattr(ax, 'set_'+v+'lim')([-lim, lim]) 232 232 getattr(ax, v+'axis').label.set_text(v) … … 297 297 Should allow free movement in theta, but phi is distorted. 298 298 """ 299 theta, phi, psi = view300 dtheta, dphi, dpsi = jitter301 302 299 t = np.linspace(-1, 1, n) 303 300 weights = np.ones_like(t) … … 314 311 315 312 if projection == 'equirectangular': #define PROJECTION 1 316 def rotate(theta_i, phi_j):313 def _rotate(theta_i, phi_j): 317 314 return Rx(phi_j)*Ry(theta_i) 318 def weight(theta_i, phi_j, wi, wj):315 def _weight(theta_i, phi_j, wi, wj): 319 316 return wi*wj*abs(cos(radians(theta_i))) 320 317 elif projection == 'sinusoidal': #define PROJECTION 2 321 def rotate(theta_i, phi_j):318 def _rotate(theta_i, phi_j): 322 319 latitude = theta_i 323 320 scale = cos(radians(latitude)) … … 325 322 #print("(%+7.2f, %+7.2f) => (%+7.2f, %+7.2f)"%(theta_i, phi_j, latitude, longitude)) 326 323 return Rx(longitude)*Ry(latitude) 327 def weight(theta_i, phi_j, wi, wj):324 def _weight(theta_i, phi_j, wi, wj): 328 325 latitude = theta_i 329 326 scale = cos(radians(latitude)) … … 331 328 return w*wi*wj 332 329 elif projection == 'guyou': #define PROJECTION 3 (eventually?) 333 def rotate(theta_i, phi_j):330 def _rotate(theta_i, phi_j): 334 331 from guyou import guyou_invert 335 332 #latitude, longitude = guyou_invert([theta_i], [phi_j]) 336 333 longitude, latitude = guyou_invert([phi_j], [theta_i]) 337 334 return Rx(longitude[0])*Ry(latitude[0]) 338 def weight(theta_i, phi_j, wi, wj):335 def _weight(theta_i, phi_j, wi, wj): 339 336 return wi*wj 340 337 elif projection == 'azimuthal_equidistance': # Note: Rz Ry, not Rx Ry 341 def rotate(theta_i, phi_j):338 def _rotate(theta_i, phi_j): 342 339 latitude = sqrt(theta_i**2 + phi_j**2) 343 340 longitude = degrees(np.arctan2(phi_j, theta_i)) 344 341 #print("(%+7.2f, %+7.2f) => (%+7.2f, %+7.2f)"%(theta_i, phi_j, latitude, longitude)) 345 342 return Rz(longitude)*Ry(latitude) 346 def weight(theta_i, phi_j, wi, wj):343 def _weight(theta_i, phi_j, wi, wj): 347 344 # Weighting for each point comes from the integral: 348 345 # \int\int I(q, lat, log) sin(lat) dlat dlog … … 377 374 return w*wi*wj if latitude < 180 else 0 378 375 elif projection == 'azimuthal_equal_area': 379 def rotate(theta_i, phi_j):376 def _rotate(theta_i, phi_j): 380 377 R = min(1, sqrt(theta_i**2 + phi_j**2)/180) 381 378 latitude = 180-degrees(2*np.arccos(R)) … … 383 380 #print("(%+7.2f, %+7.2f) => (%+7.2f, %+7.2f)"%(theta_i, phi_j, latitude, longitude)) 384 381 return Rz(longitude)*Ry(latitude) 385 def weight(theta_i, phi_j, wi, wj):382 def _weight(theta_i, phi_j, wi, wj): 386 383 latitude = sqrt(theta_i**2 + phi_j**2) 387 384 w = sin(radians(latitude))/latitude if latitude != 0 else 1 … … 391 388 392 389 # mesh in theta, phi formed by rotating z 390 dtheta, dphi, dpsi = jitter 393 391 z = np.matrix([[0], [0], [radius]]) 394 points = np.hstack([ rotate(theta_i, phi_j)*z392 points = np.hstack([_rotate(theta_i, phi_j)*z 395 393 for theta_i in dtheta*t 396 394 for phi_j in dphi*t]) 397 395 # select just the active points (i.e., those with phi < 180 398 w = np.array([ weight(theta_i, phi_j, wi, wj)396 w = np.array([_weight(theta_i, phi_j, wi, wj) 399 397 for wi, theta_i in zip(weights, dtheta*t) 400 398 for wj, phi_j in zip(weights, dphi*t)]) 401 399 #print(max(w), min(w), min(w[w>0])) 402 points = points[:, w >0]403 w = w[w >0]400 points = points[:, w > 0] 401 w = w[w > 0] 404 402 w /= max(w) 405 403 … … 469 467 x, y, z = [np.asarray(v) for v in (x, y, z)] 470 468 shape = x.shape 471 points = np.matrix([x.flatten(), y.flatten(),z.flatten()])469 points = np.matrix([x.flatten(), y.flatten(), z.flatten()]) 472 470 points = apply_jitter(jitter, points) 473 471 points = orient_relative_to_beam(view, points) … … 543 541 theta, phi, psi = view 544 542 theta_pd, phi_pd, psi_pd = [scale*v for v in jitter] 545 theta_pd_n, phi_pd_n, psi_pd_n = PD_N_TABLE[(theta_pd >0, phi_pd>0, psi_pd>0)]543 theta_pd_n, phi_pd_n, psi_pd_n = PD_N_TABLE[(theta_pd > 0, phi_pd > 0, psi_pd > 0)] 546 544 ## increase pd_n for testing jitter integration rather than simple viz 547 545 #theta_pd_n, phi_pd_n, psi_pd_n = [5*v for v in (theta_pd_n, phi_pd_n, psi_pd_n)] … … 571 569 if 0: 572 570 level = np.asarray(255*(Iqxy - vmin)/(vmax - vmin), 'i') 573 level[level <0] = 0571 level[level < 0] = 0 574 572 colors = plt.get_cmap()(level) 575 573 ax.plot_surface(qx, qy, -1.1, rstride=1, cstride=1, facecolors=colors) … … 618 616 return calculator 619 617 620 def select_calculator(model_name, n=150, size=(10, 40,100)):618 def select_calculator(model_name, n=150, size=(10, 40, 100)): 621 619 """ 622 620 Create a model calculator for the given shape. … … 641 639 radius = 0.5*c 642 640 calculator = build_model('sc_paracrystal', n=n, dnn=dnn, 643 644 641 d_factor=d_factor, radius=(1-d_factor)*radius, 642 background=0) 645 643 elif model_name == 'fcc_paracrystal': 646 644 a = b = c … … 650 648 radius = sqrt(2)/4 * c 651 649 calculator = build_model('fcc_paracrystal', n=n, dnn=dnn, 652 653 650 d_factor=d_factor, radius=(1-d_factor)*radius, 651 background=0) 654 652 elif model_name == 'bcc_paracrystal': 655 653 a = b = c … … 659 657 radius = sqrt(3)/2 * c 660 658 calculator = build_model('bcc_paracrystal', n=n, dnn=dnn, 661 662 659 d_factor=d_factor, radius=(1-d_factor)*radius, 660 background=0) 663 661 elif model_name == 'cylinder': 664 662 calculator = build_model('cylinder', n=n, qmax=0.3, radius=b, length=c) … … 685 683 'cylinder', 686 684 'fcc_paracrystal', 'bcc_paracrystal', 'sc_paracrystal', 687 685 ] 688 686 689 687 DRAW_SHAPES = { … … 761 759 762 760 ## add control widgets to plot 763 axtheta 761 axtheta = plt.axes([0.1, 0.15, 0.45, 0.04], axisbg=axcolor) 764 762 axphi = plt.axes([0.1, 0.1, 0.45, 0.04], axisbg=axcolor) 765 763 axpsi = plt.axes([0.1, 0.05, 0.45, 0.04], axisbg=axcolor) … … 768 766 spsi = Slider(axpsi, 'Psi', -180, 180, valinit=psi) 769 767 770 axdtheta 768 axdtheta = plt.axes([0.75, 0.15, 0.15, 0.04], axisbg=axcolor) 771 769 axdphi = plt.axes([0.75, 0.1, 0.15, 0.04], axisbg=axcolor) 772 axdpsi = plt.axes([0.75, 0.05, 0.15, 0.04], axisbg=axcolor)770 axdpsi = plt.axes([0.75, 0.05, 0.15, 0.04], axisbg=axcolor) 773 771 # Note: using ridiculous definition of rectangle distribution, whose width 774 772 # in sasmodels is sqrt(3) times the given width. Divide by sqrt(3) to keep … … 797 795 798 796 ## bind control widgets to view updater 799 stheta.on_changed(lambda v: update(v, 'theta'))797 stheta.on_changed(lambda v: update(v, 'theta')) 800 798 sphi.on_changed(lambda v: update(v, 'phi')) 801 799 spsi.on_changed(lambda v: update(v, 'psi')) … … 815 813 formatter_class=argparse.ArgumentDefaultsHelpFormatter, 816 814 ) 817 parser.add_argument('-p', '--projection', choices=PROJECTIONS, default=PROJECTIONS[0], help='coordinate projection') 818 parser.add_argument('-s', '--size', type=str, default='10,40,100', help='a,b,c lengths') 819 parser.add_argument('-d', '--distribution', choices=DISTRIBUTIONS, default=DISTRIBUTIONS[0], help='jitter distribution') 820 parser.add_argument('-m', '--mesh', type=int, default=30, help='#points in theta-phi mesh') 821 parser.add_argument('shape', choices=SHAPES, nargs='?', default=SHAPES[0], help='oriented shape') 815 parser.add_argument('-p', '--projection', choices=PROJECTIONS, 816 default=PROJECTIONS[0], 817 help='coordinate projection') 818 parser.add_argument('-s', '--size', type=str, default='10,40,100', 819 help='a,b,c lengths') 820 parser.add_argument('-d', '--distribution', choices=DISTRIBUTIONS, 821 default=DISTRIBUTIONS[0], 822 help='jitter distribution') 823 parser.add_argument('-m', '--mesh', type=int, default=30, 824 help='#points in theta-phi mesh') 825 parser.add_argument('shape', choices=SHAPES, nargs='?', default=SHAPES[0], 826 help='oriented shape') 822 827 opts = parser.parse_args() 823 828 size = tuple(int(v) for v in opts.size.split(',')) -
sasmodels/kernel_iq.c
raadec17 rd86f0fc 173 173 // Apply the rotation matrix returned from qac_rotation to the point (qx,qy), 174 174 // returning R*[qx,qy]' = [qa,qc]' 175 static double175 static void 176 176 qac_apply( 177 177 QACRotation *rotation, … … 246 246 // Apply the rotation matrix returned from qabc_rotation to the point (qx,qy), 247 247 // returning R*[qx,qy]' = [qa,qb,qc]' 248 static double248 static void 249 249 qabc_apply( 250 250 QABCRotation *rotation, -
sasmodels/kernelcl.py
r6cbdcd4 rd86f0fc 151 151 if not HAVE_OPENCL: 152 152 raise RuntimeError("OpenCL startup failed with ***" 153 + OPENCL_ERROR + "***; using C compiler instead")153 + OPENCL_ERROR + "***; using C compiler instead") 154 154 reset_environment() 155 155 if ENV is None: -
sasmodels/models/core_shell_cylinder.c
r108e70e rd86f0fc 48 48 49 49 50 double Iqac(double qab, double qc, 50 static double 51 Iqac(double qab, double qc, 51 52 double core_sld, 52 53 double shell_sld, -
sasmodels/models/hollow_rectangular_prism.c
r108e70e rd86f0fc 1 double form_volume(double length_a, double b2a_ratio, double c2a_ratio, double thickness); 2 double Iq(double q, double sld, double solvent_sld, double length_a, 3 double b2a_ratio, double c2a_ratio, double thickness); 4 5 double form_volume(double length_a, double b2a_ratio, double c2a_ratio, double thickness) 1 static double 2 form_volume(double length_a, double b2a_ratio, double c2a_ratio, double thickness) 6 3 { 7 4 double length_b = length_a * b2a_ratio; … … 16 13 } 17 14 18 double Iq(double q, 15 static double 16 Iq(double q, 19 17 double sld, 20 18 double solvent_sld, … … 85 83 } 86 84 87 double Iqabc(double qa, double qb, double qc, 85 static double 86 Iqabc(double qa, double qb, double qc, 88 87 double sld, 89 88 double solvent_sld, -
sasmodels/models/hollow_rectangular_prism_thin_walls.c
r74768cb rd86f0fc 1 double form_volume(double length_a, double b2a_ratio, double c2a_ratio); 2 double Iq(double q, double sld, double solvent_sld, double length_a, 3 double b2a_ratio, double c2a_ratio); 4 5 double form_volume(double length_a, double b2a_ratio, double c2a_ratio) 1 static double 2 form_volume(double length_a, double b2a_ratio, double c2a_ratio) 6 3 { 7 4 double length_b = length_a * b2a_ratio; … … 11 8 } 12 9 13 double Iq(double q, 10 static double 11 Iq(double q, 14 12 double sld, 15 13 double solvent_sld, -
sasmodels/models/rectangular_prism.c
r108e70e rd86f0fc 1 double form_volume(double length_a, double b2a_ratio, double c2a_ratio); 2 double Iq(double q, double sld, double solvent_sld, double length_a, 3 double b2a_ratio, double c2a_ratio); 4 5 double form_volume(double length_a, double b2a_ratio, double c2a_ratio) 1 static double 2 form_volume(double length_a, double b2a_ratio, double c2a_ratio) 6 3 { 7 4 return length_a * (length_a*b2a_ratio) * (length_a*c2a_ratio); 8 5 } 9 6 10 double Iq(double q, 7 static double 8 Iq(double q, 11 9 double sld, 12 10 double solvent_sld, … … 71 69 72 70 73 double Iqabc(double qa, double qb, double qc, 71 static double 72 Iqabc(double qa, double qb, double qc, 74 73 double sld, 75 74 double solvent_sld, -
sasmodels/multiscat.py
r49d1f8b8 rd86f0fc 261 261 262 262 def scattering_coeffs(p, coverage=0.99): 263 r""" 264 Return the coefficients of the scattering powers for transmission 265 probability *p*. This is just the corresponding values for the 266 Poisson distribution for $\lambda = -\ln(1-p)$ such that 267 $\sum_{k = 0 \ldots n} P(k; \lambda)$ is larger than *coverage*. 268 """ 263 269 L = -np.log(1-p) 264 270 num_scatter = truncated_poisson_invcdf(coverage, L) … … 266 272 return coeffs 267 273 268 def truncated_poisson_invcdf( p, L):274 def truncated_poisson_invcdf(coverage, L): 269 275 r""" 270 Return smallest k such that cdf(k; L) > pfrom the truncated Poisson276 Return smallest k such that cdf(k; L) > coverage from the truncated Poisson 271 277 probability excluding k=0 272 278 """ … … 275 281 pmf = -np.exp(-L) / np.expm1(-L) 276 282 k = 0 277 while cdf < p:283 while cdf < coverage: 278 284 k += 1 279 285 pmf *= L/k … … 305 311 306 312 class MultipleScattering(Resolution): 313 r""" 314 Compute multiple scattering using Fourier convolution. 315 316 The fourier steps are determined by *qmax*, the maximum $q$ value 317 desired, *nq* the number of $q$ steps and *window*, the amount 318 of padding around the circular convolution. The $q$ spacing 319 will be $\Delta q = 2 q_\mathrm{max} w / n_q$. If *nq* is not 320 given it will use $n_q = 2^k$ such that $\Delta q < q_\mathrm{min}$. 321 322 *probability* is related to the expected number of scattering 323 events in the sample $\lambda$ as $p = 1 = e^{-\lambda}$. As a 324 hack to allow probability to be a fitted parameter, the "value" 325 can be a function that takes no parameters and returns the current 326 value of the probability. *coverage* determines how many scattering 327 steps to consider. The default is 0.99, which sets $n$ such that 328 $1 \ldots n$ covers 99% of the Poisson probability mass function. 329 330 *is2d* is True then 2D scattering is used, otherwise it accepts 331 and returns 1D scattering. 332 333 *resolution* is the resolution function to apply after multiple 334 scattering. If present, then the resolution $q$ vectors will provide 335 default values for *qmin*, *qmax* and *nq*. 336 """ 307 337 def __init__(self, qmin=None, qmax=None, nq=None, window=2, 308 338 probability=None, coverage=0.99, 309 339 is2d=False, resolution=None, 310 340 dtype=PRECISION): 311 r"""312 Compute multiple scattering using Fourier convolution.313 314 The fourier steps are determined by *qmax*, the maximum $q$ value315 desired, *nq* the number of $q$ steps and *window*, the amount316 of padding around the circular convolution. The $q$ spacing317 will be $\Delta q = 2 q_\mathrm{max} w / n_q$. If *nq* is not318 given it will use $n_q = 2^k$ such that $\Delta q < q_\mathrm{min}$.319 320 *probability* is related to the expected number of scattering321 events in the sample $\lambda$ as $p = 1 = e^{-\lambda}$. As a322 hack to allow probability to be a fitted parameter, the "value"323 can be a function that takes no parameters and returns the current324 value of the probability. *coverage* determines how many scattering325 steps to consider. The default is 0.99, which sets $n$ such that326 $1 \ldots n$ covers 99% of the Poisson probability mass function.327 328 *is2d* is True then 2D scattering is used, otherwise it accepts329 and returns 1D scattering.330 331 *resolution* is the resolution function to apply after multiple332 scattering. If present, then the resolution $q$ vectors will provide333 default values for *qmin*, *qmax* and *nq*.334 """335 341 # Infer qmin, qmax from instrument resolution calculator, if present 336 342 if resolution is not None: … … 424 430 # Prepare the multiple scattering calculator (either numpy or OpenCL) 425 431 self.transform = Calculator((2*nq, 2*nq), dtype=dtype) 432 433 # Iq and Iqxy will be set during apply 434 self.Iq = None # type: np.ndarray 435 self.Iqxy = None # type: np.ndarray 426 436 427 437 def apply(self, theory): … … 471 481 472 482 def radial_profile(self, Iqxy): 483 """ 484 Compute that radial profile for the given Iqxy grid. The grid should 485 be defined as for 486 """ 473 487 # circular average, no anti-aliasing 474 488 Iq = np.histogram(self._radius, bins=self._edges, weights=Iqxy)[0]/self._norm … … 478 492 def annular_average(qxy, Iqxy, qbins): 479 493 """ 480 Compute annular average of points at 494 Compute annular average of points in *Iqxy* at *qbins*. The $q_x$, $q_y$ 495 coordinates for *Iqxy* are given in *qxy*. 481 496 """ 482 497 qxy, Iqxy = qxy.flatten(), Iqxy.flatten()
Note: See TracChangeset
for help on using the changeset viewer.