def test_interp_rbf(): from dipy.core.sphere import Sphere, interp_rbf from dipy.core.subdivide_octahedron import create_unit_hemisphere import numpy as np s0 = create_unit_hemisphere(2) s1 = create_unit_hemisphere(3) data = np.cos(s0.theta) + np.sin(s0.phi) expected = np.cos(s1.theta) + np.sin(s1.phi) interp_data_en = interp_rbf(data, s0, s1, norm="euclidean_norm") interp_data_a = interp_rbf(data, s0, s1, norm="angle") nt.assert_(np.mean(np.abs(interp_data_en - expected)) < 0.1) nt.assert_(np.mean(np.abs(interp_data_a - expected)) < 0.1)
def test_interp_rbf(): from dipy.core.sphere import Sphere, interp_rbf from dipy.core.subdivide_octahedron import create_unit_hemisphere import numpy as np s0 = create_unit_hemisphere(2) s1 = create_unit_hemisphere(3) data = np.cos(s0.theta) + np.sin(s0.phi) expected = np.cos(s1.theta) + np.sin(s1.phi) interp_data_en = interp_rbf(data, s0, s1, norm = "euclidean_norm") interp_data_a = interp_rbf(data, s0, s1, norm = "angle") nt.assert_(np.mean(np.abs(interp_data_en - expected)) < 0.1) nt.assert_(np.mean(np.abs(interp_data_a - expected)) < 0.1)
def odf(self, sphere): ## Override the odf method to subclass OdfFit bvec = self.model.bvec[self.model.bval > 0] data = self.data[self.model.bval > 0] origin_sphere = Sphere(xyz=bvec) discrete_odf = 1. / data return interp_rbf(discrete_odf, origin_sphere, sphere)
def test_interp_rbf(): def data_func(s, a, b): return a * np.cos(s.theta) + b * np.sin(s.phi) from dipy.core.sphere import Sphere, interp_rbf import numpy as np s0 = create_unit_sphere(3) s1 = create_unit_sphere(4) for a, b in zip([1, 2, 0.5], [1, 0.5, 2]): data = data_func(s0, a, b) expected = data_func(s1, a, b) interp_data_a = interp_rbf(data, s0, s1, norm="angle") nt.assert_(np.mean(np.abs(interp_data_a - expected)) < 0.1) # Test that using the euclidean norm raises a warning # (following https://docs.python.org/2/library/warnings.html#testing-warnings) with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") interp_data_en = interp_rbf(data, s0, s1, norm ="euclidean_norm") nt.assert_(len(w) == 1) nt.assert_(issubclass(w[-1].category, DeprecationWarning)) nt.assert_("deprecated" in str(w[-1].message))
def test_interp_rbf(): def data_func(s, a, b): return a * np.cos(s.theta) + b * np.sin(s.phi) from dipy.core.sphere import Sphere, interp_rbf import numpy as np s0 = create_unit_sphere(3) s1 = create_unit_sphere(4) for a, b in zip([1, 2, 0.5], [1, 0.5, 2]): data = data_func(s0, a, b) expected = data_func(s1, a, b) interp_data_a = interp_rbf(data, s0, s1, norm="angle") nt.assert_(np.mean(np.abs(interp_data_a - expected)) < 0.1) # Test that using the euclidean norm raises a warning # (following # https://docs.python.org/2/library/warnings.html#testing-warnings) with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") interp_data_en = interp_rbf(data, s0, s1, norm="euclidean_norm") nt.assert_(len(w) == 1) nt.assert_(issubclass(w[-1].category, DeprecationWarning)) nt.assert_("deprecated" in str(w[-1].message))
def odf(self, sphere, interp_kwargs=dict(function='multiquadric', smooth=0)): """ Interpolate the fiber odf into a provided sphere class instance (from dipy) """ s0 = dps.Sphere(xyz=self.bvecs[:, self.b_idx].T) s1 = sphere params_flat = self.model_params[self.mask] out_flat = np.empty((self._n_vox, len(sphere.x))) if self._n_vox==1: this_params = params_flat this_params[np.isnan(this_params)] = 0 out = dps.interp_rbf(this_params, s0, s1, **interp_kwargs) return np.squeeze(out) else: for vox in range(self._n_vox): this_params = params_flat[vox] this_params[np.isnan(this_params)] = 0 out_flat[vox] = dps.interp_rbf(this_params, s0, s1, **interp_kwargs) out = ozu.nans(self.model_params.shape[:3] + (len(sphere.x),)) out[self.mask] = out_flat return out
def plot_signal_interp(bvecs, signal, origin=[0,0,0], maya=True, cmap='jet', file_name=None, colorbar=False, figure=None, vmin=None, vmax=None, offset=0, azimuth=60, elevation=90, roll=0, points=False, cmap_points=None, scale_points=False, non_neg=False, interp_kwargs=dict(function='thin_plate', smooth=0)): """ Interpolate a measured signal, using RBF interpolation. Parameters ---------- signal: bvecs: array (3,n) the x,y,z locations where the signal was measured offset : float where to place the plotted voxel (on the z axis) points : bool whether to show the sampling points on the interpolated surface. Default: False. """ bvecs_new = np.hstack([bvecs, -bvecs]) new_signal = np.hstack([signal, signal]) s0 = Sphere(xyz=bvecs_new.T) s1 = create_unit_sphere(7) signal[np.isnan(signal)] = 0 interp_signal = interp_rbf(new_signal, s0, s1, **interp_kwargs) vertices = s1.vertices if non_neg: interp_signal[interp_signal<0] = 0 faces = s1.faces x,y,z = vertices.T r, phi, theta = geo.cart2sphere(x,y,z) x_plot, y_plot, z_plot = geo.sphere2cart(interp_signal, phi, theta) if points: r, phi, theta = geo.cart2sphere(s0.x, s0.y, s0.z) x_p, y_p, z_p = geo.sphere2cart(signal, phi, theta) figure = _display_maya_voxel(x_p, y_p, z_p, faces, signal, origin, cmap=cmap, colorbar=colorbar, figure=figure, vmin=vmin, vmax=vmax, file_name=file_name, azimuth=azimuth, elevation=elevation, points=True, cmap_points=cmap_points, scale_points=scale_points) # Call and return straightaway: return _display_maya_voxel(x_plot, y_plot, z_plot, faces, interp_signal, origin, cmap=cmap, colorbar=colorbar, figure=figure, vmin=vmin, vmax=vmax, file_name=file_name, azimuth=azimuth, elevation=elevation)
def plot_signal_interp(bvecs, signal, origin=[0, 0, 0], maya=True, cmap='jet', file_name=None, colorbar=False, figure=None, vmin=None, vmax=None, offset=0, azimuth=60, elevation=90, roll=0, points=False, cmap_points=None, scale_points=False, non_neg=False, interp_kwargs=dict(function='thin_plate', smooth=0)): """ Interpolate a measured signal, using RBF interpolation. Parameters ---------- signal: bvecs: array (3,n) the x,y,z locations where the signal was measured offset : float where to place the plotted voxel (on the z axis) points : bool whether to show the sampling points on the interpolated surface. Default: False. """ bvecs_new = np.hstack([bvecs, -bvecs]) new_signal = np.hstack([signal, signal]) s0 = Sphere(xyz=bvecs_new.T) s1 = create_unit_sphere(7) signal[np.isnan(signal)] = 0 interp_signal = interp_rbf(new_signal, s0, s1, **interp_kwargs) vertices = s1.vertices if non_neg: interp_signal[interp_signal < 0] = 0 faces = s1.faces x, y, z = vertices.T r, phi, theta = geo.cart2sphere(x, y, z) x_plot, y_plot, z_plot = geo.sphere2cart(interp_signal, phi, theta) if points: r, phi, theta = geo.cart2sphere(s0.x, s0.y, s0.z) x_p, y_p, z_p = geo.sphere2cart(signal, phi, theta) figure = _display_maya_voxel(x_p, y_p, z_p, faces, signal, origin, cmap=cmap, colorbar=colorbar, figure=figure, vmin=vmin, vmax=vmax, file_name=file_name, azimuth=azimuth, elevation=elevation, points=True, cmap_points=cmap_points, scale_points=scale_points) # Call and return straightaway: return _display_maya_voxel(x_plot, y_plot, z_plot, faces, interp_signal, origin, cmap=cmap, colorbar=colorbar, figure=figure, vmin=vmin, vmax=vmax, file_name=file_name, azimuth=azimuth, elevation=elevation)