|
13 | 13 | from six.moves import zip
|
14 | 14 |
|
15 | 15 | from .. import tractogram as module_tractogram
|
| 16 | +from ..tractogram import is_data_dict, is_lazy_dict |
16 | 17 | from ..tractogram import TractogramItem, Tractogram, LazyTractogram
|
17 | 18 | from ..tractogram import PerArrayDict, PerArraySequenceDict, LazyDict
|
18 | 19 |
|
@@ -406,14 +407,20 @@ def test_extend(self):
|
406 | 407 | class TestLazyDict(unittest.TestCase):
|
407 | 408 |
|
408 | 409 | def test_lazydict_creation(self):
|
409 |
| - data_dict = LazyDict(DATA['data_per_streamline_func']) |
410 |
| - assert_equal(data_dict.keys(), DATA['data_per_streamline_func'].keys()) |
411 |
| - for k in data_dict.keys(): |
412 |
| - assert_array_equal(list(data_dict[k]), |
413 |
| - list(DATA['data_per_streamline'][k])) |
| 410 | + # Different ways of creating LazyDict |
| 411 | + lazy_dicts = [] |
| 412 | + lazy_dicts += [LazyDict(DATA['data_per_streamline_func'])] |
| 413 | + lazy_dicts += [LazyDict(**DATA['data_per_streamline_func'])] |
414 | 414 |
|
415 |
| - assert_equal(len(data_dict), |
416 |
| - len(DATA['data_per_streamline_func'])) |
| 415 | + for data_dict in lazy_dicts: |
| 416 | + assert_true(is_lazy_dict(data_dict)) |
| 417 | + assert_equal(data_dict.keys(), DATA['data_per_streamline_func'].keys()) |
| 418 | + for k in data_dict.keys(): |
| 419 | + assert_array_equal(list(data_dict[k]), |
| 420 | + list(DATA['data_per_streamline'][k])) |
| 421 | + |
| 422 | + assert_equal(len(data_dict), |
| 423 | + len(DATA['data_per_streamline_func'])) |
417 | 424 |
|
418 | 425 |
|
419 | 426 | class TestTractogramItem(unittest.TestCase):
|
@@ -470,6 +477,9 @@ def test_tractogram_creation(self):
|
470 | 477 | DATA['data_per_streamline'],
|
471 | 478 | DATA['data_per_point'])
|
472 | 479 |
|
| 480 | + assert_true(is_data_dict(tractogram.data_per_streamline)) |
| 481 | + assert_true(is_data_dict(tractogram.data_per_point)) |
| 482 | + |
473 | 483 | # Create a tractogram from another tractogram attributes.
|
474 | 484 | tractogram2 = Tractogram(tractogram.streamlines,
|
475 | 485 | tractogram.data_per_streamline,
|
@@ -795,6 +805,9 @@ def test_lazy_tractogram_creation(self):
|
795 | 805 | DATA['data_per_streamline_func'],
|
796 | 806 | DATA['data_per_point_func'])
|
797 | 807 |
|
| 808 | + assert_true(is_lazy_dict(tractogram.data_per_streamline)) |
| 809 | + assert_true(is_lazy_dict(tractogram.data_per_point)) |
| 810 | + |
798 | 811 | [t for t in tractogram] # Force iteration through tractogram.
|
799 | 812 | assert_equal(len(tractogram), len(DATA['streamlines']))
|
800 | 813 |
|
@@ -910,6 +923,22 @@ def test_lazy_tractogram_apply_affine(self):
|
910 | 923 | tractogram.affine_to_rasmm = None
|
911 | 924 | assert_raises(ValueError, tractogram.to_world)
|
912 | 925 |
|
| 926 | + # But calling apply_affine when affine_to_rasmm is None should work. |
| 927 | + tractogram = DATA['lazy_tractogram'].copy() |
| 928 | + tractogram.affine_to_rasmm = None |
| 929 | + transformed_tractogram = tractogram.apply_affine(affine) |
| 930 | + assert_array_equal(transformed_tractogram._affine_to_apply, affine) |
| 931 | + assert_true(transformed_tractogram.affine_to_rasmm is None) |
| 932 | + check_tractogram(transformed_tractogram, |
| 933 | + streamlines=[s*scaling for s in DATA['streamlines']], |
| 934 | + data_per_streamline=DATA['data_per_streamline'], |
| 935 | + data_per_point=DATA['data_per_point']) |
| 936 | + |
| 937 | + # Calling apply_affine with lazy=False should fail for LazyTractogram. |
| 938 | + tractogram = DATA['lazy_tractogram'].copy() |
| 939 | + assert_raises(ValueError, tractogram.apply_affine, |
| 940 | + affine=np.eye(4), lazy=False) |
| 941 | + |
913 | 942 | def test_tractogram_to_world(self):
|
914 | 943 | tractogram = DATA['lazy_tractogram'].copy()
|
915 | 944 | affine = np.random.RandomState(1234).randn(4, 4)
|
|
0 commit comments