Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trilinear_interpolate4d only works on float64 #832

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion dipy/direction/probabilistic_direction_getter.py
Expand Up @@ -33,7 +33,7 @@ def get_pmf(self, point):
class SHCoeffPmfGen(PmfGen):

def __init__(self, shcoeff, sphere, basis_type):
self.shcoeff = shcoeff
self.shcoeff = shcoeff.astype(np.float64)
self.sphere = sphere
sh_order = order_from_ncoef(shcoeff.shape[-1])
try:
Expand Down
83 changes: 44 additions & 39 deletions dipy/direction/tests/test_prob_direction_getter.py
Expand Up @@ -5,6 +5,7 @@
from dipy.reconst.shm import SphHarmFit, SphHarmModel
from dipy.direction import ProbabilisticDirectionGetter


def test_ProbabilisticDirectionGetter():
# Test the constructors and errors of the ProbabilisticDirectionGetter

Expand All @@ -20,43 +21,47 @@ def fit(self, data, mask=None):
data = np.zeros((3, 3, 3, 7))
fit = model.fit(data)

# Sample point and direction
point = np.zeros(3)
dir = unit_octahedron.vertices[0].copy()

# make a dg from a fit
dg = ProbabilisticDirectionGetter.from_shcoeff(fit.shm_coeff, 90,
unit_octahedron)
state = dg.get_direction(point, dir)
npt.assert_equal(state, 1)

# Make a dg from a pmf
N = unit_octahedron.theta.shape[0]
pmf = np.zeros((3, 3, 3, N))
dg = ProbabilisticDirectionGetter.from_pmf(pmf, 90, unit_octahedron)
state = dg.get_direction(point, dir)
npt.assert_equal(state, 1)

# pmf shape must match sphere
bad_pmf = pmf[..., 1:]
npt.assert_raises(ValueError, ProbabilisticDirectionGetter.from_pmf,
bad_pmf, 90, unit_octahedron)

# pmf must have 4 dimensions
bad_pmf = pmf[0, ...]
npt.assert_raises(ValueError, ProbabilisticDirectionGetter.from_pmf,
bad_pmf, 90, unit_octahedron)
# pmf cannot have negative values
pmf[0, 0, 0, 0] = -1
npt.assert_raises(ValueError, ProbabilisticDirectionGetter.from_pmf, pmf,
90, unit_octahedron)

# Check basis_type keyword
dg = ProbabilisticDirectionGetter.from_shcoeff(fit.shm_coeff, 90,
unit_octahedron,
basis_type="mrtrix")

npt.assert_raises(ValueError, ProbabilisticDirectionGetter.from_shcoeff,
fit.shm_coeff, 90, unit_octahedron,
basis_type="not a basis")
# Test if the tracking works on different dtype of the same data.
for dtype in [np.float32, np.float64]:

fit = fit.astype(dtype)

# Sample point and direction
point = np.zeros(3)
dir = unit_octahedron.vertices[0].copy()

# make a dg from a fit
dg = ProbabilisticDirectionGetter.from_shcoeff(fit.shm_coeff, 90,
unit_octahedron)
state = dg.get_direction(point, dir)
npt.assert_equal(state, 1)

# Make a dg from a pmf
N = unit_octahedron.theta.shape[0]
pmf = np.zeros((3, 3, 3, N))
dg = ProbabilisticDirectionGetter.from_pmf(pmf, 90, unit_octahedron)
state = dg.get_direction(point, dir)
npt.assert_equal(state, 1)

# pmf shape must match sphere
bad_pmf = pmf[..., 1:]
npt.assert_raises(ValueError, ProbabilisticDirectionGetter.from_pmf,
bad_pmf, 90, unit_octahedron)

# pmf must have 4 dimensions
bad_pmf = pmf[0, ...]
npt.assert_raises(ValueError, ProbabilisticDirectionGetter.from_pmf,
bad_pmf, 90, unit_octahedron)
# pmf cannot have negative values
pmf[0, 0, 0, 0] = -1
npt.assert_raises(ValueError, ProbabilisticDirectionGetter.from_pmf, pmf,
90, unit_octahedron)

# Check basis_type keyword
dg = ProbabilisticDirectionGetter.from_shcoeff(fit.shm_coeff, 90,
unit_octahedron,
basis_type="mrtrix")

npt.assert_raises(ValueError, ProbabilisticDirectionGetter.from_shcoeff,
fit.shm_coeff, 90, unit_octahedron,
basis_type="not a basis")