-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Decorators for helping with the multichannel->channel_axis transition #5228
Conversation
Hello @grlee77! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2021-03-05 13:21:09 UTC |
…tion deprecate_multichannel_kwarg handles deprecation of the multichannel argument and conversion to the new channel_axis form channel_as_last_axis helps automatically move channels to the end for compatibility with existing code channels in the output will be restored back to their original position Apply the channel_axis change to montage and test with different channel axes
2c9babb
to
14ace98
Compare
skimage/util/tests/test_montage.py
Outdated
@@ -21,15 +21,16 @@ def test_montage_simple_gray(): | |||
assert_array_equal(arr_out, arr_ref) | |||
|
|||
|
|||
def test_montage_simple_rgb(): | |||
def test_montage_simple_rgb(channel_pos=-1): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure what channel_pos
is used for here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should not be there. I originally started modifying this test class, but later decided to leave this one using multichannel
and add a new test_montage_simple_rgb_channel_axes
test case instead to test the channel_axis
argument.
Thanks @grlee77 the approach looks sound to me. So
? |
silence whitespace errors E201, E202, E203 in test_*.py and colorconv.py where small arrays are defined using spacing favorable for reading by humans
Yes, this way we don't have to make solutions for every functions individually to support alternative channel positions. If there are cases where it makes sense to handle the channels in a different manner, then those functions can implement that internally and stop using the
Yes, If the input array is C-contiguous with channels as the first axis then after import numpy as np
a = np.ones((3, 256, 256))
a_reordered = np.moveaxis(a, 0, -1)
# overall array is now no longer C-contiguous
print(a_reordered.flags)
# but invidual channels are C-contiguous
print(a_reordered[..., 0].flags) Also |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @grlee77 the PR is ready as far as I'm concerned. @scikit-image/core we need another review please :-)
Looks good to me; I guess we'll know more once we start using this in practice. |
DOC: add channel_axis description to docstrings
I added a couple of additional functions to illustrate additional arguments for the
This PR now covers all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@grlee77 I've left a minor suggestion. It'd be great if the docstrings were PEP257 compliant (first line must be a one-liner), but it's in private classes so 🤷 I really don't mind. =)
Thanks @jni, I made the requested modifications. |
Thank you @grlee77! The failed checks appeared to be due to a stalled VM. |
This PR is related to #4294. It introduces two new decorators to help with the proposed transition from
multichannel
tochannel_axis
:1.)
deprecate_multichannel_kwarg
is a decorated based ondeprecate_kwarg
, but additionally takes care of converting values from:multichannel=False -> channel_axis=None
multichannel=True -> channel_axis=(-1,)
2.)
channel_as_last_axis
can be used to help automate shuffling of axes to/from the last position. This will not be needed for functdions capable of handling arbitrary channel positions, but is a quick way to adapt many existing functions that all assume channels correspond to the last axis.For now I just applied these to the existing
montage
function as a concrete example. I want to get initial feedback before extending the approach further. Right now only a single channel axis is supported, but thechannel_as_last_axis
decorator could also be adapted to handle more general cases.