Skip to content

Commit 48ac04a

Browse files
committed
fix: do not shave off time avoiding mask computation
1 parent a9b0705 commit 48ac04a

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

dmriprep/workflows/dwi/base.py

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def init_dwi_preproc_wf(dwi_file, has_fieldmap=False):
7272
SimpleBeforeAfterRPT as SimpleBeforeAfter,
7373
)
7474
from niworkflows.workflows.epi.refmap import init_epi_reference_wf
75+
from sdcflows.workflows.ancillary import init_brainextraction_wf
7576

7677
from ...interfaces.vectors import CheckGradientTable
7778
from .outputs import init_dwi_derivatives_wf, init_reportlets_wf
@@ -148,7 +149,16 @@ def init_dwi_preproc_wf(dwi_file, has_fieldmap=False):
148149
name="dwi_reference_wf",
149150
)
150151

151-
dwi_derivatives_wf = init_dwi_derivatives_wf(output_dir=str(config.execution.output_dir))
152+
brainextraction_wf = init_brainextraction_wf()
153+
dwi_derivatives_wf = init_dwi_derivatives_wf(
154+
output_dir=str(config.execution.output_dir)
155+
)
156+
157+
# If has_fieldmaps this will hold the corrected reference, original otherwise
158+
buffernode = pe.Node(
159+
niu.IdentityInterface(fields=["dwi_reference", "dwi_mask"]),
160+
name="buffernode",
161+
)
152162

153163
# MAIN WORKFLOW STRUCTURE
154164
# fmt: off
@@ -158,12 +168,16 @@ def init_dwi_preproc_wf(dwi_file, has_fieldmap=False):
158168
("in_bvec", "in_bvec"),
159169
("in_bval", "in_bval")]),
160170
(inputnode, dwi_reference_wf, [(("dwi_file", _aslist), "inputnode.in_files")]),
171+
(dwi_reference_wf, brainextraction_wf, [
172+
("outputnode.epi_ref_file", "inputnode.in_file")]),
161173
(gradient_table, dwi_reference_wf, [(("b0_mask", _aslist), "inputnode.t_masks")]),
162-
(gradient_table, outputnode, [("out_rasb", "gradients_rasb")]),
163-
(outputnode, dwi_derivatives_wf, [
174+
(buffernode, dwi_derivatives_wf, [
164175
("dwi_reference", "inputnode.dwi_ref"),
165176
("dwi_mask", "inputnode.dwi_mask"),
166177
]),
178+
(buffernode, outputnode, [("dwi_reference", "dwi_reference"),
179+
("dwi_mask", "dwi_mask")]),
180+
(gradient_table, outputnode, [("out_rasb", "gradients_rasb")]),
167181
])
168182
# fmt: on
169183

@@ -205,21 +219,14 @@ def _bold_reg_suffix(fallback):
205219
("t1w_mask", "in_mask")]),
206220
(inputnode, ds_report_reg, [("dwi_file", "source_file")]),
207221
# BBRegister
208-
(dwi_reference_wf, bbr_wf, [
209-
("outputnode.epi_ref_file", "inputnode.in_file")
210-
]),
222+
(buffernode, bbr_wf, [("dwi_reference", "inputnode.in_file")]),
211223
(bbr_wf, ds_report_reg, [
212-
('outputnode.out_report', 'in_file'),
213-
(('outputnode.fallback', _bold_reg_suffix), 'desc')]),
224+
("outputnode.out_report", "in_file"),
225+
(("outputnode.fallback", _bold_reg_suffix), "desc")]),
214226
])
215227
# fmt: on
216228

217229
if "eddy" not in config.workflow.ignore:
218-
from sdcflows.workflows.ancillary import init_brainextraction_wf
219-
220-
# Brain extraction not run just yet
221-
brainextraction_wf = init_brainextraction_wf()
222-
223230
# Eddy distortion correction
224231
eddy_wf = init_eddy_wf(debug=config.execution.debug)
225232
eddy_wf.inputs.inputnode.metadata = layout.get_metadata(str(dwi_file))
@@ -249,13 +256,9 @@ def _bold_reg_suffix(fallback):
249256
("in_bvec", "inputnode.in_bvec"),
250257
("in_bval", "inputnode.in_bval")]),
251258
(inputnode, ds_report_eddy, [("dwi_file", "source_file")]),
252-
(dwi_reference_wf, brainextraction_wf, [
253-
("outputnode.epi_ref_file", "inputnode.in_file")]),
254-
(brainextraction_wf, eddy_wf, [
255-
("outputnode.out_mask", "inputnode.dwi_mask"),
256-
]),
259+
(brainextraction_wf, eddy_wf, [("outputnode.out_mask", "inputnode.dwi_mask")]),
257260
(brainextraction_wf, eddy_report, [("outputnode.out_file", "before")]),
258-
(eddy_wf, eddy_report, [('outputnode.eddy_ref_image', 'after')]),
261+
(eddy_wf, eddy_report, [("outputnode.eddy_ref_image", "after")]),
259262
(eddy_report, ds_report_eddy, [("out_report", "in_file")]),
260263
])
261264
# fmt:on
@@ -281,7 +284,10 @@ def _bold_reg_suffix(fallback):
281284
if not has_fieldmap:
282285
# fmt: off
283286
workflow.connect([
284-
(dwi_reference_wf, outputnode, [("outputnode.epi_ref_file", "dwi_reference")]),
287+
(brainextraction_wf, buffernode, [
288+
("outputnode.out_file", "dwi_reference"),
289+
("outputnode.out_mask", "dwi_mask"),
290+
]),
285291
])
286292
# fmt: on
287293
return workflow
@@ -337,11 +343,11 @@ def _bold_reg_suffix(fallback):
337343
(dwi_reference_wf, unwarp_wf, [("outputnode.epi_ref_file", "inputnode.distorted")]),
338344
(coeff2epi_wf, unwarp_wf, [
339345
("outputnode.fmap_coeff", "inputnode.fmap_coeff")]),
340-
(dwi_reference_wf, sdc_report, [("outputnode.epi_ref_file", "before")]),
346+
(brainextraction_wf, sdc_report, [("outputnode.out_file", "before")]),
341347
(unwarp_wf, sdc_report, [("outputnode.corrected", "after"),
342348
("outputnode.corrected_mask", "wm_seg")]),
343349
(sdc_report, reportlets_wf, [("out_report", "inputnode.sdc_report")]),
344-
(unwarp_wf, outputnode, [("outputnode.corrected", "dwi_reference"),
350+
(unwarp_wf, buffernode, [("outputnode.corrected", "dwi_reference"),
345351
("outputnode.corrected_mask", "dwi_mask")]),
346352
])
347353
# fmt: on
@@ -355,10 +361,10 @@ def _get_wf_name(filename):
355361
356362
Examples
357363
--------
358-
>>> _get_wf_name('/completely/made/up/path/sub-01_dir-AP_acq-64grad_dwi.nii.gz')
364+
>>> _get_wf_name("/completely/made/up/path/sub-01_dir-AP_acq-64grad_dwi.nii.gz")
359365
'dwi_preproc_dir_AP_acq_64grad_wf'
360366
361-
>>> _get_wf_name('/completely/made/up/path/sub-01_dir-RL_run-01_echo-1_dwi.nii.gz')
367+
>>> _get_wf_name("/completely/made/up/path/sub-01_dir-RL_run-01_echo-1_dwi.nii.gz")
362368
'dwi_preproc_dir_RL_run_01_echo_1_wf'
363369
364370
"""

0 commit comments

Comments
 (0)