Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Reverse transform order for multi-step #430

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mgxd
Copy link
Collaborator

@mgxd mgxd commented Jan 17, 2025

Fixes #429

Alter the order when loading a composite transform that includes 2 composite transforms, like is generated if using --multi-step-reg. This is required when mapping from the target space to the source voxels.

# Retrieve the RAS coordinates of the target space
coordinates = nt.base.SpatialReference.factory(target).ndcoords.astype('f4').T
# We will operate in voxel space, so get the source affine
vox2ras = source.affine
ras2vox = np.linalg.inv(vox2ras)
# Transform RAS2RAS head motion transforms to VOX2VOX
hmc_xfms = [ras2vox @ xfm.matrix @ vox2ras for xfm in hmc]
# After removing the head-motion transforms, add a mapping from boldref
# world space to voxels. This new transform maps from world coordinates
# in the target space to voxel coordinates in the source space.
ref2vox = nt.TransformChain(transform_list + [nt.Affine(ras2vox)])
mapped_coordinates = ref2vox.map(coordinates)

It's not clear to me if this is something that needs to be accounted for in nitransforms, or if we should handle this unorthodox case internally here - would love hear any thoughts

@mgxd mgxd requested review from effigies and oesteban January 17, 2025 17:41
Copy link

codecov bot commented Jan 17, 2025

Codecov Report

Attention: Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.

Project coverage is 56.12%. Comparing base (6599e40) to head (1e5083a).

Files with missing lines Patch % Lines
nibabies/utils/transforms.py 71.42% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #430      +/-   ##
==========================================
+ Coverage   56.11%   56.12%   +0.01%     
==========================================
  Files          70       70              
  Lines        6690     6697       +7     
  Branches      832      834       +2     
==========================================
+ Hits         3754     3759       +5     
- Misses       2732     2734       +2     
  Partials      204      204              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error running new unstable version of NiBabies
1 participant