Skip to content

Commit

Permalink
updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tvcastillod committed Jul 10, 2023
1 parent 9445de6 commit 291b4d2
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 17 deletions.
53 changes: 42 additions & 11 deletions fury/actors/tests/test_uncertainty.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,73 @@
"""
This spript includes the implementation of dti_uncertainty actor for the

Check failure on line 2 in fury/actors/tests/test_uncertainty.py

View workflow job for this annotation

GitHub Actions / Check for spelling errors

spript ==> script
visualization of the cones of uncertainty which uses matrix perturbation
analysis for its calculation
visualization of the cones of uncertainty along with the diffusion tensors for
comparison
"""
from dipy.reconst import dti
from dipy.segment.mask import median_otsu

from fury import actor, window

from dipy.io.image import load_nifti
from dipy.io.gradients import read_bvals_bvecs

from dipy.data import get_fnames
from dipy.data import get_fnames, read_stanford_hardi

from fury.primitive import prim_sphere


def test_uncertainty():
hardi_fname, hardi_bval_fname, hardi_bvec_fname =\
get_fnames('stanford_hardi')

data, affine = load_nifti(hardi_fname)
data_ = data[20:24, 68:72, 28:29]
print(data_)
print(data_.shape)

# load the b-values and b-vectors
bvals, bvecs = read_bvals_bvecs(hardi_bval_fname, hardi_bvec_fname)
print(bvals, bvecs)

from dipy.segment.mask import median_otsu

maskdata, mask = median_otsu(data, vol_idx=range(10, 50), median_radius=3,
numpass=1, autocrop=True, dilate=2)

uncertainty_cones = actor.dti_uncertainty(
data=maskdata[20:24, 68:72, 28:29], bvals=bvals, bvecs=bvecs)
data=maskdata[13:43, 44:74, 28:29], bvals=bvals, bvecs=bvecs)

scene = window.Scene()
scene.background([255, 255, 255])

scene.add(diffusion_tensors())
window.show(scene, reset_camera=False)
scene.clear()

scene.add(uncertainty_cones)
window.show(scene, reset_camera=False)

scene.reset_camera()
scene.reset_clipping_range()

window.show(scene, reset_camera=False)
class Sphere:

vertices = None
faces = None

def diffusion_tensors():
# https://dipy.org/documentation/1.0.0./examples_built/reconst_dti/
img, gtab = read_stanford_hardi()
data = img.get_data()

maskdata, mask = median_otsu(data, vol_idx=range(10, 50), median_radius=3,
numpass=1, autocrop=True, dilate=2)
tenmodel = dti.TensorModel(gtab)
tenfit = tenmodel.fit(maskdata)

evals = tenfit.evals[13:43, 44:74, 28:29]
evecs = tenfit.evecs[13:43, 44:74, 28:29]

vertices, faces = prim_sphere('symmetric724', True)
sphere = Sphere()
sphere.vertices = vertices
sphere.faces = faces

from dipy.data import get_sphere
sphere = get_sphere('symmetric724')

return actor.tensor_slicer(evals, evecs, sphere=sphere, scale=0.3)
31 changes: 25 additions & 6 deletions fury/tests/test_actors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1736,21 +1736,40 @@ def test_marker_actor(interactive=False):

def test_uncertainty_actor(interactive=False):
scene = window.Scene()
scene.background((0, 0, 0))

data = np.array([0, 0, 0])
bvals = np.array([0, 0, 0])
bvecs = np.array([0, 0, 0])
from dipy.data import get_fnames
from dipy.io import read_bvals_bvecs
_, fbvals, fbvecs = get_fnames('small_101D')
bvals, bvecs = read_bvals_bvecs(fbvals, fbvecs)

uncert_cones = actor.dti_uncertainty(data=data, bvals=bvals, bvecs=bvecs,
scales=1.0, opacity=1.0)
n = bvals.shape[0]
data = np.ones((10, 10, 1, n)) * 0.1

uncert_cones = actor.dti_uncertainty(data=data, bvals=bvals, bvecs=bvecs)
scene.add(uncert_cones)

if interactive:
window.show(scene)

report = window.analyze_scene(scene)
npt.assert_equal(report.actors, 1)
arr = window.snapshot(scene, offscreen=True)
report = window.analyze_snapshot(arr)
npt.assert_equal(report.objects, 100)
scene.clear()

n = bvals.shape[0]
data = np.ones((5, 5, 5, n)) * 0.5
uncert_cones = actor.dti_uncertainty(data=data, bvals=bvals, bvecs=bvecs)
scene.add(uncert_cones)

if interactive:
window.show(scene)

report = window.analyze_scene(scene)
npt.assert_equal(report.actors, 1)
scene.clear()


def test_actors_primitives_count():
centers = np.array([[1, 1, 1], [2, 2, 2]])
Expand Down

0 comments on commit 291b4d2

Please sign in to comment.