Skip to content

Commit dcfd45d

Browse files
committed
make bedpostx test faster
1 parent 3352caa commit dcfd45d

File tree

1 file changed

+38
-37
lines changed

1 file changed

+38
-37
lines changed
Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import os
22

3-
from nipype.testing import (skipif, example_data, assert_equal)
4-
import nipype.workflows.fmri.fsl as fsl_wf
3+
from nipype.testing import skipif
54
import nipype.interfaces.fsl as fsl
65
import nipype.interfaces.utility as util
76
from nipype.interfaces.fsl import no_fsl, no_fsl_course_data
@@ -11,6 +10,7 @@
1110
import tempfile
1211
import shutil
1312
from nipype.workflows.dmri.fsl.dti import create_bedpostx_pipeline
13+
from nipype.utils.filemanip import list_to_filename
1414

1515

1616
@skipif(no_fsl)
@@ -22,63 +22,64 @@ def test_create_bedpostx_pipeline():
2222
bvecs_file = os.path.join(fsl_course_dir, "fdt2/subj1/bvecs")
2323
bvals_file = os.path.join(fsl_course_dir, "fdt2/subj1/bvals")
2424
dwi_file = os.path.join(fsl_course_dir, "fdt2/subj1/data.nii.gz")
25+
z_min = 62
26+
z_size = 2
27+
28+
slice_mask = pe.Node(fsl.ExtractROI(x_min=0,
29+
x_size=-1,
30+
y_min=0,
31+
y_size=-1,
32+
z_min=z_min,
33+
z_size=z_size), name="slice_mask")
34+
slice_mask.inputs.in_file = mask_file
35+
36+
slice_dwi = pe.Node(fsl.ExtractROI(x_min=0,
37+
x_size=-1,
38+
y_min=0,
39+
y_size=-1,
40+
z_min=z_min,
41+
z_size=z_size), name="slice_dwi")
42+
slice_dwi.inputs.in_file = dwi_file
2543

2644
nipype_bedpostx = create_bedpostx_pipeline("nipype_bedpostx")
27-
nipype_bedpostx.inputs.inputnode.dwi = dwi_file
28-
nipype_bedpostx.inputs.inputnode.mask = mask_file
2945
nipype_bedpostx.inputs.inputnode.bvecs = bvecs_file
3046
nipype_bedpostx.inputs.inputnode.bvals = bvals_file
3147
nipype_bedpostx.inputs.xfibres.n_fibres = 1
3248
nipype_bedpostx.inputs.xfibres.fudge = 1
33-
nipype_bedpostx.inputs.xfibres.burn_in = 10
34-
nipype_bedpostx.inputs.xfibres.n_jumps = 25
35-
nipype_bedpostx.inputs.xfibres.sample_every = 25
49+
nipype_bedpostx.inputs.xfibres.burn_in = 0
50+
nipype_bedpostx.inputs.xfibres.n_jumps = 1
51+
nipype_bedpostx.inputs.xfibres.sample_every = 1
52+
nipype_bedpostx.inputs.xfibres.cnlinear = True
53+
nipype_bedpostx.inputs.xfibres.seed = 0
3654

3755
with warnings.catch_warnings():
3856
warnings.simplefilter("ignore")
3957
original_bedpostx = pe.Node(interface=fsl.BEDPOSTX(), name="original_bedpostx")
40-
original_bedpostx.inputs.dwi = dwi_file
41-
original_bedpostx.inputs.mask = mask_file
4258
original_bedpostx.inputs.bvecs = bvecs_file
4359
original_bedpostx.inputs.bvals = bvals_file
4460
original_bedpostx.inputs.environ['FSLPARALLEL'] = ""
4561
original_bedpostx.inputs.n_fibres = 1
4662
original_bedpostx.inputs.fudge = 1
47-
original_bedpostx.inputs.burn_in = 10
48-
original_bedpostx.inputs.n_jumps = 25
49-
original_bedpostx.inputs.sample_every = 25
63+
original_bedpostx.inputs.burn_in = 0
64+
original_bedpostx.inputs.n_jumps = 1
65+
original_bedpostx.inputs.sample_every = 1
66+
original_bedpostx.inputs.seed = 0
5067

5168
test_f1 = pe.Node(util.AssertEqual(), name="mean_f1_test")
52-
test_f2 = pe.Node(util.AssertEqual(), name="mean_f2_test")
53-
test_th1 = pe.Node(util.AssertEqual(), name="mean_th1_test")
54-
test_th2 = pe.Node(util.AssertEqual(), name="mean_th2_test")
55-
test_ph1 = pe.Node(util.AssertEqual(), name="mean_ph1_test")
56-
test_ph2 = pe.Node(util.AssertEqual(), name="mean_ph2_test")
5769

5870
pipeline = pe.Workflow(name="test_bedpostx")
5971
pipeline.base_dir = tempfile.mkdtemp(prefix="nipype_test_bedpostx_")
6072

61-
def pickFirst(l):
62-
return l[0]
63-
64-
def pickSecond(l):
65-
return l[1]
66-
67-
pipeline.connect([(nipype_bedpostx, test_f1, [(("outputnode.mean_fsamples", pickFirst), "volume1")]),
68-
(nipype_bedpostx, test_f2, [(("outputnode.mean_fsamples", pickSecond), "volume1")]),
69-
(nipype_bedpostx, test_th1, [(("outputnode.mean_thsamples", pickFirst), "volume1")]),
70-
(nipype_bedpostx, test_th2, [(("outputnode.mean_thsamples", pickSecond), "volume1")]),
71-
(nipype_bedpostx, test_ph1, [(("outputnode.mean_phsamples", pickFirst), "volume1")]),
72-
(nipype_bedpostx, test_ph2, [(("outputnode.mean_phsamples", pickSecond), "volume1")]),
73-
74-
(original_bedpostx, test_f1, [(("mean_fsamples", pickFirst), "volume2")]),
75-
(original_bedpostx, test_f2, [(("mean_fsamples", pickSecond), "volume2")]),
76-
(original_bedpostx, test_th1, [(("mean_thsamples", pickFirst), "volume2")]),
77-
(original_bedpostx, test_th2, [(("mean_thsamples", pickSecond), "volume2")]),
78-
(original_bedpostx, test_ph1, [(("mean_phsamples", pickFirst), "volume2")]),
79-
(original_bedpostx, test_ph2, [(("mean_phsamples", pickSecond), "volume2")])
73+
pipeline.connect([(slice_mask, original_bedpostx, [("roi_file", "mask")]),
74+
(slice_mask, nipype_bedpostx, [("roi_file", "inputnode.mask")]),
75+
76+
(slice_dwi, original_bedpostx, [("roi_file", "dwi")]),
77+
(slice_dwi, nipype_bedpostx, [("roi_file", "inputnode.dwi")]),
78+
79+
(nipype_bedpostx, test_f1, [(("outputnode.mean_fsamples",list_to_filename), "volume1")]),
80+
(original_bedpostx, test_f1, [("mean_fsamples", "volume2")]),
8081
])
8182

8283
pipeline.run(plugin='Linear')
83-
shutil.rmtree(pipeline.base_dir)
84+
#shutil.rmtree(pipeline.base_dir)
8485

0 commit comments

Comments
 (0)