Statistical Methods
Check Transform Direction Before Resampling an Array
Define the task
A coordinate transform can describe where an input point moves or where an output point samples from. Confusing these directions reverses shifts and scales. Write the intended forward mapping with axis order, units and origin first. SciPy affine_transform performs pull resampling: it maps each output index back to a position in the input. It does not accept an arbitrary forward transform unchanged.
Carry out the check
Derive the inverse linear map and its offset together. For a forward relation y=F x+t, the pull relation is x=F⁻¹y−F⁻¹t when F is invertible. Check a known landmark, then specify output shape, interpolation order and boundary treatment. A valid coordinate calculation does not establish registration quality. Label arrays also need an interpolation choice that respects category meaning; keep that separate from the transform algebra.
Worked hypothetical example
Hypothetical one-dimensional example: the intended forward mapping is y=2x+3. Therefore output position y=7 must sample input x=(7−3)/2=2. The pull matrix is 0.5 and the offset is −1.5. Passing 2 and 3 instead would sample input 17 at output 7, a different transformation. Keep this hand calculation as a regression test and inspect output coverage for clipping or extrapolation.
Method checked 23 November 2026 against Primary method documentation: affine_transform.