def surf_grid_3D(r, theta, phi, scale_radius=False, **mesh_args): """Draw a function r = f(theta, phi), evaluated on a grid, on the sphere. Parameters ---------- r : (M, N) ndarray Function values. theta : (M,) ndarray Inclination / polar angles of function values. phi : (N,) ndarray Azimuth angles of function values. scale_radius : bool Whether to scale the radius with the function value (changes the surface height to reflect function values). ax : mpl axis, optional If specified, draw onto this existing axis instead. mesh_args : dict / kwds Keyword arguments passed to the ``mlab.mesh`` call. """ phi, theta = np.meshgrid(phi, theta) if scale_radius: x, y, z = coord.sph2car(theta, phi, r) else: x, y, z = coord.sph2car(theta, phi) return get_mlab().mesh(x, y, z, scalars=r, **mesh_args)
def scatter_3D(theta, phi, scalar=None, **points3d_args): points3d_args.setdefault('scale_factor', 0.1) points3d_args.setdefault('color', (1, 0, 0)) if scalar is None: scalar = np.ones_like(theta) x, y, z = coord.sph2car(theta, phi) get_mlab().points3d(x, y, z, scalar, **points3d_args)
def saff_kuijlaars(N): k = np.arange(N) h = -1 + 2 * k / (N - 1) theta = np.arccos(h) phi = np.zeros_like(h) for i in range(1, N - 1): phi[i] = (phi[i - 1] + 3.6 / np.sqrt(N * (1 - h[i]**2))) % (2 * np.pi) x,y,z = coord.sph2car(theta, phi) return x, y, z, len(x)
def saff_kuijlaars(N): k = np.arange(N) h = -1 + 2 * k / (N - 1) theta = np.arccos(h) phi = np.zeros_like(h) for i in range(1, N - 1): phi[i] = (phi[i - 1] + 3.6 / np.sqrt(N * (1 - h[i]**2))) % (2 * np.pi) x, y, z = coord.sph2car(theta, phi) return x, y, z, len(x)
rotation = np.eye(3) out_shape = r.shape[:r.ndim - 1] R = np.asarray(rotation) Di = np.linalg.inv(R.dot(np.diag(evals)).dot(R.T)) r = r.reshape(-1, 3) P = np.zeros(len(r)) for (i, u) in enumerate(r): P[i] = u.T.dot(Di).dot(u)**(3 / 2) return (1 / (4 * np.pi * np.prod(evals)**(1/2) * P)).reshape(out_shape) if __name__ == "__main__": import sphere, coord, plot npts = 150 theta, phi = sphere.mesh(npts) xyz = np.dstack(coord.sph2car(theta, phi)) ODF = single_tensor_ODF(xyz, rotation=None) signal = single_tensor(gradients=xyz, bvals=1000 * np.ones(npts * npts), rotation=None, S0=1, SNR=None) plot.surf_grid_3D(ODF, theta, phi, scale_radius=True) plot.show() plot.surf_grid_3D(signal, theta, phi, scale_radius=True) plot.show()