diff --git a/dipy/direction/bootstrap_direction_getter.pyx b/dipy/direction/bootstrap_direction_getter.pyx index 0eaea34995..701709e8f1 100644 --- a/dipy/direction/bootstrap_direction_getter.pyx +++ b/dipy/direction/bootstrap_direction_getter.pyx @@ -101,8 +101,8 @@ cdef class BootDirectionGetter(DirectionGetter): Angular threshold for excluding ODF peaks. """ - return cls(data, model, max_angle, sphere, max_attempts, sh_order, - b_tol, **kwargs) + return cls(data, model, max_angle, sphere=sphere, max_attempts=max_attempts, sh_order=sh_order, + b_tol=b_tol, **kwargs) cpdef cnp.ndarray[cnp.float_t, ndim=2] initial_direction(self, diff --git a/dipy/direction/closest_peak_direction_getter.pyx b/dipy/direction/closest_peak_direction_getter.pyx index 7fddf48d43..367199eaf2 100644 --- a/dipy/direction/closest_peak_direction_getter.pyx +++ b/dipy/direction/closest_peak_direction_getter.pyx @@ -163,11 +163,11 @@ cdef class PmfGenDirectionGetter(BasePmfDirectionGetter): raise ValueError(msg) pmf_gen = SimplePmfGen(np.asarray(pmf,dtype=float), sphere) - return cls(pmf_gen, max_angle, sphere, pmf_threshold, **kwargs) + return cls(pmf_gen, max_angle, sphere, pmf_threshold=pmf_threshold, **kwargs) @classmethod def from_shcoeff(cls, shcoeff, max_angle, sphere=default_sphere, - pmf_threshold=0.1, basis_type=None, legacy=True, + pmf_threshold=0.1, basis_type=None, legacy=True, sh_to_pmf=False, **kwargs): """Probabilistic direction getter from a distribution of directions on the sphere @@ -219,7 +219,7 @@ cdef class PmfGenDirectionGetter(BasePmfDirectionGetter): else: pmf_gen = SHCoeffPmfGen(np.asarray(shcoeff,dtype=float), sphere, basis_type, legacy=legacy) - return cls(pmf_gen, max_angle, sphere, pmf_threshold, **kwargs) + return cls(pmf_gen, max_angle, sphere, pmf_threshold=pmf_threshold, **kwargs) cdef class ClosestPeakDirectionGetter(PmfGenDirectionGetter): diff --git a/dipy/direction/peaks.py b/dipy/direction/peaks.py index 548a35e20a..dcf3106b21 100644 --- a/dipy/direction/peaks.py +++ b/dipy/direction/peaks.py @@ -18,12 +18,15 @@ search_descending, ) from dipy.reconst.shm import sh_to_sf_matrix +from dipy.testing.decorators import warning_for_keywords from dipy.utils.deprecator import deprecated_params from dipy.utils.multiproc import determine_num_processes +@warning_for_keywords() def peak_directions_nl( sphere_eval, + *, relative_peak_threshold=0.25, min_separation_angle=25, sphere=default_sphere, @@ -95,8 +98,14 @@ def _helper(x): return directions, values +@warning_for_keywords() def peak_directions( - odf, sphere, relative_peak_threshold=0.5, min_separation_angle=25, is_symmetric=True + odf, + sphere, + *, + relative_peak_threshold=0.5, + min_separation_angle=25, + is_symmetric=True, ): """Get the directions of odf peaks. @@ -420,29 +429,31 @@ def _peaks_from_model_parallel_sub(args): sphere, relative_peak_threshold, min_separation_angle, - mask, - return_odf, - return_sh, - gfa_thr, - normalize_peaks, - sh_order, - sh_basis_type, - legacy, - npeaks, - B, - invB, + mask=mask, + return_odf=return_odf, + return_sh=return_sh, + gfa_thr=gfa_thr, + normalize_peaks=normalize_peaks, + sh_order_max=sh_order, + sh_basis_type=sh_basis_type, + legacy=legacy, + npeaks=npeaks, + B=B, + invB=invB, parallel=False, num_processes=None, ) @deprecated_params("sh_order", new_name="sh_order_max", since="1.9", until="2.0") +@warning_for_keywords() def peaks_from_model( model, data, sphere, relative_peak_threshold, min_separation_angle, + *, mask=None, return_odf=False, return_sh=True, @@ -601,7 +612,10 @@ def peaks_from_model( # Get peaks of odf direction, pk, ind = peak_directions( - odf, sphere, relative_peak_threshold, min_separation_angle + odf, + sphere, + relative_peak_threshold=relative_peak_threshold, + min_separation_angle=min_separation_angle, ) # Calculate peak metrics @@ -713,7 +727,11 @@ def peaks_from_positions( for i, s in enumerate(vox_positions): odf = trilinear_interpolate4d(odfs, s) peaks, _, _ = peak_directions( - odf, sphere, relative_peak_threshold, min_separation_angle, is_symmetric + odf, + sphere, + relative_peak_threshold=relative_peak_threshold, + min_separation_angle=min_separation_angle, + is_symmetric=is_symmetric, ) nbr_peaks = min(npeaks, peaks.shape[0]) peaks_arr[i, :nbr_peaks, :] = peaks[:nbr_peaks, :] diff --git a/dipy/direction/probabilistic_direction_getter.pyx b/dipy/direction/probabilistic_direction_getter.pyx index ddc039b7f9..1f74f7c727 100644 --- a/dipy/direction/probabilistic_direction_getter.pyx +++ b/dipy/direction/probabilistic_direction_getter.pyx @@ -27,7 +27,6 @@ cdef class ProbabilisticDirectionGetter(PmfGenDirectionGetter): directions more than ``max_angle`` degrees from the incoming direction are set to 0 and the result is normalized. """ - def __init__(self, pmf_gen, max_angle, sphere, pmf_threshold=.1, **kwargs): """Direction getter from a pmf generator. @@ -57,7 +56,7 @@ cdef class ProbabilisticDirectionGetter(PmfGenDirectionGetter): """ PmfGenDirectionGetter.__init__(self, pmf_gen, max_angle, sphere, - pmf_threshold, **kwargs) + pmf_threshold=pmf_threshold, **kwargs) # The vertices need to be in a contiguous array self.vertices = self.sphere.vertices.copy() @@ -128,10 +127,9 @@ cdef class DeterministicMaximumDirectionGetter(ProbabilisticDirectionGetter): """Return direction of a sphere with the highest probability mass function (pmf). """ - def __init__(self, pmf_gen, max_angle, sphere, pmf_threshold=.1, **kwargs): ProbabilisticDirectionGetter.__init__(self, pmf_gen, max_angle, sphere, - pmf_threshold, **kwargs) + pmf_threshold=pmf_threshold, **kwargs) cdef int get_direction_c(self, double[::1] point, double[::1] direction): """Find direction with the highest pmf to updates ``direction`` array diff --git a/dipy/direction/ptt_direction_getter.pyx b/dipy/direction/ptt_direction_getter.pyx index e5e9cf9d63..fc9791aae2 100644 --- a/dipy/direction/ptt_direction_getter.pyx +++ b/dipy/direction/ptt_direction_getter.pyx @@ -126,7 +126,7 @@ cdef class PTTDirectionGetter(ProbabilisticDirectionGetter): self.rejection_sampling_nbr_sample = 10 # Adaptively set in Trekker. ProbabilisticDirectionGetter.__init__(self, pmf_gen, max_angle, sphere, - pmf_threshold, **kwargs) + pmf_threshold=pmf_threshold, **kwargs) cdef void initialize_candidate(self, double[:] init_dir): diff --git a/dipy/direction/tests/test_bootstrap_direction_getter.py b/dipy/direction/tests/test_bootstrap_direction_getter.py index 8e0f45bad1..599e9ecb96 100644 --- a/dipy/direction/tests/test_bootstrap_direction_getter.py +++ b/dipy/direction/tests/test_bootstrap_direction_getter.py @@ -219,7 +219,13 @@ def test_bdg_residual(rng): ) csd_model = ConstrainedSphericalDeconvModel(gtab, response, sh_order_max=6) npt.assert_raises( - ValueError, BootDirectionGetter, data, csd_model, 60, hsph_updated, 6 + ValueError, + BootDirectionGetter, + data, + csd_model, + 60, + sphere=hsph_updated, + max_attempts=6, ) @@ -291,8 +297,22 @@ def test_boot_pmf(): category=PendingDeprecationWarning, ) npt.assert_raises( - ValueError, BootDirectionGetter, data, tensor_model, 60, hsph_updated, 6, 20 + ValueError, + BootDirectionGetter, + data, + tensor_model, + 60, + sphere=hsph_updated, + max_attempts=6, + b_tol=20, ) npt.assert_raises( - ValueError, BootDirectionGetter, data, tensor_model, 60, hsph_updated, 6, -1 + ValueError, + BootDirectionGetter, + data, + tensor_model, + 60, + sphere=hsph_updated, + max_attempts=6, + b_tol=-1, ) diff --git a/dipy/direction/tests/test_peaks.py b/dipy/direction/tests/test_peaks.py index e51f9c5562..c157b3fc17 100644 --- a/dipy/direction/tests/test_peaks.py +++ b/dipy/direction/tests/test_peaks.py @@ -56,16 +56,16 @@ def discrete_eval(sphere): B = 1 + (x * z > 0) + 2 * (y * z > 0) return A * B - directions, values = peak_directions_nl(discrete_eval, 0.01) + directions, values = peak_directions_nl(discrete_eval, relative_peak_threshold=0.01) assert_equal(directions.shape, (4, 3)) - directions, values = peak_directions_nl(discrete_eval, 0.3) + directions, values = peak_directions_nl(discrete_eval, relative_peak_threshold=0.3) assert_equal(directions.shape, (3, 3)) - directions, values = peak_directions_nl(discrete_eval, 0.6) + directions, values = peak_directions_nl(discrete_eval, relative_peak_threshold=0.6) assert_equal(directions.shape, (2, 3)) - directions, values = peak_directions_nl(discrete_eval, 0.8) + directions, values = peak_directions_nl(discrete_eval, relative_peak_threshold=0.8) assert_equal(directions.shape, (1, 3)) assert_almost_equal(values, 4 * 3 / np.sqrt(3)) @@ -76,13 +76,13 @@ def discrete_eval(sphere): B = (x * z > 0) + 2 * (y * z > 0) return A * B - directions, values = peak_directions_nl(discrete_eval, 0.0) + directions, values = peak_directions_nl(discrete_eval, relative_peak_threshold=0.0) assert_equal(directions.shape, (3, 3)) - directions, values = peak_directions_nl(discrete_eval, 0.6) + directions, values = peak_directions_nl(discrete_eval, relative_peak_threshold=0.6) assert_equal(directions.shape, (2, 3)) - directions, values = peak_directions_nl(discrete_eval, 0.8) + directions, values = peak_directions_nl(discrete_eval, relative_peak_threshold=0.8) assert_equal(directions.shape, (1, 3)) assert_almost_equal(values, 3 * 3 / np.sqrt(3)) @@ -127,7 +127,9 @@ def test_peak_directions(): sphere = fit.model.sphere # Only one peak - direction, val, ind = peak_directions(odf, sphere, 0.5, 45) + direction, val, ind = peak_directions( + odf, sphere, relative_peak_threshold=0.5, min_separation_angle=45 + ) dir_e = sphere.vertices[[argmax]] assert_array_equal(ind, [argmax]) assert_array_equal(val, odf[ind]) @@ -135,24 +137,32 @@ def test_peak_directions(): odf[0] = mx * 0.9 # Two peaks, relative_threshold - direction, val, ind = peak_directions(odf, sphere, 1.0, 0) + direction, val, ind = peak_directions( + odf, sphere, relative_peak_threshold=1.0, min_separation_angle=0 + ) dir_e = sphere.vertices[[argmax]] assert_array_equal(direction, dir_e) assert_array_equal(ind, [argmax]) assert_array_equal(val, odf[ind]) - direction, val, ind = peak_directions(odf, sphere, 0.8, 0) + direction, val, ind = peak_directions( + odf, sphere, relative_peak_threshold=0.8, min_separation_angle=0 + ) dir_e = sphere.vertices[[argmax, 0]] assert_array_equal(direction, dir_e) assert_array_equal(ind, [argmax, 0]) assert_array_equal(val, odf[ind]) # Two peaks, angle_sep - direction, val, ind = peak_directions(odf, sphere, 0.0, 90) + direction, val, ind = peak_directions( + odf, sphere, relative_peak_threshold=0.0, min_separation_angle=90 + ) dir_e = sphere.vertices[[argmax]] assert_array_equal(direction, dir_e) assert_array_equal(ind, [argmax]) assert_array_equal(val, odf[ind]) - direction, val, ind = peak_directions(odf, sphere, 0.0, 0) + direction, val, ind = peak_directions( + odf, sphere, relative_peak_threshold=0.0, min_separation_angle=0 + ) dir_e = sphere.vertices[[argmax, 0]] assert_array_equal(direction, dir_e) assert_array_equal(ind, [argmax, 0]) @@ -189,17 +199,23 @@ def test_peak_directions_thorough(): fractions = [50, 50] odf_gt, sticks, sphere = _create_mt_sim(mevals, angles, fractions, 100, None) - directions, values, indices = peak_directions(odf_gt, sphere, 0.5, 25.0) + directions, values, indices = peak_directions( + odf_gt, sphere, relative_peak_threshold=0.5, min_separation_angle=25.0 + ) assert_almost_equal(angular_similarity(directions, sticks), 2, 2) # two unequal fibers fractions = [75, 25] odf_gt, sticks, sphere = _create_mt_sim(mevals, angles, fractions, 100, None) - directions, values, indices = peak_directions(odf_gt, sphere, 0.5, 25.0) + directions, values, indices = peak_directions( + odf_gt, sphere, relative_peak_threshold=0.5, min_separation_angle=25.0 + ) assert_almost_equal(angular_similarity(directions, sticks), 1, 2) - directions, values, indices = peak_directions(odf_gt, sphere, 0.20, 25.0) + directions, values, indices = peak_directions( + odf_gt, sphere, relative_peak_threshold=0.20, min_separation_angle=25.0 + ) assert_almost_equal(angular_similarity(directions, sticks), 2, 2) # two equal fibers short angle (simulating very sharp ODF) @@ -208,10 +224,14 @@ def test_peak_directions_thorough(): angles = [(0, 0), (20, 0)] odf_gt, sticks, sphere = _create_mt_sim(mevals, angles, fractions, 100, None) - directions, values, indices = peak_directions(odf_gt, sphere, 0.5, 25.0) + directions, values, indices = peak_directions( + odf_gt, sphere, relative_peak_threshold=0.5, min_separation_angle=25.0 + ) assert_almost_equal(angular_similarity(directions, sticks), 1, 2) - directions, values, indices = peak_directions(odf_gt, sphere, 0.5, 15.0) + directions, values, indices = peak_directions( + odf_gt, sphere, relative_peak_threshold=0.5, min_separation_angle=15.0 + ) assert_almost_equal(angular_similarity(directions, sticks), 2, 2) @@ -221,7 +241,9 @@ def test_peak_directions_thorough(): angles = [(15, 0), (15, 0)] odf_gt, sticks, sphere = _create_mt_sim(mevals, angles, fractions, 100, None) - directions, values, indices = peak_directions(odf_gt, sphere, 0.5, 15.0) + directions, values, indices = peak_directions( + odf_gt, sphere, relative_peak_threshold=0.5, min_separation_angle=15.0 + ) assert_almost_equal(angular_similarity(directions, sticks), 1, 2) AE = np.rad2deg(np.arccos(np.dot(directions[0], sticks[0]))) @@ -235,7 +257,9 @@ def test_peak_directions_thorough(): fractions = [45, 45, 10] odf_gt, sticks, sphere = _create_mt_sim(mevals, angles, fractions, 100, None) - directions, values, indices = peak_directions(odf_gt, sphere, 0.5, 25.0) + directions, values, indices = peak_directions( + odf_gt, sphere, relative_peak_threshold=0.5, min_separation_angle=25.0 + ) assert_almost_equal(angular_similarity(directions, sticks), 2, 2) # two equal fibers and one faulty @@ -246,7 +270,9 @@ def test_peak_directions_thorough(): fractions = [45, 45, 10] odf_gt, sticks, sphere = _create_mt_sim(mevals, angles, fractions, 100, None) - directions, values, indices = peak_directions(odf_gt, sphere, 0.5, 25.0) + directions, values, indices = peak_directions( + odf_gt, sphere, relative_peak_threshold=0.5, min_separation_angle=25.0 + ) assert_almost_equal(angular_similarity(directions, sticks), 2, 2) # two equal fibers and one very very annoying one @@ -257,7 +283,9 @@ def test_peak_directions_thorough(): fractions = [40, 40, 20] odf_gt, sticks, sphere = _create_mt_sim(mevals, angles, fractions, 100, None) - directions, values, indices = peak_directions(odf_gt, sphere, 0.5, 25.0) + directions, values, indices = peak_directions( + odf_gt, sphere, relative_peak_threshold=0.5, min_separation_angle=25.0 + ) assert_almost_equal(angular_similarity(directions, sticks), 2, 2) # three peaks and one faulty @@ -273,7 +301,9 @@ def test_peak_directions_thorough(): fractions = [35, 35, 20, 10] odf_gt, sticks, sphere = _create_mt_sim(mevals, angles, fractions, 100, None) - directions, values, indices = peak_directions(odf_gt, sphere, 0.5, 25.0) + directions, values, indices = peak_directions( + odf_gt, sphere, relative_peak_threshold=0.5, min_separation_angle=25.0 + ) assert_almost_equal(angular_similarity(directions, sticks), 3, 2) # four peaks @@ -289,7 +319,9 @@ def test_peak_directions_thorough(): fractions = [25, 25, 25, 25] odf_gt, sticks, sphere = _create_mt_sim(mevals, angles, fractions, 100, None) - directions, values, indices = peak_directions(odf_gt, sphere, 0.15, 5.0) + directions, values, indices = peak_directions( + odf_gt, sphere, relative_peak_threshold=0.15, min_separation_angle=5.0 + ) assert_almost_equal(angular_similarity(directions, sticks), 4, 2) # four difficult peaks @@ -305,11 +337,19 @@ def test_peak_directions_thorough(): fractions = [30, 30, 20, 20] odf_gt, sticks, sphere = _create_mt_sim(mevals, angles, fractions, 100, None) - directions, values, indices = peak_directions(odf_gt, sphere, 0, 0) + directions, values, indices = peak_directions( + odf_gt, sphere, relative_peak_threshold=0, min_separation_angle=0 + ) assert_almost_equal(angular_similarity(directions, sticks), 4, 1) # test the asymmetric case - directions, values, indices = peak_directions(odf_gt, sphere, 0, 0, False) + directions, values, indices = peak_directions( + odf_gt, + sphere, + relative_peak_threshold=0, + min_separation_angle=0, + is_symmetric=False, + ) expected = np.concatenate([sticks, -sticks], axis=0) assert_almost_equal(angular_similarity(directions, expected), 8, 1) @@ -317,7 +357,9 @@ def test_peak_directions_thorough(): mevals, angles, fractions, 100, None, half_sphere=True ) - directions, values, indices = peak_directions(odf_gt, hsphere, 0, 0) + directions, values, indices = peak_directions( + odf_gt, hsphere, relative_peak_threshold=0, min_separation_angle=0 + ) assert_equal(angular_similarity(directions, sticks) < 4, True) # four peaks and one them quite small @@ -325,14 +367,18 @@ def test_peak_directions_thorough(): odf_gt, sticks, sphere = _create_mt_sim(mevals, angles, fractions, 100, None) - directions, values, indices = peak_directions(odf_gt, sphere, 0, 0) + directions, values, indices = peak_directions( + odf_gt, sphere, relative_peak_threshold=0, min_separation_angle=0 + ) assert_equal(angular_similarity(directions, sticks) < 4, True) odf_gt, sticks, hsphere = _create_mt_sim( mevals, angles, fractions, 100, None, half_sphere=True ) - directions, values, indices = peak_directions(odf_gt, hsphere, 0, 0) + directions, values, indices = peak_directions( + odf_gt, hsphere, relative_peak_threshold=0, min_separation_angle=0 + ) assert_equal(angular_similarity(directions, sticks) < 4, True) # isotropic case @@ -341,7 +387,9 @@ def test_peak_directions_thorough(): fractions = [100.0] odf_gt, sticks, sphere = _create_mt_sim(mevals, angles, fractions, 100, None) - directions, values, indices = peak_directions(odf_gt, sphere, 0.5, 25.0) + directions, values, indices = peak_directions( + odf_gt, sphere, relative_peak_threshold=0.5, min_separation_angle=25.0 + ) assert_equal(len(values) > 10, True) @@ -367,11 +415,15 @@ def test_difference_with_minmax(): odf_gt_minmax = (odf_gt - odf_gt.min()) / (odf_gt.max() - odf_gt.min()) - _, values_1, _ = peak_directions(odf_gt, sphere, 0.30, 25.0) + _, values_1, _ = peak_directions( + odf_gt, sphere, relative_peak_threshold=0.30, min_separation_angle=25.0 + ) assert_equal(len(values_1), 3) - _, values_2, _ = peak_directions(odf_gt_minmax, sphere, 0.30, 25.0) + _, values_2, _ = peak_directions( + odf_gt_minmax, sphere, relative_peak_threshold=0.30, min_separation_angle=25.0 + ) assert_equal(len(values_2), 3) @@ -381,8 +433,8 @@ def test_difference_with_minmax(): _, values_3, _ = peak_directions( odf_gt, sphere, - 0.30, - 25.0, + relative_peak_threshold=0.30, + min_separation_angle=25.0, ) assert_equal(len(values_3), 4) @@ -392,8 +444,8 @@ def test_difference_with_minmax(): directions, values_4, indices = peak_directions( odf_gt, sphere, - 0.60, - 25.0, + relative_peak_threshold=0.60, + min_separation_angle=25.0, ) assert_equal(len(values_4), 3) @@ -406,7 +458,9 @@ def test_degenerate_cases(rng): # completely isotropic and degenerate case odf = np.zeros(sphere.vertices.shape[0]) - directions, values, indices = peak_directions(odf, sphere, 0.5, 25) + directions, values, indices = peak_directions( + odf, sphere, relative_peak_threshold=0.5, min_separation_angle=25 + ) print(directions, values, indices) assert_equal(len(values), 0) @@ -417,13 +471,17 @@ def test_degenerate_cases(rng): odf[0] = 0.020 odf[1] = 0.018 - directions, values, indices = peak_directions(odf, sphere, 0.5, 25) + directions, values, indices = peak_directions( + odf, sphere, relative_peak_threshold=0.5, min_separation_angle=25 + ) print(directions, values, indices) assert_equal(values[0], 0.02) odf = -np.ones(sphere.vertices.shape[0]) - directions, values, indices = peak_directions(odf, sphere, 0.5, 25) + directions, values, indices = peak_directions( + odf, sphere, relative_peak_threshold=0.5, min_separation_angle=25 + ) print(directions, values, indices) assert_equal(len(values), 0) @@ -433,18 +491,24 @@ def test_degenerate_cases(rng): odf[1] = 0.018 odf[2] = -0.018 - directions, values, indices = peak_directions(odf, sphere, 0.5, 25) + directions, values, indices = peak_directions( + odf, sphere, relative_peak_threshold=0.5, min_separation_angle=25 + ) assert_equal(values[0], 0.02) odf = np.ones(sphere.vertices.shape[0]) odf += 0.1 * rng.random(odf.shape[0]) - directions, values, indices = peak_directions(odf, sphere, 0.5, 25) + directions, values, indices = peak_directions( + odf, sphere, relative_peak_threshold=0.5, min_separation_angle=25 + ) assert_(all(values > values[0] * 0.5)) assert_array_equal(values, odf[indices]) odf = np.ones(sphere.vertices.shape[0]) odf[1:] = np.finfo(float).eps * rng.random(odf.shape[0] - 1) - directions, values, indices = peak_directions(odf, sphere, 0.5, 25) + directions, values, indices = peak_directions( + odf, sphere, relative_peak_threshold=0.5, min_separation_angle=25 + ) assert_equal(values[0], 1) assert_equal(len(values), 1) @@ -583,8 +647,8 @@ def test_peaksFromModelParallel(): model, data, sphere, - 0.5, - 45, + relative_peak_threshold=0.5, + min_separation_angle=45, normalize_peaks=True, return_odf=True, return_sh=True, @@ -595,8 +659,8 @@ def test_peaksFromModelParallel(): model, data, sphere, - 0.5, - 45, + relative_peak_threshold=0.5, + min_separation_angle=45, normalize_peaks=True, return_odf=True, return_sh=True, @@ -607,8 +671,8 @@ def test_peaksFromModelParallel(): model, data, sphere, - 0.5, - 45, + relative_peak_threshold=0.5, + min_separation_angle=45, normalize_peaks=True, return_odf=True, return_sh=True, @@ -620,8 +684,8 @@ def test_peaksFromModelParallel(): model, data, sphere, - 0.5, - 45, + relative_peak_threshold=0.5, + min_separation_angle=45, normalize_peaks=True, return_odf=True, return_sh=True, diff --git a/dipy/reconst/tests/test_dsi_deconv.py b/dipy/reconst/tests/test_dsi_deconv.py index 13ad121ea9..e8b36a4362 100644 --- a/dipy/reconst/tests/test_dsi_deconv.py +++ b/dipy/reconst/tests/test_dsi_deconv.py @@ -28,14 +28,18 @@ def test_dsi(): # repulsion724 dsfit = ds.fit(data) odf = dsfit.odf(sphere) - directions, _, _ = peak_directions(odf, sphere, 0.35, 25) + directions, _, _ = peak_directions( + odf, sphere, relative_peak_threshold=0.35, min_separation_angle=25 + ) assert_equal(len(directions), 2) assert_almost_equal(angular_similarity(directions, golden_directions), 2, 1) # 5 subdivisions dsfit = ds.fit(data) odf2 = dsfit.odf(sphere2) - directions, _, _ = peak_directions(odf2, sphere2, 0.35, 25) + directions, _, _ = peak_directions( + odf2, sphere2, relative_peak_threshold=0.35, min_separation_angle=25 + ) assert_equal(len(directions), 2) assert_almost_equal(angular_similarity(directions, golden_directions), 2, 1) @@ -44,7 +48,9 @@ def test_dsi(): for sbd in sb_dummies: data, golden_directions = sb_dummies[sbd] odf = ds.fit(data).odf(sphere2) - directions, _, _ = peak_directions(odf, sphere2, 0.35, 25) + directions, _, _ = peak_directions( + odf, sphere2, relative_peak_threshold=0.35, min_separation_angle=25 + ) if len(directions) <= 3: assert_equal(len(directions), len(golden_directions)) if len(directions) > 3: diff --git a/dipy/reconst/tests/test_forecast.py b/dipy/reconst/tests/test_forecast.py index 55ec5b7b84..fcf7fedf5b 100644 --- a/dipy/reconst/tests/test_forecast.py +++ b/dipy/reconst/tests/test_forecast.py @@ -136,7 +136,9 @@ def test_forecast_odf(): category=PendingDeprecationWarning, ) fodf = f_fit.odf(sphere) - directions, _, _ = peak_directions(fodf, sphere, 0.35, 25) + directions, _, _ = peak_directions( + fodf, sphere, relative_peak_threshold=0.35, min_separation_angle=25 + ) assert_equal(len(directions), 2) assert_almost_equal(angular_similarity(directions, data.sticks), 2, 1) @@ -155,7 +157,9 @@ def test_forecast_odf(): category=PendingDeprecationWarning, ) fodf = f_fit.odf(sphere) - directions, _, _ = peak_directions(fodf, sphere, 0.35, 25) + directions, _, _ = peak_directions( + fodf, sphere, relative_peak_threshold=0.35, min_separation_angle=25 + ) assert_equal(len(directions), 2) assert_almost_equal(angular_similarity(directions, data.sticks), 2, 1) @@ -174,7 +178,9 @@ def test_forecast_odf(): category=PendingDeprecationWarning, ) fodf = f_fit.odf(sphere) - directions, _, _ = peak_directions(fodf, sphere, 0.35, 25) + directions, _, _ = peak_directions( + fodf, sphere, relative_peak_threshold=0.35, min_separation_angle=25 + ) assert_equal(len(directions), 2) assert_almost_equal(angular_similarity(directions, data.sticks), 2, 1) @@ -196,7 +202,9 @@ def test_forecast_odf(): category=PendingDeprecationWarning, ) fodf = f_fit.odf(sphere) - directions, _, _ = peak_directions(fodf, sphere, 0.35, 25) + directions, _, _ = peak_directions( + fodf, sphere, relative_peak_threshold=0.35, min_separation_angle=25 + ) assert_equal(len(directions), 2) assert_almost_equal(angular_similarity(directions, data.sticks), 2, 1) @@ -217,7 +225,9 @@ def test_forecast_odf(): category=PendingDeprecationWarning, ) fodf = f_fit.odf(sphere) - directions, _, _ = peak_directions(fodf, sphere, 0.35, 25) + directions, _, _ = peak_directions( + fodf, sphere, relative_peak_threshold=0.35, min_separation_angle=25 + ) assert_equal(len(directions), 2) assert_almost_equal(angular_similarity(directions, data.sticks), 2, 1) diff --git a/dipy/reconst/tests/test_gqi.py b/dipy/reconst/tests/test_gqi.py index f7910e16fa..2e0c3626cf 100644 --- a/dipy/reconst/tests/test_gqi.py +++ b/dipy/reconst/tests/test_gqi.py @@ -29,14 +29,18 @@ def test_gqi(): # repulsion724 gqfit = gq.fit(data) odf = gqfit.odf(sphere) - directions, values, indices = peak_directions(odf, sphere, 0.35, 25) + directions, values, indices = peak_directions( + odf, sphere, relative_peak_threshold=0.35, min_separation_angle=25 + ) assert_equal(len(directions), 2) assert_almost_equal(angular_similarity(directions, golden_directions), 2, 1) # 5 subdivisions gqfit = gq.fit(data) odf2 = gqfit.odf(sphere2) - directions, values, indices = peak_directions(odf2, sphere2, 0.35, 25) + directions, values, indices = peak_directions( + odf2, sphere2, relative_peak_threshold=0.35, min_separation_angle=25 + ) assert_equal(len(directions), 2) assert_almost_equal(angular_similarity(directions, golden_directions), 2, 1) @@ -44,7 +48,9 @@ def test_gqi(): for sbd in sb_dummies: data, golden_directions = sb_dummies[sbd] odf = gq.fit(data).odf(sphere2) - directions, values, indices = peak_directions(odf, sphere2, 0.35, 25) + directions, values, indices = peak_directions( + odf, sphere2, relative_peak_threshold=0.35, min_separation_angle=25 + ) if len(directions) <= 3: assert_equal(len(directions), len(golden_directions)) if len(directions) > 3: @@ -61,8 +67,12 @@ def test_mvoxel_gqi(): # Check that the first and last voxels each have 2 peaks odf = all_odfs[0, 0, 0] - directions, values, indices = peak_directions(odf, sphere, 0.35, 25) + directions, values, indices = peak_directions( + odf, sphere, relative_peak_threshold=0.35, min_separation_angle=25 + ) assert_equal(directions.shape[0], 2) odf = all_odfs[-1, -1, -1] - directions, values, indices = peak_directions(odf, sphere, 0.35, 25) + directions, values, indices = peak_directions( + odf, sphere, relative_peak_threshold=0.35, min_separation_angle=25 + ) assert_equal(directions.shape[0], 2) diff --git a/dipy/reconst/tests/test_mapmri.py b/dipy/reconst/tests/test_mapmri.py index 88cdccd8e2..5b04afc26b 100644 --- a/dipy/reconst/tests/test_mapmri.py +++ b/dipy/reconst/tests/test_mapmri.py @@ -1099,13 +1099,17 @@ def test_mapmri_odf(radial_order=6): mapfit = mapmod.fit(data) odf = mapfit.odf(sphere) - directions, _, _ = peak_directions(odf, sphere, 0.35, 25) + directions, _, _ = peak_directions( + odf, sphere, relative_peak_threshold=0.35, min_separation_angle=25 + ) assert_equal(len(directions), 2) assert_almost_equal(angular_similarity(directions, golden_directions), 2, 1) # 5 subdivisions odf = mapfit.odf(sphere2) - directions, _, _ = peak_directions(odf, sphere2, 0.35, 25) + directions, _, _ = peak_directions( + odf, sphere2, relative_peak_threshold=0.35, min_separation_angle=25 + ) assert_equal(len(directions), 2) assert_almost_equal(angular_similarity(directions, golden_directions), 2, 1) @@ -1114,7 +1118,9 @@ def test_mapmri_odf(radial_order=6): data, golden_directions = sb_dummies[sbd] asmfit = mapmod.fit(data) odf = asmfit.odf(sphere2) - directions, _, _ = peak_directions(odf, sphere2, 0.35, 25) + directions, _, _ = peak_directions( + odf, sphere2, relative_peak_threshold=0.35, min_separation_angle=25 + ) if len(directions) <= 3: assert_equal(len(directions), len(golden_directions)) if len(directions) > 3: diff --git a/dipy/reconst/tests/test_rumba.py b/dipy/reconst/tests/test_rumba.py index 5e48d53696..6047af66be 100644 --- a/dipy/reconst/tests/test_rumba.py +++ b/dipy/reconst/tests/test_rumba.py @@ -70,7 +70,9 @@ def test_rumba(): assert_raises(ValueError, model_fit.odf, sphere2) odf = model_fit.odf(sphere) - directions, _, _ = peak_directions(odf, sphere, 0.35, 25) + directions, _, _ = peak_directions( + odf, sphere, relative_peak_threshold=0.35, min_separation_angle=25 + ) assert_equal(len(directions), 2) assert_almost_equal(angular_similarity(directions, golden_directions), 2, 1) @@ -81,7 +83,9 @@ def test_rumba(): data, golden_directions = sb_dummies[sbd] model_fit = model.fit(data) odf = model_fit.odf(sphere) - directions, _, _ = peak_directions(odf, sphere, 0.35, 25) + directions, _, _ = peak_directions( + odf, sphere, relative_peak_threshold=0.35, min_separation_angle=25 + ) if len(directions) <= 3: # Verify small isotropic fraction in anisotropic case assert_equal(model_fit.f_iso < 0.1, True) @@ -139,7 +143,9 @@ def test_recursive_rumba(): # Test peaks odf = model_fit.odf(sphere) - directions, _, _ = peak_directions(odf, sphere, 0.35, 25) + directions, _, _ = peak_directions( + odf, sphere, relative_peak_threshold=0.35, min_separation_angle=25 + ) assert_equal(len(directions), 2) assert_almost_equal(angular_similarity(directions, golden_directions), 2, 1) @@ -164,7 +170,9 @@ def test_multishell_rumba(): # Test peaks odf = model_fit.odf(sphere) - directions, _, _ = peak_directions(odf, sphere, 0.35, 25) + directions, _, _ = peak_directions( + odf, sphere, relative_peak_threshold=0.35, min_separation_angle=25 + ) assert_equal(len(directions), 2) assert_almost_equal(angular_similarity(directions, golden_directions), 2, 1) @@ -286,7 +294,9 @@ def test_global_fit(): odf = model_fit.odf(sphere) - directions, _, _ = peak_directions(odf[0, 0, 0], sphere, 0.35, 25) + directions, _, _ = peak_directions( + odf[0, 0, 0], sphere, relative_peak_threshold=0.35, min_separation_angle=25 + ) assert_equal(len(directions), 2) assert_almost_equal(angular_similarity(directions, golden_directions), 2, 1) @@ -300,7 +310,9 @@ def test_global_fit(): odf = rumba_fit.odf(sphere) f_iso = rumba_fit.f_iso - directions, _, _ = peak_directions(odf[0, 0, 0], sphere, 0.35, 25) + directions, _, _ = peak_directions( + odf[0, 0, 0], sphere, relative_peak_threshold=0.35, min_separation_angle=25 + ) if len(directions) <= 3: # Verify small isotropic fraction in anisotropic case assert_equal(f_iso[0, 0, 0] < 0.1, True) diff --git a/dipy/reconst/tests/test_shore_odf.py b/dipy/reconst/tests/test_shore_odf.py index 64d641c182..5ee804d7d4 100644 --- a/dipy/reconst/tests/test_shore_odf.py +++ b/dipy/reconst/tests/test_shore_odf.py @@ -57,7 +57,9 @@ def test_shore_odf(): np.dot(expected_phi, asmfit.shore_coeff), asmfit.fitted_signal() ) - directions, _, _ = peak_directions(odf, sphere, 0.35, 25) + directions, _, _ = peak_directions( + odf, sphere, relative_peak_threshold=0.35, min_separation_angle=25 + ) npt.assert_equal(len(directions), 2) npt.assert_almost_equal(angular_similarity(directions, golden_directions), 2, 1) @@ -69,7 +71,9 @@ def test_shore_odf(): category=PendingDeprecationWarning, ) odf = asmfit.odf(sphere2) - directions, _, _ = peak_directions(odf, sphere2, 0.35, 25) + directions, _, _ = peak_directions( + odf, sphere2, relative_peak_threshold=0.35, min_separation_angle=25 + ) npt.assert_equal(len(directions), 2) npt.assert_almost_equal(angular_similarity(directions, golden_directions), 2, 1) @@ -78,7 +82,9 @@ def test_shore_odf(): data, golden_directions = sb_dummies[sbd] asmfit = asm.fit(data) odf = asmfit.odf(sphere2) - directions, _, _ = peak_directions(odf, sphere2, 0.35, 25) + directions, _, _ = peak_directions( + odf, sphere2, relative_peak_threshold=0.35, min_separation_angle=25 + ) if len(directions) <= 3: npt.assert_equal(len(directions), len(golden_directions)) if len(directions) > 3: