From da4c183e799690da49ef30a1aaee7918bb649f55 Mon Sep 17 00:00:00 2001 From: Oscar Esteban Date: Fri, 11 Aug 2023 16:03:13 +0200 Subject: [PATCH] enh: disable head-motion transforms consideration --- sdcflows/transform.py | 36 +++++++++++++++++++++++++----------- sdcflows/utils/wrangler.py | 6 +----- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/sdcflows/transform.py b/sdcflows/transform.py index 89aced4f73..a4f79092ea 100644 --- a/sdcflows/transform.py +++ b/sdcflows/transform.py @@ -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) @@ -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( @@ -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) @@ -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( diff --git a/sdcflows/utils/wrangler.py b/sdcflows/utils/wrangler.py index 4ec346b372..953a9cb776 100644 --- a/sdcflows/utils/wrangler.py +++ b/sdcflows/utils/wrangler.py @@ -131,11 +131,7 @@ def find_estimators( ... subject="101006", ... ) # doctest: +ELLIPSIS [FieldmapEstimation(sources=<2 files>, method=, - bids_id='auto_00006'), - FieldmapEstimation(sources=<2 files>, method=, - bids_id='auto_00007'), - FieldmapEstimation(sources=<2 files>, method=, - 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: