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

Update voxel / world method #28

Merged
merged 6 commits into from
Sep 7, 2023
Merged

Update voxel / world method #28

merged 6 commits into from
Sep 7, 2023

Conversation

kaitj
Copy link
Contributor

@kaitj kaitj commented Aug 30, 2023

Proposed changes
This updates the methods for transforming from world-to-voxel coordinates and also adds in method for voxel-to-world coordinates. Also updates to return either an AfidPosition or AfidVoxel as needed instead of a numpy array of values. This still retains using of NumPy, which is helpful for manipulating matrices.

I debated adding this as a method of either the AfidPosition or AfidVoxel class, but opted against it for now. Open for discussion on this though.

Types of changes
What types of changes does your code introduce? Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Other (if none of the other choices apply)

Checklist
Put an x in the boxes that apply. You can also fill these out after creating the PR. If you are unsure about any of the choices, don't hesitate to ask!

  • Changes have been tested to ensure that fix is effective or that a feature works.
  • Changes pass the unit tests
  • Code has been run through the poe quality task
  • I have included necessary documentation or comments (as necessary)
  • Any dependent changes have been merged and published

Notes
All PRs will undergo the unit testing before being reviewed. You may be requested to explain or make additional changes before the PR is accepted.

@kaitj kaitj added the enhancement New feature or request label Aug 30, 2023
@github-actions github-actions bot requested a review from tkkuehn August 30, 2023 18:33
@kaitj kaitj linked an issue Aug 30, 2023 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Aug 30, 2023

Codecov Report

Merging #28 (9005dc3) into main (8f2b03f) will not change coverage.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #28   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            8         8           
  Lines          440       503   +63     
=========================================
+ Hits           440       503   +63     
Components Coverage Δ
afids_utils/afids.py ∅ <ø> (∅)
afids_utils/ext 100.00% <ø> (ø)
afids_utils/transforms.py 100.00% <100.00%> (ø)

@tkkuehn
Copy link
Contributor

tkkuehn commented Aug 31, 2023

Starting to review this but needs a merge from main

Copy link
Contributor

@tkkuehn tkkuehn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fundamentally looks good to me, just one suggested test if you have the inclination to figure it out

world_to_voxel(voxel_coord, nii_affine)


class TestAfidVoxel2World:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to add a round-trip test that confirms that going back and forth yields a value close to the original (I think numpy has some method for "floats approximately equal"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some tests for this, though really had to loosen the approximation for the world_to_voxel round trip tests to pass. I think this is a combination of the rounding errors and also a lack of constraints on the affine matrix.

- renamed valid_coords() -> valid_position_coords()
- added strategy for generating valid_voxel_coords()
- constrained coords to be about 90mm (in either direction) or 200
  voxels
- added strategy for generating afid_voxels
- removed obsolete world_coords strategy (replaced by afid_positions)
@kaitj
Copy link
Contributor Author

kaitj commented Sep 2, 2023

Note to self to check transformation methods (can refer to nibabel docs)

Note: `world_to_voxel` round trip required very loose approximation, due
to lack of constraints in generated transformation and rounding errors
@kaitj kaitj merged commit 59d8c76 into afids:main Sep 7, 2023
7 checks passed
@kaitj kaitj deleted the maint/world_voxel branch September 7, 2023 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ENH] Handling transformations
2 participants