def test_odfdeconv(): SNR = 100 S0 = 1 _, fbvals, fbvecs = get_data('small_64D') bvals = np.load(fbvals) bvecs = np.load(fbvecs) gtab = gradient_table(bvals, bvecs) mevals = np.array(([0.0015, 0.0003, 0.0003], [0.0015, 0.0003, 0.0003])) angles = [(0, 0), (90, 0)] S, sticks = multi_tensor(gtab, mevals, S0, angles=angles, fractions=[50, 50], snr=SNR) sphere = get_sphere('symmetric362') odf_gt = multi_tensor_odf(sphere.vertices, mevals, angles, [50, 50]) e1 = 15.0 e2 = 3.0 ratio = e2 / e1 csd = ConstrainedSDTModel(gtab, ratio, None) csd_fit = csd.fit(S) fodf = csd_fit.odf(sphere) directions, _, _ = peak_directions(odf_gt, sphere) directions2, _, _ = peak_directions(fodf, sphere) ang_sim = angular_similarity(directions, directions2) assert_equal(ang_sim > 1.9, True) assert_equal(directions.shape[0], 2) assert_equal(directions2.shape[0], 2) with warnings.catch_warnings(record=True) as w: ConstrainedSDTModel(gtab, ratio, sh_order=10) assert_equal(len(w) > 0, True) with warnings.catch_warnings(record=True) as w: ConstrainedSDTModel(gtab, ratio, sh_order=8) assert_equal(len(w) > 0, False) csd_fit = csd.fit(np.zeros_like(S)) fodf = csd_fit.odf(sphere) assert_array_equal(fodf, np.zeros_like(fodf)) odf_sh = np.zeros_like(fodf) odf_sh[1] = np.nan fodf, it = odf_deconv(odf_sh, csd.R, csd.B_reg) assert_array_equal(fodf, np.zeros_like(fodf))
def odf(self, sphere): self.gqi_vector = self.model.cache_get('gqi_vector', key=sphere) if self.gqi_vector is None: if self.model.method == 'gqi2': H = squared_radial_component self.gqi_vector = np.real(H(np.dot(self.model.b_vector, sphere.vertices.T) * self.model.Lambda / np.pi)) if self.model.method == 'standard': self.gqi_vector = np.real( np.sinc(np.dot(self.model.b_vector, sphere.vertices.T) * self.model.Lambda / np.pi)) self.model.cache_set('gqi_vector', sphere, self.gqi_vector) gqi_odf = np.dot(self.data, self.gqi_vector) gqi_odf_sh = np.dot(gqi_odf, self.model.invB) fodf_sh, num_it = odf_deconv(gqi_odf_sh, self.model.sh_order, self.model.R, self.model.B_reg, lambda_=self.model.lambda_, tau=self.model.tau, r2_term=r2) return np.dot(fodf_sh, self.model.invB.T)
def odf(self, sphere): r""" Calculates the real analytical odf for a given discrete sphere. """ upsilon = self.model.cache_get('shore_matrix_odf', key=sphere) if upsilon is None: upsilon = SHOREmatrix_odf(self.radial_order, self.zeta, sphere.vertices) self.model.cache_set('shore_matrix_odf', sphere, upsilon) odf = np.dot(upsilon, self._shore_coef) odf_sh = np.dot(odf, self.model.invB) fodf_sh, num_it = odf_deconv(odf_sh, self.model.sh_order, self.model.R, self.model.B_reg, lambda_=self.model.lambda_, tau=self.model.tau, r2_term=True) return np.dot(fodf_sh, self.model.invB.T)
def test_odfdeconv(): SNR = 100 S0 = 1 _, fbvals, fbvecs = get_fnames('small_64D') bvals, bvecs = read_bvals_bvecs(fbvals, fbvecs) gtab = gradient_table(bvals, bvecs) mevals = np.array(([0.0015, 0.0003, 0.0003], [0.0015, 0.0003, 0.0003])) angles = [(0, 0), (90, 0)] S, _ = multi_tensor(gtab, mevals, S0, angles=angles, fractions=[50, 50], snr=SNR) sphere = get_sphere('symmetric362') odf_gt = multi_tensor_odf(sphere.vertices, mevals, angles, [50, 50]) e1 = 15.0 e2 = 3.0 ratio = e2 / e1 csd = ConstrainedSDTModel(gtab, ratio, None) csd_fit = csd.fit(S) fodf = csd_fit.odf(sphere) directions, _, _ = peak_directions(odf_gt, sphere) directions2, _, _ = peak_directions(fodf, sphere) ang_sim = angular_similarity(directions, directions2) assert_equal(ang_sim > 1.9, True) assert_equal(directions.shape[0], 2) assert_equal(directions2.shape[0], 2) with warnings.catch_warnings(record=True) as w: ConstrainedSDTModel(gtab, ratio, sh_order=10) w_count = len(w) # A warning is expected from the ConstrainedSDTModel constructor # and additionnal warnings should be raised where legacy SH bases # are used assert_equal(w_count > 1, True) with warnings.catch_warnings(record=True) as w: ConstrainedSDTModel(gtab, ratio, sh_order=8) # Test that the warning from ConstrainedSDTModel # constructor is no more raised assert_equal(len(w) == w_count - 1, True) csd_fit = csd.fit(np.zeros_like(S)) fodf = csd_fit.odf(sphere) assert_array_equal(fodf, np.zeros_like(fodf)) odf_sh = np.zeros_like(fodf) odf_sh[1] = np.nan fodf, _ = odf_deconv(odf_sh, csd.R, csd.B_reg) assert_array_equal(fodf, np.zeros_like(fodf))