Skip to content

Commit

Permalink
enh: disable head-motion transforms consideration
Browse files Browse the repository at this point in the history
  • Loading branch information
oesteban committed Aug 11, 2023
1 parent 53663d4 commit da4c183
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
36 changes: 25 additions & 11 deletions sdcflows/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,16 @@ def fit(
approx &= xfm_data2fmap is not None # Approximate iff xfm_data2fmap is defined
xfm_data2fmap = xfm_data2fmap if xfm_data2fmap is not None else np.eye(4)
target_affine = target_reference.affine.copy()
target_header = target_reference.header.copy()

if approx:
_tmp_shape = target_reference.shape[:3]

# Project the reference's grid onto the fieldmap's
target_reference = target_reference.__class__(
target_reference.dataobj,
xfm_data2fmap @ target_affine,
target_reference.header,
target_header,
)

# Make sure the data array has all cosines positive (i.e., no axes are flipped)
Expand Down Expand Up @@ -320,7 +324,6 @@ def fit(
if approx:
from sdcflows.utils.tools import deoblique_and_zooms

_tmp_reference = target_reference
# Generate a sampling reference on the fieldmap's space that fully covers
# the target_reference's grid.
target_reference = deoblique_and_zooms(
Expand Down Expand Up @@ -352,7 +355,12 @@ def fit(
if approx:
from nitransforms.linear import Affine

# Interpolate fmap given on target_reference in target_reference_back
_tmp_reference = nb.Nifti1Image(
np.zeros(_tmp_shape, dtype=target_header.get_data_dtype()),
target_affine,
target_header,
)
# Interpolate fmap given on target_reference in the original target_reference
# voxel locations (overwrite fmap)
self.mapped = Affine(reference=_tmp_reference).apply(self.mapped)

Expand Down Expand Up @@ -497,14 +505,20 @@ def apply(

# Convert head-motion transforms to voxel-to-voxel:
if xfms is not None:
if len(xfms) != n_volumes:
raise RuntimeError(
f"Number of head-motion estimates ({len(xfms)}) does not match the "
f"number of volumes ({n_volumes})"
)
vox2ras = moving.affine.copy()
ras2vox = np.linalg.inv(vox2ras)
xfms = [ras2vox @ xfm @ vox2ras for xfm in xfms]
# if len(xfms) != n_volumes:
# raise RuntimeError(
# f"Number of head-motion estimates ({len(xfms)}) does not match the "
# f"number of volumes ({n_volumes})"
# )
# vox2ras = moving.affine.copy()
# ras2vox = np.linalg.inv(vox2ras)
# xfms = [ras2vox @ xfm @ vox2ras for xfm in xfms]
xfms = None
warn(
"Head-motion compensating (realignment) transforms are ignored when applying "
"the unwarp with SDCFlows. This feature will be enabled as soon as unit tests "
"are implemented for its quality assurance."
)

# Resample
resampled = asyncio.run(unwarp_parallel(
Expand Down
6 changes: 1 addition & 5 deletions sdcflows/utils/wrangler.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,7 @@ def find_estimators(
... subject="101006",
... ) # doctest: +ELLIPSIS
[FieldmapEstimation(sources=<2 files>, method=<EstimatorType.PHASEDIFF: 3>,
bids_id='auto_00006'),
FieldmapEstimation(sources=<2 files>, method=<EstimatorType.PEPOLAR: 2>,
bids_id='auto_00007'),
FieldmapEstimation(sources=<2 files>, method=<EstimatorType.PEPOLAR: 2>,
bids_id='auto_00008')]
bids_id='auto_00006')]
Finally, *SDCFlows*' "*dataset A*" and "*dataset B*" contain BIDS structures
with zero-byte NIfTI files and some corresponding metadata:
Expand Down

0 comments on commit da4c183

Please sign in to comment.