1
- from os .path import join , exists
1
+ from os .path import exists
2
2
import numpy as np
3
3
from nibabel import Nifti1Image , save
4
4
from numpy .testing import assert_equal
@@ -43,14 +43,13 @@ def test_parcel_intra_from_3d_image():
43
43
shape = (10 , 10 , 10 )
44
44
n_parcel , nn , mu = 10 , 6 , 1.
45
45
mask_image = Nifti1Image (np .ones (shape ), np .eye (4 ))
46
- dir_context = InTemporaryDirectory ()
47
- with dir_context :
46
+ with InTemporaryDirectory () as dir_context :
48
47
surrogate_3d_dataset (mask = mask_image , out_image_file = 'image.nii' )
49
48
50
49
#run the algo
51
50
for method in ['ward' , 'kmeans' , 'gkm' ]:
52
51
osp = fixed_parcellation (mask_image , ['image.nii' ], n_parcel , nn ,
53
- method , dir_context . name , mu )
52
+ method , dir_context , mu )
54
53
result = 'parcel_%s.nii' % method
55
54
assert exists (result )
56
55
assert_equal (osp .k , n_parcel )
@@ -65,15 +64,14 @@ def test_parcel_intra_from_3d_images_list():
65
64
method = 'ward'
66
65
mask_image = Nifti1Image (np .ones (shape ), np .eye (4 ))
67
66
68
- dir_context = InTemporaryDirectory ()
69
- with dir_context :
67
+ with InTemporaryDirectory () as dir_context :
70
68
data_image = ['image_%d.nii' % i for i in range (5 )]
71
69
for datim in data_image :
72
70
surrogate_3d_dataset (mask = mask_image , out_image_file = datim )
73
71
74
72
#run the algo
75
73
osp = fixed_parcellation (mask_image , data_image , n_parcel , nn ,
76
- method , dir_context . name , mu )
74
+ method , dir_context , mu )
77
75
assert exists ('parcel_%s.nii' % method )
78
76
assert_equal (osp .k , n_parcel )
79
77
@@ -86,12 +84,11 @@ def test_parcel_intra_from_4d_image():
86
84
n_parcel , nn , mu = 10 , 6 , 1.
87
85
method = 'ward'
88
86
mask_image = Nifti1Image (np .ones (shape ), np .eye (4 ))
89
- dir_context = InTemporaryDirectory ()
90
- with dir_context :
87
+ with InTemporaryDirectory () as dir_context :
91
88
surrogate_3d_dataset (n_subj = 10 , mask = mask_image ,
92
89
out_image_file = 'image.nii' )
93
90
osp = fixed_parcellation (mask_image , ['image.nii' ], n_parcel , nn ,
94
- method , dir_context . name , mu )
91
+ method , dir_context , mu )
95
92
assert exists ('parcel_%s.nii' % method )
96
93
assert_equal (osp .k , n_parcel )
97
94
0 commit comments