Skip to content

Commit 1138b4c

Browse files
joey-scangamgxd
authored andcommitted
fix: Orient fieldmap before checking spline fit
1 parent e87d9b3 commit 1138b4c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

nibabies/interfaces/resampling.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,18 @@ def reconstruct_fieldmap(
679679
target.__class__(target.dataobj, projected_affine, target.header),
680680
)
681681
else:
682+
# Below if statement was taken from fmriprep pull request #3439,
683+
# along with the same explanation:
684+
#
685+
# Hack. Sometimes the reference array is rotated relative to the fieldmap
686+
# and coefficient grids. As far as I know, coefficients are always RAS,
687+
# but good to check before doing this.
688+
if (
689+
nb.aff2axcodes(coefficients[-1].affine)
690+
== ('R', 'A', 'S')
691+
!= nb.aff2axcodes(fmap_reference.affine)
692+
):
693+
fmap_reference = nb.as_closest_canonical(fmap_reference)
682694
if not aligned(fmap_reference.affine, coefficients[-1].affine):
683695
raise ValueError('Reference passed is not aligned with spline grids')
684696
reference, _ = ensure_positive_cosines(fmap_reference)

0 commit comments

Comments
 (0)