diff --git a/pyproject.toml b/pyproject.toml index 7730a84dd1..06d5759b79 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,8 @@ dependencies = [ "matplotlib >= 2.2.0", "nibabel >= 4.0.1", "nipype >= 1.7.0", - "niworkflows >= 1.10.1", +# "niworkflows >= 1.10.1", + "niworkflows@git+https://github.com/bpinsard/niworkflows.git@enh/gradunwarp", "numpy", "packaging", "pybids >= 0.11.1", diff --git a/smriprep/workflows/anatomical.py b/smriprep/workflows/anatomical.py index 5b54fb11b7..989abc3049 100644 --- a/smriprep/workflows/anatomical.py +++ b/smriprep/workflows/anatomical.py @@ -1480,7 +1480,22 @@ def init_anat_template_wf( ) anat_conform = pe.MapNode(Conform(), iterfield='in_file', name='anat_conform') - # -1 Gradient unwarping (optional) + # fmt:off + workflow.connect([ + (inputnode, anat_ref_dimensions, [('anat_files', 't1w_list')]), + (anat_ref_dimensions, denoise, [('t1w_valid_list', 'input_image')]), + (anat_ref_dimensions, anat_conform, [ + ('target_zooms', 'target_zooms'), + ('target_shape', 'target_shape'), + ]), + (anat_ref_dimensions, outputnode, [ + ('out_report', 'out_report'), + ('t1w_valid_list', 'anat_valid_list'), + ]), + ]) + # fmt:on + + # 0.5 Gradient unwarping (optional) if gradunwarp_file: nds = [ ( @@ -1495,7 +1510,9 @@ def init_anat_template_wf( f'Inconsistent distortion correction metadata across {contrast} images.' ) if not any(nds): + # gradient unwarping not needed for that contrast gradunwarp_file = None + if gradunwarp_file: gradunwarp_ver = GradUnwarp.version() workflow.__desc__ = ( @@ -1508,32 +1525,13 @@ def init_anat_template_wf( gradunwarp_wf.inputs.inputnode.grad_file = gradunwarp_file # fmt:off workflow.connect([ - (inputnode, gradunwarp_wf, [('anat_files', 'inputnode.input_file')]), - (gradunwarp_wf, anat_ref_dimensions, [('outputnode.corrected_file', 't1w_list')]), + (denoise, gradunwarp_wf, [('output_image', 'inputnode.input_file')]), + (gradunwarp_wf, anat_conform, [('outputnode.corrected_file', 'in_file')]), ]) else: - workflow.connect( - [ - (inputnode, anat_ref_dimensions, [('anat_files', 't1w_list')]), - ] - ) + workflow.connect(denoise, anat_conform, [('output_image', 'in_file')]) # fmt:on - # fmt:off - workflow.connect([ - (anat_ref_dimensions, denoise, [('t1w_valid_list', 'input_image')]), - (anat_ref_dimensions, anat_conform, [ - ('target_zooms', 'target_zooms'), - ('target_shape', 'target_shape'), - ]), - (denoise, anat_conform, [('output_image', 'in_file')]), - (anat_ref_dimensions, outputnode, [ - ('out_report', 'out_report'), - ('t1w_valid_list', 'anat_valid_list'), - ]), - ]) - # fmt:on - if num_files == 1: get1st = pe.Node(niu.Select(index=[0]), name='get1st') outputnode.inputs.anat_realign_xfm = [str(load_resource('itkIdentityTransform.txt'))] diff --git a/smriprep/workflows/tests/test_anatomical.py b/smriprep/workflows/tests/test_anatomical.py index 1df49a7860..09315529f6 100644 --- a/smriprep/workflows/tests/test_anatomical.py +++ b/smriprep/workflows/tests/test_anatomical.py @@ -5,17 +5,13 @@ import numpy as np import pytest from nipype.pipeline.engine.utils import generate_expanded_graph -from niworkflows.interfaces import gradunwarp +from niworkflows.tests.data import load_test_data from niworkflows.utils.spaces import Reference, SpatialReferences from niworkflows.utils.testing import generate_bids_skeleton from ..anatomical import init_anat_fit_wf, init_anat_preproc_wf -gradunwarp_file_params = [None] -if gradunwarp.GradUnwarp.version(): - from gradunwarp.core.tests.test_regression import siemens_gradfile - - gradunwarp_file_params.append(siemens_gradfile) +gradunwarp_file_params = [None, load_test_data('gradunwarp_coeffs.grad')] BASE_LAYOUT = { '01': {