Skip to content

Commit 43712de

Browse files
committed
fix: restrict_deformation should be in RAS coordinates
1 parent d4b6567 commit 43712de

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

sdcflows/workflows/fit/syn.py

+20-14
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ def init_syn_sdc_wf(
254254
run_without_submitting=True,
255255
name="warp_dir",
256256
)
257+
warp_dir.inputs.nlevels = 2
257258
atlas_msk = pe.Node(Binarize(thresh_low=atlas_threshold), name="atlas_msk")
258259
anat_dilmsk = pe.Node(BinaryDilation(), name="anat_dilmsk")
259260
amask2epi = pe.Node(
@@ -356,15 +357,15 @@ def init_syn_sdc_wf(
356357
(inputnode, fixed_masks, [("anat_mask", "in1"),
357358
("anat_mask", "in2")]),
358359
(inputnode, anat_dilmsk, [("anat_mask", "in_file")]),
359-
(inputnode, warp_dir, [("epi_ref", "intuple")]),
360+
(inputnode, warp_dir, [("anat_ref", "fixed_image")]),
360361
(inputnode, anat_merge, [("anat_ref", "in1")]),
361362
(inputnode, lap_anat, [("anat_ref", "op1")]),
362363
(inputnode, find_zooms, [("anat_ref", "in_anat"),
363364
(("epi_ref", _pop), "in_epi")]),
364365
(inputnode, zooms_field, [(("epi_ref", _pop), "reference_image")]),
366+
(inputnode, epi_umask, [("epi_mask", "in1")]),
365367
(lap_anat, lap_anat_norm, [("output_image", "in_file")]),
366368
(lap_anat_norm, anat_merge, [("out", "in2")]),
367-
(inputnode, epi_umask, [("epi_mask", "in1")]),
368369
(epi_umask, moving_masks, [("out_file", "in1"),
369370
("out_file", "in2"),
370371
("out_file", "in3")]),
@@ -377,6 +378,7 @@ def init_syn_sdc_wf(
377378
(atlas_msk, fixed_masks, [("out_mask", "in3")]),
378379
(anat_dilmsk, amask2epi, [("out_file", "input_image")]),
379380
(amask2epi, epi_umask, [("output_image", "in2")]),
381+
(readout_time, warp_dir, [("pe_direction", "pe_dir")]),
380382
(warp_dir, syn, [("out", "restrict_deformation")]),
381383
(anat_merge, syn, [("out", "fixed_image")]),
382384
(fixed_masks, syn, [("out", "fixed_image_masks")]),
@@ -649,21 +651,25 @@ def _remove_first_mask(in_file):
649651
return workflow
650652

651653

652-
def _warp_dir(intuple, nlevels=3):
653-
"""
654-
Extract the ``restrict_deformation`` argument from metadata.
654+
def _warp_dir(fixed_image, pe_dir, nlevels=3):
655+
"""Extract the ``restrict_deformation`` argument from metadata."""
656+
import numpy as np
657+
import nibabel as nb
655658

656-
Example
657-
-------
658-
>>> _warp_dir(("epi.nii.gz", {"PhaseEncodingDirection": "i-"}))
659-
[[1, 0.1, 0.1], [1, 0.1, 0.1], [1, 0.1, 0.1]]
659+
img = nb.load(fixed_image)
660660

661-
>>> _warp_dir(("epi.nii.gz", {"PhaseEncodingDirection": "j-"}), nlevels=2)
662-
[[0.1, 1, 0.1], [0.1, 1, 0.1]]
661+
if np.any(nb.affines.obliquity(img.affine) > 0.05):
662+
from nipype import logging
663663

664-
"""
665-
pe = intuple[1]["PhaseEncodingDirection"][0]
666-
return nlevels * [[1 if pe == ax else 0.1 for ax in "ijk"]]
664+
logging.getLogger("nipype.interface").warn(
665+
"Running fieldmap-less registration on an oblique dataset"
666+
)
667+
668+
vs = nb.affines.voxel_sizes(img.affine)
669+
order = np.around(np.abs(img.affine[:3, :3] / vs))
670+
retval = order @ [1 if pe_dir[0] == ax else 0.1 for ax in "ijk"]
671+
672+
return nlevels * [retval.tolist()]
667673

668674

669675
def _merge_meta(epi_ref, meta_list):

0 commit comments

Comments
 (0)