-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathtest_dipy.py
More file actions
69 lines (55 loc) · 2.3 KB
/
test_dipy.py
File metadata and controls
69 lines (55 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import unittest
import os.path
import numpy as np
import numpy.testing as npt
import tempfile
from dipy.core.graph import Graph
from dipy.denoise.enhancement_kernel import EnhancementKernel
from dipy.tracking.fbcmeasures import FBCMeasures
from dipy.core.sphere import Sphere
from dipy.viz import window, actor
class TestDipy(unittest.TestCase):
def test_scene(self):
xyz = 10 * np.random.rand(100, 3)
colors = np.random.rand(100, 4)
radii = np.random.rand(100) + 0.5
sphere_actor = actor.sphere(centers=xyz, colors=colors, radii=radii)
scene = window.Scene()
scene.add(sphere_actor)
self.assertEqual((0, 0), scene.GetSize())
def test_graph(self):
g = Graph()
g.add_node('a', 5)
g.add_node('b', 6)
self.assertEqual(2, len(g.node))
# From: https://github.com/nipy/dipy/blob/51234a4437638535ff8f6e5819e14ccf7e1d1483/dipy/tracking/tests/test_fbc.py
def test_fbc(self):
"""Test the FBC measures on a set of fibers"""
# Generate two fibers of 10 points
streamlines = []
for i in range(2):
fiber = np.zeros((10, 3))
for j in range(10):
fiber[j, 0] = j
fiber[j, 1] = i*0.2
fiber[j, 2] = 0
streamlines.append(fiber)
# Create lookup table.
# A fixed set of orientations is used to guarantee deterministic results
D33 = 1.0
D44 = 0.04
t = 1
sphere = Sphere(xyz=np.array([[0.82819078, 0.51050355, 0.23127074],
[-0.10761926, -0.95554309, 0.27450957],
[0.4101745, -0.07154038, 0.90919682],
[-0.75573448, 0.64854889, 0.09082809],
[-0.56874549, 0.01377562, 0.8223982]]))
k = EnhancementKernel(D33, D44, t, orientations=sphere,
force_recompute=True)
# run FBC
fbc = FBCMeasures(streamlines, k, verbose=True)
# get FBC values
fbc_sl_orig, clrs_orig, rfbc_orig = \
fbc.get_points_rfbc_thresholded(0, emphasis=0.01)
# check mean RFBC against tested value
npt.assert_almost_equal(np.mean(rfbc_orig), 1.0500466494329224, decimal=4)