Repository navigation
Mpl_normalize refactored and cleaned up - #19646
Iquecs2005 wants to merge 9 commits into
Conversation
|
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
neutrinoceros
left a comment
There was a problem hiding this comment.
Thank you !
I think this is going the right direction. Some high level comments for now. In particular I think we should test more than just isinstance calls.
|
I think this last commit should address most (if not all) of the feedbacks given. |
neutrinoceros
left a comment
There was a problem hiding this comment.
thanks. CI failures are caused by an annotation using a name that is undefined at runtime. I suggested a fix. I recommend paying attention to CI results so you don't need to wait for reviewers to find out that something's broken. I also recommend running the test suite locally before pushing so you get to find out even sooner. Preferably, we wouldn't push broken code into a PR, though it is still useful to do so if you're stuck and you need help deciphering errors.
please revert this. I don't want to set a precedent for this; we have a lot of import statements that could be made For reference, here's the tooling I'm refering to: |
|
Hi! |
|
Hi humans 👋 - this pull request hasn't had any new commits for approximately 5 months. I plan to close this in a month if the pull request doesn't have any new commits by then. In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. Maintainers may also choose to add keep-open label to keep this PR open but it is discouraged unless absolutely necessary. If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock. If you believe I commented on this pull request incorrectly, please report this here. |
|
Hi humans 👋 - this pull request hasn't had any new commits for approximately 5 months. I plan to close this in a month if the pull request doesn't have any new commits by then. In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. Maintainers may also choose to add keep-open label to keep this PR open but it is discouraged unless absolutely necessary. If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock. If you believe I commented on this pull request incorrectly, please report this here. |
8203800 to
deba5e8
Compare
|
since we lost the "keep open" label recently, and there wasn't any merge conflict, I took the liberty to rebase your branch to keep the stale bot off for a bit longer, hope you don't mind. I apologize for letting this PR drop at the bottom of my todo list, I'll try to help you get it to the finish line now ! |
|
FYI, I'm about to push a couple commits to address my own, previous reviews |
deba5e8 to
78f7411
Compare
78f7411 to
356c2b3
Compare
neutrinoceros
left a comment
There was a problem hiding this comment.
The only thing left for me to figure out is what, if anything, should I do with the new contributor bot
If you are confident that this PR is good to merge, you can ignore it. That check does not block merge. |
|
But I would feel better if visualization maintainers can approve first... @larrybradley or @astrofrog ? |
|
It's been a week without a response. Please @larrybradley or @astrofrog, let me know if you want to have another review or whether this could be merged with just my approval. Thanks ! |
larrybradley
left a comment
There was a problem hiding this comment.
Thanks for this, @Iquecs2005, and for sticking with it. This PR needs a few cleanups before it can be merged.
| @@ -0,0 +1 @@ | |||
| Created ``ImShowNormSimpleResult``, a class inheriting from ``NamedTuple``, and added it as the return type of ``imshow_norm`` and ``imshow_norm_simple``. | |||
There was a problem hiding this comment.
The class and function names here don't match the code (ImShowNormResults and imshow_simple_norm). Since tuple unpacking still works, it may also be worth saying that this is backward compatible.
| Created ``ImShowNormSimpleResult``, a class inheriting from ``NamedTuple``, and added it as the return type of ``imshow_norm`` and ``imshow_norm_simple``. | |
| ``imshow_norm`` and ``imshow_simple_norm`` now return an ``ImShowNormResults`` named tuple with ``image`` and ``norm`` fields. Unpacking the result as a 2-tuple still works. |
Also, since nothing breaks, feature might be a better category than api.
| image: "AxesImage" | ||
| """The `~matplotlib.image.AxesImage` instance generated by `~matplotlib.pyplot.imshow`.""" | ||
| norm: ImageNormalize | ||
| """The `ImageNormalize` instance generated by `SimpleNorm`.""" |
There was a problem hiding this comment.
For imshow_norm, the norm is an ImageNormalize built directly, not one generated by SimpleNorm.
| """The `ImageNormalize` instance generated by `SimpleNorm`.""" | |
| """The `ImageNormalize` instance used as the normalization.""" |
Also, these attribute docstrings are only picked up by Sphinx. At runtime, ImShowNormResults.norm.__doc__ is just "Alias for field number 1". A numpydoc Attributes section in the class docstring would cover both cases.
| fig = plt.figure() | ||
| ax = fig.add_subplot(1, 1, 1) | ||
| im, norm = imshow_norm(image, ax, origin='lower', | ||
| imNorm = imshow_norm(image, ax, origin='lower', |
There was a problem hiding this comment.
Small style point: astropy uses snake_case names, and after the rename the continuation lines no longer line up with the opening parenthesis. Something like result = imshow_norm(...) followed by fig.colorbar(result.image) would read more naturally. The same applies to the imshow_simple_norm example below.
| fig = plt.figure() | ||
| ax = fig.add_subplot(1, 1, 1) | ||
| im, norm = imshow_simple_norm(image, ax, origin='lower', | ||
| imNorm = imshow_simple_norm(image, ax, origin='lower', |
| "scipy-stubs>=1.14.1.6", | ||
| "narwhals>=1.42.0" # keep in sync with dependency-groups.dataframe | ||
| "narwhals>=1.42.0", # keep in sync with dependency-groups.dataframe | ||
| "matplotlib>=3.8.4" |
There was a problem hiding this comment.
Is this needed? mypy doesn't check astropy.visualization yet, the mypy tox env installs the test extras, and dev already gets matplotlib through astropy[recommended].
| imshow_kwargs: Mapping[str | Any] | None = None, | ||
| simple_norm_imshow_kwargs: Mapping[str | Any] | None = None, |
There was a problem hiding this comment.
Mapping takes a key type and a value type.
| imshow_kwargs: Mapping[str | Any] | None = None, | |
| simple_norm_imshow_kwargs: Mapping[str | Any] | None = None, | |
| imshow_kwargs: Mapping[str, Any] | None = None, | |
| simple_norm_imshow_kwargs: Mapping[str, Any] | None = None, |
| assert_array_equal( | ||
| ax.imshow(image, **imshow_kwargs).get_array(), | ||
| results.image.get_array(), | ||
| ) |
There was a problem hiding this comment.
I don't think this assertion can fail. AxesImage.get_array() returns the input data whatever norm is used. Maybe replace it with a check that the norm was actually applied?
assert results.image.norm is results.norm|
|
||
| if simple_norm_imshow_kwargs is None: | ||
| simple_norm_imshow_kwargs = {} | ||
| match stretch_spec := simple_norm_imshow_kwargs.get("stretch"): |
There was a problem hiding this comment.
Nit: the helper is shared by the imshow_norm and imshow_simple_norm tests, so check_imshow_simple_norm_results reads a bit oddly. Also, this match only handles "sinh". An expected_stretch argument checked with isinstance(results.norm.stretch, expected_stretch) would be simpler and work for any stretch.
Description
This pull request is to address the refactoring of mpl_normalize.py, mostly focused on the functions imshow_norm imshow_norm_simple. This pr changes the return of these two functions for a Named Tuple called
ImShowNormResults, declared in the same file, containing theAxesImageandImageNormalizeinstances. Not only that, but it also separates this function test cases in several other with more asserts.Fixes #19635