Skip to content

Commit

Permalink
move gradunwarp after denoise to not mess rician distribution, and be…
Browse files Browse the repository at this point in the history
…fore conform to keep scanner-relative affines intact
  • Loading branch information
bpinsard committed May 17, 2024
1 parent 792efd4 commit dfcfcb6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 30 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
44 changes: 21 additions & 23 deletions smriprep/workflows/anatomical.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
(
Expand All @@ -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__ = (
Expand All @@ -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'))]
Expand Down
8 changes: 2 additions & 6 deletions smriprep/workflows/tests/test_anatomical.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down

0 comments on commit dfcfcb6

Please sign in to comment.