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

BUG: fix crash in image normalization for RGBA image arrays #4094

Merged
merged 1 commit into from
Aug 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion yt/visualization/_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,11 @@ def get_norm(self, data: np.ndarray, *args, **kw) -> Normalize:
dvmax = 1 * getattr(data, "units", 1)
kw.setdefault("vmax", dvmax)

if self.norm_type is not None:
if data.ndim == 3:
assert data.shape[-1] == 4
# this is an RGBA array, only linear normalization makes sense here
norm_type = Normalize
Copy link
Member

Choose a reason for hiding this comment

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

If it's RGBA then I'm not sure I understand in what cases we'd want normalization. If it's not already scaled 0..1 or 0..255, then we need to apply that manually, and I don't think we want colorbars for that.

Copy link
Member Author

Choose a reason for hiding this comment

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

indeed, this is just the simplest patch to restore previous behaviour. Before merging #3849 we used to pass a Normalize object in _init_image, and MPL didn't complain, because it's what it uses by default.
A different approach would be to patch this in _init_image, though I have a strong preference for leaving this responsability entirely to the NormHandler class because it's its sole purpose. Does it make sense ? Maybe I can add a little more details in the comment here ?

elif self.norm_type is not None:
# this is a convenience mechanism for backward compat,
# allowing to toggle between lin and log scaling without detailed user input
norm_type = self.norm_type
Expand Down