Skip to content

RF: Move reorientation into image classes #544

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

Merged
merged 9 commits into from
Jun 28, 2017

Conversation

effigies
Copy link
Member

#526 seems to have stalled. I'd like to incorporate these changes, as well as those discussed by @matthew-brett and myself.

On renaming transpose to as_oriented, while I agree that distinguishing from np.transpose may be desirable, I disagree that this would be a more appropriate name. That is, the ornt matrix doesn't describe an orientation, but a transformation. I would expect as_oriented to be idempotent for a given orientation, which it is not. With ornt = [[0, -1], [2, 1], [1, 1]], I could flip back and forth between RAS and LSA all day long.

I also moved the identity transform check into transpose, and let Nifti1Pair.transpose call SpatialImage.transpose, which I think helps clarify which parts of the operation are specific to NIfTIs.

Closes #526.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.009%) to 96.227% when pulling 84bda4b on effigies:improve_as_closest_canonical into acfd925 on nipy:master.

@codecov-io
Copy link

codecov-io commented Jun 22, 2017

Codecov Report

Merging #544 into master will increase coverage by 0.01%.
The diff coverage is 97.95%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #544      +/-   ##
==========================================
+ Coverage   94.26%   94.27%   +0.01%     
==========================================
  Files         177      177              
  Lines       24300    24333      +33     
  Branches     2608     2610       +2     
==========================================
+ Hits        22906    22941      +35     
+ Misses        919      918       -1     
+ Partials      475      474       -1
Impacted Files Coverage Δ
nibabel/tests/test_funcs.py 100% <100%> (ø) ⬆️
nibabel/funcs.py 80.55% <100%> (+0.06%) ⬆️
nibabel/spatialimages.py 96.05% <100%> (+0.19%) ⬆️
nibabel/nifti1.py 91.13% <91.66%> (+0.15%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update acfd925...e6de59d. Read the comment docs.

@effigies effigies requested a review from matthew-brett June 28, 2017 14:27
@effigies
Copy link
Member Author

Can't request a review, but @markhymers, if you have any feedback, please jump in.

Copy link
Member

@matthew-brett matthew-brett left a comment

Choose a reason for hiding this comment

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

Looks good in general, but the name transpose still makes me suffer. It is not only that this transpose has a different meaning from np.transpose, but also that the transformation can also be an axis flip. Can you think of anything better than the current options?

def transpose(self, ornt):
"""Apply an orientation change and return a new image

If image already has orientation, return the original image, unchanged
Copy link
Member

Choose a reason for hiding this comment

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

I guess you mean, if ornt is the identity?

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right. I wrote that bit while I thought ornt was the target orientation, not the transformation.

def transpose(self, ornt):
"""Apply an orientation change and return a new image

If image already has orientation, return the original image, unchanged
Copy link
Member

Choose a reason for hiding this comment

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

See comment above.

@effigies
Copy link
Member Author

I agree transpose isn't great. What about reorient?

@effigies effigies force-pushed the improve_as_closest_canonical branch from 6448853 to 7e8c4b8 Compare June 28, 2017 15:22
@matthew-brett
Copy link
Member

How do you feel about as_reoriented?

@effigies
Copy link
Member Author

Fine by me.

@matthew-brett
Copy link
Member

Then fine by me too. Merge when tests pass?

@effigies effigies force-pushed the improve_as_closest_canonical branch from 7e8c4b8 to 99a7e85 Compare June 28, 2017 15:27
@effigies
Copy link
Member Author

Sounds good. I'll add a changelog entry, as well.

markhymers and others added 9 commits June 28, 2017 11:32
This avoids make failing to cause a rebuild when files are changed

Signed-off-by: Mark Hymers <mark.hymers@ynic.york.ac.uk>
At present, we leave misleading information in dim_info when
using as_closest_canonical.  This patch makes us update the
information based on our axis re-ordering and adds tests that
it has been done.

Signed-off-by: Mark Hymers <mark.hymers@ynic.york.ac.uk>
Use of the set_dim_info function showed up a FutureWarning error in
python3.   python3 now really dislikes comparing to None using ==,
which is what "in" does.  Work around this to silence the warning.

Signed-off-by: Mark Hymers <mark.hymers@ynic.york.ac.uk>
Signed-off-by: Mark Hymers <mark.hymers@ynic.york.ac.uk>
As per Matthew's comments, place the logic which re-orients
the data into a function in SpatialImage and override this
in Nifti1Pair with a version which updates dim_info.

Also add new test cases using AnalyzeImage so that we
cover both possibilities.

Signed-off-by: Mark Hymers <mark.hymers@ynic.york.ac.uk>
Signed-off-by: Mark Hymers <mark.hymers@ynic.york.ac.uk>
Return original image if no transform is to be made
@effigies effigies force-pushed the improve_as_closest_canonical branch from 70a7994 to e6de59d Compare June 28, 2017 15:33
@coveralls
Copy link

Coverage Status

Coverage increased (+0.009%) to 96.227% when pulling e6de59d on effigies:improve_as_closest_canonical into acfd925 on nipy:master.

@effigies effigies merged commit c6e06d9 into nipy:master Jun 28, 2017
@effigies effigies deleted the improve_as_closest_canonical branch June 28, 2017 19:29
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.

5 participants