23
23
"""Test unwarp."""
24
24
from pathlib import Path
25
25
from nipype .pipeline import engine as pe
26
+ from nipype .interfaces import utility as niu
26
27
27
28
from ...fit .fieldmap import init_magnitude_wf
28
29
from ..correction import init_unwarp_wf
@@ -83,6 +84,8 @@ def test_unwarp_wf(tmpdir, datadir, workdir, outdir):
83
84
from ...outputs import DerivativesDataSink
84
85
from ....interfaces .reportlets import FieldmapReportlet
85
86
87
+ squeeze = pe .Node (niu .Function (function = _squeeze ), name = "squeeze" )
88
+
86
89
report = pe .Node (
87
90
SimpleBeforeAfter (
88
91
before_label = "Distorted" ,
@@ -122,8 +125,9 @@ def test_unwarp_wf(tmpdir, datadir, workdir, outdir):
122
125
# fmt: off
123
126
workflow .connect ([
124
127
(epi_ref_wf , report , [("outputnode.fmap_ref" , "before" )]),
125
- (unwarp_wf , report , [("outputnode.corrected" , "after" ),
126
- ("outputnode.corrected_mask" , "wm_seg" )]),
128
+ (unwarp_wf , squeeze , [("outputnode.corrected" , "in_file" )]),
129
+ (unwarp_wf , report , [("outputnode.corrected_mask" , "wm_seg" )]),
130
+ (squeeze , report , [("out" , "after" )]),
127
131
(report , ds_report , [("out_report" , "in_file" )]),
128
132
(epi_ref_wf , rep , [("outputnode.fmap_ref" , "reference" ),
129
133
("outputnode.fmap_mask" , "mask" )]),
@@ -135,3 +139,18 @@ def test_unwarp_wf(tmpdir, datadir, workdir, outdir):
135
139
if workdir :
136
140
workflow .base_dir = str (workdir )
137
141
workflow .run (plugin = "Linear" )
142
+
143
+
144
+ def _squeeze (in_file ):
145
+ from pathlib import Path
146
+ import nibabel as nb
147
+
148
+ img = nb .load (in_file )
149
+ squeezed = nb .squeeze_image (img )
150
+
151
+ if squeezed .shape == img .shape :
152
+ return in_file
153
+
154
+ out_fname = Path .cwd () / Path (in_file ).name
155
+ squeezed .to_filename (out_fname )
156
+ return str (out_fname )
0 commit comments