Skip to content

Commit dfc0d7d

Browse files
committed
move gradunwarp after denoise to not mess rician distribution, and before conform to keep scanner-relative affines intact
1 parent 792efd4 commit dfc0d7d

File tree

3 files changed

+25
-30
lines changed

3 files changed

+25
-30
lines changed

pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ dependencies = [
2525
"matplotlib >= 2.2.0",
2626
"nibabel >= 4.0.1",
2727
"nipype >= 1.7.0",
28-
"niworkflows >= 1.10.1",
28+
# "niworkflows >= 1.10.1",
29+
"niworkflows@git+https://github.com/bpinsard/niworkflows.git@enh/gradunwarp",
2930
"numpy",
3031
"packaging",
3132
"pybids >= 0.11.1",

smriprep/workflows/anatomical.py

+21-23
Original file line numberDiff line numberDiff line change
@@ -1480,7 +1480,22 @@ def init_anat_template_wf(
14801480
)
14811481
anat_conform = pe.MapNode(Conform(), iterfield='in_file', name='anat_conform')
14821482

1483-
# -1 Gradient unwarping (optional)
1483+
# fmt:off
1484+
workflow.connect([
1485+
(inputnode, anat_ref_dimensions, [('anat_files', 't1w_list')]),
1486+
(anat_ref_dimensions, denoise, [('t1w_valid_list', 'input_image')]),
1487+
(anat_ref_dimensions, anat_conform, [
1488+
('target_zooms', 'target_zooms'),
1489+
('target_shape', 'target_shape'),
1490+
]),
1491+
(anat_ref_dimensions, outputnode, [
1492+
('out_report', 'out_report'),
1493+
('t1w_valid_list', 'anat_valid_list'),
1494+
]),
1495+
])
1496+
# fmt:on
1497+
1498+
# 0.5 Gradient unwarping (optional)
14841499
if gradunwarp_file:
14851500
nds = [
14861501
(
@@ -1495,7 +1510,9 @@ def init_anat_template_wf(
14951510
f'Inconsistent distortion correction metadata across {contrast} images.'
14961511
)
14971512
if not any(nds):
1513+
# gradient unwarping not needed for that contrast
14981514
gradunwarp_file = None
1515+
14991516
if gradunwarp_file:
15001517
gradunwarp_ver = GradUnwarp.version()
15011518
workflow.__desc__ = (
@@ -1508,32 +1525,13 @@ def init_anat_template_wf(
15081525
gradunwarp_wf.inputs.inputnode.grad_file = gradunwarp_file
15091526
# fmt:off
15101527
workflow.connect([
1511-
(inputnode, gradunwarp_wf, [('anat_files', 'inputnode.input_file')]),
1512-
(gradunwarp_wf, anat_ref_dimensions, [('outputnode.corrected_file', 't1w_list')]),
1528+
(denoise, gradunwarp_wf, [('output_image', 'inputnode.input_file')]),
1529+
(gradunwarp_wf, anat_conform, [('outputnode.corrected_file', 'in_file')]),
15131530
])
15141531
else:
1515-
workflow.connect(
1516-
[
1517-
(inputnode, anat_ref_dimensions, [('anat_files', 't1w_list')]),
1518-
]
1519-
)
1532+
workflow.connect([(denoise, anat_conform, [('output_image', 'in_file')])])
15201533
# fmt:on
15211534

1522-
# fmt:off
1523-
workflow.connect([
1524-
(anat_ref_dimensions, denoise, [('t1w_valid_list', 'input_image')]),
1525-
(anat_ref_dimensions, anat_conform, [
1526-
('target_zooms', 'target_zooms'),
1527-
('target_shape', 'target_shape'),
1528-
]),
1529-
(denoise, anat_conform, [('output_image', 'in_file')]),
1530-
(anat_ref_dimensions, outputnode, [
1531-
('out_report', 'out_report'),
1532-
('t1w_valid_list', 'anat_valid_list'),
1533-
]),
1534-
])
1535-
# fmt:on
1536-
15371535
if num_files == 1:
15381536
get1st = pe.Node(niu.Select(index=[0]), name='get1st')
15391537
outputnode.inputs.anat_realign_xfm = [str(load_resource('itkIdentityTransform.txt'))]

smriprep/workflows/tests/test_anatomical.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@
55
import numpy as np
66
import pytest
77
from nipype.pipeline.engine.utils import generate_expanded_graph
8-
from niworkflows.interfaces import gradunwarp
8+
from niworkflows.tests.data import load_test_data
99
from niworkflows.utils.spaces import Reference, SpatialReferences
1010
from niworkflows.utils.testing import generate_bids_skeleton
1111

1212
from ..anatomical import init_anat_fit_wf, init_anat_preproc_wf
1313

14-
gradunwarp_file_params = [None]
15-
if gradunwarp.GradUnwarp.version():
16-
from gradunwarp.core.tests.test_regression import siemens_gradfile
17-
18-
gradunwarp_file_params.append(siemens_gradfile)
14+
gradunwarp_file_params = [None, load_test_data('gradunwarp_coeffs.grad')]
1915

2016
BASE_LAYOUT = {
2117
'01': {

0 commit comments

Comments
 (0)