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

DM-40525: Fix numpy invalid warnings with numpy 1.24 #827

Merged
merged 1 commit into from
Aug 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion python/lsst/pipe/tasks/hips.py
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,9 @@ def _write_hips_image(self, hips_base_path, order, pixel, image, png_mapping, sh

# And make a grayscale png as well

vals = 255 - png_mapping.map_intensity_to_uint8(image.array).astype(np.uint8)
with np.errstate(invalid="ignore"):
vals = 255 - png_mapping.map_intensity_to_uint8(image.array).astype(np.uint8)
Comment on lines +1155 to +1156
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking into the astropy code (which I contributed from our afw version), it has exactly this context manager, except it doesn't do the astype(uint8) cast (intentionally, per the docstring). It's unfortunate that we need to wrap it twice like this, but I guess it's fine (since the astropy method can't do the cast, due to how it's used internally).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, the unfortunate part is that the astropy wrap is unnecessary; or at least I couldn't figure out how to get a warning to trigger with just the clip. But maybe I wasn't giving it the "correct" inputs?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm... those lines go back to RHL's initial implementation circa 2016, so who knows:

https://github.com/lsst/afw/blame/d3e8bac1ddff3274abec121fc06602073268ac50/python/lsst/afw/display/rgb.py


vals[~np.isfinite(image.array) | (image.array < 0)] = 0
im = Image.fromarray(vals[::-1, :], "L")

Expand Down