DOC: transform.resize: document output dtype#7761
DOC: transform.resize: document output dtype#7761mdhaber wants to merge 3 commits intoscikit-image:mainfrom
Conversation
matthew-brett
left a comment
There was a problem hiding this comment.
Looks good. Suggestion for phrasing.
skimage/transform/_warps.py
Outdated
| Resized version of the input. | ||
| The dtype is ``float64`` with the following exceptions: | ||
|
|
||
| - ``order==0``: resized dtype is ``image.dtype``. |
There was a problem hiding this comment.
Maybe something to explain why the type is np.float64? Such as "resize uses interpolation. Unless this interpolation (order) is nearest neighbor (order==0), then the algorithm will generate new values by a sum of variously weighted nearby values, so generating floating point values as output. Accordingly, the output is generally float64 with the following exceptions:
And maybe adding the alternative of scipy.ndimage.zoom as in Stefan's suggestion? https://docs.scipy.org/doc/scipy-1.15.2/reference/generated/scipy.ndimage.zoom.html
There was a problem hiding this comment.
I concur but I would suggest including all this under a 'Notes' section (and refer to it in the 'Returns' section).
skimage/transform/_warps.py
Outdated
| Resized version of the input. | ||
| The dtype is ``float64`` with the following exceptions: | ||
|
|
||
| - ``order==0``: resized dtype is ``image.dtype``. |
There was a problem hiding this comment.
| - ``order==0``: resized dtype is ``image.dtype``. | |
| - When using `order=0`, output dtype is `image.dtype`. |
There was a problem hiding this comment.
I actually had something like that originally. I changed it for concision. Is there risk of confusion as written?
The backticks are correct as they are. See https://numpydoc.readthedocs.io/en/latest/format.html#common-rest-concepts.
There was a problem hiding this comment.
The backticks are correct as they are. See https://numpydoc.readthedocs.io/en/latest/format.html#common-rest-concepts.
Thanks for sharing this page, @mdhaber. My suggestion is based on: "When referring to a parameter anywhere within the docstring, enclose its name in single backticks" (from https://numpydoc.readthedocs.io/en/latest/format.html#parameters). We've been following this style guide lately, when updating docstrings.
Here, order and image are parameters, unlike float64 which I agree could/should render in monospaced font and, hence, be enclosed within double backticks.
There was a problem hiding this comment.
I actually had something like that originally. I changed it for concision. Is there risk of confusion as written?
@mdhaber I agree that concision is welcome under a 'Returns' section; my suggestion falls within a broader one about creating a 'Notes' section where, on the contrary, it's fine/good to be verbose.
There was a problem hiding this comment.
My suggestion is based on: "When referring to a parameter anywhere within the docstring, enclose its name in single backticks"
I see how that can still be misunderstood, but it intends to refer to just the name of the parameter, when it appears alone.
I am sure because I wrote the style guide's new recommendations regarding backticks (numpy/numpydoc#525). Do you think it needs to be clarified?
Through that and pydata/pydata-sphinx-theme#1852, I've been trying to move the ecosystem's docs to consistently render code in monospaced font so it is easy to distinguish from English. I proposed to change the recommendation to use double-backticks across the board, even for individual parameter names, but the intent is that someday all these individual parameter names will render as monospaced-font links to the parameter section of the docstring. Feel free to add a thumbs up to numpy/numpydoc#484 if you'd like to see that happen!
As for the rest, I can move it if you and Matthew agree.
There was a problem hiding this comment.
Moving is fine with me.
There was a problem hiding this comment.
I am sure because I wrote the style guide's new recommendations regarding backticks (numpy/numpydoc#525).
Oh, wonderful!! I'm glad I can ask you questions directly then. 😁 (Nice to meet you, @mdhaber!)
I see how that can still be misunderstood, but it intends to refer to just the name of the parameter, when it appears alone.
Aaaah!
Do you think it needs to be clarified?
I would say yes, since I was never sure. I would suggest appending "When referring to a parameter anywhere within the docstring, enclose its name in single backticks if and only if it appears alone."
Through that and pydata/pydata-sphinx-theme#1852, I've been trying to move the ecosystem's docs to consistently render code in monospaced font so it is easy to distinguish from English.
I admit that I never 'adhered' to the italic-like rendering of parameter names, since I already use/need this rendering to express emphasis in plain English. I once left a comment about this, somewhere in a PR in this repo. But I wanted to be obedient and consistent...
I proposed to change the recommendation to use double-backticks across the board, even for individual parameter names,
I would support this. Ouch, we started replacing double backticks which enclosed parameter names with single backticks (not systematically, just when running into them). Now there is a mix of conventions in our docstrings... 😬
but the intent is that someday all these individual parameter names will render as monospaced-font links to the parameter section of the docstring. Feel free to add a thumbs up to numpy/numpydoc#484 if you'd like to see that happen!
Nice! Done; incremented the 🚀 emoji.
skimage/transform/_warps.py
Outdated
| Resized version of the input. | ||
| The dtype is ``float64`` with the following exceptions: | ||
|
|
||
| - ``order==0``: resized dtype is ``image.dtype``. |
There was a problem hiding this comment.
I concur but I would suggest including all this under a 'Notes' section (and refer to it in the 'Returns' section).
|
Moved this to the Notes and referred to the Notes in the Returns section. Added explanation of why output dtype is floating point and changed exceptions to full sentences. Mentioned |
mkcor
left a comment
There was a problem hiding this comment.
Thanks for this nice improvement, @mdhaber!
Unrelated to this PR but, after reading the entire docstring, I wonder what "n-dimensional" really means in the context of channels, and whether that's the same as "N-dimensional" (mentioned earlier).
Co-authored-by: Marianne Corvellec <[email protected]>
|
Wait, @mdhaber did you intend to close this PR? It got two approvals so it was meant to get merged into |
|
Reopening – at least for now – so we don't eventually forget this due to its "closed" status. |
|
Apologies; I'm not familiar with scikit-image review policies. I didn't want to have this open any more, but at the same time, I didn't want to ask for any more maintainer time. Please feel free to leave it open for another few weeks. After that, I'll close again, but you're welcome to use the commits in a separate PR. I'd just rather not have this in my PR list for too long. Thanks! |
Description
Closes gh-7524
gh-7524 noted that the output dtype of
transform.resizeis not the same as the input dtype. This appears to be an intended feature, so perhaps the issue can be closed by documenting the output dtype. (Feel free to close if there is standard dtype behavior documented elsewhere.)I traced the code a bit, but ultimately determined the relationship between input and output dtype using this script. I varied some of the other parameters manually rather than looping over all possibilities. If you know of another exception, I'd be happy to add it, but I think the consequences of missing an obscure one are rather low.