From bcc7d3e2c3bcf8635febafdf97ce5727d67b2cec Mon Sep 17 00:00:00 2001 From: mathiasg Date: Wed, 5 Jun 2024 15:08:05 -0400 Subject: [PATCH] FIX: Catch cases of unexpected resampling --- fmriprep/utils/transforms.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fmriprep/utils/transforms.py b/fmriprep/utils/transforms.py index 23105efa..8937f5b2 100644 --- a/fmriprep/utils/transforms.py +++ b/fmriprep/utils/transforms.py @@ -71,6 +71,16 @@ def load_ants_h5(filename: Path) -> nt.base.TransformBase: fixed_params = transform2['TransformFixedParameters'][:] + spacing = fixed_params[6:9] + direction = fixed_params[9:] + + # Supported spacing + if not np.array_equal(spacing, np.array([1.0, 1.0, 1.0])): + raise ValueError(f'Unexpected spacing: {spacing}') + + if not np.array_equal(direction, np.diag([-1, -1, -1])): + raise ValueError(f'Asymmetric direction matrix: {direction}') + shape = tuple(fixed_params[:3].astype(int)) # ITK stores warps in Fortran-order, where the vector components change fastest # Nitransforms expects 3 volumes, not a volume of three-vectors, so transpose