def show_coverage_2d(rg, field, rm=None, projection='moll', vmin=None, markersize=30, ax=None): """Show field coverage by projecting the sphere onto a flat 2d surface. Parameters ---------- rg : (M, 3) ndarray Gradient directions in Cartesian coordinates. field : (M, N) ndarray Field values on a grid. The grid is on ``theta = [0, pi]`` and ``phi = [0, 2 * pi]``. rm : (M, 3) ndarray Missing / dropped gradient directions. projection : 'moll', 'ortho', etc. Basemap projection. """ import matplotlib.pyplot as plt npts_lat, npts_lon = field.shape theta = np.linspace(0, np.pi, npts_lat) phi = np.linspace(0, 2 * np.pi, npts_lon) m = plot.surf_grid(field, theta, phi, projection=projection, vmin=vmin, ax=ax) plt.colorbar(orientation='horizontal', format='%.2g', ax=ax) x, y, z = rg theta, phi, rho = coord.car2sph(x, y, z) plot.scatter(theta, phi, basemap=m, color='g', s=markersize, ax=ax) if rm is not None and rm.shape[1] > 0: x, y, z = rm theta, phi, rho = coord.car2sph(x, y, z) plot.scatter(theta, phi, basemap=m, color='r', s=markersize, ax=ax)
def show_coverage_3d(rg, field, rm=None, vmin=None, sphere_colormap='jet'): """ """ # Resolution with which the small spheres are drawn pt_resolution = 20 # Size factor for small spheres scale_factor = 0.1 # missing directions in red, if any if rm is not None: xm, ym, zm = rm theta, phi, rho = coord.car2sph(xm, ym, zm) plot.scatter_3D(theta, phi, resolution=pt_resolution, scale_factor=scale_factor, name='Bad direction') # 'good' directions in green xg, yg, zg = rg theta, phi, rho = coord.car2sph(xg, yg, zg) # As simple spheres plot.scatter_3D(theta, phi, color=(0, 1, 0), scale_factor=scale_factor, resolution=pt_resolution, name='Good directions') npts_lat, npts_lon = field.shape theta = np.linspace(0, np.pi, npts_lat) phi = np.linspace(0, 2 * np.pi, npts_lon) s = plot.surf_grid_3D(field, theta, phi, vmin=vmin, name='Coverage') mlab = plot.get_mlab() mlab.colorbar(s, orientation='horizontal') mlab.show()
def test_car2sph(): theta, phi, r = car2sph(1, 0, 0) assert_almost_equal(r, 1, decimal=5) assert_almost_equal(theta, np.pi / 2, decimal=5) assert_almost_equal(phi, 0, decimal=5) theta, phi, r = car2sph(0, 1, 0) assert_almost_equal(r, 1, decimal=5) assert_almost_equal(theta, np.pi / 2, decimal=5) assert_almost_equal(phi, np.pi / 2, decimal=5)
from dipy.reconst.shm import SlowAdcOpdfModel, MonoExpOpdfModel, QballOdfModel coords = sph_io.load('sphere_pts.npz') #from dipy.data import get_sphere #verts, faces = get_sphere('symmetric724') ## from dipy.core.triangle_subdivide import create_unit_sphere ## verts, edges, sides = create_unit_sphere(5) ## faces = edges[sides, 0] from dipy.core.triangle_subdivide import create_unit_sphere verts, edges, sides = create_unit_sphere(5) faces = edges[sides, 0] theta, phi, r = car2sph(*verts.T) sampling_xyz = np.column_stack( sph2car(coords['gradient_theta'], coords['gradient_phi']) ) ## verts = np.column_stack(sph2car(theta, phi)) ## from dipy.core.meshes import faces_from_vertices ## faces = faces_from_vertices(verts) def separation_from_odf(odf): # Find angles from dipy.reconst.recspeed import local_maxima p, i = local_maxima(odf, edges) p = p[:2]
theta72, phi72, w72 = sphere.quadrature_points(N=72) theta132, phi132, w132 = sphere.quadrature_points(N=132) #theta492, phi492, w492 = sphere.quadrature_points(N=492) theta, phi = theta72, phi72 from dipy.data import get_data img, bvals, bvecs = get_data('small_64D') b = np.load(bvals) bvecs = np.load(bvecs) bvecs = bvecs[b > 0] b = b[b > 0] theta, phi, _ = coord.car2sph(*bvecs.T) theta_odf, phi_odf = theta132, phi132 kernel = inv_funk_radon_even_kernel kernel_N = 8 X = kernel_matrix(theta, phi, theta_odf, phi_odf, kernel=kernel, N=kernel_N) D = 150 # Grid density for plots (higher => more dense) b = 3000 + np.random.normal(scale=4, size=len(theta)) # Make up somewhat realistic b-values xyz = np.column_stack(coord.sph2car(theta, phi)) sph_io.savez('sphere_pts', gradient_theta=theta, gradient_phi=phi, odf_theta=theta_odf, odf_phi=phi_odf, b=b) # Fiber weights